From f7b36f827cfcc8ae62ead18bee901d3d8dbbef14 Mon Sep 17 00:00:00 2001 From: doublechest <114690331+doublechest0@users.noreply.github.com> Date: Sat, 2 Nov 2024 18:44:45 +0300 Subject: [PATCH] fix conversion remove roles (#220) Co-authored-by: Doublechest --- .../Conversion/ConversionSystem.API.cs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) 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); } }