Skip to content

Commit

Permalink
fix conversion remove roles (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: Doublechest <twin01v@gmail.com>
  • Loading branch information
doublechest0 and Doublechest authored Nov 2, 2024
1 parent fb1866b commit f7b36f8
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Content.Server/Stories/Conversion/ConversionSystem.API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityUid> GetEntitiesConvertedBy(EntityUid? uid, ProtoId<ConversionPrototype> prototype)
Expand Down Expand Up @@ -138,21 +139,31 @@ public void MindRemoveRoles(EntityUid mindId, List<ProtoId<EntityPrototype>>? 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<MindRoleComponent>(mindRole).Antag;
var antagonist = Comp<MindRoleComponent>(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<ProtoId<EntityPrototype>> roles)
{
var proto = MetaData(role).EntityPrototype;

if (proto == null)
return false;

return roles.Contains(proto);
}
}

0 comments on commit f7b36f8

Please sign in to comment.