1
0

IgnitionSourceSystem.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Content.Server.Atmos.EntitySystems;
  2. using Content.Shared.IgnitionSource;
  3. using Content.Shared.Item.ItemToggle.Components;
  4. using Content.Shared.Temperature;
  5. using Robust.Server.GameObjects;
  6. namespace Content.Server.IgnitionSource;
  7. /// <summary>
  8. /// This handles ignition, Jez basically coded this.
  9. /// </summary>
  10. public sealed class IgnitionSourceSystem : EntitySystem
  11. {
  12. [Dependency] private readonly AtmosphereSystem _atmosphere = default!;
  13. [Dependency] private readonly TransformSystem _transform = default!;
  14. public override void Initialize()
  15. {
  16. base.Initialize();
  17. SubscribeLocalEvent<IgnitionSourceComponent, IsHotEvent>(OnIsHot);
  18. SubscribeLocalEvent<ItemToggleHotComponent, ItemToggledEvent>(OnItemToggle);
  19. SubscribeLocalEvent<IgnitionSourceComponent, IgnitionEvent>(OnIgnitionEvent);
  20. }
  21. private void OnIsHot(Entity<IgnitionSourceComponent> ent, ref IsHotEvent args)
  22. {
  23. args.IsHot = ent.Comp.Ignited;
  24. }
  25. private void OnItemToggle(Entity<ItemToggleHotComponent> ent, ref ItemToggledEvent args)
  26. {
  27. if (TryComp<IgnitionSourceComponent>(ent, out var comp))
  28. SetIgnited((ent.Owner, comp), args.Activated);
  29. }
  30. private void OnIgnitionEvent(Entity<IgnitionSourceComponent> ent, ref IgnitionEvent args)
  31. {
  32. SetIgnited((ent.Owner, ent.Comp), args.Ignite);
  33. }
  34. /// <summary>
  35. /// Simply sets the ignited field to the ignited param.
  36. /// </summary>
  37. public void SetIgnited(Entity<IgnitionSourceComponent?> ent, bool ignited = true)
  38. {
  39. if (!Resolve(ent, ref ent.Comp, false))
  40. return;
  41. ent.Comp.Ignited = ignited;
  42. }
  43. public override void Update(float frameTime)
  44. {
  45. base.Update(frameTime);
  46. var query = EntityQueryEnumerator<IgnitionSourceComponent, TransformComponent>();
  47. while (query.MoveNext(out var uid, out var comp, out var xform))
  48. {
  49. if (!comp.Ignited)
  50. continue;
  51. if (xform.GridUid is { } gridUid)
  52. {
  53. var position = _transform.GetGridOrMapTilePosition(uid, xform);
  54. _atmosphere.HotspotExpose(gridUid, position, comp.Temperature, 50, uid, true);
  55. }
  56. }
  57. }
  58. }