]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
add IsMemberOfAny to faction system (#32975)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Fri, 1 Nov 2024 02:34:27 +0000 (02:34 +0000)
committerGitHub <noreply@github.com>
Fri, 1 Nov 2024 02:34:27 +0000 (21:34 -0500)
* add IsMemberOfAny to faction system

* pro

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Shared/NPC/Systems/NpcFactionSystem.cs

index 98f14afe2a6f140fa962b6ba9fde4945e378d8c8..0d684de80b9adb8863a12c6dd7e9098b2f3a842e 100644 (file)
@@ -81,6 +81,24 @@ public sealed partial class NpcFactionSystem : EntitySystem
         return ent.Comp.Factions.Contains(faction);
     }
 
+    /// <summary>
+    /// Returns whether an entity is a member of any listed faction.
+    /// If the list is empty this returns false.
+    /// </summary>
+    public bool IsMemberOfAny(Entity<NpcFactionMemberComponent?> ent, IEnumerable<ProtoId<NpcFactionPrototype>> factions)
+    {
+        if (!Resolve(ent, ref ent.Comp, false))
+            return false;
+
+        foreach (var faction in factions)
+        {
+            if (ent.Comp.Factions.Contains(faction))
+                return true;
+        }
+
+        return false;
+    }
+
     /// <summary>
     /// Adds this entity to the particular faction.
     /// </summary>