1
0

RadiationProtectionSystem.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Content.Server.Radiation.Components;
  2. using Content.Shared.Damage.Components;
  3. using Robust.Shared.Prototypes;
  4. namespace Content.Server.Radiation.EntitySystems;
  5. public sealed class RadiationProtectionSystem : EntitySystem
  6. {
  7. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  8. public override void Initialize()
  9. {
  10. base.Initialize();
  11. SubscribeLocalEvent<RadiationProtectionComponent, ComponentInit>(OnInit);
  12. SubscribeLocalEvent<RadiationProtectionComponent, ComponentShutdown>(OnShutdown);
  13. }
  14. private void OnInit(EntityUid uid, RadiationProtectionComponent component, ComponentInit args)
  15. {
  16. if (!_prototypeManager.TryIndex(component.RadiationProtectionModifierSetId, out var modifier))
  17. return;
  18. var buffComp = EnsureComp<DamageProtectionBuffComponent>(uid);
  19. // add the damage modifier if it isn't in the dict yet
  20. if (!buffComp.Modifiers.ContainsKey(component.RadiationProtectionModifierSetId))
  21. buffComp.Modifiers.Add(component.RadiationProtectionModifierSetId, modifier);
  22. }
  23. private void OnShutdown(EntityUid uid, RadiationProtectionComponent component, ComponentShutdown args)
  24. {
  25. if (!TryComp<DamageProtectionBuffComponent>(uid, out var buffComp))
  26. return;
  27. // remove the damage modifier from the dict
  28. buffComp.Modifiers.Remove(component.RadiationProtectionModifierSetId);
  29. // if the dict is empty now, remove the buff component
  30. if (buffComp.Modifiers.Count == 0)
  31. RemComp<DamageProtectionBuffComponent>(uid);
  32. }
  33. }