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:
DrSmugleaf
2023-08-28 16:53:24 -07:00
committed by GitHub
parent e0ee397af7
commit 15c0211fb2
119 changed files with 1445 additions and 1289 deletions

View File

@@ -1,5 +1,5 @@
using Content.Server.GameTicking;
using Content.Server.Players;
using Content.Server.Mind;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
@@ -9,6 +9,8 @@ namespace Content.Server.Ghost
[AnyCommand]
public sealed class Ghost : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entities = default!;
public string Command => "ghost";
public string Description => "Give up on life and become a ghost.";
public string Help => "ghost";
@@ -22,14 +24,14 @@ namespace Content.Server.Ghost
return;
}
var mind = player.ContentData()?.Mind;
if (mind == null)
var minds = _entities.System<MindSystem>();
if (!minds.TryGetMind(player, out var mindId, out var mind))
{
shell.WriteLine("You have no Mind, you can't ghost.");
return;
}
if (!EntitySystem.Get<GameTicker>().OnGhostAttempt(mind, true, viaCommand:true))
if (!EntitySystem.Get<GameTicker>().OnGhostAttempt(mindId, true, true, mind))
{
shell.WriteLine("You can't ghost right now.");
}

View File

@@ -4,7 +4,7 @@ using Content.Server.GameTicking;
using Content.Server.Ghost.Components;
using Content.Server.Mind;
using Content.Server.Mind.Components;
using Content.Server.Players;
using Content.Server.Roles.Jobs;
using Content.Server.Visible;
using Content.Server.Warps;
using Content.Shared.Actions;
@@ -16,7 +16,6 @@ using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Events;
using Content.Shared.Storage.Components;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Console;
@@ -38,6 +37,8 @@ namespace Content.Server.Ghost
[Dependency] private readonly FollowerSystem _followerSystem = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly JobSystem _jobs = default!;
public override void Initialize()
{
@@ -92,13 +93,13 @@ namespace Content.Server.Ghost
if (EntityManager.HasComponent<VisitingMindComponent>(uid))
return;
if (!EntityManager.TryGetComponent<MindContainerComponent>(uid, out var mind) || !mind.HasMind || mind.Mind.IsVisitingEntity)
if (!_minds.TryGetMind(uid, out var mindId, out var mind) || mind.IsVisitingEntity)
return;
if (component.MustBeDead && (_mobState.IsAlive(uid) || _mobState.IsCritical(uid)))
return;
_ticker.OnGhostAttempt(mind.Mind, component.CanReturn);
_ticker.OnGhostAttempt(mindId, component.CanReturn, mind: mind);
}
private void OnGhostStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
@@ -199,7 +200,7 @@ namespace Content.Server.Ghost
return;
}
_mindSystem.UnVisit(actor.PlayerSession.ContentData()!.Mind);
_mindSystem.UnVisit(actor.PlayerSession);
}
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
@@ -260,7 +261,8 @@ namespace Content.Server.Ghost
TryComp<MindContainerComponent>(attached, out var mind);
string playerInfo = $"{EntityManager.GetComponent<MetaDataComponent>(attached).EntityName} ({mind?.Mind?.CurrentJob?.Name ?? "Unknown"})";
var jobName = _jobs.MindTryGetJobName(mind?.Mind);
var playerInfo = $"{EntityManager.GetComponent<MetaDataComponent>(attached).EntityName} ({jobName})";
if (_mobState.IsAlive(attached) || _mobState.IsCritical(attached))
yield return new GhostWarp(attached, playerInfo, false);

View File

@@ -1,17 +0,0 @@
using Content.Server.Roles;
namespace Content.Server.Ghost
{
/// <summary>
/// This is used to mark Observers properly, as they get Minds
/// </summary>
public sealed class ObserverRole : Role
{
public override string Name => Loc.GetString("observer-role-name");
public override bool Antagonist => false;
public ObserverRole(Mind.Mind mind) : base(mind)
{
}
}
}

View File

@@ -0,0 +1,11 @@
namespace Content.Server.Ghost
{
/// <summary>
/// This is used to mark Observers properly, as they get Minds
/// </summary>
[RegisterComponent]
public sealed partial class ObserverRoleComponent : Component
{
public string Name => Loc.GetString("observer-role-name");
}
}

View File

@@ -1,6 +1,5 @@
using Content.Server.EUI;
using Content.Server.Mind;
using Content.Server.Players;
using Content.Shared.Eui;
using Content.Shared.Ghost;
@@ -10,9 +9,9 @@ public sealed class ReturnToBodyEui : BaseEui
{
private readonly MindSystem _mindSystem;
private readonly Mind.Mind _mind;
private readonly MindComponent _mind;
public ReturnToBodyEui(Mind.Mind mind, MindSystem mindSystem)
public ReturnToBodyEui(MindComponent mind, MindSystem mindSystem)
{
_mind = mind;
_mindSystem = mindSystem;
@@ -29,8 +28,8 @@ public sealed class ReturnToBodyEui : BaseEui
return;
}
if (_mindSystem.TryGetSession(_mind, out var session))
_mindSystem.UnVisit(session.ContentData()!.Mind);
_mindSystem.UnVisit(_mind.Session);
Close();
}
}

View File

@@ -1,20 +0,0 @@
using Content.Server.Roles;
namespace Content.Server.Ghost.Roles
{
/// <summary>
/// This is used for round end display of ghost roles.
/// It may also be used to ensure some ghost roles count as antagonists in future.
/// </summary>
public sealed class GhostRoleMarkerRole : Role
{
private readonly string _name;
public override string Name => _name;
public override bool Antagonist => false;
public GhostRoleMarkerRole(Mind.Mind mind, string name) : base(mind)
{
_name = name;
}
}
}

View File

@@ -0,0 +1,11 @@
namespace Content.Server.Ghost.Roles;
/// <summary>
/// This is used for round end display of ghost roles.
/// It may also be used to ensure some ghost roles count as antagonists in future.
/// </summary>
[RegisterComponent]
public sealed partial class GhostRoleMarkerRoleComponent : Component
{
[DataField("name")] public string? Name;
}

View File

@@ -3,10 +3,11 @@ using Content.Server.EUI;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Ghost.Roles.Events;
using Content.Server.Ghost.Roles.UI;
using Content.Server.Mind.Commands;
using Content.Server.Mind;
using Content.Server.Mind.Commands;
using Content.Server.Mind.Components;
using Content.Server.Players;
using Content.Server.Roles;
using Content.Shared.Administration;
using Content.Shared.Database;
using Content.Shared.Follower;
@@ -34,6 +35,7 @@ namespace Content.Server.Ghost.Roles
[Dependency] private readonly FollowerSystem _followerSystem = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly RoleSystem _roleSystem = default!;
private uint _nextRoleIdentifier;
private bool _needsUpdateGhostRoleCount = true;
@@ -219,7 +221,7 @@ namespace Content.Server.Ghost.Roles
var newMind = _mindSystem.CreateMind(player.UserId,
EntityManager.GetComponent<MetaDataComponent>(mob).EntityName);
_mindSystem.AddRole(newMind, new GhostRoleMarkerRole(newMind, role.RoleName));
_roleSystem.MindAddRole(newMind, new GhostRoleMarkerRoleComponent { Name = role.RoleName });
_mindSystem.SetUserId(newMind, player.UserId);
_mindSystem.TransferTo(newMind, mob);

View File

@@ -107,12 +107,12 @@ public sealed class ToggleableGhostRoleSystem : EntitySystem
Text = Loc.GetString(component.WipeVerbText),
Act = () =>
{
if (!TryComp<MindContainerComponent>(uid, out var mindComp) || mindComp.Mind == null)
if (!_mind.TryGetMind(uid, out var mindId, out var mind))
return;
// Wiping device :(
// The shutdown of the Mind should cause automatic reset of the pAI during OnMindRemoved
// EDIT: But it doesn't!!!! Wtf? Do stuff manually
_mind.TransferTo(mindComp.Mind, null);
_mind.TransferTo(mindId, null, mind: mind);
_popup.PopupEntity(Loc.GetString(component.WipeVerbPopup), uid, args.User, PopupType.Large);
UpdateAppearance(uid, ToggleableGhostRoleStatus.Off);
_pai.PAITurningOff(uid);