Move minds, roles, jobs and objectives to shared (#19679)

This commit is contained in:
DrSmugleaf
2023-08-30 21:46:11 -07:00
committed by GitHub
parent b702963d5e
commit 3f3ba6ac62
139 changed files with 1209 additions and 1041 deletions

View File

@@ -1,23 +1,17 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Globalization;
using Content.Server.Chat.Managers;
using Content.Server.Mind;
using Content.Server.Players;
using Content.Shared.Mind;
using Content.Shared.Roles;
using Robust.Server.Player;
using Robust.Shared.Prototypes;
using Content.Shared.Roles.Jobs;
namespace Content.Server.Roles.Jobs;
/// <summary>
/// Handles the job data on mind entities.
/// </summary>
public sealed class JobSystem : EntitySystem
public sealed class JobSystem : SharedJobSystem
{
[Dependency] private readonly IChatManager _chat = default!;
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly RoleSystem _roles = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
[Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly SharedRoleSystem _roles = default!;
public override void Initialize()
{
@@ -29,7 +23,7 @@ public sealed class JobSystem : EntitySystem
if (args.Silent)
return;
if (!_mind.TryGetSession(mindId, out var session))
if (!_minds.TryGetSession(mindId, out var session))
return;
if (!MindTryGetJob(mindId, out _, out var prototype))
@@ -51,59 +45,4 @@ public sealed class JobSystem : EntitySystem
_roles.MindAddRole(mindId, new JobComponent { PrototypeId = jobPrototypeId });
}
public bool MindHasJobWithId(EntityUid? mindId, string prototypeId)
{
return CompOrNull<JobComponent>(mindId)?.PrototypeId == prototypeId;
}
public bool MindTryGetJob(
[NotNullWhen(true)] EntityUid? mindId,
[NotNullWhen(true)] out JobComponent? comp,
[NotNullWhen(true)] out JobPrototype? prototype)
{
comp = null;
prototype = null;
return TryComp(mindId, out comp) &&
comp.PrototypeId != null &&
_prototypes.TryIndex(comp.PrototypeId, out prototype);
}
/// <summary>
/// Tries to get the job name for this mind.
/// Returns unknown if not found.
/// </summary>
public bool MindTryGetJobName([NotNullWhen(true)] EntityUid? mindId, out string name)
{
if (MindTryGetJob(mindId, out _, out var prototype))
{
name = prototype.LocalizedName;
return true;
}
name = Loc.GetString("generic-unknown-title");
return false;
}
/// <summary>
/// Tries to get the job name for this mind.
/// Returns unknown if not found.
/// </summary>
public string MindTryGetJobName([NotNullWhen(true)] EntityUid? mindId)
{
MindTryGetJobName(mindId, out var name);
return name;
}
public bool CanBeAntag(IPlayerSession player)
{
if (player.ContentData() is not { Mind: { } mindId })
return false;
if (!MindTryGetJob(mindId, out _, out var prototype))
return true;
return prototype.CanBeAntag;
}
}