From 8005cf31bb0562634406ba6b94f0f3c7bdfcf99e Mon Sep 17 00:00:00 2001 From: mirrorcult Date: Sun, 13 Mar 2022 23:03:49 -0700 Subject: [PATCH] Generic clothing speed modifiers + hardsuit slowdown (#7094) --- Content.Client/Clothing/MagbootsSystem.cs | 11 --- Content.Server/Clothing/MagbootsSystem.cs | 6 -- .../ClothingSpeedModifierComponent.cs | 36 ++++++++++ .../Clothing/ClothingSpeedModifierSystem.cs | 70 +++++++++++++++++++ .../Clothing/SharedMagbootsComponent.cs | 16 +---- .../OuterClothing/base_clothingouter.yml | 3 + .../Clothing/OuterClothing/hardsuits.yml | 18 +++++ .../Entities/Clothing/Shoes/magboots.yml | 10 ++- 8 files changed, 136 insertions(+), 34 deletions(-) create mode 100644 Content.Shared/Clothing/ClothingSpeedModifierComponent.cs create mode 100644 Content.Shared/Clothing/ClothingSpeedModifierSystem.cs diff --git a/Content.Client/Clothing/MagbootsSystem.cs b/Content.Client/Clothing/MagbootsSystem.cs index 46905601c5..220d8db819 100644 --- a/Content.Client/Clothing/MagbootsSystem.cs +++ b/Content.Client/Clothing/MagbootsSystem.cs @@ -5,16 +5,5 @@ namespace Content.Client.Clothing { public sealed class MagbootsSystem : SharedMagbootsSystem { - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent(OnRefreshMovespeed); - } - - private void OnRefreshMovespeed(EntityUid uid, MagbootsComponent component, RefreshMovementSpeedModifiersEvent args) - { - args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier); - } } } diff --git a/Content.Server/Clothing/MagbootsSystem.cs b/Content.Server/Clothing/MagbootsSystem.cs index 8e14b61da3..412b0f5909 100644 --- a/Content.Server/Clothing/MagbootsSystem.cs +++ b/Content.Server/Clothing/MagbootsSystem.cs @@ -21,7 +21,6 @@ namespace Content.Server.Clothing SubscribeLocalEvent>(AddToggleVerb); SubscribeLocalEvent(OnSlipAttempt); - SubscribeLocalEvent(OnRefreshMovespeed); SubscribeLocalEvent(OnGotEquipped); SubscribeLocalEvent(OnGotUnequipped); } @@ -63,11 +62,6 @@ namespace Content.Server.Clothing } } - private void OnRefreshMovespeed(EntityUid uid, MagbootsComponent component, RefreshMovementSpeedModifiersEvent args) - { - args.ModifySpeed(component.WalkSpeedModifier, component.SprintSpeedModifier); - } - private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetVerbsEvent args) { if (!args.CanAccess || !args.CanInteract) diff --git a/Content.Shared/Clothing/ClothingSpeedModifierComponent.cs b/Content.Shared/Clothing/ClothingSpeedModifierComponent.cs new file mode 100644 index 0000000000..e3823553f2 --- /dev/null +++ b/Content.Shared/Clothing/ClothingSpeedModifierComponent.cs @@ -0,0 +1,36 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + +namespace Content.Shared.Clothing; + +[RegisterComponent, NetworkedComponent, Friend(typeof(ClothingSpeedModifierSystem))] +public sealed class ClothingSpeedModifierComponent : Component +{ + [DataField("walkModifier", required: true)] [ViewVariables(VVAccess.ReadWrite)] + public float WalkModifier = 1.0f; + + [DataField("sprintModifier", required: true)] [ViewVariables(VVAccess.ReadWrite)] + public float SprintModifier = 1.0f; + + /// + /// Is this clothing item currently 'actively' slowing you down? + /// e.g. magboots can be turned on and off. + /// + [DataField("enabled")] public bool Enabled = true; +} + +[Serializable, NetSerializable] +public sealed class ClothingSpeedModifierComponentState : ComponentState +{ + public float WalkModifier; + public float SprintModifier; + + public bool Enabled; + + public ClothingSpeedModifierComponentState(float walkModifier, float sprintModifier, bool enabled) + { + WalkModifier = walkModifier; + SprintModifier = sprintModifier; + Enabled = enabled; + } +} diff --git a/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs b/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs new file mode 100644 index 0000000000..ee759cc96d --- /dev/null +++ b/Content.Shared/Clothing/ClothingSpeedModifierSystem.cs @@ -0,0 +1,70 @@ +using Content.Shared.Movement.EntitySystems; +using Robust.Shared.Containers; +using Robust.Shared.GameStates; + +namespace Content.Shared.Clothing; + +public sealed class ClothingSpeedModifierSystem : EntitySystem +{ + [Dependency] private readonly MovementSpeedModifierSystem _movementSpeed = default!; + [Dependency] private readonly SharedContainerSystem _container = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnGetState); + SubscribeLocalEvent(OnHandleState); + SubscribeLocalEvent(OnRefreshMoveSpeed); + } + + // Public API + + public void SetClothingSpeedModifierEnabled(EntityUid uid, bool enabled, ClothingSpeedModifierComponent? component = null) + { + if (!Resolve(uid, ref component, false)) + return; + + if (component.Enabled != enabled) + { + component.Enabled = enabled; + Dirty(component); + + // inventory system will automatically hook into the event raised by this and update accordingly + if (_container.TryGetContainingContainer(uid, out var container)) + { + _movementSpeed.RefreshMovementSpeedModifiers(container.Owner); + } + } + } + + // Event handlers + + private void OnGetState(EntityUid uid, ClothingSpeedModifierComponent component, ref ComponentGetState args) + { + args.State = new ClothingSpeedModifierComponentState(component.WalkModifier, component.SprintModifier, component.Enabled); + } + + private void OnHandleState(EntityUid uid, ClothingSpeedModifierComponent component, ref ComponentHandleState args) + { + if (args.Current is ClothingSpeedModifierComponentState state) + { + component.WalkModifier = state.WalkModifier; + component.SprintModifier = state.SprintModifier; + component.Enabled = state.Enabled; + + if (_container.TryGetContainingContainer(uid, out var container)) + { + _movementSpeed.RefreshMovementSpeedModifiers(container.Owner); + } + } + } + + private void OnRefreshMoveSpeed(EntityUid uid, ClothingSpeedModifierComponent component, RefreshMovementSpeedModifiersEvent args) + { + if (!component.Enabled) + return; + + args.ModifySpeed(component.WalkModifier, component.SprintModifier); + } +} diff --git a/Content.Shared/Clothing/SharedMagbootsComponent.cs b/Content.Shared/Clothing/SharedMagbootsComponent.cs index 6a6bb4cf7a..dc37088364 100644 --- a/Content.Shared/Clothing/SharedMagbootsComponent.cs +++ b/Content.Shared/Clothing/SharedMagbootsComponent.cs @@ -18,22 +18,8 @@ namespace Content.Shared.Clothing protected void OnChanged() { EntitySystem.Get().SetToggled(ToggleAction, On); - - // inventory system will automatically hook into the event raised by this and update accordingly - if (Owner.TryGetContainer(out var container)) - { - EntitySystem.Get().RefreshMovementSpeedModifiers(container.Owner); - } + EntitySystem.Get().SetClothingSpeedModifierEnabled(Owner, On); } - [DataField("walkMoveCoeffecient", required: true)] - [ViewVariables(VVAccess.ReadWrite)] - public float WalkMoveCoeffecient = 0.85f; - - [DataField("sprintMoveCoeffecient", required: true)] - [ViewVariables(VVAccess.ReadWrite)] - public float SprintMoveCoeffecient = 0.65f; - public float WalkSpeedModifier => On ? WalkMoveCoeffecient : 1; - public float SprintSpeedModifier => On ? SprintMoveCoeffecient : 1; [Serializable, NetSerializable] public sealed class MagbootsComponentState : ComponentState diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml index 3638d7242f..fad452a850 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml @@ -20,6 +20,9 @@ lowPressureMultiplier: 100 - type: TemperatureProtection coefficient: 0.001 # yes it needs to be this low, fires are fucking deadly apparently!!!! + - type: ClothingSpeedModifier + walkModifier: 0.6 + sprintModifier: 0.4 - type: Clothing size: 50 - type: Armor diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml index 95b30f26f1..382915b0be 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml @@ -33,6 +33,9 @@ - type: PressureProtection highPressureMultiplier: 0.5 lowPressureMultiplier: 100 + - type: ClothingSpeedModifier + walkModifier: 0.8 + sprintModifier: 0.8 - type: Armor modifiers: coefficients: @@ -55,6 +58,9 @@ - type: PressureProtection highPressureMultiplier: 0.45 lowPressureMultiplier: 100 + - type: ClothingSpeedModifier + walkModifier: 1.0 + sprintModifier: 1.0 - type: Armor modifiers: coefficients: @@ -133,6 +139,9 @@ sprite: Clothing/OuterClothing/Hardsuits/eva.rsi - type: Clothing sprite: Clothing/OuterClothing/Hardsuits/eva.rsi + - type: ClothingSpeedModifier + walkModifier: 0.8 + sprintModifier: 0.8 - type: PressureProtection highPressureMultiplier: 1 lowPressureMultiplier: 100 @@ -152,6 +161,9 @@ - type: PressureProtection highPressureMultiplier: 1 lowPressureMultiplier: 100 + - type: ClothingSpeedModifier + walkModifier: 0.8 + sprintModifier: 0.8 - type: entity parent: ClothingOuterHardsuitBase @@ -268,6 +280,9 @@ - type: PressureProtection highPressureMultiplier: 0.45 lowPressureMultiplier: 100 + - type: ClothingSpeedModifier + walkModifier: 1.0 + sprintModifier: 1.0 - type: Armor modifiers: coefficients: @@ -290,6 +305,9 @@ - type: PressureProtection highPressureMultiplier: 0.45 lowPressureMultiplier: 100 + - type: ClothingSpeedModifier + walkModifier: 0.8 + sprintModifier: 0.8 - type: Armor modifiers: coefficients: diff --git a/Resources/Prototypes/Entities/Clothing/Shoes/magboots.yml b/Resources/Prototypes/Entities/Clothing/Shoes/magboots.yml index efaa070122..260a769e1c 100644 --- a/Resources/Prototypes/Entities/Clothing/Shoes/magboots.yml +++ b/Resources/Prototypes/Entities/Clothing/Shoes/magboots.yml @@ -17,6 +17,10 @@ description: action-decription-magboot-toggle itemIconStyle: NoItem event: !type:ToggleActionEvent + - type: ClothingSpeedModifier + walkModifier: 0.85 + sprintModifier: 0.65 + enabled: false - type: entity parent: ClothingShoesBootsMag @@ -30,5 +34,7 @@ - type: Clothing sprite: Clothing/Shoes/Boots/magboots-advanced.rsi - type: Magboots - walkMoveCoeffecient: 1 - sprintMoveCoeffecient: 1 + - type: ClothingSpeedModifier + walkModifier: 1 + sprintModifier: 1 + enabled: false