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,10 +1,9 @@
using System.Globalization;
using System.Linq;
using Content.Server.Administration.Managers;
using Content.Server.GameTicking.Events;
using Content.Server.IdentityManagement;
using Content.Server.Players;
using Content.Server.Mind;
using Content.Server.Roles;
using Content.Server.Roles.Jobs;
using Content.Shared.Administration;
using Content.Shared.Administration.Events;
using Content.Shared.GameTicking;
@@ -20,6 +19,9 @@ namespace Content.Server.Administration.Systems
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly JobSystem _jobs = default!;
[Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly RoleSystem _role = default!;
private readonly Dictionary<NetUserId, PlayerInfo> _playerList = new();
@@ -102,10 +104,10 @@ namespace Content.Server.Administration.Systems
private void OnRoleEvent(RoleEvent ev)
{
if (!ev.Role.Antagonist || ev.Role.Mind.Session == null)
if (!ev.Antagonist || ev.Mind.Session == null)
return;
UpdatePlayerList(ev.Role.Mind.Session);
UpdatePlayerList(ev.Mind.Session);
}
private void OnAdminPermsChanged(AdminPermsChangedEventArgs obj)
@@ -169,12 +171,13 @@ namespace Content.Server.Administration.Systems
identityName = Identity.Name(session.AttachedEntity.Value, EntityManager);
}
var mind = data.ContentData()?.Mind;
var job = mind?.AllRoles.FirstOrDefault(role => role is Job);
var startingRole = job != null ? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(job.Name) : string.Empty;
var antag = mind?.AllRoles.Any(r => r.Antagonist) ?? false;
var antag = false;
var startingRole = string.Empty;
if (_minds.TryGetMind(session, out var mindId, out _))
{
antag = _role.MindIsAntagonist(mindId);
startingRole = _jobs.MindTryGetJobName(mindId);
}
var connected = session != null && session.Status is SessionStatus.Connected or SessionStatus.InGame;

View File

@@ -1,4 +1,5 @@
using Content.Server.GameTicking.Rules;
using Content.Server.Mind;
using Content.Server.Mind.Components;
using Content.Server.Zombies;
using Content.Shared.Administration;
@@ -15,6 +16,7 @@ public sealed partial class AdminVerbSystem
[Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
[Dependency] private readonly NukeopsRuleSystem _nukeopsRule = default!;
[Dependency] private readonly PiratesRuleSystem _piratesRule = default!;
[Dependency] private readonly MindSystem _minds = default!;
// All antag verbs have names so invokeverb works.
private void AddAntagVerbs(GetVerbsEvent<Verb> args)
@@ -38,10 +40,10 @@ public sealed partial class AdminVerbSystem
Icon = new SpriteSpecifier.Rsi(new ResPath("/Textures/Structures/Wallmounts/posters.rsi"), "poster5_contraband"),
Act = () =>
{
if (targetMindComp.Mind == null || targetMindComp.Mind.Session == null)
if (!_minds.TryGetSession(targetMindComp.Mind, out var session))
return;
_traitorRule.MakeTraitor(targetMindComp.Mind.Session);
_traitorRule.MakeTraitor(session);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-make-traitor"),
@@ -70,10 +72,10 @@ public sealed partial class AdminVerbSystem
Icon = new SpriteSpecifier.Rsi(new("/Textures/Structures/Wallmounts/signs.rsi"), "radiation"),
Act = () =>
{
if (targetMindComp.Mind == null || targetMindComp.Mind.Session == null)
if (!_minds.TryGetMind(args.Target, out var mindId, out var mind))
return;
_nukeopsRule.MakeLoneNukie(targetMindComp.Mind);
_nukeopsRule.MakeLoneNukie(mindId, mind);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-make-nuclear-operative"),
@@ -87,10 +89,10 @@ public sealed partial class AdminVerbSystem
Icon = new SpriteSpecifier.Rsi(new("/Textures/Clothing/Head/Hats/pirate.rsi"), "icon"),
Act = () =>
{
if (targetMindComp.Mind == null || targetMindComp.Mind.Session == null)
if (!_minds.TryGetMind(args.Target, out var mindId, out var mind))
return;
_piratesRule.MakePirate(targetMindComp.Mind);
_piratesRule.MakePirate(mindId, mind);
},
Impact = LogImpact.High,
Message = Loc.GetString("admin-verb-make-pirate"),

View File

@@ -11,7 +11,6 @@ using Content.Server.Ghost.Roles;
using Content.Server.Mind;
using Content.Server.Mind.Commands;
using Content.Server.Mind.Components;
using Content.Server.Players;
using Content.Server.Prayer;
using Content.Server.Xenoarchaeology.XenoArtifacts;
using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components;
@@ -262,11 +261,10 @@ namespace Content.Server.Administration.Systems
{
MakeSentientCommand.MakeSentient(args.Target, EntityManager);
var mind = player.ContentData()?.Mind;
if (mind == null)
if (!_minds.TryGetMind(player, out var mindId, out var mind))
return;
_mindSystem.TransferTo(mind, args.Target, ghostCheckOverride: true);
_mindSystem.TransferTo(mindId, args.Target, ghostCheckOverride: true, mind: mind);
},
Impact = LogImpact.High,
ConfirmationPopup = true

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
using Content.Server.Administration.Managers;
using Content.Server.Discord;
using Content.Server.GameTicking;
using Content.Server.Players;
using Content.Server.Mind;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using JetBrains.Annotations;
@@ -31,6 +31,7 @@ namespace Content.Server.Administration.Systems
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerLocator _playerLocator = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly MindSystem _minds = default!;
private ISawmill _sawmill = default!;
private readonly HttpClient _httpClient = new();
@@ -221,8 +222,6 @@ namespace Content.Server.Administration.Systems
return;
}
var characterName = _playerManager.GetPlayerData(userId).ContentData()?.Mind?.CharacterName;
var linkToPrevious = string.Empty;
// If we have all the data required, we can link to the embed of the previous round or embed that was too long
@@ -238,6 +237,7 @@ namespace Content.Server.Administration.Systems
}
}
var characterName = _minds.GetCharacterName(userId);
existingEmbed = (null, lookup.Username, linkToPrevious, characterName, _gameTicker.RunLevel);
}