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
This commit is contained in:
@@ -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".
|
||||
|
||||
@@ -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);
|
||||
Dirty(blindable);
|
||||
UpdateIsBlind(blindable);
|
||||
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);
|
||||
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>
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (blindness.Comp.Blindness != 0)
|
||||
_blinding.SetMinDamage(new Entity<BlindableComponent?>(blindness.Owner, blindable), blindness.Comp.Blindness);
|
||||
else
|
||||
{
|
||||
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);
|
||||
var maxMagnitudeInt = (int) BlurryVisionComponent.MaxMagnitude;
|
||||
_blinding.SetMinDamage(new Entity<BlindableComponent?>(blindness.Owner, blindable), maxMagnitudeInt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user