InteractionTestSystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections.Generic;
  2. using Content.Server.Construction;
  3. using Content.Shared.Construction;
  4. using Robust.Shared.GameObjects;
  5. namespace Content.IntegrationTests.Tests.Interaction;
  6. /// <summary>
  7. /// System for listening to events that get raised when construction entities change.
  8. /// In particular, when construction ghosts become real entities, and when existing entities get replaced with
  9. /// new ones.
  10. /// </summary>
  11. public sealed class InteractionTestSystem : EntitySystem
  12. {
  13. public Dictionary<int, NetEntity> Ghosts = new();
  14. public Dictionary<NetEntity, NetEntity> EntChanges = new();
  15. public override void Initialize()
  16. {
  17. SubscribeNetworkEvent<AckStructureConstructionMessage>(OnAck);
  18. SubscribeLocalEvent<ConstructionChangeEntityEvent>(OnEntChange);
  19. }
  20. private void OnEntChange(ConstructionChangeEntityEvent ev)
  21. {
  22. Assert.That(!IsClientSide(ev.Old) && !IsClientSide(ev.New));
  23. EntChanges[GetNetEntity(ev.Old)] = GetNetEntity(ev.New);
  24. }
  25. private void OnAck(AckStructureConstructionMessage ev)
  26. {
  27. if (ev.Uid != null)
  28. Ghosts[ev.GhostId] = ev.Uid.Value;
  29. }
  30. }