PyroclasticAnomalySystem.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Content.Server.Atmos.Components;
  2. using Content.Server.Atmos.EntitySystems;
  3. using Content.Shared.Anomaly.Components;
  4. using Content.Shared.Anomaly.Effects.Components;
  5. using Robust.Shared.Map;
  6. namespace Content.Server.Anomaly.Effects;
  7. /// <summary>
  8. /// This handles <see cref="PyroclasticAnomalyComponent"/> and the events from <seealso cref="AnomalySystem"/>
  9. /// </summary>
  10. public sealed class PyroclasticAnomalySystem : EntitySystem
  11. {
  12. [Dependency] private readonly EntityLookupSystem _lookup = default!;
  13. [Dependency] private readonly FlammableSystem _flammable = default!;
  14. /// <inheritdoc/>
  15. public override void Initialize()
  16. {
  17. SubscribeLocalEvent<PyroclasticAnomalyComponent, AnomalyPulseEvent>(OnPulse);
  18. SubscribeLocalEvent<PyroclasticAnomalyComponent, AnomalySupercriticalEvent>(OnSupercritical);
  19. }
  20. private void OnPulse(EntityUid uid, PyroclasticAnomalyComponent component, ref AnomalyPulseEvent args)
  21. {
  22. var xform = Transform(uid);
  23. var ignitionRadius = component.MaximumIgnitionRadius * args.Stability * args.PowerModifier;
  24. IgniteNearby(uid, xform.Coordinates, args.Severity, ignitionRadius);
  25. }
  26. private void OnSupercritical(EntityUid uid, PyroclasticAnomalyComponent component, ref AnomalySupercriticalEvent args)
  27. {
  28. var xform = Transform(uid);
  29. IgniteNearby(uid, xform.Coordinates, 1, component.MaximumIgnitionRadius * 2 * args.PowerModifier);
  30. }
  31. public void IgniteNearby(EntityUid uid, EntityCoordinates coordinates, float severity, float radius)
  32. {
  33. var flammables = new HashSet<Entity<FlammableComponent>>();
  34. _lookup.GetEntitiesInRange(coordinates, radius, flammables);
  35. foreach (var flammable in flammables)
  36. {
  37. var ent = flammable.Owner;
  38. var stackAmount = 1 + (int) (severity / 0.15f);
  39. _flammable.AdjustFireStacks(ent, stackAmount, flammable);
  40. _flammable.Ignite(ent, uid, flammable);
  41. }
  42. }
  43. }