diff --git a/Content.Shared/Stacks/SharedStackComponent.cs b/Content.Shared/Stacks/SharedStackComponent.cs index c9c0b8c300..06fc58cf78 100644 --- a/Content.Shared/Stacks/SharedStackComponent.cs +++ b/Content.Shared/Stacks/SharedStackComponent.cs @@ -14,9 +14,6 @@ namespace Content.Shared.Stacks public sealed override string Name => "Stack"; public sealed override uint? NetID => ContentNetIDs.STACK; - [DataField("max")] - private int _maxCount = 30; - [ViewVariables(VVAccess.ReadWrite)] [DataField("stackType", required:true, customTypeSerializer:typeof(PrototypeIdSerializer))] public string StackTypeId { get; private set; } = string.Empty; @@ -29,19 +26,12 @@ namespace Content.Shared.Stacks [DataField("count")] public int Count { get; set; } = 30; - [ViewVariables] - public int MaxCount - { - get => _maxCount; - private set - { - if (_maxCount == value) - return; - - _maxCount = value; - Dirty(); - } - } + /// + /// Max amount of things that can be in the stack. + /// + [ViewVariables(VVAccess.ReadOnly)] + [DataField("max")] + public int MaxCount { get; set; } = 30; [ViewVariables] public int AvailableSpace => MaxCount - Count; @@ -50,29 +40,18 @@ namespace Content.Shared.Stacks { return new StackComponentState(Count, MaxCount); } + } - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) + [Serializable, NetSerializable] + public sealed class StackComponentState : ComponentState + { + public int Count { get; } + public int MaxCount { get; } + + public StackComponentState(int count, int maxCount) : base(ContentNetIDs.STACK) { - if (curState is not StackComponentState cast) - return; - - // This will change the count and call events. - EntitySystem.Get().SetCount(Owner.Uid, this, cast.Count); - MaxCount = cast.MaxCount; - } - - - [Serializable, NetSerializable] - private sealed class StackComponentState : ComponentState - { - public int Count { get; } - public int MaxCount { get; } - - public StackComponentState(int count, int maxCount) : base(ContentNetIDs.STACK) - { - Count = count; - MaxCount = maxCount; - } + Count = count; + MaxCount = maxCount; } } } diff --git a/Content.Shared/Stacks/SharedStackSystem.cs b/Content.Shared/Stacks/SharedStackSystem.cs index 9c62543d42..a9a74547fd 100644 --- a/Content.Shared/Stacks/SharedStackSystem.cs +++ b/Content.Shared/Stacks/SharedStackSystem.cs @@ -1,6 +1,7 @@ using Content.Shared.Examine; using JetBrains.Annotations; using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; using Robust.Shared.Localization; namespace Content.Shared.Stacks @@ -12,6 +13,7 @@ namespace Content.Shared.Stacks { base.Initialize(); + SubscribeLocalEvent(OnStackHandleState); SubscribeLocalEvent(OnStackStarted); SubscribeLocalEvent(OnStackExamined); } @@ -60,6 +62,16 @@ namespace Content.Shared.Stacks RaiseLocalEvent(uid, new StackCountChangedEvent(old, component.Count)); } + private void OnStackHandleState(EntityUid uid, SharedStackComponent component, ComponentHandleState args) + { + if (args.Current is not StackComponentState cast) + return; + + // This will change the count and call events. + SetCount(uid, component, cast.Count); + component.MaxCount = cast.MaxCount; + } + private void OnStackExamined(EntityUid uid, SharedStackComponent component, ExaminedEvent args) { if (!args.IsInDetailsRange)