From 1ec2f3929165df65b6545f2d46643dbfc41ccdec Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Sun, 30 May 2021 08:53:02 +0200 Subject: [PATCH] Fix some things setting StackComponent count manually. --- .../Construction/Completions/SetStackCount.cs | 10 +++------- .../Construction/Completions/SpawnPrototype.cs | 7 +++---- .../Construction/WelderRefinableComponent.cs | 7 +++++-- .../Thresholds/Behaviors/SpawnEntitiesBehavior.cs | 4 ++-- .../GameObjects/Components/Power/WireComponent.cs | 6 ++++-- Resources/Changelog/Parts/stacks.yml | 4 ++++ 6 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 Resources/Changelog/Parts/stacks.yml diff --git a/Content.Server/Construction/Completions/SetStackCount.cs b/Content.Server/Construction/Completions/SetStackCount.cs index 87c001f18c..36d730a9f4 100644 --- a/Content.Server/Construction/Completions/SetStackCount.cs +++ b/Content.Server/Construction/Completions/SetStackCount.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Stack; using Content.Shared.Construction; +using Content.Shared.GameObjects.EntitySystems; using JetBrains.Annotations; using Robust.Shared.GameObjects; using Robust.Shared.Log; @@ -19,14 +20,9 @@ namespace Content.Server.Construction.Completions public async Task PerformAction(IEntity entity, IEntity? user) { if (entity.Deleted) return; - if(!entity.TryGetComponent(out StackComponent? stackComponent)) return; + if(!entity.HasComponent()) return; - stackComponent.Count = Math.Min(stackComponent.MaxCount, Amount); - - if (Amount > stackComponent.MaxCount) - { - Logger.Warning("StackCount is bigger than maximum stack capacity, for entity " + entity.Name); - } + entity.EntityManager.EventBus.RaiseLocalEvent(entity.Uid, new StackChangeCountEvent(Amount), false); } } } diff --git a/Content.Server/Construction/Completions/SpawnPrototype.cs b/Content.Server/Construction/Completions/SpawnPrototype.cs index bf0a1d020b..ce8864c50c 100644 --- a/Content.Server/Construction/Completions/SpawnPrototype.cs +++ b/Content.Server/Construction/Completions/SpawnPrototype.cs @@ -3,6 +3,7 @@ using System; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Stack; using Content.Shared.Construction; +using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Utility; using JetBrains.Annotations; using Robust.Shared.GameObjects; @@ -27,10 +28,8 @@ namespace Content.Server.Construction.Completions if (EntityPrototypeHelpers.HasComponent(Prototype)) { - var _entity = entityManager.SpawnEntity(Prototype, coordinates); - StackComponent stackComponent = _entity.GetComponent(); - - stackComponent.Count = Math.Min(stackComponent.MaxCount, Amount); + var stack = entityManager.SpawnEntity(Prototype, coordinates); + stack.EntityManager.EventBus.RaiseLocalEvent(stack.Uid, new StackChangeCountEvent(Amount), false); } else { diff --git a/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs b/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs index a73bb19907..8d2ab518ce 100644 --- a/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/WelderRefinableComponent.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Stack; using Content.Shared.GameObjects.Components.Interactable; +using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Prototypes; @@ -58,8 +59,10 @@ namespace Content.Server.GameObjects.Components.Construction { var droppedEnt = Owner.EntityManager.SpawnEntity(result, resultPosition); - if (droppedEnt.TryGetComponent(out var stackComp)) - stackComp.Count = 1; + // TODO: If something has a stack... Just use a prototype with a single thing in the stack. + // This is not a good way to do it. + if (droppedEnt.HasComponent()) + Owner.EntityManager.EventBus.RaiseLocalEvent(droppedEnt.Uid, new StackChangeCountEvent(1), false); } return true; diff --git a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs index 5c708e1fc1..64a288a070 100644 --- a/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs +++ b/Content.Server/GameObjects/Components/Destructible/Thresholds/Behaviors/SpawnEntitiesBehavior.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; +using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Utility; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; @@ -32,8 +33,7 @@ namespace Content.Server.GameObjects.Components.Destructible.Thresholds.Behavior if (EntityPrototypeHelpers.HasComponent(entityId)) { var spawned = owner.EntityManager.SpawnEntity(entityId, owner.Transform.MapPosition); - var stack = spawned.GetComponent(); - stack.Count = count; + owner.EntityManager.EventBus.RaiseLocalEvent(spawned.Uid, new StackChangeCountEvent(count), false); spawned.RandomOffset(0.5f); } else diff --git a/Content.Server/GameObjects/Components/Power/WireComponent.cs b/Content.Server/GameObjects/Components/Power/WireComponent.cs index 4495c1b5ea..ff8400fb82 100644 --- a/Content.Server/GameObjects/Components/Power/WireComponent.cs +++ b/Content.Server/GameObjects/Components/Power/WireComponent.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Stack; using Content.Shared.GameObjects.Components.Interactable; +using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; using Robust.Shared.Prototypes; @@ -44,8 +45,9 @@ namespace Content.Server.GameObjects.Components.Power Owner.Delete(); var droppedEnt = Owner.EntityManager.SpawnEntity(_wireDroppedOnCutPrototype, eventArgs.ClickLocation); - if (droppedEnt.TryGetComponent(out var stackComp)) - stackComp.Count = 1; + // TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated... + if (droppedEnt.HasComponent()) + Owner.EntityManager.EventBus.RaiseLocalEvent(droppedEnt.Uid, new StackChangeCountEvent(1), false); return true; } diff --git a/Resources/Changelog/Parts/stacks.yml b/Resources/Changelog/Parts/stacks.yml new file mode 100644 index 0000000000..d0fe6b1a45 --- /dev/null +++ b/Resources/Changelog/Parts/stacks.yml @@ -0,0 +1,4 @@ +author: Zumorica +changes: + - type: Fix # One of the following: Add, Remove, Tweak, Fix + message: Fix some bugs with stacks where their appearance and count would be incorrect client-side.