]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fixed portal artifacts targeting the Ai (#32677)
authorKevin Matuschzik <92296572+Gamer3107@users.noreply.github.com>
Mon, 14 Oct 2024 05:55:46 +0000 (07:55 +0200)
committerGitHub <noreply@github.com>
Mon, 14 Oct 2024 05:55:46 +0000 (16:55 +1100)
* Added checks to not target AIs and people in containers

* made the change to use IsEntityInContainer. Much Better!

* returned old Mindquerry and removed wrong use of admin logger

* guard statment

* removed unnecessery refs and fixed position swap

* Minor change

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Server/Xenoarchaeology/XenoArtifacts/Effects/Systems/PortalArtifactSystem.cs

index e44ee6baa12f8375e6319d31b753914832ab5da7..b1a08fb5056094ac6d98144c8de9e915a89a9c5b 100644 (file)
@@ -2,6 +2,8 @@ using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
 using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
 using Content.Shared.Mind.Components;
 using Content.Shared.Teleportation.Systems;
+using Robust.Shared.Collections;
+using Robust.Shared.Containers;
 using Robust.Shared.Random;
 
 namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
@@ -11,6 +13,7 @@ public sealed class PortalArtifactSystem : EntitySystem
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly LinkedEntitySystem _link = default!;
     [Dependency] private readonly SharedTransformSystem _transform = default!;
+    [Dependency] private readonly SharedContainerSystem _container = default!;
 
     public override void Initialize()
     {
@@ -21,21 +24,28 @@ public sealed class PortalArtifactSystem : EntitySystem
     private void OnActivate(Entity<PortalArtifactComponent> artifact, ref ArtifactActivatedEvent args)
     {
         var map = Transform(artifact).MapID;
-        var firstPortal = Spawn(artifact.Comp.PortalProto, _transform.GetMapCoordinates(artifact));
-
-        var minds = new List<EntityUid>();
-        var mindQuery = EntityQueryEnumerator<MindContainerComponent, TransformComponent>();
-        while (mindQuery.MoveNext(out var uid, out var mc, out var xform))
+        var validMinds = new ValueList<EntityUid>();
+        var mindQuery = EntityQueryEnumerator<MindContainerComponent, TransformComponent, MetaDataComponent>();
+        while (mindQuery.MoveNext(out var uid, out var mc, out var xform, out var meta))
         {
-            if (mc.HasMind && xform.MapID == map)
-                minds.Add(uid);
+            // check if the MindContainer has a Mind and if the entity is not in a container (this also auto excludes AI) and if they are on the same map
+            if (mc.HasMind && !_container.IsEntityOrParentInContainer(uid, meta: meta, xform: xform) && xform.MapID == map)
+            {
+                validMinds.Add(uid);
+            }
         }
+        //this would only be 0 if there were a station full of AIs and no one else, in that case just stop this function
+        if (validMinds.Count == 0)
+            return;
+
+        var firstPortal = Spawn(artifact.Comp.PortalProto, _transform.GetMapCoordinates(artifact));
+
+        var target = _random.Pick(validMinds);
 
-        var target = _random.Pick(minds);
         var secondPortal = Spawn(artifact.Comp.PortalProto, _transform.GetMapCoordinates(target));
 
         //Manual position swapping, because the portal that opens doesn't trigger a collision, and doesn't teleport targets the first time.
-        _transform.SwapPositions(target, secondPortal);
+        _transform.SwapPositions(target, artifact.Owner);
 
         _link.TryLink(firstPortal, secondPortal, true);
     }