Mind Role Entities (#31318)
* Mind Role Entities wip * headrev count fix * silicon stuff, cleanup * exclusive antag config, cleanup * jobroleadd overwerite * logging stuff * MindHasRole cleanup, admin log stuff * last second cleanup * ocd * minor cleanup * remove createdTime datafield * now actually using the event replacement I made for role time tracking * weh
This commit is contained in:
@@ -13,8 +13,10 @@ namespace Content.Shared.Roles.Jobs;
|
||||
/// </summary>
|
||||
public abstract class SharedJobSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
[Dependency] private readonly SharedPlayerSystem _playerSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypes = default!;
|
||||
[Dependency] private readonly SharedRoleSystem _roles = default!;
|
||||
|
||||
private readonly Dictionary<string, string> _inverseTrackerLookup = new();
|
||||
|
||||
public override void Initialize()
|
||||
@@ -100,32 +102,44 @@ public abstract class SharedJobSystem : EntitySystem
|
||||
|
||||
public bool MindHasJobWithId(EntityUid? mindId, string prototypeId)
|
||||
{
|
||||
return CompOrNull<JobComponent>(mindId)?.Prototype == prototypeId;
|
||||
|
||||
MindRoleComponent? comp = null;
|
||||
if (mindId is null)
|
||||
return false;
|
||||
|
||||
_roles.MindHasRole<JobRoleComponent>(mindId.Value, out var role);
|
||||
|
||||
if (role is null)
|
||||
return false;
|
||||
|
||||
comp = role.Value.Comp;
|
||||
|
||||
return (comp.JobPrototype == prototypeId);
|
||||
}
|
||||
|
||||
public bool MindTryGetJob(
|
||||
[NotNullWhen(true)] EntityUid? mindId,
|
||||
[NotNullWhen(true)] out JobComponent? comp,
|
||||
[NotNullWhen(true)] out JobPrototype? prototype)
|
||||
{
|
||||
comp = null;
|
||||
prototype = null;
|
||||
MindTryGetJobId(mindId, out var protoId);
|
||||
|
||||
return TryComp(mindId, out comp) &&
|
||||
comp.Prototype != null &&
|
||||
_prototypes.TryIndex(comp.Prototype, out prototype);
|
||||
return (_prototypes.TryIndex<JobPrototype>(protoId, out prototype) || prototype is not null);
|
||||
}
|
||||
|
||||
public bool MindTryGetJobId([NotNullWhen(true)] EntityUid? mindId, out ProtoId<JobPrototype>? job)
|
||||
public bool MindTryGetJobId(
|
||||
[NotNullWhen(true)] EntityUid? mindId,
|
||||
out ProtoId<JobPrototype>? job)
|
||||
{
|
||||
if (!TryComp(mindId, out JobComponent? comp))
|
||||
{
|
||||
job = null;
|
||||
return false;
|
||||
}
|
||||
job = null;
|
||||
|
||||
job = comp.Prototype;
|
||||
return true;
|
||||
if (mindId is null)
|
||||
return false;
|
||||
|
||||
if (_roles.MindHasRole<JobRoleComponent>(mindId.Value, out var role))
|
||||
job = role.Value.Comp.JobPrototype;
|
||||
|
||||
return (job is not null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -134,7 +148,7 @@ public abstract class SharedJobSystem : EntitySystem
|
||||
/// </summary>
|
||||
public bool MindTryGetJobName([NotNullWhen(true)] EntityUid? mindId, out string name)
|
||||
{
|
||||
if (MindTryGetJob(mindId, out _, out var prototype))
|
||||
if (MindTryGetJob(mindId, out var prototype))
|
||||
{
|
||||
name = prototype.LocalizedName;
|
||||
return true;
|
||||
@@ -161,7 +175,7 @@ public abstract class SharedJobSystem : EntitySystem
|
||||
if (_playerSystem.ContentData(player) is not { Mind: { } mindId })
|
||||
return true;
|
||||
|
||||
if (!MindTryGetJob(mindId, out _, out var prototype))
|
||||
if (!MindTryGetJob(mindId, out var prototype))
|
||||
return true;
|
||||
|
||||
return prototype.CanBeAntag;
|
||||
|
||||
Reference in New Issue
Block a user