]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Adds new "Short-Sighted" trait! (#26037)
authorMoomoobeef <62638182+Moomoobeef@users.noreply.github.com>
Fri, 10 May 2024 01:40:49 +0000 (18:40 -0700)
committerGitHub <noreply@github.com>
Fri, 10 May 2024 01:40:49 +0000 (18:40 -0700)
* initial commit

* blindness trait now uses minDamage as suggested by deathride

* made fixes for review for shortsightedness

* review appeasal

* removed PermanentPoorVision & merged its functionality into PermanentBlindness

Content.Shared/Eye/Blinding/Components/BlindableComponent.cs
Content.Shared/Eye/Blinding/Systems/BlindableSystem.cs
Content.Shared/Traits/Assorted/PermanentBlindnessComponent.cs
Content.Shared/Traits/Assorted/PermanentBlindnessSystem.cs
Resources/Locale/en-US/traits/traits.ftl
Resources/Prototypes/Traits/disabilities.yml

index 4379d309bc4952427b7457180ec1c3123f279f13..39718bd4cf5a6c8e046308deb25fcbcfa750ee4c 100644 (file)
@@ -24,8 +24,12 @@ public sealed partial class BlindableComponent : Component
     [ViewVariables(VVAccess.ReadWrite), DataField("EyeDamage"), AutoNetworkedField]
     public int EyeDamage = 0;
 
+    [ViewVariables(VVAccess.ReadOnly), DataField]
     public const int MaxDamage = 9;
 
+    [ViewVariables(VVAccess.ReadOnly), DataField]
+    public int MinDamage = 0;
+
     /// <description>
     /// Used to ensure that this doesn't break with sandbox or admin tools.
     /// This is not "enabled/disabled".
index 5f24ff20188de224cd1abf218b043fd425a783c5..0232bcf9376309a6e46e81d68a4776fc288ccde6 100644 (file)
@@ -62,13 +62,31 @@ public sealed class BlindableSystem : EntitySystem
             return;
 
         blindable.Comp.EyeDamage += amount;
-        blindable.Comp.EyeDamage = Math.Clamp(blindable.Comp.EyeDamage, 0, BlindableComponent.MaxDamage);
+        UpdateEyeDamage(blindable, true);
+    }
+    private void UpdateEyeDamage(Entity<BlindableComponent?> blindable, bool isDamageChanged)
+    {
+        if (!Resolve(blindable, ref blindable.Comp, false))
+            return;
+
+        var previousDamage = blindable.Comp.EyeDamage;
+        blindable.Comp.EyeDamage = Math.Clamp(blindable.Comp.EyeDamage, blindable.Comp.MinDamage, BlindableComponent.MaxDamage);
         Dirty(blindable);
-        UpdateIsBlind(blindable);
+        if (!isDamageChanged && previousDamage == blindable.Comp.EyeDamage)
+            return;
 
+        UpdateIsBlind(blindable);
         var ev = new EyeDamageChangedEvent(blindable.Comp.EyeDamage);
         RaiseLocalEvent(blindable.Owner, ref ev);
     }
+    public void SetMinDamage(Entity<BlindableComponent?> blindable, int amount)
+    {
+        if (!Resolve(blindable, ref blindable.Comp, false))
+            return;
+
+        blindable.Comp.MinDamage = amount;
+        UpdateEyeDamage(blindable, false);
+    }
 }
 
 /// <summary>
index 76ff3e1005e3fc5299c788346d1a8ff166bf45e2..c1b90b910e1802741367fdee9d6b96625ecde76b 100644 (file)
@@ -8,5 +8,7 @@ namespace Content.Shared.Traits.Assorted;
 [RegisterComponent, NetworkedComponent]
 public sealed partial class PermanentBlindnessComponent : Component
 {
+    [ViewVariables(VVAccess.ReadWrite), DataField]
+    public int Blindness = 0; // How damaged should their eyes be. Set 0 for maximum damage.
 }
 
index 9fd5db849725823b63337781aac4e516ebefcd26..6245118466f5896e9c64e50c5dcc3a806490149b 100644 (file)
@@ -18,15 +18,14 @@ public sealed class PermanentBlindnessSystem : EntitySystem
     /// <inheritdoc/>
     public override void Initialize()
     {
-        SubscribeLocalEvent<PermanentBlindnessComponent, ComponentStartup>(OnStartup);
+        SubscribeLocalEvent<PermanentBlindnessComponent, MapInitEvent>(OnMapInit);
         SubscribeLocalEvent<PermanentBlindnessComponent, ComponentShutdown>(OnShutdown);
-        SubscribeLocalEvent<PermanentBlindnessComponent, EyeDamageChangedEvent>(OnDamageChanged);
         SubscribeLocalEvent<PermanentBlindnessComponent, ExaminedEvent>(OnExamined);
     }
 
     private void OnExamined(Entity<PermanentBlindnessComponent> blindness, ref ExaminedEvent args)
     {
-        if (args.IsInDetailsRange && !_net.IsClient)
+        if (args.IsInDetailsRange && !_net.IsClient && blindness.Comp.Blindness == 0)
         {
             args.PushMarkup(Loc.GetString("permanent-blindness-trait-examined", ("target", Identity.Entity(blindness, EntityManager))));
         }
@@ -37,28 +36,17 @@ public sealed class PermanentBlindnessSystem : EntitySystem
         _blinding.UpdateIsBlind(blindness.Owner);
     }
 
-    private void OnStartup(Entity<PermanentBlindnessComponent> blindness, ref ComponentStartup args)
+    private void OnMapInit(Entity<PermanentBlindnessComponent> blindness, ref MapInitEvent args)
     {
         if (!_entityManager.TryGetComponent<BlindableComponent>(blindness, out var blindable))
             return;
 
-        var damageToDeal = (int) BlurryVisionComponent.MaxMagnitude - blindable.EyeDamage;
-
-        if (damageToDeal <= 0)
-            return;
-
-        _blinding.AdjustEyeDamage(blindness.Owner, damageToDeal);
-    }
-
-    private void OnDamageChanged(Entity<PermanentBlindnessComponent> blindness, ref EyeDamageChangedEvent args)
-    {
-        if (args.Damage >= BlurryVisionComponent.MaxMagnitude)
-            return;
-
-        if (!_entityManager.TryGetComponent<BlindableComponent>(blindness, out var blindable))
-            return;
-
-        var damageRestoration = (int) BlurryVisionComponent.MaxMagnitude - args.Damage;
-        _blinding.AdjustEyeDamage(blindness.Owner, damageRestoration);
+        if (blindness.Comp.Blindness != 0)
+            _blinding.SetMinDamage(new Entity<BlindableComponent?>(blindness.Owner, blindable), blindness.Comp.Blindness);
+        else
+        {
+            var maxMagnitudeInt = (int) BlurryVisionComponent.MaxMagnitude;
+            _blinding.SetMinDamage(new Entity<BlindableComponent?>(blindness.Owner, blindable), maxMagnitudeInt);
+        }
     }
 }
index c387f2975316bf5f26c38230c9a5c4b402861882..cbf65308f3ea4e087fad5696f5af5873b4dd1399 100644 (file)
@@ -1,6 +1,9 @@
 trait-blindness-name = Blindness
 trait-blindness-desc = You are legally blind, and can't see clearly past a few meters in front of you.
 
+trait-poor-vision-name = Short-sighted
+trait-poor-vision-desc = Your eyes are not what they once were, you have difficulty seeing things far away without corrective glasses.
+
 trait-narcolepsy-name = Narcolepsy
 trait-narcolepsy-desc = You fall asleep randomly
 
index 0f785c75c7eccb94950ec51c26ab051197972245..be1e981549c6a2a518b0fddfe80454d866515325 100644 (file)
@@ -9,6 +9,18 @@
   components:
     - type: PermanentBlindness
 
+- type: trait
+  id: PoorVision
+  name: trait-poor-vision-name
+  description: trait-poor-vision-desc
+  traitGear: ClothingEyesGlasses
+  whitelist:
+    components:
+      - Blindable
+  components:
+    - type: PermanentBlindness
+      blindness: 4
+
 - type: trait
   id: Narcolepsy
   name: trait-narcolepsy-name