[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".
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>
[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.
}
/// <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))));
}
_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);
+ }
}
}
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
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