2024-01-12 23:22:01 +01:00
|
|
|
using System.Linq;
|
2023-08-25 18:50:46 +10:00
|
|
|
using Content.Shared.Ghost;
|
2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Mind;
|
2023-06-20 16:29:26 +12:00
|
|
|
using Robust.Server.Player;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests.Minds;
|
|
|
|
|
|
|
|
|
|
public sealed partial class MindTests
|
|
|
|
|
{
|
|
|
|
|
// This test will do the following:
|
|
|
|
|
// - attach a player to a ghost (not visiting)
|
|
|
|
|
// - disconnect
|
|
|
|
|
// - reconnect
|
|
|
|
|
// - assert that they spawned in as a new entity
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestGhostsCanReconnect()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await SetupPair();
|
2023-06-20 16:29:26 +12:00
|
|
|
var entMan = pair.Server.ResolveDependency<IEntityManager>();
|
|
|
|
|
var mind = GetMind(pair);
|
|
|
|
|
|
|
|
|
|
var ghost = await BecomeGhost(pair);
|
|
|
|
|
await DisconnectReconnect(pair);
|
|
|
|
|
|
2023-06-21 13:04:07 +12:00
|
|
|
// Player in control of a new ghost, but with the same mind
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(GetMind(pair), Is.EqualTo(mind));
|
|
|
|
|
Assert.That(entMan.Deleted(ghost));
|
2023-08-28 16:53:24 -07:00
|
|
|
Assert.That(entMan.HasComponent<GhostComponent>(mind.Comp.OwnedEntity));
|
|
|
|
|
Assert.That(mind.Comp.VisitingEntity, Is.Null);
|
2023-07-05 21:54:25 -07:00
|
|
|
});
|
2023-06-20 16:29:26 +12:00
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2023-06-20 16:29:26 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This test will do the following:
|
|
|
|
|
// - disconnect a player
|
|
|
|
|
// - delete their original entity
|
|
|
|
|
// - reconnect
|
|
|
|
|
// - assert that they spawned in as a new entity
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestDeletedCanReconnect()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await SetupPair();
|
2023-06-20 16:29:26 +12:00
|
|
|
var entMan = pair.Server.ResolveDependency<IEntityManager>();
|
|
|
|
|
var mind = GetMind(pair);
|
|
|
|
|
|
|
|
|
|
var playerMan = pair.Server.ResolveDependency<IPlayerManager>();
|
2023-10-28 09:59:53 +11:00
|
|
|
var player = playerMan.Sessions.Single();
|
2023-06-20 16:29:26 +12:00
|
|
|
var name = player.Name;
|
|
|
|
|
var user = player.UserId;
|
2023-08-28 16:53:24 -07:00
|
|
|
Assert.That(mind.Comp.OwnedEntity, Is.Not.Null);
|
|
|
|
|
var entity = mind.Comp.OwnedEntity.Value;
|
2023-06-20 16:29:26 +12:00
|
|
|
|
|
|
|
|
// Player is not a ghost
|
2023-08-28 16:53:24 -07:00
|
|
|
Assert.That(!entMan.HasComponent<GhostComponent>(mind.Comp.CurrentEntity));
|
2023-06-20 16:29:26 +12:00
|
|
|
|
|
|
|
|
// Disconnect
|
|
|
|
|
await Disconnect(pair);
|
|
|
|
|
|
|
|
|
|
// Delete entity
|
|
|
|
|
Assert.That(entMan.EntityExists(entity));
|
|
|
|
|
await pair.Server.WaitPost(() => entMan.DeleteEntity(entity));
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(entMan.Deleted(entity));
|
2023-08-28 16:53:24 -07:00
|
|
|
Assert.That(mind.Comp.OwnedEntity, Is.Null);
|
2023-07-05 21:54:25 -07:00
|
|
|
});
|
2023-06-20 16:29:26 +12:00
|
|
|
|
|
|
|
|
// Reconnect
|
|
|
|
|
await Connect(pair, name);
|
2023-10-28 09:59:53 +11:00
|
|
|
player = playerMan.Sessions.Single();
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(user, Is.EqualTo(player.UserId));
|
2023-06-20 16:29:26 +12:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Player is now a new ghost entity
|
|
|
|
|
Assert.That(GetMind(pair), Is.EqualTo(mind));
|
2023-08-28 16:53:24 -07:00
|
|
|
Assert.That(mind.Comp.OwnedEntity, Is.Not.EqualTo(entity));
|
|
|
|
|
Assert.That(entMan.HasComponent<GhostComponent>(mind.Comp.OwnedEntity));
|
2023-07-05 21:54:25 -07:00
|
|
|
});
|
2023-06-20 16:29:26 +12:00
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2023-06-20 16:29:26 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This test will do the following:
|
|
|
|
|
// - visit a ghost
|
|
|
|
|
// - disconnect
|
|
|
|
|
// - reconnect
|
|
|
|
|
// - assert that they return to their original entity
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestVisitingGhostReconnect()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await SetupPair();
|
2023-06-20 16:29:26 +12:00
|
|
|
var entMan = pair.Server.ResolveDependency<IEntityManager>();
|
|
|
|
|
var mind = GetMind(pair);
|
|
|
|
|
|
2023-08-28 16:53:24 -07:00
|
|
|
var original = mind.Comp.CurrentEntity;
|
2023-06-20 16:29:26 +12:00
|
|
|
var ghost = await VisitGhost(pair);
|
|
|
|
|
await DisconnectReconnect(pair);
|
|
|
|
|
|
|
|
|
|
// Player now controls their original mob, mind was preserved
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(mind, Is.EqualTo(GetMind(pair)));
|
2023-08-28 16:53:24 -07:00
|
|
|
Assert.That(mind.Comp.CurrentEntity, Is.EqualTo(original));
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.That(entMan.Deleted(original), Is.False);
|
|
|
|
|
Assert.That(entMan.Deleted(ghost));
|
|
|
|
|
});
|
2023-06-20 16:29:26 +12:00
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2023-06-20 16:29:26 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This test will do the following:
|
|
|
|
|
// - visit a normal (non-ghost) entity,
|
|
|
|
|
// - disconnect
|
|
|
|
|
// - reconnect
|
|
|
|
|
// - assert that they return to the visited entity.
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestVisitingReconnect()
|
|
|
|
|
{
|
2023-11-01 19:56:07 -07:00
|
|
|
await using var pair = await SetupPair(true);
|
2023-06-20 16:29:26 +12:00
|
|
|
var entMan = pair.Server.ResolveDependency<IEntityManager>();
|
2023-08-30 21:46:11 -07:00
|
|
|
var mindSys = entMan.System<SharedMindSystem>();
|
2023-06-20 16:29:26 +12:00
|
|
|
var mind = GetMind(pair);
|
|
|
|
|
|
2024-01-12 23:22:01 +01:00
|
|
|
Assert.That(mind.Comp.VisitingEntity, Is.Null);
|
2023-10-28 09:59:53 +11:00
|
|
|
|
2023-06-20 16:29:26 +12:00
|
|
|
// Make player visit a new mob
|
2023-10-28 09:59:53 +11:00
|
|
|
var original = mind.Comp.OwnedEntity;
|
2023-06-20 16:29:26 +12:00
|
|
|
EntityUid visiting = default;
|
|
|
|
|
await pair.Server.WaitAssertion(() =>
|
|
|
|
|
{
|
2023-06-21 14:11:58 +12:00
|
|
|
visiting = entMan.SpawnEntity(null, MapCoordinates.Nullspace);
|
2023-08-28 16:53:24 -07:00
|
|
|
mindSys.Visit(mind.Id, visiting);
|
2023-06-20 16:29:26 +12:00
|
|
|
});
|
2023-08-25 04:13:11 +02:00
|
|
|
await pair.RunTicksSync(5);
|
2023-06-20 16:29:26 +12:00
|
|
|
|
2023-10-28 09:59:53 +11:00
|
|
|
Assert.That(mind.Comp.VisitingEntity, Is.EqualTo(visiting));
|
2023-06-20 16:29:26 +12:00
|
|
|
await DisconnectReconnect(pair);
|
|
|
|
|
|
|
|
|
|
// Player is back in control of the visited mob, mind was preserved
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(GetMind(pair), Is.EqualTo(mind));
|
|
|
|
|
Assert.That(entMan.Deleted(original), Is.False);
|
|
|
|
|
Assert.That(entMan.Deleted(visiting), Is.False);
|
2023-08-28 16:53:24 -07:00
|
|
|
Assert.That(mind.Comp.CurrentEntity, Is.EqualTo(visiting));
|
2023-07-05 21:54:25 -07:00
|
|
|
});
|
2023-06-20 16:29:26 +12:00
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2023-06-20 16:29:26 +12:00
|
|
|
}
|
2023-10-28 09:59:53 +11:00
|
|
|
|
|
|
|
|
// This test will do the following
|
|
|
|
|
// - connect as a normal player
|
|
|
|
|
// - disconnect
|
|
|
|
|
// - reconnect
|
|
|
|
|
// - assert that they return to the original entity.
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task TestReconnect()
|
|
|
|
|
{
|
|
|
|
|
await using var pair = await SetupPair();
|
|
|
|
|
var mind = GetMind(pair);
|
|
|
|
|
|
2024-01-12 23:22:01 +01:00
|
|
|
Assert.That(mind.Comp.VisitingEntity, Is.Null);
|
|
|
|
|
Assert.That(mind.Comp.OwnedEntity, Is.Not.Null);
|
2023-10-28 09:59:53 +11:00
|
|
|
var entity = mind.Comp.OwnedEntity;
|
|
|
|
|
|
|
|
|
|
await pair.RunTicksSync(5);
|
|
|
|
|
await DisconnectReconnect(pair);
|
|
|
|
|
await pair.RunTicksSync(5);
|
|
|
|
|
|
|
|
|
|
var newMind = GetMind(pair);
|
|
|
|
|
|
2024-01-12 23:22:01 +01:00
|
|
|
Assert.That(newMind.Comp.VisitingEntity, Is.Null);
|
2023-10-28 09:59:53 +11:00
|
|
|
Assert.That(newMind.Comp.OwnedEntity, Is.EqualTo(entity));
|
|
|
|
|
Assert.That(newMind.Id, Is.EqualTo(mind.Id));
|
|
|
|
|
|
|
|
|
|
await pair.CleanReturnAsync();
|
|
|
|
|
}
|
2023-06-20 16:29:26 +12:00
|
|
|
}
|