ArtifactDamageTriggerSystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components;
  2. using Content.Shared.Damage;
  3. namespace Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems;
  4. public sealed class ArtifactDamageTriggerSystem : EntitySystem
  5. {
  6. [Dependency] private readonly ArtifactSystem _artifact = default!;
  7. /// <inheritdoc/>
  8. public override void Initialize()
  9. {
  10. SubscribeLocalEvent<ArtifactDamageTriggerComponent, DamageChangedEvent>(OnDamageChanged);
  11. }
  12. private void OnDamageChanged(EntityUid uid, ArtifactDamageTriggerComponent component, DamageChangedEvent args)
  13. {
  14. if (!args.DamageIncreased)
  15. return;
  16. if (args.DamageDelta == null)
  17. return;
  18. foreach (var (type, amount) in args.DamageDelta.DamageDict)
  19. {
  20. if (component.DamageTypes != null && !component.DamageTypes.Contains(type))
  21. continue;
  22. component.AccumulatedDamage += (float) amount;
  23. }
  24. if (component.AccumulatedDamage >= component.DamageThreshold)
  25. _artifact.TryActivateArtifact(uid, args.Origin);
  26. }
  27. }