From 94c3a7019d61dda51dfb79624a06bd0588356002 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 6 Dec 2023 22:41:29 -0500 Subject: [PATCH] Mirror speed penalty for worn duffels and hardsuits when in-hand (#22168) * Add speed penalty for holding hardsuits and duffels * just inherit from ClothingSpeedModifier * comment godo --- .../EntitySystems/SharedHandsSystem.Relay.cs | 21 +++++++++ .../Hands/EntitySystems/SharedHandsSystem.cs | 1 + Content.Shared/Hands/HandEvents.cs | 11 +++++ .../Item/HeldSpeedModifierComponent.cs | 34 ++++++++++++++ .../Item/HeldSpeedModifierSystem.cs | 44 +++++++++++++++++++ .../Entities/Clothing/Back/duffel.yml | 3 ++ .../Entities/Clothing/OuterClothing/armor.yml | 3 ++ .../OuterClothing/base_clothingouter.yml | 3 ++ .../Clothing/OuterClothing/hardsuits.yml | 25 +++++++++++ .../Clothing/OuterClothing/softsuits.yml | 3 ++ .../Entities/Clothing/OuterClothing/suits.yml | 2 + 11 files changed, 150 insertions(+) create mode 100644 Content.Shared/Hands/EntitySystems/SharedHandsSystem.Relay.cs create mode 100644 Content.Shared/Item/HeldSpeedModifierComponent.cs create mode 100644 Content.Shared/Item/HeldSpeedModifierSystem.cs diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Relay.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Relay.cs new file mode 100644 index 0000000000..9e8e0fa744 --- /dev/null +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Relay.cs @@ -0,0 +1,21 @@ +using Content.Shared.Hands.Components; +using Content.Shared.Movement.Systems; + +namespace Content.Shared.Hands.EntitySystems; + +public abstract partial class SharedHandsSystem +{ + private void InitializeRelay() + { + SubscribeLocalEvent(RelayEvent); + } + + private void RelayEvent(Entity entity, ref T args) where T : EntityEventArgs + { + var ev = new HeldRelayedEvent(args); + foreach (var held in EnumerateHeld(entity, entity.Comp)) + { + RaiseLocalEvent(held, ref ev); + } + } +} diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs index 6b786fdfaa..4f34d6fc54 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs @@ -31,6 +31,7 @@ public abstract partial class SharedHandsSystem InitializeDrop(); InitializePickup(); InitializeVirtual(); + InitializeRelay(); } public override void Shutdown() diff --git a/Content.Shared/Hands/HandEvents.cs b/Content.Shared/Hands/HandEvents.cs index 059728ff4d..0499c05f42 100644 --- a/Content.Shared/Hands/HandEvents.cs +++ b/Content.Shared/Hands/HandEvents.cs @@ -319,4 +319,15 @@ namespace Content.Shared.Hands public EntityUid Sender { get; } } + + [ByRefEvent] + public sealed class HeldRelayedEvent : EntityEventArgs + { + public TEvent Args; + + public HeldRelayedEvent(TEvent args) + { + Args = args; + } + } } diff --git a/Content.Shared/Item/HeldSpeedModifierComponent.cs b/Content.Shared/Item/HeldSpeedModifierComponent.cs new file mode 100644 index 0000000000..1fbe7437ea --- /dev/null +++ b/Content.Shared/Item/HeldSpeedModifierComponent.cs @@ -0,0 +1,34 @@ +using Content.Shared.Clothing; +using Robust.Shared.GameStates; + +namespace Content.Shared.Item; + +/// +/// This is used for items that change your speed when they are held. +/// +/// +/// This is separate from because things like boots increase/decrease speed when worn, but +/// shouldn't do that when just held in hand. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +[Access(typeof(HeldSpeedModifierSystem))] +public sealed partial class HeldSpeedModifierComponent : Component +{ + /// + /// A multiplier applied to the walk speed. + /// + [DataField] [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + public float WalkModifier = 1.0f; + + /// + /// A multiplier applied to the sprint speed. + /// + [DataField] [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + public float SprintModifier = 1.0f; + + /// + /// If true, values from will attempted to be used before the ones in this component. + /// + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + public bool MirrorClothingModifier = true; +} diff --git a/Content.Shared/Item/HeldSpeedModifierSystem.cs b/Content.Shared/Item/HeldSpeedModifierSystem.cs new file mode 100644 index 0000000000..d7afa8f40f --- /dev/null +++ b/Content.Shared/Item/HeldSpeedModifierSystem.cs @@ -0,0 +1,44 @@ +using Content.Shared.Clothing; +using Content.Shared.Hands; +using Content.Shared.Movement.Systems; + +namespace Content.Shared.Item; + +/// +/// This handles +/// +public sealed class HeldSpeedModifierSystem : EntitySystem +{ + [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!; + + /// + public override void Initialize() + { + SubscribeLocalEvent(OnGotEquippedHand); + SubscribeLocalEvent(OnGotUnequippedHand); + SubscribeLocalEvent>(OnRefreshMovementSpeedModifiers); + } + + private void OnGotEquippedHand(Entity ent, ref GotEquippedHandEvent args) + { + _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User); + } + + private void OnGotUnequippedHand(Entity ent, ref GotUnequippedHandEvent args) + { + _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User); + } + + private void OnRefreshMovementSpeedModifiers(EntityUid uid, HeldSpeedModifierComponent component, HeldRelayedEvent args) + { + var walkMod = component.WalkModifier; + var sprintMod = component.SprintModifier; + if (component.MirrorClothingModifier && TryComp(uid, out var clothingSpeedModifier)) + { + walkMod = clothingSpeedModifier.WalkModifier; + sprintMod = clothingSpeedModifier.SprintModifier; + } + + args.Args.ModifySpeed(walkMod, sprintMod); + } +} diff --git a/Resources/Prototypes/Entities/Clothing/Back/duffel.yml b/Resources/Prototypes/Entities/Clothing/Back/duffel.yml index 683dfd9250..2dd26c1cc8 100644 --- a/Resources/Prototypes/Entities/Clothing/Back/duffel.yml +++ b/Resources/Prototypes/Entities/Clothing/Back/duffel.yml @@ -11,6 +11,7 @@ - type: ClothingSpeedModifier walkModifier: 1 sprintModifier: 0.9 + - type: HeldSpeedModifier - type: entity parent: ClothingBackpackDuffel @@ -232,6 +233,7 @@ capacity: 9999 - type: ClothingSpeedModifier sprintModifier: 1 # makes its stats identical to other variants of bag of holding + - type: HeldSpeedModifier - type: entity parent: ClothingBackpackDuffel @@ -244,3 +246,4 @@ - type: ClothingSpeedModifier walkModifier: 1 sprintModifier: 1 + - type: HeldSpeedModifier \ No newline at end of file diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml index 84db1e8e8b..fdaee45ccc 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml @@ -230,6 +230,7 @@ - type: ClothingSpeedModifier walkModifier: 1.0 sprintModifier: 1.0 + - type: HeldSpeedModifier - type: ExplosionResistance damageCoefficient: 0.65 - type: GroupExamine @@ -255,6 +256,7 @@ - type: ClothingSpeedModifier walkModifier: 0.7 sprintModifier: 0.65 + - type: HeldSpeedModifier - type: ExplosionResistance damageCoefficient: 0.5 - type: GroupExamine @@ -277,6 +279,7 @@ Piercing: 0.4 - type: ClothingSpeedModifier walkModifier: 0.8 + - type: HeldSpeedModifier - type: ExplosionResistance damageCoefficient: 0.4 - type: GroupExamine diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml index f92592f65e..a1c2de0c87 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml @@ -22,6 +22,7 @@ - type: ClothingSpeedModifier walkModifier: 0.9 sprintModifier: 0.9 + - type: HeldSpeedModifier - type: entity abstract: true @@ -71,6 +72,7 @@ - type: ClothingSpeedModifier walkModifier: 0.4 sprintModifier: 0.6 + - type: HeldSpeedModifier - type: Item size: 121 - type: Armor @@ -106,6 +108,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: Item size: 80 diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml index aecb23c992..f229c10a10 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml @@ -24,6 +24,7 @@ - type: ClothingSpeedModifier walkModifier: 0.80 sprintModifier: 0.80 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitBasic @@ -57,6 +58,7 @@ - type: ClothingSpeedModifier walkModifier: 0.7 sprintModifier: 0.7 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitAtmos - type: ReverseEngineering # Nyano @@ -95,6 +97,7 @@ - type: ClothingSpeedModifier walkModifier: 0.7 sprintModifier: 0.7 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitEngineering @@ -123,6 +126,7 @@ - type: ClothingSpeedModifier walkModifier: 0.9 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitSpatio @@ -153,6 +157,7 @@ - type: ClothingSpeedModifier walkModifier: 0.75 sprintModifier: 0.75 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitSalvage @@ -182,6 +187,7 @@ - type: ClothingSpeedModifier walkModifier: 0.75 sprintModifier: 0.75 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitSecurity @@ -208,6 +214,7 @@ - type: ClothingSpeedModifier walkModifier: 0.65 sprintModifier: 0.65 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitBrigmedic @@ -237,6 +244,7 @@ - type: ClothingSpeedModifier walkModifier: 0.7 sprintModifier: 0.7 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitWarden @@ -268,6 +276,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitCap @@ -299,6 +308,7 @@ - type: ClothingSpeedModifier walkModifier: 0.75 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitEngineeringWhite @@ -323,6 +333,7 @@ - type: ClothingSpeedModifier walkModifier: 0.9 sprintModifier: 0.95 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitMedical @@ -354,6 +365,7 @@ - type: ClothingSpeedModifier walkModifier: 0.75 sprintModifier: 0.75 + - type: HeldSpeedModifier - type: Item size: 50 - type: Tag @@ -392,6 +404,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitSecurityRed @@ -422,6 +435,7 @@ - type: ClothingSpeedModifier walkModifier: 0.85 sprintModifier: 0.9 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitLuxury @@ -454,6 +468,7 @@ - type: ClothingSpeedModifier walkModifier: 0.9 sprintModifier: 0.9 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitSyndie - type: ReverseEngineering # Nyano @@ -506,6 +521,7 @@ - type: ClothingSpeedModifier walkModifier: 1.0 sprintModifier: 1.0 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitSyndieElite @@ -537,6 +553,7 @@ - type: ClothingSpeedModifier walkModifier: 1.0 sprintModifier: 1.0 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitSyndieCommander @@ -568,6 +585,7 @@ - type: ClothingSpeedModifier walkModifier: 0.9 sprintModifier: 0.65 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitCybersun @@ -599,6 +617,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitWizard @@ -628,6 +647,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitLing @@ -657,6 +677,7 @@ - type: ClothingSpeedModifier walkModifier: 0.6 sprintModifier: 0.6 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitPirateEVA - type: StaticPrice @@ -689,6 +710,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitPirateCap - type: StaticPrice @@ -795,6 +817,7 @@ - type: ClothingSpeedModifier walkModifier: 1.0 sprintModifier: 1.0 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitDeathsquad @@ -830,6 +853,7 @@ - type: ClothingSpeedModifier walkModifier: 1.0 sprintModifier: 1.0 + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetCBURN @@ -863,5 +887,6 @@ # - type: Construction # DeltaV - Prevent clowns from making the hardsuit # graph: ClownHardsuit # node: clownHardsuit + - type: HeldSpeedModifier - type: ToggleableClothing clothingPrototype: ClothingHeadHelmetHardsuitClown diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/softsuits.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/softsuits.yml index 3d0adacf7e..e46db13bd2 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/softsuits.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/softsuits.yml @@ -44,6 +44,7 @@ - type: ClothingSpeedModifier walkModifier: 0.5 sprintModifier: 0.5 + - type: HeldSpeedModifier - type: TemperatureProtection coefficient: 0.5 - type: ToggleableClothing @@ -83,6 +84,7 @@ - type: ClothingSpeedModifier walkModifier: 0.85 sprintModifier: 0.85 + - type: HeldSpeedModifier #Paramedic Voidsuit #Despite having resistances and looking like one, this is two-piece and parents off the EVA suit so it goes here. @@ -102,6 +104,7 @@ - type: ClothingSpeedModifier walkModifier: 0.9 sprintModifier: 0.9 + - type: HeldSpeedModifier - type: TemperatureProtection coefficient: 0.1 - type: Armor diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml index 16bef8c7b2..dc334de7f3 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml @@ -46,6 +46,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.7 + - type: HeldSpeedModifier - type: GroupExamine - type: entity @@ -72,6 +73,7 @@ - type: ClothingSpeedModifier walkModifier: 0.8 sprintModifier: 0.8 + - type: HeldSpeedModifier - type: GroupExamine - type: entity