Adds a refund button & action upgrades for stores (#24518)

* adds refunds to stores

* Adds method to check for starting map

* comments, datafields, some requested changes

* turns event into ref event

* Adds datafields

* Switches to entity terminating event

* Changes store entity to be nullable and checks if store is terminating to remove reference.

* Tryadd instead of containskey

* Adds a refund disable method, disables refund on bought ent container changes if not an action

* Removes datafield specification

* Readds missing using statement

* Removes unused using statements

* What the heck is listing data

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
keronshb
2024-02-03 19:48:51 -05:00
committed by GitHub
parent c15b0691ec
commit 257909fd97
10 changed files with 318 additions and 6 deletions

View File

@@ -0,0 +1,56 @@
using Content.Server.Actions;
using Content.Server.Store.Components;
using Content.Shared.Actions;
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);
}
private void OnEntityRemoved(EntityUid uid, StoreRefundComponent component, EntRemovedFromContainerMessage args)
{
if (component.StoreEntity == null || _actions.TryGetActionData(uid, out _) || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp))
return;
DisableRefund(component.StoreEntity.Value, storeComp);
}
private void OnEntityInserted(EntityUid uid, StoreRefundComponent component, EntInsertedIntoContainerMessage args)
{
if (component.StoreEntity == null || _actions.TryGetActionData(uid, out _) || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp))
return;
DisableRefund(component.StoreEntity.Value, storeComp);
}
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);
}
}