ActionPvsDetachTest.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Linq;
  2. using Content.Shared.Actions;
  3. using Content.Shared.Eye;
  4. using Robust.Server.GameObjects;
  5. using Robust.Shared.GameObjects;
  6. namespace Content.IntegrationTests.Tests.Actions;
  7. [TestFixture]
  8. public sealed class ActionPvsDetachTest
  9. {
  10. [Test]
  11. public async Task TestActionDetach()
  12. {
  13. await using var pair = await PoolManager.GetServerClient(new PoolSettings { Connected = true });
  14. var (server, client) = pair;
  15. var sys = server.System<SharedActionsSystem>();
  16. var cSys = client.System<SharedActionsSystem>();
  17. // Spawn mob that has some actions
  18. EntityUid ent = default;
  19. var map = await pair.CreateTestMap();
  20. await server.WaitPost(() => ent = server.EntMan.SpawnAtPosition("MobHuman", map.GridCoords));
  21. await pair.RunTicksSync(5);
  22. var cEnt = pair.ToClientUid(ent);
  23. // Verify that both the client & server agree on the number of actions
  24. var initActions = sys.GetActions(ent).Count();
  25. Assert.That(initActions, Is.GreaterThan(0));
  26. Assert.That(initActions, Is.EqualTo(cSys.GetActions(cEnt).Count()));
  27. // PVS-detach action entities
  28. // We do this by just giving them the ghost layer
  29. var visSys = server.System<VisibilitySystem>();
  30. server.Post(() =>
  31. {
  32. var enumerator = server.Transform(ent).ChildEnumerator;
  33. while (enumerator.MoveNext(out var child))
  34. {
  35. visSys.AddLayer(child, (int) VisibilityFlags.Ghost);
  36. }
  37. });
  38. await pair.RunTicksSync(5);
  39. // Client's actions have left been detached / are out of view, but action comp state has not changed
  40. Assert.That(sys.GetActions(ent).Count(), Is.EqualTo(initActions));
  41. Assert.That(cSys.GetActions(cEnt).Count(), Is.EqualTo(initActions));
  42. // Re-enter PVS view
  43. server.Post(() =>
  44. {
  45. var enumerator = server.Transform(ent).ChildEnumerator;
  46. while (enumerator.MoveNext(out var child))
  47. {
  48. visSys.RemoveLayer(child, (int) VisibilityFlags.Ghost);
  49. }
  50. });
  51. await pair.RunTicksSync(5);
  52. Assert.That(sys.GetActions(ent).Count(), Is.EqualTo(initActions));
  53. Assert.That(cSys.GetActions(cEnt).Count(), Is.EqualTo(initActions));
  54. await server.WaitPost(() => server.EntMan.DeleteEntity(map.MapUid));
  55. await pair.CleanReturnAsync();
  56. }
  57. }