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:
keronshb
2025-02-15 11:17:29 -05:00
committed by GitHub
parent 71b5133a53
commit 0cb11241d7
4 changed files with 68 additions and 11 deletions

View File

@@ -2,12 +2,31 @@
namespace Content.Server.Store.Components; 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> /// <summary>
/// Keeps track of entities bought from stores for refunds, especially useful if entities get deleted before they can be refunded. /// Keeps track of entities bought from stores for refunds, especially useful if entities get deleted before they can be refunded.
/// </summary> /// </summary>
[RegisterComponent, Access(typeof(StoreSystem))] [RegisterComponent, Access(typeof(StoreSystem))]
public sealed partial class StoreRefundComponent : Component public sealed partial class StoreRefundComponent : Component
{ {
[ViewVariables, DataField] /// <summary>
/// The store this entity was bought from
/// </summary>
[DataField]
public EntityUid? StoreEntity; 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);
} }

View File

@@ -1,5 +1,8 @@
using Content.Server.Store.Components; using Content.Server.Store.Components;
using Content.Shared.Actions.Events;
using Content.Shared.Interaction.Events;
using Content.Shared.Store.Components; using Content.Shared.Store.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Containers; using Robust.Shared.Containers;
namespace Content.Server.Store.Systems; namespace Content.Server.Store.Systems;
@@ -12,22 +15,39 @@ public sealed partial class StoreSystem
SubscribeLocalEvent<StoreRefundComponent, EntityTerminatingEvent>(OnRefundTerminating); SubscribeLocalEvent<StoreRefundComponent, EntityTerminatingEvent>(OnRefundTerminating);
SubscribeLocalEvent<StoreRefundComponent, EntRemovedFromContainerMessage>(OnEntityRemoved); SubscribeLocalEvent<StoreRefundComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
SubscribeLocalEvent<StoreRefundComponent, EntInsertedIntoContainerMessage>(OnEntityInserted); 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)) CheckDisableRefund(ent);
return;
DisableRefund(component.StoreEntity.Value, storeComp);
} }
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; return;
DisableRefund(component.StoreEntity.Value, storeComp); CheckDisableRefund(ent);
} }
private void OnStoreTerminating(Entity<StoreComponent> ent, ref EntityTerminatingEvent args) private void OnStoreTerminating(Entity<StoreComponent> ent, ref EntityTerminatingEvent args)
@@ -52,4 +72,19 @@ public sealed partial class StoreSystem
var ev = new RefundEntityDeletedEvent(ent); var ev = new RefundEntityDeletedEvent(ent);
RaiseLocalEvent(ent.Comp.StoreEntity.Value, ref ev); 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);
}
} }

View File

@@ -164,7 +164,7 @@ public sealed partial class StoreSystem
} }
if (!IsOnStartingMap(uid, component)) if (!IsOnStartingMap(uid, component))
component.RefundAllowed = false; DisableRefund(uid, component);
//subtract the cash //subtract the cash
foreach (var (currency, amount) in cost) foreach (var (currency, amount) in cost)
@@ -332,7 +332,7 @@ public sealed partial class StoreSystem
if (!IsOnStartingMap(uid, component)) if (!IsOnStartingMap(uid, component))
{ {
component.RefundAllowed = false; DisableRefund(uid, component);
UpdateUserInterface(buyer, uid, component); UpdateUserInterface(buyer, uid, component);
} }
@@ -376,6 +376,7 @@ public sealed partial class StoreSystem
component.BoughtEntities.Add(purchase); component.BoughtEntities.Add(purchase);
var refundComp = EnsureComp<StoreRefundComponent>(purchase); var refundComp = EnsureComp<StoreRefundComponent>(purchase);
refundComp.StoreEntity = uid; refundComp.StoreEntity = uid;
refundComp.BoughtTime = _timing.CurTime;
} }
private bool IsOnStartingMap(EntityUid store, StoreComponent component) private bool IsOnStartingMap(EntityUid store, StoreComponent component)

View File

@@ -10,6 +10,7 @@ using JetBrains.Annotations;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using System.Linq; using System.Linq;
using Robust.Shared.Timing;
using Content.Shared.Mind; using Content.Shared.Mind;
namespace Content.Server.Store.Systems; namespace Content.Server.Store.Systems;
@@ -22,6 +23,7 @@ public sealed partial class StoreSystem : EntitySystem
{ {
[Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize() public override void Initialize()
{ {