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>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
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;
|
||||
@@ -12,22 +15,39 @@ public sealed partial class StoreSystem
|
||||
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(EntityUid uid, StoreRefundComponent component, EntRemovedFromContainerMessage args)
|
||||
private void OnEntityRemoved(Entity<StoreRefundComponent> ent, ref EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (component.StoreEntity == null || _actions.TryGetActionData(uid, out _, false) || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp))
|
||||
return;
|
||||
|
||||
DisableRefund(component.StoreEntity.Value, storeComp);
|
||||
CheckDisableRefund(ent);
|
||||
}
|
||||
|
||||
private void OnEntityInserted(EntityUid uid, StoreRefundComponent component, EntInsertedIntoContainerMessage args)
|
||||
private void OnEntityInserted(Entity<StoreRefundComponent> ent, ref EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (component.StoreEntity == null || _actions.TryGetActionData(uid, out _) || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp))
|
||||
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;
|
||||
|
||||
DisableRefund(component.StoreEntity.Value, storeComp);
|
||||
CheckDisableRefund(ent);
|
||||
}
|
||||
|
||||
private void OnStoreTerminating(Entity<StoreComponent> ent, ref EntityTerminatingEvent args)
|
||||
@@ -52,4 +72,19 @@ public sealed partial class StoreSystem
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user