Files

130 lines
5.1 KiB
C#
Raw Permalink Normal View History

2023-06-18 11:33:19 -07:00
#nullable enable
2023-06-21 14:11:58 +12:00
using System.Linq;
Cherrypicks 3 (#382) * Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
2024-06-25 21:39:44 +00:00
using Content.IntegrationTests.Pair;
2023-06-18 11:33:19 -07:00
using Content.Server.Ghost.Roles;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Players;
2023-08-25 18:50:46 +10:00
using Content.Shared.Ghost;
using Content.Shared.Mind;
using Content.Shared.Players;
2023-06-18 11:33:19 -07:00
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Content.IntegrationTests.Tests.Minds;
[TestFixture]
public sealed class GhostRoleTests
{
[TestPrototypes]
2023-06-18 11:33:19 -07:00
private const string Prototypes = @"
- type: entity
2023-06-21 14:11:58 +12:00
id: GhostRoleTestEntity
2023-06-18 11:33:19 -07:00
components:
- type: MindContainer
- type: GhostRole
- type: GhostTakeoverAvailable
";
/// <summary>
Cherrypicks 3 (#382) * Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
2024-06-25 21:39:44 +00:00
/// This is a simple test that just checks if a player can take a ghost role and then regain control of their
2023-06-18 11:33:19 -07:00
/// original entity without encountering errors.
/// </summary>
[Test]
public async Task TakeRoleAndReturn()
{
2023-08-25 02:56:51 +02:00
await using var pair = await PoolManager.GetServerClient(new PoolSettings
{
Cherrypicks 3 (#382) * Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
2024-06-25 21:39:44 +00:00
Dirty = true,
DummyTicker = false,
Connected = true
});
2023-08-25 02:56:51 +02:00
var server = pair.Server;
var client = pair.Client;
2023-06-18 11:33:19 -07:00
Cherrypicks 3 (#382) * Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
2024-06-25 21:39:44 +00:00
var mapData = await pair.CreateTestMap();
2023-06-18 11:33:19 -07:00
var entMan = server.ResolveDependency<IEntityManager>();
var sPlayerMan = server.ResolveDependency<Robust.Server.Player.IPlayerManager>();
var conHost = client.ResolveDependency<IConsoleHost>();
var mindSystem = entMan.System<SharedMindSystem>();
var session = sPlayerMan.Sessions.Single();
var originalMindId = session.ContentData()!.Mind!.Value;
2023-06-18 11:33:19 -07:00
// Spawn player entity & attach
EntityUid originalMob = default;
await server.WaitPost(() =>
{
Cherrypicks 3 (#382) * Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
2024-06-25 21:39:44 +00:00
originalMob = entMan.SpawnEntity(null, mapData.GridCoords);
mindSystem.TransferTo(originalMindId, originalMob, true);
2023-06-18 11:33:19 -07:00
});
// Check player got attached.
await pair.RunTicksSync(10);
2023-06-21 14:11:58 +12:00
Assert.That(session.AttachedEntity, Is.EqualTo(originalMob));
var originalMind = entMan.GetComponent<MindComponent>(originalMindId);
2023-08-07 15:29:10 +12:00
Assert.That(originalMind.OwnedEntity, Is.EqualTo(originalMob));
Assert.That(originalMind.VisitingEntity, Is.Null);
2023-06-18 11:33:19 -07:00
// Use the ghost command
conHost.ExecuteCommand("ghost");
await pair.RunTicksSync(10);
2023-08-07 15:29:10 +12:00
var ghost = session.AttachedEntity;
Assert.That(entMan.HasComponent<GhostComponent>(ghost));
Assert.That(ghost, Is.Not.EqualTo(originalMob));
Assert.That(session.ContentData()?.Mind, Is.EqualTo(originalMindId));
Cherrypicks 3 (#382) * Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
2024-06-25 21:39:44 +00:00
Assert.That(originalMind.OwnedEntity, Is.EqualTo(originalMob), $"Original mob: {originalMob}, Ghost: {ghost}");
2023-08-07 15:29:10 +12:00
Assert.That(originalMind.VisitingEntity, Is.EqualTo(ghost));
2023-06-18 11:33:19 -07:00
// Spawn ghost takeover entity.
EntityUid ghostRole = default;
Cherrypicks 3 (#382) * Mobs burn to ashes on excessive heat damage (#26971) * mobs burn to ashes on excessive heat damage * remove comment, remove random lines I didn't mean to add * combine code into behavior * clean unused * fix namespace * drop next to * fix spawn entities behavior spawning entities outside container * fix burning to ash not working on all mobs (#27158) * add ghostnado button to warp menu (#27556) * add ghostnado button to warp menu * translator ops --------- Co-authored-by: deltanedas <@deltanedas:kde.org> * Make arguments and parameters wrap to one variable per line (#27766) * Fix ghosts getting spawned in nullspace (#27617) * Add tests for ghost spawn position * Make ghosts spawn immediately * Format mind system * Move ghost spawning to GhostSystem * Spawn ghost on grid or map This fixes the ghosts being attached the parent entity instead of the grid. * Move logging out of the ghost system * Make round start observer spawn using GhostSystem * Move GameTicker ghost spawning to GhostSystem Moved the more robust character name selection code over. Moved the TimeOfDeath code over. Added canReturn logic. * Add overrides and default for ghost spawn coordinates * Add warning log to ghost spawn fail * Clean up test * Dont spawn ghost on map delete * Minor changes to the role test * Fix role test failing to spawn ghost It was failing the map check due to using Nullspace * Fix ghost tests when running in parallel Not sure what happened, but it seems to be because they were running simultaneously and overwriting values. * Clean up ghost tests * Test that map deletion does not spawn ghosts * Spawn ghost on the next available map * Disallow spawning on deleted maps * Fix map deletion ghost test * Cleanup --------- Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: ShadowCommander <shadowjjt@gmail.com>
2024-06-25 21:39:44 +00:00
await server.WaitPost(() => ghostRole = entMan.SpawnEntity("GhostRoleTestEntity", mapData.GridCoords));
2023-06-18 11:33:19 -07:00
// Take the ghost role
await server.WaitPost(() =>
{
var id = entMan.GetComponent<GhostRoleComponent>(ghostRole).Identifier;
entMan.EntitySysManager.GetEntitySystem<GhostRoleSystem>().Takeover(session, id);
});
// Check player got attached to ghost role.
await pair.RunTicksSync(10);
var newMindId = session.ContentData()!.Mind!.Value;
var newMind = entMan.GetComponent<MindComponent>(newMindId);
Assert.That(newMindId, Is.Not.EqualTo(originalMindId));
2023-06-21 14:11:58 +12:00
Assert.That(session.AttachedEntity, Is.EqualTo(ghostRole));
2023-08-07 15:29:10 +12:00
Assert.That(newMind.OwnedEntity, Is.EqualTo(ghostRole));
Assert.That(newMind.VisitingEntity, Is.Null);
2023-08-07 15:29:10 +12:00
// Original mind should be unaffected, but the ghost will have deleted itself.
Assert.That(originalMind.OwnedEntity, Is.EqualTo(originalMob));
Assert.That(originalMind.VisitingEntity, Is.Null);
2023-08-07 15:29:10 +12:00
Assert.That(entMan.Deleted(ghost));
2023-06-18 11:33:19 -07:00
// Ghost again.
conHost.ExecuteCommand("ghost");
await pair.RunTicksSync(10);
2023-08-07 15:29:10 +12:00
var otherGhost = session.AttachedEntity;
Assert.That(entMan.HasComponent<GhostComponent>(otherGhost));
Assert.That(otherGhost, Is.Not.EqualTo(originalMob));
Assert.That(otherGhost, Is.Not.EqualTo(ghostRole));
Assert.That(session.ContentData()?.Mind, Is.EqualTo(newMindId));
2023-08-07 15:29:10 +12:00
Assert.That(newMind.OwnedEntity, Is.EqualTo(ghostRole));
Assert.That(newMind.VisitingEntity, Is.EqualTo(session.AttachedEntity));
2023-06-18 11:33:19 -07:00
// Next, control the original entity again:
await server.WaitPost(() => mindSystem.SetUserId(originalMindId, session.UserId));
await pair.RunTicksSync(10);
2023-06-21 14:11:58 +12:00
Assert.That(session.AttachedEntity, Is.EqualTo(originalMob));
2023-08-07 15:29:10 +12:00
Assert.That(originalMind.OwnedEntity, Is.EqualTo(originalMob));
Assert.That(originalMind.VisitingEntity, Is.Null);
2023-08-07 15:29:10 +12:00
// the ghost-role mind is unaffected, though the ghost will have deleted itself
Assert.That(newMind.OwnedEntity, Is.EqualTo(ghostRole));
Assert.That(newMind.VisitingEntity, Is.Null);
2023-08-07 15:29:10 +12:00
Assert.That(entMan.Deleted(otherGhost));
2023-06-18 11:33:19 -07:00
2023-08-25 02:56:51 +02:00
await pair.CleanReturnAsync();
2023-06-18 11:33:19 -07:00
}
}