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,6 +1,5 @@
using Content.Server.Administration;
using Content.Server.Mind;
using Content.Server.Players;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
@@ -12,7 +11,7 @@ namespace Content.Server.Objectives.Commands
public sealed class AddObjectiveCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public string Command => "addobjective";
public string Description => "Adds an objective to the player's mind.";
public string Help => "addobjective <username> <objectiveID>";
@@ -25,15 +24,14 @@ namespace Content.Server.Objectives.Commands
}
var mgr = IoCManager.Resolve<IPlayerManager>();
if (!mgr.TryGetPlayerDataByUsername(args[0], out var data))
if (!mgr.TryGetSessionByUsername(args[0], out var data))
{
shell.WriteLine("Can't find the playerdata.");
return;
}
var mind = data.ContentData()?.Mind;
if (mind == null)
var minds = _entityManager.System<MindSystem>();
if (!minds.TryGetMind(data, out var mindId, out var mind))
{
shell.WriteLine("Can't find the mind.");
return;
@@ -45,14 +43,12 @@ namespace Content.Server.Objectives.Commands
shell.WriteLine($"Can't find matching ObjectivePrototype {objectivePrototype}");
return;
}
var mindSystem = _entityManager.System<MindSystem>();
if (!mindSystem.TryAddObjective(mind, objectivePrototype))
var mindSystem = _entityManager.System<MindSystem>();
if (!mindSystem.TryAddObjective(mindId, mind, objectivePrototype))
{
shell.WriteLine("Objective requirements dont allow that objective to be added.");
}
}
}
}

View File

@@ -1,6 +1,6 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.Players;
using Content.Server.Mind;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
@@ -10,39 +10,38 @@ namespace Content.Server.Objectives.Commands
[AdminCommand(AdminFlags.Logs)]
public sealed class ListObjectivesCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IPlayerManager _players = default!;
public override string Command => "lsobjectives";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
IPlayerData? data;
if (args.Length == 0 && player != null)
{
data = player.Data;
}
else if (player == null || !IoCManager.Resolve<IPlayerManager>().TryGetPlayerDataByUsername(args[0], out data))
if (player == null || !_players.TryGetSessionByUsername(args[0], out player))
{
shell.WriteError(LocalizationManager.GetString("shell-target-player-does-not-exist"));
return;
}
var mind = data.ContentData()?.Mind;
if (mind == null)
var minds = _entities.System<MindSystem>();
if (!minds.TryGetMind(player, out _, out var mind))
{
shell.WriteError(LocalizationManager.GetString("shell-target-entity-does-not-have-message", ("missing", "mind")));
return;
}
shell.WriteLine($"Objectives for player {data.UserId}:");
shell.WriteLine($"Objectives for player {player.UserId}:");
var objectives = mind.AllObjectives.ToList();
if (objectives.Count == 0)
{
shell.WriteLine("None.");
}
for (var i = 0; i < objectives.Count; i++)
{
shell.WriteLine($"- [{i}] {objectives[i].Conditions[0].Title}");
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)

View File

@@ -1,6 +1,5 @@
using Content.Server.Administration;
using Content.Server.Mind;
using Content.Server.Players;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
@@ -11,7 +10,7 @@ namespace Content.Server.Objectives.Commands
public sealed class RemoveObjectiveCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public string Command => "rmobjective";
public string Description => "Removes an objective from the player's mind.";
public string Help => "rmobjective <username> <index>";
@@ -24,30 +23,29 @@ namespace Content.Server.Objectives.Commands
}
var mgr = IoCManager.Resolve<IPlayerManager>();
if (mgr.TryGetPlayerDataByUsername(args[0], out var data))
var minds = _entityManager.System<MindSystem>();
if (!mgr.TryGetSessionByUsername(args[0], out var session))
{
var mind = data.ContentData()?.Mind;
if (mind == null)
{
shell.WriteLine("Can't find the mind.");
return;
}
shell.WriteLine("Can't find the playerdata.");
return;
}
if (int.TryParse(args[1], out var i))
{
var mindSystem = _entityManager.System<MindSystem>();
shell.WriteLine(mindSystem.TryRemoveObjective(mind, i)
? "Objective successfully removed!"
: "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
}
else
{
shell.WriteLine($"Invalid index {args[1]}!");
}
if (!minds.TryGetMind(session, out _, out var mind))
{
shell.WriteLine("Can't find the mind.");
return;
}
if (int.TryParse(args[1], out var i))
{
var mindSystem = _entityManager.System<MindSystem>();
shell.WriteLine(mindSystem.TryRemoveObjective(mind, i)
? "Objective successfully removed!"
: "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
}
else
{
shell.WriteLine("Can't find the playerdata.");
shell.WriteLine($"Invalid index {args[1]}!");
}
}
}