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:
@@ -1,10 +1,10 @@
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Traitor;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Store;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Shared.Store.Conditions;
|
||||
namespace Content.Server.Store.Conditions;
|
||||
|
||||
/// <summary>
|
||||
/// Allows a store entry to be filtered out based on the user's antag role.
|
||||
@@ -28,18 +28,22 @@ public sealed partial class BuyerAntagCondition : ListingCondition
|
||||
public override bool Condition(ListingConditionArgs args)
|
||||
{
|
||||
var ent = args.EntityManager;
|
||||
var minds = ent.System<MindSystem>();
|
||||
|
||||
if (!ent.TryGetComponent<MindContainerComponent>(args.Buyer, out var mind) || mind.Mind == null)
|
||||
if (!minds.TryGetMind(args.Buyer, out var mindId, out var mind))
|
||||
return true;
|
||||
|
||||
var roleSystem = ent.System<RoleSystem>();
|
||||
var roles = roleSystem.MindGetAllRoles(mindId);
|
||||
|
||||
if (Blacklist != null)
|
||||
{
|
||||
foreach (var role in mind.Mind.AllRoles)
|
||||
foreach (var role in roles)
|
||||
{
|
||||
if (role is not AntagonistRole blacklistantag)
|
||||
if (role.Component is not AntagonistRoleComponent blacklistantag)
|
||||
continue;
|
||||
|
||||
if (Blacklist.Contains(blacklistantag.Prototype.ID))
|
||||
if (blacklistantag.PrototypeId != null && Blacklist.Contains(blacklistantag.PrototypeId))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -47,12 +51,12 @@ public sealed partial class BuyerAntagCondition : ListingCondition
|
||||
if (Whitelist != null)
|
||||
{
|
||||
var found = false;
|
||||
foreach (var role in mind.Mind.AllRoles)
|
||||
foreach (var role in roles)
|
||||
{
|
||||
if (role is not AntagonistRole antag)
|
||||
if (role.Component is not AntagonistRoleComponent antag)
|
||||
continue;
|
||||
|
||||
if (Whitelist.Contains(antag.Prototype.ID))
|
||||
if (antag.PrototypeId != null && Whitelist.Contains(antag.PrototypeId))
|
||||
found = true;
|
||||
}
|
||||
if (!found)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Roles.Jobs;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Store;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Store.Conditions;
|
||||
|
||||
@@ -30,45 +30,45 @@ public sealed partial class BuyerDepartmentCondition : ListingCondition
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
var ent = args.EntityManager;
|
||||
var minds = ent.System<MindSystem>();
|
||||
|
||||
if (!ent.TryGetComponent<MindContainerComponent>(args.Buyer, out var mind) || mind.Mind == null)
|
||||
return true; //this is for things like surplus crate
|
||||
// this is for things like surplus crate
|
||||
if (!minds.TryGetMind(args.Buyer, out var mindId, out _))
|
||||
return true;
|
||||
|
||||
if (Blacklist != null)
|
||||
var jobs = ent.System<JobSystem>();
|
||||
if (jobs.MindTryGetJob(mindId, out var job, out _))
|
||||
{
|
||||
foreach (var role in mind.Mind.AllRoles)
|
||||
if (Blacklist != null)
|
||||
{
|
||||
if (role is not Job job)
|
||||
continue;
|
||||
|
||||
foreach (var department in prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
|
||||
if (department.Roles.Contains(job.Prototype.ID))
|
||||
if (Blacklist.Contains(department.ID))
|
||||
return false;
|
||||
{
|
||||
if (job.PrototypeId == null ||
|
||||
!department.Roles.Contains(job.PrototypeId) ||
|
||||
!Blacklist.Contains(department.ID))
|
||||
continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Whitelist != null)
|
||||
{
|
||||
var found = false;
|
||||
foreach (var role in mind.Mind.AllRoles)
|
||||
if (Whitelist != null)
|
||||
{
|
||||
if (role is not Job job)
|
||||
continue;
|
||||
|
||||
var found = false;
|
||||
foreach (var department in prototypeManager.EnumeratePrototypes<DepartmentPrototype>())
|
||||
if (department.Roles.Contains(job.Prototype.ID))
|
||||
if (Whitelist.Contains(department.ID))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
{
|
||||
if (job.PrototypeId == null ||
|
||||
!department.Roles.Contains(job.PrototypeId) ||
|
||||
!Whitelist.Contains(department.ID))
|
||||
continue;
|
||||
|
||||
if (found)
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Roles.Jobs;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Store;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
@@ -27,35 +27,26 @@ public sealed partial class BuyerJobCondition : ListingCondition
|
||||
public override bool Condition(ListingConditionArgs args)
|
||||
{
|
||||
var ent = args.EntityManager;
|
||||
var minds = ent.System<MindSystem>();
|
||||
|
||||
if (!ent.TryGetComponent<MindContainerComponent>(args.Buyer, out var mind) || mind.Mind == null)
|
||||
return true; //this is for things like surplus crate
|
||||
// this is for things like surplus crate
|
||||
if (!minds.TryGetMind(args.Buyer, out var mindId, out _))
|
||||
return true;
|
||||
|
||||
if (Blacklist != null)
|
||||
var jobs = ent.System<JobSystem>();
|
||||
if (jobs.MindTryGetJob(mindId, out var job, out _))
|
||||
{
|
||||
foreach (var role in mind.Mind.AllRoles)
|
||||
if (Blacklist != null)
|
||||
{
|
||||
if (role is not Job job)
|
||||
continue;
|
||||
|
||||
if (Blacklist.Contains(job.Prototype.ID))
|
||||
if (job.PrototypeId != null && Blacklist.Contains(job.PrototypeId))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Whitelist != null)
|
||||
{
|
||||
var found = false;
|
||||
foreach (var role in mind.Mind.AllRoles)
|
||||
if (Whitelist != null)
|
||||
{
|
||||
if (role is not Job job)
|
||||
continue;
|
||||
|
||||
if (Whitelist.Contains(job.Prototype.ID))
|
||||
found = true;
|
||||
if (job.PrototypeId == null || !Whitelist.Contains(job.PrototypeId))
|
||||
return false;
|
||||
}
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user