]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Mirror speed penalty for worn duffels and hardsuits when in-hand (#22168)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Thu, 7 Dec 2023 03:41:29 +0000 (22:41 -0500)
committerGitHub <noreply@github.com>
Thu, 7 Dec 2023 03:41:29 +0000 (20:41 -0700)
* Add speed penalty for holding hardsuits and duffels

* just inherit from ClothingSpeedModifier

* comment godo

Content.Shared/Hands/EntitySystems/SharedHandsSystem.Relay.cs [new file with mode: 0644]
Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs
Content.Shared/Hands/HandEvents.cs
Content.Shared/Item/HeldSpeedModifierComponent.cs [new file with mode: 0644]
Content.Shared/Item/HeldSpeedModifierSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Clothing/Back/duffel.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/base_clothingouter.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/hardsuits.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/softsuits.yml
Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml

diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Relay.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Relay.cs
new file mode 100644 (file)
index 0000000..9e8e0fa
--- /dev/null
@@ -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<HandsComponent, RefreshMovementSpeedModifiersEvent>(RelayEvent);
+    }
+
+    private void RelayEvent<T>(Entity<HandsComponent> entity, ref T args) where T : EntityEventArgs
+    {
+        var ev = new HeldRelayedEvent<T>(args);
+        foreach (var held in EnumerateHeld(entity, entity.Comp))
+        {
+            RaiseLocalEvent(held, ref ev);
+        }
+    }
+}
index 6b786fdfaa83227db132b2715097460bd3aeedd3..4f34d6fc5403ae1ba66ddfe6f39fff28e31fd8b0 100644 (file)
@@ -31,6 +31,7 @@ public abstract partial class SharedHandsSystem
         InitializeDrop();
         InitializePickup();
         InitializeVirtual();
+        InitializeRelay();
     }
 
     public override void Shutdown()
index 059728ff4dd09a81d62345d5aa95de3ee9aa9d34..0499c05f4261af5ba9a8210691b0bfabc8cb7fb1 100644 (file)
@@ -319,4 +319,15 @@ namespace Content.Shared.Hands
 
         public EntityUid Sender { get; }
     }
+
+    [ByRefEvent]
+    public sealed class HeldRelayedEvent<TEvent> : 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 (file)
index 0000000..1fbe743
--- /dev/null
@@ -0,0 +1,34 @@
+using Content.Shared.Clothing;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Item;
+
+/// <summary>
+/// This is used for items that change your speed when they are held.
+/// </summary>
+/// <remarks>
+/// This is separate from <see cref="ClothingSpeedModifierComponent"/> because things like boots increase/decrease speed when worn, but
+/// shouldn't do that when just held in hand.
+/// </remarks>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(HeldSpeedModifierSystem))]
+public sealed partial class HeldSpeedModifierComponent : Component
+{
+    /// <summary>
+    /// A multiplier applied to the walk speed.
+    /// </summary>
+    [DataField] [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+    public float WalkModifier = 1.0f;
+
+    /// <summary>
+    /// A multiplier applied to the sprint speed.
+    /// </summary>
+    [DataField] [ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
+    public float SprintModifier = 1.0f;
+
+    /// <summary>
+    /// If true, values from <see cref="ClothingSpeedModifierComponent"/> will attempted to be used before the ones in this component.
+    /// </summary>
+    [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 (file)
index 0000000..d7afa8f
--- /dev/null
@@ -0,0 +1,44 @@
+using Content.Shared.Clothing;
+using Content.Shared.Hands;
+using Content.Shared.Movement.Systems;
+
+namespace Content.Shared.Item;
+
+/// <summary>
+/// This handles <see cref="HeldSpeedModifierComponent"/>
+/// </summary>
+public sealed class HeldSpeedModifierSystem : EntitySystem
+{
+    [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<HeldSpeedModifierComponent, GotEquippedHandEvent>(OnGotEquippedHand);
+        SubscribeLocalEvent<HeldSpeedModifierComponent, GotUnequippedHandEvent>(OnGotUnequippedHand);
+        SubscribeLocalEvent<HeldSpeedModifierComponent, HeldRelayedEvent<RefreshMovementSpeedModifiersEvent>>(OnRefreshMovementSpeedModifiers);
+    }
+
+    private void OnGotEquippedHand(Entity<HeldSpeedModifierComponent> ent, ref GotEquippedHandEvent args)
+    {
+        _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
+    }
+
+    private void OnGotUnequippedHand(Entity<HeldSpeedModifierComponent> ent, ref GotUnequippedHandEvent args)
+    {
+        _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
+    }
+
+    private void OnRefreshMovementSpeedModifiers(EntityUid uid, HeldSpeedModifierComponent component, HeldRelayedEvent<RefreshMovementSpeedModifiersEvent> args)
+    {
+        var walkMod = component.WalkModifier;
+        var sprintMod = component.SprintModifier;
+        if (component.MirrorClothingModifier && TryComp<ClothingSpeedModifierComponent>(uid, out var clothingSpeedModifier))
+        {
+            walkMod = clothingSpeedModifier.WalkModifier;
+            sprintMod = clothingSpeedModifier.SprintModifier;
+        }
+
+        args.Args.ModifySpeed(walkMod, sprintMod);
+    }
+}
index 9a2c3f62f36f8827f01e517ab4c93777a4ad68f8..ca1281eb9d66c4ed268db0e6a95d263074169180 100644 (file)
@@ -13,6 +13,7 @@
   - type: ClothingSpeedModifier
     walkModifier: 1
     sprintModifier: 0.9
+  - type: HeldSpeedModifier
 
 - type: entity
   parent: ClothingBackpackDuffel
     - 0,0,19,9
   - type: ClothingSpeedModifier
     sprintModifier: 1 # makes its stats identical to other variants of bag of holding
+  - type: HeldSpeedModifier
 
 - type: entity
   parent: ClothingBackpackDuffel
   - type: ClothingSpeedModifier
     walkModifier: 1
     sprintModifier: 1
+  - type: HeldSpeedModifier
index 84db1e8e8ba8ffddc5e8713deebebe2b1de6a9a4..fdaee45ccc8f2bc8524849d48a80b16c1d21e938 100644 (file)
   - type: ClothingSpeedModifier
     walkModifier: 1.0
     sprintModifier: 1.0
+  - type: HeldSpeedModifier
   - type: ExplosionResistance
     damageCoefficient: 0.65
   - type: GroupExamine
   - type: ClothingSpeedModifier
     walkModifier: 0.7
     sprintModifier: 0.65
+  - type: HeldSpeedModifier
   - type: ExplosionResistance
     damageCoefficient: 0.5
   - type: GroupExamine
         Piercing: 0.4
   - type: ClothingSpeedModifier
     walkModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ExplosionResistance
     damageCoefficient: 0.4
   - type: GroupExamine
index 4fbdc88526d8123c3265055c4b90c554e42bc903..38c1fa11260a2290f1c04d12a6f3c5c37d61c429 100644 (file)
@@ -22,6 +22,7 @@
   - type: ClothingSpeedModifier
     walkModifier: 0.9
     sprintModifier: 0.9
+  - type: HeldSpeedModifier
 
 - type: entity
   abstract: true
@@ -70,6 +71,7 @@
   - type: ClothingSpeedModifier
     walkModifier: 0.4
     sprintModifier: 0.6
+  - type: HeldSpeedModifier
   - type: Item
     size: Ginormous
   - type: Armor
   - type: ClothingSpeedModifier
     walkModifier: 0.8
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: Item
     size: Huge
 
index e71c503e9290276b88ad5ae6a85163fee79639e3..f65ecc08775fa1ab67a4dd284f01f4fbdd426256 100644 (file)
@@ -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
 
@@ -90,6 +92,7 @@
   - type: ClothingSpeedModifier
     walkModifier: 0.7
     sprintModifier: 0.7
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitEngineering
 
   - type: ClothingSpeedModifier
     walkModifier: 0.9
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitSpatio
 
   - type: ClothingSpeedModifier
     walkModifier: 0.75
     sprintModifier: 0.75
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitSalvage
 
   - type: ClothingSpeedModifier
     walkModifier: 0.75
     sprintModifier: 0.75
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitSecurity
 
   - type: ClothingSpeedModifier
     walkModifier: 0.65
     sprintModifier: 0.65
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitBrigmedic
 
   - type: ClothingSpeedModifier
     walkModifier: 0.7
     sprintModifier: 0.7
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitWarden
 
   - type: ClothingSpeedModifier
     walkModifier: 0.8
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitCap
 
   - type: ClothingSpeedModifier
     walkModifier: 0.75
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitEngineeringWhite
 
   - type: ClothingSpeedModifier
     walkModifier: 0.9
     sprintModifier: 0.95
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitMedical
 
   - type: ClothingSpeedModifier
     walkModifier: 0.75
     sprintModifier: 0.75
+  - type: HeldSpeedModifier
   - type: Item
     size: Normal
   - type: Tag
   - type: ClothingSpeedModifier
     walkModifier: 0.8
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitSecurityRed
 
   - type: ClothingSpeedModifier
     walkModifier: 0.85
     sprintModifier: 0.9
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitLuxury
 
   - type: ClothingSpeedModifier
     walkModifier: 0.9
     sprintModifier: 0.9
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitSyndie
 
   - type: ClothingSpeedModifier
     walkModifier: 1.0
     sprintModifier: 1.0
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitSyndieElite
 
   - type: ClothingSpeedModifier
     walkModifier: 1.0
     sprintModifier: 1.0
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitSyndieCommander
 
   - type: ClothingSpeedModifier
     walkModifier: 0.9
     sprintModifier: 0.65
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitCybersun
 
   - type: ClothingSpeedModifier
     walkModifier: 0.8
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitWizard
 
   - type: ClothingSpeedModifier
     walkModifier: 0.8
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitLing
 
   - type: ClothingSpeedModifier
     walkModifier: 0.6
     sprintModifier: 0.6
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitPirateEVA
   - type: StaticPrice
   - type: ClothingSpeedModifier
     walkModifier: 0.8
     sprintModifier: 0.8
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitPirateCap
   - type: StaticPrice
   - type: ClothingSpeedModifier
     walkModifier: 1.0
     sprintModifier: 1.0
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetHardsuitDeathsquad
 
   - type: ClothingSpeedModifier
     walkModifier: 1.0
     sprintModifier: 1.0
+  - type: HeldSpeedModifier
   - type: ToggleableClothing
     clothingPrototype: ClothingHeadHelmetCBURN
 
   - type: ClothingSpeedModifier
     walkModifier: 0.9
     sprintModifier: 0.9
+  - type: HeldSpeedModifier
   - type: Construction
     graph: ClownHardsuit
     node: clownHardsuit
index 3d0adacf7e71bd6bddb6f81f6607fa9fef337197..e46db13bd29cbb4a09f4e7f79e5c681a19444056 100644 (file)
@@ -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.
   - type: ClothingSpeedModifier
     walkModifier: 0.9
     sprintModifier: 0.9
+  - type: HeldSpeedModifier
   - type: TemperatureProtection
     coefficient: 0.1
   - type: Armor
index f0aa96f613d390262304a810eeca309b27fcee12..57d100fd9a44ae248658e4b8c0f3fc20d3d10485 100644 (file)
@@ -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