PolymorphSystem.Trigger.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Content.Shared.Polymorph;
  2. using Content.Server.Polymorph.Components;
  3. using Content.Server.Explosion.EntitySystems;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Server.Polymorph.Systems;
  6. public sealed partial class PolymorphSystem
  7. {
  8. /// <summary>
  9. /// Need to do this so we don't get a collection enumeration error in physics by polymorphing
  10. /// an entity we're colliding with in case of TriggerOnCollide.
  11. /// Also makes sure other trigger effects don't activate in nullspace after we have polymorphed.
  12. /// </summary>
  13. private Queue<(EntityUid Ent, ProtoId<PolymorphPrototype> Polymorph)> _queuedPolymorphUpdates = new();
  14. private void InitializeTrigger()
  15. {
  16. SubscribeLocalEvent<PolymorphOnTriggerComponent, TriggerEvent>(OnTrigger);
  17. }
  18. private void OnTrigger(Entity<PolymorphOnTriggerComponent> ent, ref TriggerEvent args)
  19. {
  20. if (args.User == null)
  21. return;
  22. _queuedPolymorphUpdates.Enqueue((args.User.Value, ent.Comp.Polymorph));
  23. args.Handled = true;
  24. }
  25. public void UpdateTrigger()
  26. {
  27. while (_queuedPolymorphUpdates.TryDequeue(out var data))
  28. {
  29. if (TerminatingOrDeleted(data.Item1))
  30. continue;
  31. PolymorphEntity(data.Item1, data.Item2);
  32. }
  33. }
  34. }