]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Impaired Mobility Disability (#39398)
authorMora <46364955+TrixxedHeart@users.noreply.github.com>
Thu, 21 Aug 2025 00:43:06 +0000 (16:43 -0800)
committerGitHub <noreply@github.com>
Thu, 21 Aug 2025 00:43:06 +0000 (17:43 -0700)
* Implements mobility impairment

* Implements mobility impairment

* Implements mobility impairment

* Removed white cane related stuff (impaired cane replacement and removed mobility aid component)

* fix development.toml

* Implements slower standing

* Prevent speed stacking by checking if the entity is already holding a mobility aid

* Move all speed handling into ImpairedMobilitySystem, added comments, made it so wielding a mobility aid doesn't grant the recovery benefit

* Move all speed handling into ImpairedMobilitySystem, added comments, made it so wielding a mobility aid doesn't grant the recovery benefit

* remove unused file

* Shorten description

* Apply suggestions

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
* Suggestion cleanup

* formatting fix and removed extra datafield stuff

* added comment, fixed slashes, yadda yadda

* summary comments

* removed a word

* Add trait to clone whitelist

* Fix clone.yml

* my own review

---------

Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
Co-authored-by: ScarKy0 <scarky0@onet.eu>
Content.Shared/Traits/Assorted/ImpairedMobilityComponent.cs [new file with mode: 0644]
Content.Shared/Traits/Assorted/ImpairedMobilitySystem.cs [new file with mode: 0644]
Content.Shared/Traits/Assorted/MobilityAidComponent.cs [new file with mode: 0644]
Content.Shared/Traits/Assorted/MobilityAidSystem.cs [new file with mode: 0644]
Resources/Locale/en-US/traits/traits.ftl
Resources/Prototypes/Entities/Mobs/Player/clone.yml
Resources/Prototypes/Entities/Objects/Weapons/Melee/cane.yml
Resources/Prototypes/Entities/Objects/Weapons/Melee/offset_cane.yml
Resources/Prototypes/Entities/Objects/Weapons/Melee/white_cane.yml
Resources/Prototypes/Traits/disabilities.yml

diff --git a/Content.Shared/Traits/Assorted/ImpairedMobilityComponent.cs b/Content.Shared/Traits/Assorted/ImpairedMobilityComponent.cs
new file mode 100644 (file)
index 0000000..50f7281
--- /dev/null
@@ -0,0 +1,25 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Traits.Assorted;
+
+/// <summary>
+/// Used for the Impaired Mobility disability trait.
+/// Applies a base movement speed reduction as determined by the SpeedModifier field.
+/// Also increases the time it takes to stand up after falling, as determined by the StandUpTimeModifier field.
+/// When an entity holds an item with the MobilityAidComponent, the speed penalty is nullified.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class ImpairedMobilityComponent : Component
+{
+    /// <summary>
+    /// The movement speed modifier applied to the player (0.4 is 40% slower)
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float SpeedModifier = 0.4f;
+
+    /// <summary>
+    /// The doAfter modifier when getting up after falling (1.4 is 40% slower)
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float StandUpTimeModifier = 1.4f;
+}
diff --git a/Content.Shared/Traits/Assorted/ImpairedMobilitySystem.cs b/Content.Shared/Traits/Assorted/ImpairedMobilitySystem.cs
new file mode 100644 (file)
index 0000000..678fc85
--- /dev/null
@@ -0,0 +1,70 @@
+using Content.Shared.Movement.Systems;
+using Content.Shared.Stunnable;
+using Content.Shared.Hands.EntitySystems;
+using Content.Shared.Hands.Components;
+using Content.Shared.Wieldable.Components;
+
+namespace Content.Shared.Traits.Assorted;
+
+/// <summary>
+/// Handles <see cref="ImpairedMobilityComponent"/>
+/// </summary>
+public sealed class ImpairedMobilitySystem : EntitySystem
+{
+    [Dependency] private readonly SharedHandsSystem _hands = default!;
+    [Dependency] private readonly MovementSpeedModifierSystem _speedModifier = default!;
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<ImpairedMobilityComponent, ComponentInit>(OnInit);
+        SubscribeLocalEvent<ImpairedMobilityComponent, ComponentShutdown>(OnShutdown);
+        SubscribeLocalEvent<ImpairedMobilityComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeed);
+        SubscribeLocalEvent<ImpairedMobilityComponent, GetStandUpTimeEvent>(OnGetStandUpTime);
+    }
+
+    private void OnInit(Entity<ImpairedMobilityComponent> ent, ref ComponentInit args)
+    {
+        _speedModifier.RefreshMovementSpeedModifiers(ent);
+    }
+
+    private void OnShutdown(Entity<ImpairedMobilityComponent> ent, ref ComponentShutdown args)
+    {
+        _speedModifier.RefreshMovementSpeedModifiers(ent);
+    }
+
+    // Handles movement speed for entities with impaired mobility.
+    // Applies a speed penalty, but counteracts it if the entity is holding a non-wielded mobility aid.
+    private void OnRefreshMovementSpeed(Entity<ImpairedMobilityComponent> ent, ref RefreshMovementSpeedModifiersEvent args)
+    {
+        if (HasMobilityAid(ent.Owner))
+            return;
+
+        args.ModifySpeed(ent.Comp.SpeedModifier);
+    }
+
+    // Increases the time it takes for entities to stand up from being knocked down.
+    private void OnGetStandUpTime(Entity<ImpairedMobilityComponent> ent, ref GetStandUpTimeEvent args)
+    {
+        args.DoAfterTime *= ent.Comp.StandUpTimeModifier;
+    }
+
+    // Checks if the entity is holding any non-wielded mobility aids.
+    private bool HasMobilityAid(Entity<HandsComponent?> entity)
+    {
+        if (!Resolve(entity, ref entity.Comp, false))
+            return false;
+
+        foreach (var held in _hands.EnumerateHeld(entity))
+        {
+            if (!HasComp<MobilityAidComponent>(held))
+                continue;
+
+            // Makes sure it's not wielded yet
+            if (TryComp<WieldableComponent>(held, out var wieldable) && wieldable.Wielded)
+                continue;
+
+            return true;
+        }
+
+        return false;
+    }
+}
diff --git a/Content.Shared/Traits/Assorted/MobilityAidComponent.cs b/Content.Shared/Traits/Assorted/MobilityAidComponent.cs
new file mode 100644 (file)
index 0000000..6623c82
--- /dev/null
@@ -0,0 +1,11 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Traits.Assorted;
+
+/// <summary>
+/// Component to mark items that restore normal movement speed when held in-hand for entities with the impaired mobility trait.
+/// The speed is automatically calculated to nullify the entity's speed penalty.
+/// Should be used on items that act as mobility aids, such as canes.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class MobilityAidComponent : Component;
diff --git a/Content.Shared/Traits/Assorted/MobilityAidSystem.cs b/Content.Shared/Traits/Assorted/MobilityAidSystem.cs
new file mode 100644 (file)
index 0000000..7df47ca
--- /dev/null
@@ -0,0 +1,42 @@
+using Content.Shared.Hands;
+using Content.Shared.Movement.Systems;
+using Content.Shared.Wieldable;
+
+namespace Content.Shared.Traits.Assorted;
+
+/// <summary>
+/// Handles <see cref="MobilityAidComponent"/>
+/// </summary>
+public sealed class MobilityAidSystem : EntitySystem
+{
+    [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<MobilityAidComponent, GotEquippedHandEvent>(OnGotEquippedHand);
+        SubscribeLocalEvent<MobilityAidComponent, GotUnequippedHandEvent>(OnGotUnequippedHand);
+        SubscribeLocalEvent<MobilityAidComponent, ItemWieldedEvent>(OnMobilityAidWielded);
+        SubscribeLocalEvent<MobilityAidComponent, ItemUnwieldedEvent>(OnMobilityAidUnwielded);
+    }
+
+    private void OnGotEquippedHand(Entity<MobilityAidComponent> ent, ref GotEquippedHandEvent args)
+    {
+        _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
+    }
+
+    private void OnGotUnequippedHand(Entity<MobilityAidComponent> ent, ref GotUnequippedHandEvent args)
+    {
+        _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
+    }
+
+    private void OnMobilityAidWielded(Entity<MobilityAidComponent> ent, ref ItemWieldedEvent args)
+    {
+        _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
+    }
+
+    private void OnMobilityAidUnwielded(Entity<MobilityAidComponent> ent, ref ItemUnwieldedEvent args)
+    {
+        _movementSpeedModifier.RefreshMovementSpeedModifiers(args.User);
+    }
+}
index d7ab6ca76a0716b72604578d56ff6b828ed937a4..f4c51d863e066ca5c3dc359c385e26c812dec8af 100644 (file)
@@ -65,3 +65,6 @@ trait-spanish-desc = Hola señor, donde esta la biblioteca.
 
 trait-painnumbness-name = Numb
 trait-painnumbness-desc = You lack any sense of feeling pain, being unaware of how hurt you may be.
+
+trait-impaired-mobility-name = Impaired Mobility
+trait-impaired-mobility-desc = You have difficulty moving without a mobility aid.
index 43174cfffeabdd72dd9c770b0810d054472ea13a..98d99d7321d8975303ba3183e84d8f205461b0ca 100644 (file)
@@ -16,6 +16,7 @@
   # traits
   - BlackAndWhiteOverlay
   - Clumsy
+  - ImpairedMobility
   # - LegsParalyzed (you get healed)
   - LightweightDrunk
   - Muted
index 29ce5fa8c81c37dfe3a615a3cfbffcc18d01834c..96ad8b233d92e64666e079090bd8995165a2af79 100644 (file)
@@ -11,6 +11,7 @@
     size: Normal
     sprite: Objects/Weapons/Melee/cane.rsi
   - type: Appearance
+  - type: MobilityAid
   - type: MeleeWeapon
     wideAnimationRotation: 45
     damage:
index 1d2081fe936ce5b5258ac1276175e6c68e042f66..12e2e9ae704fb953d414a73f33ae8d48f5d9ebaf 100644 (file)
@@ -10,6 +10,7 @@
   - type: Item
     size: Normal
     sprite: Objects/Weapons/Melee/offset_canes/standard.rsi
+  - type: MobilityAid
 #  - type: RandomSprite # Ideally I'd rather these be their own selectable item instead of randomly picked.
 #    available:
 #    - color: "#91949C"  # standard gray
index 997c3771d56a344514a018d2e86c223624cf3109..bba4085295ed0cd83d282333e3cd4987a312c424 100644 (file)
@@ -24,4 +24,3 @@
         Blunt: 3
   - type: UseDelay
     delay: 1
-
index a5c1f54d6b3416e45ee95489c215779c20301f42..0bb6f0da3c647c04804e26662b4ecf7e92ae6ab8 100644 (file)
   category: Disabilities
   components:
   - type: PainNumbness
+
+- type: trait
+  id: ImpairedMobility
+  name: trait-impaired-mobility-name
+  description: trait-impaired-mobility-desc
+  traitGear: OffsetCane
+  category: Disabilities
+  components:
+    - type: ImpairedMobility