From 44631c77231742ee193b7c047d87ddf626fc8a33 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:23:53 +1300 Subject: [PATCH] Remove server-sprite references from handcuffs (#13515) --- .../Cuffs/Components/CuffableComponent.cs | 21 +++----- .../Cuffs/Components/HandcuffComponent.cs | 52 +++---------------- Content.Server/Cuffs/CuffableSystem.cs | 6 --- .../EntitySystems/SharedHandsSystem.Pickup.cs | 9 +++- .../cuffs/components/handcuff-broken.ftl | 4 -- .../Entities/Objects/Misc/handcuffs.yml | 35 ++++++++++--- 6 files changed, 52 insertions(+), 75 deletions(-) delete mode 100644 Resources/Locale/en-US/cuffs/components/handcuff-broken.ftl diff --git a/Content.Server/Cuffs/Components/CuffableComponent.cs b/Content.Server/Cuffs/Components/CuffableComponent.cs index e5a526a944..26a8e3252f 100644 --- a/Content.Server/Cuffs/Components/CuffableComponent.cs +++ b/Content.Server/Cuffs/Components/CuffableComponent.cs @@ -18,6 +18,7 @@ using Robust.Shared.Audio; using Robust.Shared.Containers; using Robust.Shared.Player; using Content.Server.Recycling.Components; +using Robust.Shared.Map; namespace Content.Server.Cuffs.Components { @@ -271,22 +272,16 @@ namespace Content.Server.Cuffs.Components SoundSystem.Play(cuff.EndUncuffSound.GetSound(), Filter.Pvs(Owner), Owner); _entMan.EntitySysManager.GetEntitySystem().DeleteInHandsMatching(user, cuffsToRemove); - _entMan.EntitySysManager.GetEntitySystem().PickupOrDrop(user, cuffsToRemove); if (cuff.BreakOnRemove) { - cuff.Broken = true; - - var meta = _entMan.GetComponent(cuffsToRemove); - meta.EntityName = Loc.GetString(cuff.BrokenName); - meta.EntityDescription = Loc.GetString(cuff.BrokenDesc); - - if (_entMan.TryGetComponent(cuffsToRemove, out var sprite) && cuff.BrokenState != null) - { - sprite.LayerSetState(0, cuff.BrokenState); // TODO: safety check to see if RSI contains the state? - } - - _entMan.EnsureComponent(cuffsToRemove); + _entMan.QueueDeleteEntity(cuffsToRemove); + var trash = _entMan.SpawnEntity(cuff.BrokenPrototype, MapCoordinates.Nullspace); + _entMan.EntitySysManager.GetEntitySystem().PickupOrDrop(user, trash); + } + else + { + _entMan.EntitySysManager.GetEntitySystem().PickupOrDrop(user, cuffsToRemove); } CanStillInteract = _entMan.TryGetComponent(Owner, out HandsComponent? handsComponent) && handsComponent.SortedHands.Count() > CuffedHandCount; diff --git a/Content.Server/Cuffs/Components/HandcuffComponent.cs b/Content.Server/Cuffs/Components/HandcuffComponent.cs index 03066aece0..793595d941 100644 --- a/Content.Server/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Server/Cuffs/Components/HandcuffComponent.cs @@ -7,6 +7,8 @@ using Content.Shared.Popups; using Content.Shared.Stunnable; using Robust.Shared.Audio; using Robust.Shared.Player; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Server.Cuffs.Components { @@ -47,6 +49,12 @@ namespace Content.Server.Cuffs.Components [DataField("breakOnRemove")] public bool BreakOnRemove { get; set; } + /// + /// Will the cuffs break when removed? + /// + [DataField("brokenPrototype", customTypeSerializer:typeof(PrototypeIdSerializer))] + public string? BrokenPrototype { get; set; } + /// /// The path of the RSI file used for the player cuffed overlay. /// @@ -59,42 +67,6 @@ namespace Content.Server.Cuffs.Components [DataField("bodyIconState")] public string? OverlayIconState { get; set; } = "body-overlay"; - /// - /// The iconstate used for broken handcuffs - /// - [DataField("brokenIconState")] - public string? BrokenState { get; set; } - - /// - /// The iconstate used for broken handcuffs - /// - [DataField("brokenName", readOnly: true)] - public string BrokenName { get; private set; } = ""; - - /// - /// The iconstate used for broken handcuffs - /// - [DataField("brokenDesc", readOnly: true)] - public string BrokenDesc { get; private set; } = ""; - - [ViewVariables] - public bool Broken - { - get - { - return _isBroken; - } - set - { - if (_isBroken != value) - { - _isBroken = value; - - Dirty(); - } - } - } - [DataField("startCuffSound")] public SoundSpecifier StartCuffSound { get; set; } = new SoundPathSpecifier("/Audio/Items/Handcuffs/cuff_start.ogg"); @@ -112,19 +84,11 @@ namespace Content.Server.Cuffs.Components [DataField("color")] public Color Color { get; set; } = Color.White; - // Non-exposed data fields - private bool _isBroken = false; - /// /// Used to prevent DoAfter getting spammed. /// public bool Cuffing; - public override ComponentState GetComponentState() - { - return new HandcuffedComponentState(Broken ? BrokenState : string.Empty); - } - /// /// Update the cuffed state of an entity /// diff --git a/Content.Server/Cuffs/CuffableSystem.cs b/Content.Server/Cuffs/CuffableSystem.cs index 741e18cc4c..6d220840b1 100644 --- a/Content.Server/Cuffs/CuffableSystem.cs +++ b/Content.Server/Cuffs/CuffableSystem.cs @@ -86,12 +86,6 @@ namespace Content.Server.Cuffs if (component.Cuffing || !EntityManager.TryGetComponent(target, out var cuffed)) return; - if (component.Broken) - { - _popup.PopupEntity(Loc.GetString("handcuff-component-cuffs-broken-error"), user, user); - return; - } - if (!EntityManager.TryGetComponent(target, out var hands)) { _popup.PopupEntity(Loc.GetString("handcuff-component-target-has-no-hands-error",("targetName", target)), user, user); diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs index 8969d9e2a0..f818fff229 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs @@ -60,9 +60,14 @@ public abstract partial class SharedHandsSystem : EntitySystem // animation var xform = Transform(uid); var coordinateEntity = xform.ParentUid.IsValid() ? xform.ParentUid : uid; - var initialPosition = EntityCoordinates.FromMap(EntityManager, coordinateEntity, Transform(entity).MapPosition); - PickupAnimation(entity, initialPosition, xform.LocalPosition, animateUser ? null : uid); + var itemPos = Transform(entity).MapPosition; + if (itemPos.MapId == xform.MapID) + { + // TODO max range for animation? + var initialPosition = EntityCoordinates.FromMap(coordinateEntity, itemPos, EntityManager); + PickupAnimation(entity, initialPosition, xform.LocalPosition, animateUser ? null : uid); + } DoPickup(uid, hand, entity, handsComp); return true; diff --git a/Resources/Locale/en-US/cuffs/components/handcuff-broken.ftl b/Resources/Locale/en-US/cuffs/components/handcuff-broken.ftl deleted file mode 100644 index 1b74cc1103..0000000000 --- a/Resources/Locale/en-US/cuffs/components/handcuff-broken.ftl +++ /dev/null @@ -1,4 +0,0 @@ -handcuff-broken-cables-name = broken cables -handcuff-broken-cables-desc = These cables are broken in several places and don't seem very useful. -handcuff-broken-zipties-name = broken zipties -handcuff-broken-zipties-desc = These zipties look like they tried to manage the wrong cables. \ No newline at end of file diff --git a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml index 36c1c83eaa..5a2eaa3ef9 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/handcuffs.yml @@ -35,9 +35,7 @@ bodyIconState: body-overlay color: red breakOnRemove: true - brokenIconState: cuff-broken - brokenName: handcuff-broken-cables-name - brokenDesc: handcuff-broken-cables-desc + brokenPrototype: CablecuffsBroken startCuffSound: path: /Audio/Items/Handcuffs/rope_start.ogg endCuffSound: @@ -69,9 +67,7 @@ cuffedRSI: Objects/Misc/cablecuffs.rsi # cablecuffs will look fine bodyIconState: body-overlay breakOnRemove: true - brokenIconState: cuff-broken - brokenName: handcuff-broken-zipties-name - brokenDesc: handcuff-broken-zipties-desc + brokenPrototype: ZiptiesBroken startCuffSound: path: /Audio/Items/Handcuffs/ziptie_start.ogg endCuffSound: @@ -85,3 +81,30 @@ - type: Sprite sprite: Objects/Misc/zipties.rsi state: cuff + +- type: entity + name: broken zipties + description: These zipties look like they tried to manage the wrong cables. + id: ZiptiesBroken + parent: BaseItem + components: + - type: Sprite + sprite: Objects/Misc/zipties.rsi + state: cuff-broken + - type: Item + size: 2 + - type: Recyclable + +- type: entity + name: broken cables + description: These cables are broken in several places and don't seem very useful. + id: CablecuffsBroken + parent: BaseItem + components: + - type: Sprite + sprite: Objects/Misc/cablecuffs.rsi + state: cuff-broken + color: red + - type: Item + size: 2 + - type: Recyclable