From 0a8a3830196e8c0f879207ab72357671fd931e3a Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Thu, 2 Jul 2020 23:36:06 +0200 Subject: [PATCH] Fix lasso buckle (#1246) Co-authored-by: Pieter-Jan Briers --- .../Components/Mobs/BuckleComponent.cs | 23 +++++++++ Content.Client/IgnoredComponents.cs | 1 - .../Components/Mobs/BuckleComponent.cs | 48 +++++++++---------- .../Components/Strap/StrapComponent.cs | 2 +- Content.Server/Mobs/StandingStateHelper.cs | 1 + .../Components/Mobs/SharedBuckleComponent.cs | 33 ++++++++++++- Content.Shared/GameObjects/ContentNetIDs.cs | 5 +- .../EntitySystems/EffectBlockerSystem.cs | 2 +- SpaceStation14.sln.DotSettings | 1 + 9 files changed, 86 insertions(+), 30 deletions(-) create mode 100644 Content.Client/GameObjects/Components/Mobs/BuckleComponent.cs rename {Content.Server => Content.Shared}/GameObjects/EntitySystems/EffectBlockerSystem.cs (94%) diff --git a/Content.Client/GameObjects/Components/Mobs/BuckleComponent.cs b/Content.Client/GameObjects/Components/Mobs/BuckleComponent.cs new file mode 100644 index 0000000000..e22b23c0d0 --- /dev/null +++ b/Content.Client/GameObjects/Components/Mobs/BuckleComponent.cs @@ -0,0 +1,23 @@ +using Content.Shared.GameObjects.Components.Mobs; +using Robust.Shared.GameObjects; + +namespace Content.Client.GameObjects.Components.Mobs +{ + [RegisterComponent] + public class BuckleComponent : SharedBuckleComponent + { + private bool _buckled; + + public override void HandleComponentState(ComponentState curState, ComponentState nextState) + { + if (!(curState is BuckleComponentState buckle)) + { + return; + } + + _buckled = buckle.Buckled; + } + + protected override bool Buckled => _buckled; + } +} diff --git a/Content.Client/IgnoredComponents.cs b/Content.Client/IgnoredComponents.cs index 6a49b25753..838d82a380 100644 --- a/Content.Client/IgnoredComponents.cs +++ b/Content.Client/IgnoredComponents.cs @@ -116,7 +116,6 @@ "Utensil", "UnarmedCombat", "TimedSpawner", - "Buckle", "Strap", "NodeContainer", "PowerSupplier", diff --git a/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs b/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs index 59a33a2132..493a21e320 100644 --- a/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs +++ b/Content.Server/GameObjects/Components/Mobs/BuckleComponent.cs @@ -10,7 +10,6 @@ using Content.Shared.GameObjects.EntitySystems; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Server.GameObjects.EntitySystems; -using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; @@ -22,17 +21,29 @@ using Robust.Shared.ViewVariables; namespace Content.Server.GameObjects.Components.Mobs { [RegisterComponent] - public class BuckleComponent : SharedBuckleComponent, IActionBlocker, IInteractHand, IEffectBlocker + public class BuckleComponent : SharedBuckleComponent, IInteractHand { #pragma warning disable 649 [Dependency] private readonly IEntitySystemManager _entitySystem; [Dependency] private readonly IServerNotifyManager _notifyManager; #pragma warning restore 649 + [CanBeNull] private StrapComponent _buckledTo; private int _size; [ViewVariables, CanBeNull] - public StrapComponent BuckledTo { get; private set; } + public StrapComponent BuckledTo + { + get => _buckledTo; + private set + { + _buckledTo = value; + Dirty(); + } + } + + [ViewVariables] + protected override bool Buckled => BuckledTo != null; [ViewVariables] public int Size => _size; @@ -42,9 +53,9 @@ namespace Content.Server.GameObjects.Components.Mobs if (Owner.TryGetComponent(out ServerStatusEffectsComponent status)) { status.ChangeStatusEffectIcon(StatusEffect.Buckled, - BuckledTo == null - ? "/Textures/Mob/UI/Buckle/unbuckled.png" - : "/Textures/Mob/UI/Buckle/buckled.png"); + Buckled + ? "/Textures/Mob/UI/Buckle/buckled.png" + : "/Textures/Mob/UI/Buckle/unbuckled.png"); } } @@ -86,7 +97,7 @@ namespace Content.Server.GameObjects.Components.Mobs return false; } - if (BuckledTo != null) + if (Buckled) { _notifyManager.PopupMessage(Owner, user, Loc.GetString(Owner == user @@ -277,33 +288,22 @@ namespace Content.Server.GameObjects.Components.Mobs BuckleStatus(); } + public override ComponentState GetComponentState() + { + return new BuckleComponentState(Buckled); + } + bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs) { return TryUnbuckle(eventArgs.User); } - bool IActionBlocker.CanMove() - { - return BuckledTo == null; - } - - bool IActionBlocker.CanChangeDirection() - { - return BuckledTo == null; - } - - bool IEffectBlocker.CanFall() - { - return BuckledTo == null; - } - [Verb] private sealed class BuckleVerb : Verb { protected override void GetData(IEntity user, BuckleComponent component, VerbData data) { - if (!ActionBlockerSystem.CanInteract(user) || - component.BuckledTo == null) + if (!ActionBlockerSystem.CanInteract(user) || !component.Buckled) { data.Visibility = VerbVisibility.Invisible; return; diff --git a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs index 0391154cfd..9060193c1f 100644 --- a/Content.Server/GameObjects/Components/Strap/StrapComponent.cs +++ b/Content.Server/GameObjects/Components/Strap/StrapComponent.cs @@ -69,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Strap /// The sum of the sizes of all the buckled entities in this strap /// [ViewVariables] - public int OccupiedSize { get; private set; } + private int OccupiedSize { get; set; } public bool HasSpace(BuckleComponent buckle) { diff --git a/Content.Server/Mobs/StandingStateHelper.cs b/Content.Server/Mobs/StandingStateHelper.cs index 985dd1e448..ac912a4546 100644 --- a/Content.Server/Mobs/StandingStateHelper.cs +++ b/Content.Server/Mobs/StandingStateHelper.cs @@ -2,6 +2,7 @@ using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameObjects; using Content.Shared.Audio; using Content.Shared.GameObjects.Components.Mobs; +using Content.Shared.GameObjects.EntitySystems; using Robust.Server.GameObjects; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.Interfaces.GameObjects; diff --git a/Content.Shared/GameObjects/Components/Mobs/SharedBuckleComponent.cs b/Content.Shared/GameObjects/Components/Mobs/SharedBuckleComponent.cs index 93ea7481b1..e475b01896 100644 --- a/Content.Shared/GameObjects/Components/Mobs/SharedBuckleComponent.cs +++ b/Content.Shared/GameObjects/Components/Mobs/SharedBuckleComponent.cs @@ -1,13 +1,44 @@ using System; +using Content.Shared.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; namespace Content.Shared.GameObjects.Components.Mobs { - public class SharedBuckleComponent : Component + public abstract class SharedBuckleComponent : Component, IActionBlocker, IEffectBlocker { public sealed override string Name => "Buckle"; + public sealed override uint? NetID => ContentNetIDs.BUCKLE; + + protected abstract bool Buckled { get; } + + bool IActionBlocker.CanMove() + { + return !Buckled; + } + + bool IActionBlocker.CanChangeDirection() + { + return !Buckled; + } + + bool IEffectBlocker.CanFall() + { + return !Buckled; + } + + [Serializable, NetSerializable] + protected sealed class BuckleComponentState : ComponentState + { + public BuckleComponentState(bool buckled) : base(ContentNetIDs.BUCKLE) + { + Buckled = buckled; + } + + public bool Buckled { get; } + } + [Serializable, NetSerializable] public enum BuckleVisuals { diff --git a/Content.Shared/GameObjects/ContentNetIDs.cs b/Content.Shared/GameObjects/ContentNetIDs.cs index e4249a5aa0..566185c7e8 100644 --- a/Content.Shared/GameObjects/ContentNetIDs.cs +++ b/Content.Shared/GameObjects/ContentNetIDs.cs @@ -56,8 +56,9 @@ public const uint THIRST = 1050; public const uint FLASHABLE = 1051; - public const uint PROJECTILE = 1052; - public const uint THROWN_ITEM = 1053; + public const uint BUCKLE = 1052; + public const uint PROJECTILE = 1053; + public const uint THROWN_ITEM = 1054; // Net IDs for integration tests. public const uint PREDICTION_TEST = 10001; diff --git a/Content.Server/GameObjects/EntitySystems/EffectBlockerSystem.cs b/Content.Shared/GameObjects/EntitySystems/EffectBlockerSystem.cs similarity index 94% rename from Content.Server/GameObjects/EntitySystems/EffectBlockerSystem.cs rename to Content.Shared/GameObjects/EntitySystems/EffectBlockerSystem.cs index 9468d2ddfb..26602a64f5 100644 --- a/Content.Server/GameObjects/EntitySystems/EffectBlockerSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/EffectBlockerSystem.cs @@ -1,7 +1,7 @@ using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; -namespace Content.Server.GameObjects.EntitySystems +namespace Content.Shared.GameObjects.EntitySystems { /// /// This interface gives components the ability to block certain effects diff --git a/SpaceStation14.sln.DotSettings b/SpaceStation14.sln.DotSettings index bf0af43fd3..961aacf984 100644 --- a/SpaceStation14.sln.DotSettings +++ b/SpaceStation14.sln.DotSettings @@ -60,6 +60,7 @@ True True True + True True True True