PermanentBlindnessSystem.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Content.Shared.Examine;
  2. using Content.Shared.Eye.Blinding.Components;
  3. using Content.Shared.Eye.Blinding.Systems;
  4. using Content.Shared.IdentityManagement;
  5. using Robust.Shared.Network;
  6. namespace Content.Shared.Traits.Assorted;
  7. /// <summary>
  8. /// This handles permanent blindness, both the examine and the actual effect.
  9. /// </summary>
  10. public sealed class PermanentBlindnessSystem : EntitySystem
  11. {
  12. [Dependency] private readonly INetManager _net = default!;
  13. [Dependency] private readonly BlindableSystem _blinding = default!;
  14. /// <inheritdoc/>
  15. public override void Initialize()
  16. {
  17. SubscribeLocalEvent<PermanentBlindnessComponent, MapInitEvent>(OnMapInit);
  18. SubscribeLocalEvent<PermanentBlindnessComponent, ComponentShutdown>(OnShutdown);
  19. SubscribeLocalEvent<PermanentBlindnessComponent, ExaminedEvent>(OnExamined);
  20. }
  21. private void OnExamined(Entity<PermanentBlindnessComponent> blindness, ref ExaminedEvent args)
  22. {
  23. if (args.IsInDetailsRange && !_net.IsClient && blindness.Comp.Blindness == 0)
  24. {
  25. args.PushMarkup(Loc.GetString("permanent-blindness-trait-examined", ("target", Identity.Entity(blindness, EntityManager))));
  26. }
  27. }
  28. private void OnShutdown(Entity<PermanentBlindnessComponent> blindness, ref ComponentShutdown args)
  29. {
  30. if (!TryComp<BlindableComponent>(blindness.Owner, out var blindable))
  31. return;
  32. if (blindable.MinDamage != 0)
  33. {
  34. _blinding.SetMinDamage((blindness.Owner, blindable), 0);
  35. }
  36. }
  37. private void OnMapInit(Entity<PermanentBlindnessComponent> blindness, ref MapInitEvent args)
  38. {
  39. if(!TryComp<BlindableComponent>(blindness.Owner, out var blindable))
  40. return;
  41. if (blindness.Comp.Blindness != 0)
  42. _blinding.SetMinDamage((blindness.Owner, blindable), blindness.Comp.Blindness);
  43. else
  44. {
  45. var maxMagnitudeInt = (int) BlurryVisionComponent.MaxMagnitude;
  46. _blinding.SetMinDamage((blindness.Owner, blindable), maxMagnitudeInt);
  47. }
  48. }
  49. }