diff --git a/Content.Server/Stories/Conversion/ConversionSystem.API.cs b/Content.Server/Stories/Conversion/ConversionSystem.API.cs index be7a05f6c4..068fa1c6b5 100644 --- a/Content.Server/Stories/Conversion/ConversionSystem.API.cs +++ b/Content.Server/Stories/Conversion/ConversionSystem.API.cs @@ -3,11 +3,12 @@ using Content.Shared.Stories.Conversion; using Robust.Shared.Prototypes; using Content.Server.Radio.Components; -using Content.Shared.Database; using System.Diagnostics.CodeAnalysis; +using System.Linq; namespace Content.Server.Stories.Conversion; +// TODO: Move to shared public sealed partial class ConversionSystem { public HashSet GetEntitiesConvertedBy(EntityUid? uid, ProtoId prototype) @@ -138,21 +139,31 @@ public void MindRemoveRoles(EntityUid mindId, List>? ro if (roles == null) return; - mind.MindRoles?.ForEach((mindRole) => + var rolesUid = mind.MindRoles.Where((role) => EntityPrototyped(role, roles)).ToList(); + + rolesUid.ForEach((mindRole) => { - var proto = MetaData(mindRole).EntityPrototype; - if (proto != null && roles.Contains(proto)) - { - var antagonist = Comp(mindRole).Antag; + var antagonist = Comp(mindRole).Antag; - QueueDel(mindRole); - mind.MindRoles.Remove(mindRole); + QueueDel(mindRole); - var message = new RoleRemovedEvent(mindId, mind, antagonist); + mind.MindRoles.Remove(mindRole); - if (mind.OwnedEntity != null) - RaiseLocalEvent(mind.OwnedEntity.Value, message, true); - } + var message = new RoleRemovedEvent(mindId, mind, antagonist); + + if (mind.OwnedEntity != null) + RaiseLocalEvent(mind.OwnedEntity.Value, message, true); }); + + mind.MindRoles?.Clear(); + } + public bool EntityPrototyped(EntityUid role, List> roles) + { + var proto = MetaData(role).EntityPrototype; + + if (proto == null) + return false; + + return roles.Contains(proto); } }