]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Store Refund - Add more disable scenerios & time to disable refund. (#34671)
authorkeronshb <54602815+keronshb@users.noreply.github.com>
Sat, 15 Feb 2025 16:17:29 +0000 (11:17 -0500)
committerGitHub <noreply@github.com>
Sat, 15 Feb 2025 16:17:29 +0000 (17:17 +0100)
* 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>
Content.Server/Store/StoreRefundComponent.cs
Content.Server/Store/Systems/StoreSystem.Refund.cs
Content.Server/Store/Systems/StoreSystem.Ui.cs
Content.Server/Store/Systems/StoreSystem.cs

index 1a6b17c5eade4389601b1641113761c4b50a96c7..df35afdf53f8bc20d918c2dce28d5e58456ca3c9 100644 (file)
@@ -2,12 +2,31 @@
 
 namespace Content.Server.Store.Components;
 
+// TODO: Refund on a per-item/action level.
+//   Requires a refund button next to each purchase (disabled/invis by default)
+//   Interactions with ActionUpgrades would need to be modified to reset all upgrade progress and return the original action purchase to the store.
+
 /// <summary>
 ///     Keeps track of entities bought from stores for refunds, especially useful if entities get deleted before they can be refunded.
 /// </summary>
 [RegisterComponent, Access(typeof(StoreSystem))]
 public sealed partial class StoreRefundComponent : Component
 {
-    [ViewVariables, DataField]
+    /// <summary>
+    ///     The store this entity was bought from
+    /// </summary>
+    [DataField]
     public EntityUid? StoreEntity;
+
+    /// <summary>
+    ///     The time this entity was bought
+    /// </summary>
+    [DataField]
+    public TimeSpan? BoughtTime;
+
+    /// <summary>
+    ///     How long until this entity disables refund purchase?
+    /// </summary>
+    [DataField]
+    public TimeSpan DisableTime = TimeSpan.FromSeconds(300);
 }
index 04bd585ffcf75e8824fdca064c65858e99d2ad32..e9d801f9e17fb72c0e2c7428d08fedfcd91eb0f1 100644 (file)
@@ -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;
+        CheckDisableRefund(ent);
+    }
 
-        DisableRefund(component.StoreEntity.Value, storeComp);
+    private void OnEntityInserted(Entity<StoreRefundComponent> ent, ref EntInsertedIntoContainerMessage args)
+    {
+        CheckDisableRefund(ent);
     }
 
-    private void OnEntityInserted(EntityUid uid, StoreRefundComponent component, EntInsertedIntoContainerMessage args)
+    private void OnActionPerformed(Entity<StoreRefundComponent> ent, ref ActionPerformedEvent args)
     {
-        if (component.StoreEntity == null || _actions.TryGetActionData(uid, out _) || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp))
+        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);
+    }
 }
index 5af6ce1c975ce3275351d267c98ec8189eefff2b..3f4ccf696dff8d34dee13feb978f52c3d7ac192b 100644 (file)
@@ -164,7 +164,7 @@ public sealed partial class StoreSystem
         }
 
         if (!IsOnStartingMap(uid, component))
-            component.RefundAllowed = false;
+            DisableRefund(uid, component);
 
         //subtract the cash
         foreach (var (currency, amount) in cost)
@@ -332,7 +332,7 @@ public sealed partial class StoreSystem
 
         if (!IsOnStartingMap(uid, component))
         {
-            component.RefundAllowed = false;
+            DisableRefund(uid, component);
             UpdateUserInterface(buyer, uid, component);
         }
 
@@ -376,6 +376,7 @@ public sealed partial class StoreSystem
         component.BoughtEntities.Add(purchase);
         var refundComp = EnsureComp<StoreRefundComponent>(purchase);
         refundComp.StoreEntity = uid;
+        refundComp.BoughtTime = _timing.CurTime;
     }
 
     private bool IsOnStartingMap(EntityUid store, StoreComponent component)
index a57895364dcc5fb6a97af4cfa0410d7510acced6..0625ced08769aabcf74c050849e6167ed3926728 100644 (file)
@@ -10,6 +10,7 @@ using JetBrains.Annotations;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Utility;
 using System.Linq;
+using Robust.Shared.Timing;
 using Content.Shared.Mind;
 
 namespace Content.Server.Store.Systems;
@@ -22,6 +23,7 @@ public sealed partial class StoreSystem : EntitySystem
 {
     [Dependency] private readonly IPrototypeManager _proto = default!;
     [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
 
     public override void Initialize()
     {