Refactor minds to be entities with components, make roles components (#19591)
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
@@ -8,17 +8,17 @@ using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Roles.Jobs;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using IPlayerManager = Robust.Server.Player.IPlayerManager;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Minds;
|
||||
|
||||
@@ -66,12 +66,13 @@ public sealed partial class MindTests
|
||||
var entity = entMan.SpawnEntity(null, new MapCoordinates());
|
||||
var mindComp = entMan.EnsureComponent<MindContainerComponent>(entity);
|
||||
|
||||
var mind = mindSystem.CreateMind(null);
|
||||
var mindId = mindSystem.CreateMind(null);
|
||||
var mind = entMan.GetComponent<MindComponent>(mindId);
|
||||
|
||||
Assert.That(mind.UserId, Is.EqualTo(null));
|
||||
|
||||
mindSystem.TransferTo(mind, entity);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mind));
|
||||
mindSystem.TransferTo(mindId, entity, mind: mind);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mindId));
|
||||
});
|
||||
|
||||
await pair.CleanReturnAsync();
|
||||
@@ -92,15 +93,16 @@ public sealed partial class MindTests
|
||||
var entity = entMan.SpawnEntity(null, new MapCoordinates());
|
||||
var mindComp = entMan.EnsureComponent<MindContainerComponent>(entity);
|
||||
|
||||
var mind = mindSystem.CreateMind(null);
|
||||
mindSystem.TransferTo(mind, entity);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mind));
|
||||
var mindId = mindSystem.CreateMind(null);
|
||||
mindSystem.TransferTo(mindId, entity);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mindId));
|
||||
|
||||
var mind2 = mindSystem.CreateMind(null);
|
||||
mindSystem.TransferTo(mind2, entity);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mind2));
|
||||
var mind = entMan.GetComponent<MindComponent>(mindId);
|
||||
Assert.That(mind.OwnedEntity, Is.Not.EqualTo(entity));
|
||||
});
|
||||
});
|
||||
@@ -119,7 +121,7 @@ public sealed partial class MindTests
|
||||
|
||||
EntityUid entity = default!;
|
||||
MindContainerComponent mindContainerComp = default!;
|
||||
Mind mind = default!;
|
||||
EntityUid mindId = default!;
|
||||
var mindSystem = entMan.EntitySysManager.GetEntitySystem<MindSystem>();
|
||||
var damageableSystem = entMan.EntitySysManager.GetEntitySystem<DamageableSystem>();
|
||||
|
||||
@@ -128,12 +130,13 @@ public sealed partial class MindTests
|
||||
entity = entMan.SpawnEntity("MindTestEntityDamageable", new MapCoordinates());
|
||||
mindContainerComp = entMan.EnsureComponent<MindContainerComponent>(entity);
|
||||
|
||||
mind = mindSystem.CreateMind(null);
|
||||
mindId = mindSystem.CreateMind(null);
|
||||
|
||||
mindSystem.TransferTo(mind, entity);
|
||||
mindSystem.TransferTo(mindId, entity);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.GetMind(entity, mindContainerComp), Is.EqualTo(mind));
|
||||
Assert.That(mindSystem.GetMind(entity, mindContainerComp), Is.EqualTo(mindId));
|
||||
var mind = entMan.GetComponent<MindComponent>(mindId);
|
||||
Assert.That(!mindSystem.IsCharacterDeadPhysically(mind));
|
||||
});
|
||||
});
|
||||
@@ -149,13 +152,14 @@ public sealed partial class MindTests
|
||||
}
|
||||
|
||||
damageableSystem.SetDamage(entity, damageable, new DamageSpecifier(prototype, FixedPoint2.New(401)));
|
||||
Assert.That(mindSystem.GetMind(entity, mindContainerComp), Is.EqualTo(mind));
|
||||
Assert.That(mindSystem.GetMind(entity, mindContainerComp), Is.EqualTo(mindId));
|
||||
});
|
||||
|
||||
await pair.RunTicksSync(5);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var mind = entMan.GetComponent<MindComponent>(mindId);
|
||||
Assert.That(mindSystem.IsCharacterDeadPhysically(mind));
|
||||
});
|
||||
|
||||
@@ -211,20 +215,22 @@ public sealed partial class MindTests
|
||||
await pair.RunTicksSync(5);
|
||||
var mindSystem = entMan.EntitySysManager.GetEntitySystem<MindSystem>();
|
||||
var originalMind = GetMind(pair);
|
||||
var userId = originalMind.UserId;
|
||||
var userId = originalMind.Comp.UserId;
|
||||
|
||||
Mind mind = default!;
|
||||
EntityUid mindId = default!;
|
||||
MindComponent mind = default!;
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var entity = entMan.SpawnEntity(null, new MapCoordinates());
|
||||
var mindComp = entMan.EnsureComponent<MindContainerComponent>(entity);
|
||||
entMan.DirtyEntity(entity);
|
||||
|
||||
mind = mindSystem.CreateMind(null);
|
||||
mindSystem.TransferTo(mind, entity);
|
||||
mindId = mindSystem.CreateMind(null);
|
||||
mind = entMan.GetComponent<MindComponent>(mindId);
|
||||
mindSystem.TransferTo(mindId, entity);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mind));
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mindId));
|
||||
Assert.That(mindComp.HasMind);
|
||||
});
|
||||
});
|
||||
@@ -233,18 +239,18 @@ public sealed partial class MindTests
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
mindSystem.SetUserId(mind, userId);
|
||||
mindSystem.SetUserId(mindId, userId);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mind.UserId, Is.EqualTo(userId));
|
||||
Assert.That(originalMind.UserId, Is.EqualTo(null));
|
||||
Assert.That(originalMind.Comp.UserId, Is.EqualTo(null));
|
||||
});
|
||||
|
||||
mindSystem.SetUserId(originalMind, userId);
|
||||
mindSystem.SetUserId(originalMind.Id, userId);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mind.UserId, Is.EqualTo(null));
|
||||
Assert.That(originalMind.UserId, Is.EqualTo(userId));
|
||||
Assert.That(originalMind.Comp.UserId, Is.EqualTo(userId));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -264,57 +270,59 @@ public sealed partial class MindTests
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var mindSystem = entMan.EntitySysManager.GetEntitySystem<MindSystem>();
|
||||
var roleSystem = entMan.EntitySysManager.GetEntitySystem<RoleSystem>();
|
||||
|
||||
var entity = entMan.SpawnEntity(null, new MapCoordinates());
|
||||
var mindComp = entMan.EnsureComponent<MindContainerComponent>(entity);
|
||||
|
||||
var mind = mindSystem.CreateMind(null);
|
||||
var mindId = mindSystem.CreateMind(null);
|
||||
var mind = entMan.EnsureComponent<MindComponent>(mindId);
|
||||
|
||||
Assert.That(mind.UserId, Is.EqualTo(null));
|
||||
|
||||
mindSystem.TransferTo(mind, entity);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mind));
|
||||
mindSystem.TransferTo(mindId, entity);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mindId));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.HasRole<TraitorRole>(mind), Is.False);
|
||||
Assert.That(mindSystem.HasRole<Job>(mind), Is.False);
|
||||
Assert.That(roleSystem.MindHasRole<TraitorRoleComponent>(mindId), Is.False);
|
||||
Assert.That(roleSystem.MindHasRole<JobComponent>(mindId), Is.False);
|
||||
});
|
||||
|
||||
var traitorRole = new TraitorRole(mind, new AntagPrototype());
|
||||
var traitorRole = new TraitorRoleComponent();
|
||||
|
||||
mindSystem.AddRole(mind, traitorRole);
|
||||
roleSystem.MindAddRole(mindId, traitorRole);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.HasRole<TraitorRole>(mind));
|
||||
Assert.That(mindSystem.HasRole<Job>(mind), Is.False);
|
||||
Assert.That(roleSystem.MindHasRole<TraitorRoleComponent>(mindId));
|
||||
Assert.That(roleSystem.MindHasRole<JobComponent>(mindId), Is.False);
|
||||
});
|
||||
|
||||
var jobRole = new Job(mind, new JobPrototype());
|
||||
var jobRole = new JobComponent();
|
||||
|
||||
mindSystem.AddRole(mind, jobRole);
|
||||
roleSystem.MindAddRole(mindId, jobRole);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.HasRole<TraitorRole>(mind));
|
||||
Assert.That(mindSystem.HasRole<Job>(mind));
|
||||
Assert.That(roleSystem.MindHasRole<TraitorRoleComponent>(mindId));
|
||||
Assert.That(roleSystem.MindHasRole<JobComponent>(mindId));
|
||||
});
|
||||
|
||||
mindSystem.RemoveRole(mind, traitorRole);
|
||||
roleSystem.MindRemoveRole<TraitorRoleComponent>(mindId);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.HasRole<TraitorRole>(mind), Is.False);
|
||||
Assert.That(mindSystem.HasRole<Job>(mind));
|
||||
Assert.That(roleSystem.MindHasRole<TraitorRoleComponent>(mindId), Is.False);
|
||||
Assert.That(roleSystem.MindHasRole<JobComponent>(mindId));
|
||||
});
|
||||
|
||||
mindSystem.RemoveRole(mind, jobRole);
|
||||
roleSystem.MindRemoveRole<JobComponent>(mindId);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(mindSystem.HasRole<TraitorRole>(mind), Is.False);
|
||||
Assert.That(mindSystem.HasRole<Job>(mind), Is.False);
|
||||
Assert.That(roleSystem.MindHasRole<TraitorRoleComponent>(mindId), Is.False);
|
||||
Assert.That(roleSystem.MindHasRole<JobComponent>(mindId), Is.False);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -335,7 +343,8 @@ public sealed partial class MindTests
|
||||
var ghostSystem = entMan.EntitySysManager.GetEntitySystem<GhostSystem>();
|
||||
|
||||
EntityUid entity = default!;
|
||||
Mind mind = default!;
|
||||
EntityUid mindId = default!;
|
||||
MindComponent mind = default!;
|
||||
var player = playerMan.ServerSessions.Single();
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
@@ -343,12 +352,13 @@ public sealed partial class MindTests
|
||||
entity = entMan.SpawnEntity(null, new MapCoordinates());
|
||||
var mindComp = entMan.EnsureComponent<MindContainerComponent>(entity);
|
||||
|
||||
mind = mindSystem.CreateMind(player.UserId, "Mindy McThinker");
|
||||
mindId = mindSystem.CreateMind(player.UserId, "Mindy McThinker");
|
||||
mind = entMan.GetComponent<MindComponent>(mindId);
|
||||
|
||||
Assert.That(mind.UserId, Is.EqualTo(player.UserId));
|
||||
|
||||
mindSystem.TransferTo(mind, entity);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mind));
|
||||
mindSystem.TransferTo(mindId, entity);
|
||||
Assert.That(mindSystem.GetMind(entity, mindComp), Is.EqualTo(mindId));
|
||||
});
|
||||
|
||||
await pair.RunTicksSync(5);
|
||||
@@ -361,7 +371,8 @@ public sealed partial class MindTests
|
||||
await pair.RunTicksSync(5);
|
||||
|
||||
EntityUid mob = default!;
|
||||
Mind mobMind = default!;
|
||||
EntityUid mobMindId = default!;
|
||||
MindComponent mobMind = default!;
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
@@ -370,22 +381,25 @@ public sealed partial class MindTests
|
||||
mob = entMan.SpawnEntity(null, new MapCoordinates());
|
||||
|
||||
MakeSentientCommand.MakeSentient(mob, IoCManager.Resolve<IEntityManager>());
|
||||
mobMind = mindSystem.CreateMind(player.UserId, "Mindy McThinker the Second");
|
||||
mobMindId = mindSystem.CreateMind(player.UserId, "Mindy McThinker the Second");
|
||||
mobMind = entMan.GetComponent<MindComponent>(mobMindId);
|
||||
|
||||
mindSystem.SetUserId(mobMind, player.UserId);
|
||||
mindSystem.TransferTo(mobMind, mob);
|
||||
mindSystem.SetUserId(mobMindId, player.UserId);
|
||||
mindSystem.TransferTo(mobMindId, mob);
|
||||
});
|
||||
|
||||
await pair.RunTicksSync(5);
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var m = player.ContentData()?.Mind;
|
||||
Assert.That(m, Is.Not.Null);
|
||||
var mId = player.ContentData()?.Mind!.Value;
|
||||
Assert.That(mId, Is.Not.Null);
|
||||
Assert.That(mId, Is.Not.EqualTo(default(EntityUid)));
|
||||
var m = entMan.GetComponent<MindComponent>(mId!.Value);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(m!.OwnedEntity, Is.EqualTo(mob));
|
||||
Assert.That(m, Is.Not.EqualTo(mind));
|
||||
Assert.That(mId, Is.Not.EqualTo(mindId));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -416,7 +430,8 @@ public sealed partial class MindTests
|
||||
//EntityUid entity = default!;
|
||||
EntityUid ghostRole = default!;
|
||||
EntityUid ghost = default!;
|
||||
Mind mind = default!;
|
||||
EntityUid mindId = default!;
|
||||
MindComponent mind = default!;
|
||||
var player = playerMan.ServerSessions.Single();
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
@@ -434,7 +449,8 @@ public sealed partial class MindTests
|
||||
var data = player.ContentData();
|
||||
|
||||
Assert.That(data?.Mind, Is.Not.EqualTo(null));
|
||||
mind = data!.Mind!;
|
||||
mindId = data!.Mind!.Value;
|
||||
mind = entMan.GetComponent<MindComponent>(mindId);
|
||||
|
||||
Assert.That(mind.OwnedEntity, Is.Not.Null);
|
||||
|
||||
@@ -460,8 +476,8 @@ public sealed partial class MindTests
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var data = player.ContentData()!;
|
||||
Assert.That(data.Mind!.OwnedEntity, Is.EqualTo(ghostRole));
|
||||
var data = entMan.GetComponent<MindComponent>(player.ContentData()!.Mind!.Value);
|
||||
Assert.That(data.OwnedEntity, Is.EqualTo(ghostRole));
|
||||
|
||||
serverConsole.ExecuteCommand(player, "aghost");
|
||||
Assert.That(player.AttachedEntity, Is.Not.Null);
|
||||
|
||||
Reference in New Issue
Block a user