Files
tbd-station-14/Content.Server/Store/Systems/StoreSystem.Refund.cs
keronshb 0cb11241d7 Store Refund - Add more disable scenerios & time to disable refund. (#34671)
* Puts disable refund logic into a helper method. Removes action check. Disables refund on action use.

* Adds check if refund is disabled for the store already

* Adds a way to disable refunds based on time

* Checks if the ent is on the starting map and the end time is below the current time before disabling refund

* Replaces instances of component.RefundAllowed = false with DisableRefund for more consistency and easier tracking

* Adds methods to handle inhand and shooting events

* Removes gamestates

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
2025-02-15 17:17:29 +01:00

91 lines
3.1 KiB
C#

using Content.Server.Store.Components;
using Content.Shared.Actions.Events;
using Content.Shared.Interaction.Events;
using Content.Shared.Store.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Containers;
namespace Content.Server.Store.Systems;
public sealed partial class StoreSystem
{
private void InitializeRefund()
{
SubscribeLocalEvent<StoreComponent, EntityTerminatingEvent>(OnStoreTerminating);
SubscribeLocalEvent<StoreRefundComponent, EntityTerminatingEvent>(OnRefundTerminating);
SubscribeLocalEvent<StoreRefundComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
SubscribeLocalEvent<StoreRefundComponent, EntInsertedIntoContainerMessage>(OnEntityInserted);
SubscribeLocalEvent<StoreRefundComponent, ActionPerformedEvent>(OnActionPerformed);
SubscribeLocalEvent<StoreRefundComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<StoreRefundComponent, AttemptShootEvent>(OnShootAttempt);
// TODO: Handle guardian refund disabling when guardians support refunds.
}
private void OnEntityRemoved(Entity<StoreRefundComponent> ent, ref EntRemovedFromContainerMessage args)
{
CheckDisableRefund(ent);
}
private void OnEntityInserted(Entity<StoreRefundComponent> ent, ref EntInsertedIntoContainerMessage args)
{
CheckDisableRefund(ent);
}
private void OnActionPerformed(Entity<StoreRefundComponent> ent, ref ActionPerformedEvent args)
{
CheckDisableRefund(ent);
}
private void OnUseInHand(Entity<StoreRefundComponent> ent, ref UseInHandEvent args)
{
args.Handled = true;
CheckDisableRefund(ent);
}
private void OnShootAttempt(Entity<StoreRefundComponent> ent, ref AttemptShootEvent args)
{
if (args.Cancelled)
return;
CheckDisableRefund(ent);
}
private void OnStoreTerminating(Entity<StoreComponent> ent, ref EntityTerminatingEvent args)
{
if (ent.Comp.BoughtEntities.Count <= 0)
return;
foreach (var boughtEnt in ent.Comp.BoughtEntities)
{
if (!TryComp<StoreRefundComponent>(boughtEnt, out var refundComp))
continue;
refundComp.StoreEntity = null;
}
}
private void OnRefundTerminating(Entity<StoreRefundComponent> ent, ref EntityTerminatingEvent args)
{
if (ent.Comp.StoreEntity == null)
return;
var ev = new RefundEntityDeletedEvent(ent);
RaiseLocalEvent(ent.Comp.StoreEntity.Value, ref ev);
}
private void CheckDisableRefund(Entity<StoreRefundComponent> ent)
{
var component = ent.Comp;
if (component.StoreEntity == null || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp) || !storeComp.RefundAllowed)
return;
var endTime = component.BoughtTime + component.DisableTime;
if (IsOnStartingMap(component.StoreEntity.Value, storeComp) && _timing.CurTime < endTime)
return;
DisableRefund(component.StoreEntity.Value, storeComp);
}
}