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]
|
[ViewVariables(VVAccess.ReadWrite), DataField("EyeDamage"), AutoNetworkedField]
|
||||||
public int EyeDamage = 0;
|
public int EyeDamage = 0;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadOnly), DataField]
|
||||||
public const int MaxDamage = 9;
|
public const int MaxDamage = 9;
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadOnly), DataField]
|
||||||
|
public int MinDamage = 0;
|
||||||
|
|
||||||
/// <description>
|
/// <description>
|
||||||
/// Used to ensure that this doesn't break with sandbox or admin tools.
|
/// Used to ensure that this doesn't break with sandbox or admin tools.
|
||||||
/// This is not "enabled/disabled".
|
/// This is not "enabled/disabled".
|
||||||
|
|||||||
@@ -62,13 +62,31 @@ public sealed class BlindableSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
blindable.Comp.EyeDamage += amount;
|
blindable.Comp.EyeDamage += amount;
|
||||||
blindable.Comp.EyeDamage = Math.Clamp(blindable.Comp.EyeDamage, 0, BlindableComponent.MaxDamage);
|
UpdateEyeDamage(blindable, true);
|
||||||
Dirty(blindable);
|
}
|
||||||
UpdateIsBlind(blindable);
|
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);
|
var ev = new EyeDamageChangedEvent(blindable.Comp.EyeDamage);
|
||||||
RaiseLocalEvent(blindable.Owner, ref ev);
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -8,5 +8,7 @@ namespace Content.Shared.Traits.Assorted;
|
|||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
public sealed partial class PermanentBlindnessComponent : Component
|
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/>
|
/// <inheritdoc/>
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<PermanentBlindnessComponent, ComponentStartup>(OnStartup);
|
SubscribeLocalEvent<PermanentBlindnessComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<PermanentBlindnessComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<PermanentBlindnessComponent, ComponentShutdown>(OnShutdown);
|
||||||
SubscribeLocalEvent<PermanentBlindnessComponent, EyeDamageChangedEvent>(OnDamageChanged);
|
|
||||||
SubscribeLocalEvent<PermanentBlindnessComponent, ExaminedEvent>(OnExamined);
|
SubscribeLocalEvent<PermanentBlindnessComponent, ExaminedEvent>(OnExamined);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExamined(Entity<PermanentBlindnessComponent> blindness, ref ExaminedEvent args)
|
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))));
|
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);
|
_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))
|
if (!_entityManager.TryGetComponent<BlindableComponent>(blindness, out var blindable))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var damageToDeal = (int) BlurryVisionComponent.MaxMagnitude - blindable.EyeDamage;
|
if (blindness.Comp.Blindness != 0)
|
||||||
|
_blinding.SetMinDamage(new Entity<BlindableComponent?>(blindness.Owner, blindable), blindness.Comp.Blindness);
|
||||||
if (damageToDeal <= 0)
|
else
|
||||||
return;
|
{
|
||||||
|
var maxMagnitudeInt = (int) BlurryVisionComponent.MaxMagnitude;
|
||||||
_blinding.AdjustEyeDamage(blindness.Owner, damageToDeal);
|
_blinding.SetMinDamage(new Entity<BlindableComponent?>(blindness.Owner, blindable), maxMagnitudeInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
trait-blindness-name = Blindness
|
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-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-name = Narcolepsy
|
||||||
trait-narcolepsy-desc = You fall asleep randomly
|
trait-narcolepsy-desc = You fall asleep randomly
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,18 @@
|
|||||||
components:
|
components:
|
||||||
- type: PermanentBlindness
|
- 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
|
- type: trait
|
||||||
id: Narcolepsy
|
id: Narcolepsy
|
||||||
name: trait-narcolepsy-name
|
name: trait-narcolepsy-name
|
||||||
|
|||||||
Reference in New Issue
Block a user