From 388e717a5384d42c017b55e4960f08c0e48251e4 Mon Sep 17 00:00:00 2001 From: nuke <47336974+nuke-makes-games@users.noreply.github.com> Date: Thu, 27 Aug 2020 10:33:10 -0400 Subject: [PATCH] Get rid of CuffSystem, make CuffableComponent update its hand count properly (#1927) * Merge branch 'master' of https://github.com/space-wizards/space-station-14 into cuff-fix * yml * event bus --- .../ActionBlocking/CuffableComponent.cs | 24 +++++++++++-------- .../Components/GUI/HandsComponent.cs | 13 ++++++++++ .../GameObjects/EntitySystems/CuffSystem.cs | 18 -------------- .../Entities/Mobs/Species/human.yml | 2 ++ 4 files changed, 29 insertions(+), 28 deletions(-) delete mode 100644 Content.Server/GameObjects/EntitySystems/CuffSystem.cs diff --git a/Content.Server/GameObjects/Components/ActionBlocking/CuffableComponent.cs b/Content.Server/GameObjects/Components/ActionBlocking/CuffableComponent.cs index 4ca5bb08b8..3325fc2caa 100644 --- a/Content.Server/GameObjects/Components/ActionBlocking/CuffableComponent.cs +++ b/Content.Server/GameObjects/Components/ActionBlocking/CuffableComponent.cs @@ -22,7 +22,7 @@ using Content.Shared.GameObjects.Components.Mobs; using Robust.Shared.Maths; using System; using System.Collections.Generic; -using Serilog; +using Content.Server.GameObjects.Components.GUI; namespace Content.Server.GameObjects.Components.ActionBlocking { @@ -48,7 +48,6 @@ namespace Content.Server.GameObjects.Components.ActionBlocking [ViewVariables(VVAccess.ReadOnly)] private Container _container = default!; - private bool _dirtyThisFrame = false; private float _interactRange; private IHandsComponent _hands; @@ -61,6 +60,8 @@ namespace Content.Server.GameObjects.Components.ActionBlocking _container = ContainerManagerComponent.Ensure(Name, Owner); _interactRange = SharedInteractionSystem.InteractionRange / 2; + Owner.EntityManager.EventBus.SubscribeEvent(EventSource.Local, this, HandleHandCountChange); + if (!Owner.TryGetComponent(out _hands)) { Logger.Warning("Player does not have an IHandsComponent!"); @@ -127,29 +128,24 @@ namespace Content.Server.GameObjects.Components.ActionBlocking Dirty(); } - public void Update(float frameTime) - { - UpdateHandCount(); - } - /// /// Check the current amount of hands the owner has, and if there's less hands than active cuffs we remove some cuffs. /// private void UpdateHandCount() { - _dirtyThisFrame = false; + var dirty = false; var handCount = _hands.Hands.Count(); while (CuffedHandCount > handCount && CuffedHandCount > 0) { - _dirtyThisFrame = true; + dirty = true; var entity = _container.ContainedEntities[_container.ContainedEntities.Count - 1]; _container.Remove(entity); entity.Transform.WorldPosition = Owner.Transform.GridPosition.Position; } - if (_dirtyThisFrame) + if (dirty) { CanStillInteract = handCount > CuffedHandCount; OnCuffedStateChanged.Invoke(); @@ -157,6 +153,14 @@ namespace Content.Server.GameObjects.Components.ActionBlocking } } + private void HandleHandCountChange(HandCountChangedEvent message) + { + if (message.Sender == Owner) + { + UpdateHandCount(); + } + } + /// /// Check how many items the user is holding and if it's more than the number of cuffed hands, drop some items. /// diff --git a/Content.Server/GameObjects/Components/GUI/HandsComponent.cs b/Content.Server/GameObjects/Components/GUI/HandsComponent.cs index ade7beee0d..bda951b392 100644 --- a/Content.Server/GameObjects/Components/GUI/HandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/HandsComponent.cs @@ -29,6 +29,7 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Players; using Robust.Shared.ViewVariables; +using Content.Server.GameObjects.Components.ActionBlocking; namespace Content.Server.GameObjects.Components.GUI { @@ -444,6 +445,7 @@ namespace Content.Server.GameObjects.Components.GUI ActiveHand ??= name; OnItemChanged?.Invoke(); + Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner)); Dirty(); } @@ -466,6 +468,7 @@ namespace Content.Server.GameObjects.Components.GUI } OnItemChanged?.Invoke(); + Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new HandCountChangedEvent(Owner)); Dirty(); } @@ -791,4 +794,14 @@ namespace Content.Server.GameObjects.Components.GUI return new SharedHand(index, Name, Entity?.Uid, location); } } + + public class HandCountChangedEvent : EntitySystemMessage + { + public HandCountChangedEvent(IEntity sender) + { + Sender = sender; + } + + public IEntity Sender { get; } + } } diff --git a/Content.Server/GameObjects/EntitySystems/CuffSystem.cs b/Content.Server/GameObjects/EntitySystems/CuffSystem.cs deleted file mode 100644 index f08ddae3ba..0000000000 --- a/Content.Server/GameObjects/EntitySystems/CuffSystem.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Content.Server.GameObjects.Components.ActionBlocking; -using JetBrains.Annotations; -using Robust.Shared.GameObjects.Systems; - -namespace Content.Server.GameObjects.EntitySystems -{ - [UsedImplicitly] - internal sealed class CuffSystem : EntitySystem - { - public override void Update(float frameTime) - { - foreach (var comp in ComponentManager.EntityQuery()) - { - comp.Update(frameTime); - } - } - } -} diff --git a/Resources/Prototypes/Entities/Mobs/Species/human.yml b/Resources/Prototypes/Entities/Mobs/Species/human.yml index 0ae791261b..43a4507138 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/human.yml @@ -94,6 +94,7 @@ color: "#ffffff" sprite: Objects/Misc/handcuffs.rsi state: body-overlay-2 + visible: false - map: ["enum.Slots.IDCARD"] - map: ["enum.Slots.GLOVES"] - map: ["enum.Slots.SHOES"] @@ -231,6 +232,7 @@ color: "#ffffff" sprite: Objects/Misc/handcuffs.rsi state: body-overlay-2 + visible: false - map: ["enum.Slots.IDCARD"] - map: ["enum.Slots.GLOVES"] - map: ["enum.Slots.SHOES"]