From 1699ddecf8bec31a6c05b8fe13367f57a67da5d1 Mon Sep 17 00:00:00 2001 From: Moomoobeef <62638182+Moomoobeef@users.noreply.github.com> Date: Thu, 9 May 2024 18:40:49 -0700 Subject: [PATCH] Adds new "Short-Sighted" trait! (#26037) * 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 --- .../Blinding/Components/BlindableComponent.cs | 4 +++ .../Eye/Blinding/Systems/BlindableSystem.cs | 22 +++++++++++-- .../Assorted/PermanentBlindnessComponent.cs | 2 ++ .../Assorted/PermanentBlindnessSystem.cs | 32 ++++++------------- Resources/Locale/en-US/traits/traits.ftl | 3 ++ Resources/Prototypes/Traits/disabilities.yml | 12 +++++++ 6 files changed, 51 insertions(+), 24 deletions(-) diff --git a/Content.Shared/Eye/Blinding/Components/BlindableComponent.cs b/Content.Shared/Eye/Blinding/Components/BlindableComponent.cs index 4379d309bc..39718bd4cf 100644 --- a/Content.Shared/Eye/Blinding/Components/BlindableComponent.cs +++ b/Content.Shared/Eye/Blinding/Components/BlindableComponent.cs @@ -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; + /// /// Used to ensure that this doesn't break with sandbox or admin tools. /// This is not "enabled/disabled". diff --git a/Content.Shared/Eye/Blinding/Systems/BlindableSystem.cs b/Content.Shared/Eye/Blinding/Systems/BlindableSystem.cs index 5f24ff2018..0232bcf937 100644 --- a/Content.Shared/Eye/Blinding/Systems/BlindableSystem.cs +++ b/Content.Shared/Eye/Blinding/Systems/BlindableSystem.cs @@ -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 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 blindable, int amount) + { + if (!Resolve(blindable, ref blindable.Comp, false)) + return; + + blindable.Comp.MinDamage = amount; + UpdateEyeDamage(blindable, false); + } } /// diff --git a/Content.Shared/Traits/Assorted/PermanentBlindnessComponent.cs b/Content.Shared/Traits/Assorted/PermanentBlindnessComponent.cs index 76ff3e1005..c1b90b910e 100644 --- a/Content.Shared/Traits/Assorted/PermanentBlindnessComponent.cs +++ b/Content.Shared/Traits/Assorted/PermanentBlindnessComponent.cs @@ -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. } diff --git a/Content.Shared/Traits/Assorted/PermanentBlindnessSystem.cs b/Content.Shared/Traits/Assorted/PermanentBlindnessSystem.cs index 9fd5db8497..6245118466 100644 --- a/Content.Shared/Traits/Assorted/PermanentBlindnessSystem.cs +++ b/Content.Shared/Traits/Assorted/PermanentBlindnessSystem.cs @@ -18,15 +18,14 @@ public sealed class PermanentBlindnessSystem : EntitySystem /// public override void Initialize() { - SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnShutdown); - SubscribeLocalEvent(OnDamageChanged); SubscribeLocalEvent(OnExamined); } private void OnExamined(Entity 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 blindness, ref ComponentStartup args) + private void OnMapInit(Entity blindness, ref MapInitEvent args) { if (!_entityManager.TryGetComponent(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 blindness, ref EyeDamageChangedEvent args) - { - if (args.Damage >= BlurryVisionComponent.MaxMagnitude) - return; - - if (!_entityManager.TryGetComponent(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(blindness.Owner, blindable), blindness.Comp.Blindness); + else + { + var maxMagnitudeInt = (int) BlurryVisionComponent.MaxMagnitude; + _blinding.SetMinDamage(new Entity(blindness.Owner, blindable), maxMagnitudeInt); + } } } diff --git a/Resources/Locale/en-US/traits/traits.ftl b/Resources/Locale/en-US/traits/traits.ftl index c387f29753..cbf65308f3 100644 --- a/Resources/Locale/en-US/traits/traits.ftl +++ b/Resources/Locale/en-US/traits/traits.ftl @@ -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 diff --git a/Resources/Prototypes/Traits/disabilities.yml b/Resources/Prototypes/Traits/disabilities.yml index 0f785c75c7..be1e981549 100644 --- a/Resources/Prototypes/Traits/disabilities.yml +++ b/Resources/Prototypes/Traits/disabilities.yml @@ -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 -- 2.51.2