using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
-using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
{
Subs.CVar(_cfg, CCVars.GameRoleTimerOverride, SetRequirementOverride, true);
- SubscribeLocalEvent<MindRoleComponent, ComponentShutdown>(OnComponentShutdown);
SubscribeLocalEvent<StartingMindRoleComponent, PlayerSpawnCompleteEvent>(OnSpawn);
}
return;
}
- if (!_prototypes.TryIndex(value, out _requirementOverride ))
+ if (!_prototypes.TryIndex(value, out _requirementOverride))
Log.Error($"Unknown JobRequirementOverridePrototype: {value}");
}
//If that was somehow to occur, a second mindrole for that comp would be created
//Meaning any mind role checks could return wrong results, since they just return the first match they find
- var mindRoleId = Spawn(protoId, MapCoordinates.Nullspace);
- EnsureComp<MindRoleComponent>(mindRoleId);
- var mindRoleComp = Comp<MindRoleComponent>(mindRoleId);
+ if (!PredictedTrySpawnInContainer(protoId, mindId, MindComponent.MindRoleContainerId, out var mindRoleId))
+ {
+ Log.Error($"Failed to add role {protoId} to {ToPrettyString(mindId)} : Could not spawn the role entity inside the container");
+ return;
+ }
+
+ var mindRoleComp = EnsureComp<MindRoleComponent>(mindRoleId.Value);
- mindRoleComp.Mind = (mindId,mind);
if (jobPrototype is not null)
{
mindRoleComp.JobPrototype = jobPrototype;
- EnsureComp<JobRoleComponent>(mindRoleId);
+ EnsureComp<JobRoleComponent>(mindRoleId.Value);
DebugTools.AssertNull(mindRoleComp.AntagPrototype);
DebugTools.Assert(!mindRoleComp.Antag);
DebugTools.Assert(!mindRoleComp.ExclusiveAntag);
}
- mind.MindRoles.Add(mindRoleId);
-
var update = MindRolesUpdate((mindId, mind));
// RoleType refresh, Role time tracking, Update Admin playerlist
/// </returns>>
private bool MindRolesUpdate(Entity<MindComponent?> ent)
{
- if(!Resolve(ent.Owner, ref ent.Comp))
+ if (!Resolve(ent.Owner, ref ent.Comp))
return false;
//get the most important/latest mind role
var (roleType, subtype) = GetRoleTypeByTime(ent.Comp);
- if (ent.Comp.RoleType == roleType && ent.Comp.Subtype == subtype)
+ if (ent.Comp.RoleType == roleType && ent.Comp.Subtype == subtype)
return false;
SetRoleType(ent.Owner, roleType, subtype);
{
var roles = new List<Entity<MindRoleComponent>>();
- foreach (var role in mind.MindRoles)
+ foreach (var role in mind.MindRoleContainer.ContainedEntities)
{
var comp = Comp<MindRoleComponent>(role);
if (comp.RoleType is not null)
var original = "'" + typeof(T).Name + "'";
var deleteName = original;
- foreach (var role in mind.Comp.MindRoles)
+ foreach (var role in mind.Comp.MindRoleContainer.ContainedEntities)
{
if (!HasComp<MindRoleComponent>(role))
{
return MindRemoveRole<T>((mindId, mind));
}
- /// <summary>
+ /// <summary>
/// Finds and removes all mind roles of a specific type
/// </summary>
/// <param name="mind">The mind entity and component</param>
/// <returns>True if the role existed and was removed</returns>
public bool MindRemoveRole(Entity<MindComponent?> mind, EntProtoId<MindRoleComponent> protoId)
{
- if ( !Resolve(mind.Owner, ref mind.Comp))
+ if (!Resolve(mind.Owner, ref mind.Comp))
return false;
// If there were no matches and thus no mind role entity names, we'll need the protoId, to report what role failed to be removed
var original = "'" + protoId + "'";
var deleteName = original;
var delete = new List<EntityUid>();
- foreach (var role in mind.Comp.MindRoles)
+ foreach (var role in mind.Comp.MindRoleContainer.ContainedEntities)
{
if (!HasComp<MindRoleComponent>(role))
{
/// </summary>
private bool MindRemoveRoleDo(Entity<MindComponent?> mind, List<EntityUid> delete, string? logName = "")
{
- if ( !Resolve(mind.Owner, ref mind.Comp))
+ if (!Resolve(mind.Owner, ref mind.Comp))
return false;
if (delete.Count <= 0)
return true;
}
- // Removing the mind role's reference on component shutdown
- // to make sure the reference gets removed even if the mind role entity was deleted by outside code
- private void OnComponentShutdown(Entity<MindRoleComponent> ent, ref ComponentShutdown args)
- {
- //TODO: Just ensure that the tests don't spawn unassociated mind role entities
- if (ent.Comp.Mind.Comp is null)
- return;
-
- ent.Comp.Mind.Comp.MindRoles.Remove(ent.Owner);
- }
-
/// <summary>
/// Finds the first mind role of a specific T type on a mind entity.
/// Outputs entity components for the mind role's MindRoleComponent and for T
if (!Resolve(mind.Owner, ref mind.Comp))
return false;
- foreach (var roleEnt in mind.Comp.MindRoles)
+ foreach (var roleEnt in mind.Comp.MindRoleContainer.ContainedEntities)
{
if (!TryComp(roleEnt, out T? tcomp))
continue;
var found = false;
- foreach (var roleEnt in mind.MindRoles)
+ foreach (var roleEnt in mind.MindRoleContainer.ContainedEntities)
{
if (!HasComp(roleEnt, type))
continue;
/// </summary>
public bool MindHasRole(Entity<MindComponent> mind, EntityWhitelist whitelist)
{
- foreach (var roleEnt in mind.Comp.MindRoles)
+ foreach (var roleEnt in mind.Comp.MindRoleContainer.ContainedEntities)
{
if (_whitelist.IsWhitelistPass(whitelist, roleEnt))
return true;
var mind = Comp<MindComponent>(mindId);
- foreach (var uid in mind.MindRoles)
+ foreach (var uid in mind.MindRoleContainer.ContainedEntities)
{
if (HasComp<T>(uid) && TryComp<MindRoleComponent>(uid, out var comp))
- result = (uid,comp);
+ result = (uid, comp);
}
return result;
}
if (!Resolve(mind.Owner, ref mind.Comp))
return roleInfo;
- foreach (var role in mind.Comp.MindRoles)
+ foreach (var role in mind.Comp.MindRoleContainer.ContainedEntities)
{
var valid = false;
var name = "game-ticker-unknown-role";
return CheckAntagonistStatus(mindId.Value).ExclusiveAntag;
}
- private (bool Antag, bool ExclusiveAntag) CheckAntagonistStatus(Entity<MindComponent?> mind)
- {
- if (!Resolve(mind.Owner, ref mind.Comp))
- return (false, false);
+ private (bool Antag, bool ExclusiveAntag) CheckAntagonistStatus(Entity<MindComponent?> mind)
+ {
+ if (!Resolve(mind.Owner, ref mind.Comp))
+ return (false, false);
var antagonist = false;
var exclusiveAntag = false;
- foreach (var role in mind.Comp.MindRoles)
+ foreach (var role in mind.Comp.MindRoleContainer.ContainedEntities)
{
if (!TryComp<MindRoleComponent>(role, out var roleComp))
{