]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow for the ai's laws to be changed from its core and eye (#32461)
authornikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Sat, 2 Nov 2024 13:21:10 +0000 (15:21 +0200)
committerGitHub <noreply@github.com>
Sat, 2 Nov 2024 13:21:10 +0000 (14:21 +0100)
* Allow for the ai's laws to be changed from its core and eye

* Address reviews

Content.Server/Administration/Systems/AdminVerbSystem.cs

index 2ab27e4388e719817da8995f8b52f272d2fc95e0..0640537f57ecd93a1c4de1f40764ec59a299903a 100644 (file)
@@ -35,8 +35,10 @@ using Robust.Shared.Toolshed;
 using Robust.Shared.Utility;
 using System.Linq;
 using Content.Server.Silicons.Laws;
+using Content.Shared.Movement.Components;
 using Content.Shared.Silicons.Laws.Components;
 using Robust.Server.Player;
+using Content.Shared.Silicons.StationAi;
 using Robust.Shared.Physics.Components;
 using static Content.Shared.Configurable.ConfigurationComponent;
 
@@ -345,7 +347,30 @@ namespace Content.Server.Administration.Systems
                     Impact = LogImpact.Low
                 });
 
-                if (TryComp<SiliconLawBoundComponent>(args.Target, out var lawBoundComponent))
+                // This logic is needed to be able to modify the AI's laws through its core and eye.
+                EntityUid? target = null;
+                SiliconLawBoundComponent? lawBoundComponent = null;
+
+                if (TryComp(args.Target, out lawBoundComponent))
+                {
+                    target = args.Target;
+                }
+                // When inspecting the core we can find the entity with its laws by looking at the  AiHolderComponent.
+                else if (TryComp<StationAiHolderComponent>(args.Target, out var holder) && holder.Slot.Item != null
+                         && TryComp(holder.Slot.Item, out lawBoundComponent))
+                {
+                    target = holder.Slot.Item.Value;
+                    // For the eye we can find the entity with its laws as the source of the movement relay since the eye
+                    // is just a proxy for it to move around and look around the station.
+                }
+                else if (TryComp<MovementRelayTargetComponent>(args.Target, out var relay)
+                         && TryComp(relay.Source, out lawBoundComponent))
+                {
+                    target = relay.Source;
+
+                }
+
+                if (lawBoundComponent != null && target != null)
                 {
                     args.Verbs.Add(new Verb()
                     {
@@ -359,7 +384,7 @@ namespace Content.Server.Administration.Systems
                                 return;
                             }
                             _euiManager.OpenEui(ui, session);
-                            ui.UpdateLaws(lawBoundComponent, args.Target);
+                            ui.UpdateLaws(lawBoundComponent, target.Value);
                         },
                         Icon = new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Actions/actions_borg.rsi"), "state-laws"),
                     });