]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Prevent Quantum Spin Inverter from Teleporting Things into Microwaves (#29200)
authorCojoke <83733158+Cojoke-dot@users.noreply.github.com>
Thu, 18 Jul 2024 00:40:54 +0000 (19:40 -0500)
committerGitHub <noreply@github.com>
Thu, 18 Jul 2024 00:40:54 +0000 (10:40 +1000)
* Prevent Quantum Spin Inverter from Teleporting Things into Microwaves

* Simplifies code, GetTeleportingEntity instead of TryGet, adds failed teleport message

* remove using Linguini.Syntax.Ast;

* capital...

* re-add CanInsert and Fixes microwave issue

* beb

* beeb

Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs
Content.Shared/Teleportation/Systems/SwapTeleporterSystem.cs
Resources/Locale/en-US/portal/swap-teleporter.ftl

index eefa539149b021b25c317c2c2e68f05176e37d60..71986ae859e9a86d47c805bb025b181a67ea7d74 100644 (file)
@@ -79,6 +79,7 @@ namespace Content.Server.Kitchen.EntitySystems
             SubscribeLocalEvent<MicrowaveComponent, EntInsertedIntoContainerMessage>(OnContentUpdate);
             SubscribeLocalEvent<MicrowaveComponent, EntRemovedFromContainerMessage>(OnContentUpdate);
             SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
+            SubscribeLocalEvent<MicrowaveComponent, ContainerIsInsertingAttemptEvent>(OnInsertAttempt);
             SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
             SubscribeLocalEvent<MicrowaveComponent, PowerChangedEvent>(OnPowerChanged);
             SubscribeLocalEvent<MicrowaveComponent, AnchorStateChangedEvent>(OnAnchorChanged);
@@ -309,6 +310,32 @@ namespace Content.Server.Kitchen.EntitySystems
             UpdateUserInterfaceState(uid, component);
         }
 
+        private void OnInsertAttempt(Entity<MicrowaveComponent> ent, ref ContainerIsInsertingAttemptEvent args)
+        {
+            if (ent.Comp.Broken)
+            {
+                args.Cancel();
+                return;
+            }
+
+            if (TryComp<ItemComponent>(args.EntityUid, out var item))
+            {
+                if (_item.GetSizePrototype(item.Size) > _item.GetSizePrototype(ent.Comp.MaxItemSize))
+                {
+                    args.Cancel();
+                    return;
+                }
+            }
+            else
+            {
+                args.Cancel();
+                return;
+            }
+
+            if (ent.Comp.Storage.Count >= ent.Comp.Capacity)
+                args.Cancel();
+        }
+
         private void OnInteractUsing(Entity<MicrowaveComponent> ent, ref InteractUsingEvent args)
         {
             if (args.Handled)
index 58c249fec54f873212564f3703242a604eed4a03..a5ad77d43bf0c6ad44c5d87a4e1ae450acc37afe 100644 (file)
@@ -150,8 +150,19 @@ public sealed class SwapTeleporterSystem : EntitySystem
             return;
         }
 
-        var teleEnt = GetTeleportingEntity((uid, xform));
-        var otherTeleEnt = GetTeleportingEntity((linkedEnt, Transform(linkedEnt)));
+        var (teleEnt, cont) = GetTeleportingEntity((uid, xform));
+        var (otherTeleEnt, otherCont) = GetTeleportingEntity((linkedEnt, Transform(linkedEnt)));
+
+        if (otherCont != null && !_container.CanInsert(teleEnt, otherCont) ||
+            cont != null && !_container.CanInsert(otherTeleEnt, cont))
+        {
+            _popup.PopupEntity(Loc.GetString("swap-teleporter-popup-teleport-fail",
+                ("entity", Identity.Entity(linkedEnt, EntityManager))),
+                teleEnt,
+                teleEnt,
+                PopupType.MediumCaution);
+            return;
+        }
 
         _popup.PopupEntity(Loc.GetString("swap-teleporter-popup-teleport-other",
             ("entity", Identity.Entity(linkedEnt, EntityManager))),
@@ -184,20 +195,20 @@ public sealed class SwapTeleporterSystem : EntitySystem
             DestroyLink(linked, user); // the linked one is shown globally
     }
 
-    private EntityUid GetTeleportingEntity(Entity<TransformComponent> ent)
+    private (EntityUid, BaseContainer?) GetTeleportingEntity(Entity<TransformComponent> ent)
     {
         var parent = ent.Comp.ParentUid;
         if (_container.TryGetOuterContainer(ent, ent, out var container))
             parent = container.Owner;
 
         if (HasComp<MapGridComponent>(parent) || HasComp<MapComponent>(parent))
-            return ent;
+            return (ent, container);
 
         if (!_xformQuery.TryGetComponent(parent, out var parentXform) || parentXform.Anchored)
-            return ent;
+            return (ent, container);
 
         if (!TryComp<PhysicsComponent>(parent, out var body) || body.BodyType == BodyType.Static)
-            return ent;
+            return (ent, container);
 
         return GetTeleportingEntity((parent, parentXform));
     }
index f13fa9be423b8e06f2e425d6f9fb4e7af6503142..0040ad0a88b56c55d04396850aa4e29df6598a93 100644 (file)
@@ -5,6 +5,7 @@ swap-teleporter-popup-link-destroyed = Quantum link destroyed!
 swap-teleporter-popup-teleport-cancel-time = It's still recharging!
 swap-teleporter-popup-teleport-cancel-link = It's not linked with another device!
 swap-teleporter-popup-teleport-other = {CAPITALIZE(THE($entity))} activates, and you find yourself somewhere else.
+swap-teleporter-popup-teleport-fail = {CAPITALIZE(THE($entity))} activates and fails to transport you anywhere.
 
 swap-teleporter-verb-destroy-link = Destroy Quantum Link