]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fixes construction graphs proccing while being microwaved (#23835)
authordeathride58 <deathride58@users.noreply.github.com>
Fri, 12 Jan 2024 08:42:41 +0000 (03:42 -0500)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 08:42:41 +0000 (01:42 -0700)
* Fixes construction graphs proccing while being microwaved

* git those indents in line

* We knew we were missing something!

Content.Server/Construction/ConstructionSystem.Interactions.cs
Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs [new file with mode: 0644]
Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs

index 6112dd13ad2a39a148e15958d747eb9550a0e15c..a19ee8df6d9acb34224c37942442af8fe0781139 100644 (file)
@@ -380,6 +380,13 @@ namespace Content.Server.Construction
                     if (ev is not OnTemperatureChangeEvent)
                         break;
 
+                    // Some things, like microwaves, might need to block the temperature construction step from kicking in, or override it entirely.
+                    var tempEvent = new OnConstructionTemperatureEvent();
+                    RaiseLocalEvent(uid, tempEvent, true);
+
+                    if (tempEvent.Result is not null)
+                        return tempEvent.Result.Value;
+
                     // prefer using InternalTemperature since that's more accurate for cooking.
                     float temp;
                     if (TryComp<InternalTemperatureComponent>(uid, out var internalTemp))
@@ -588,34 +595,39 @@ namespace Content.Server.Construction
             /// </summary>
             Completed
         }
+    }
 
+    /// <summary>
+    ///     Specifies the result after attempting to handle a specific step with an event.
+    /// </summary>
+    public enum HandleResult : byte
+    {
         /// <summary>
-        ///     Specifies the result after attempting to handle a specific step with an event.
+        ///     The interaction wasn't handled or validated.
         /// </summary>
-        private enum HandleResult : byte
-        {
-            /// <summary>
-            ///     The interaction wasn't handled or validated.
-            /// </summary>
-            False,
+        False,
 
-            /// <summary>
-            ///     The interaction would be handled successfully. Nothing was modified.
-            /// </summary>
-            Validated,
+        /// <summary>
+        ///     The interaction would be handled successfully. Nothing was modified.
+        /// </summary>
+        Validated,
 
-            /// <summary>
-            ///     The interaction was handled successfully.
-            /// </summary>
-            True,
+        /// <summary>
+        ///     The interaction was handled successfully.
+        /// </summary>
+        True,
 
-            /// <summary>
-            ///     The interaction is waiting on a DoAfter now.
-            ///     This means the interaction started the DoAfter.
-            /// </summary>
-            DoAfter,
-        }
+        /// <summary>
+        ///     The interaction is waiting on a DoAfter now.
+        ///     This means the interaction started the DoAfter.
+        /// </summary>
+        DoAfter,
+    }
 
-        #endregion
+    #endregion
+
+    public sealed class OnConstructionTemperatureEvent : HandledEntityEventArgs
+    {
+        public HandleResult? Result;
     }
 }
diff --git a/Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs b/Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs
new file mode 100644 (file)
index 0000000..54a7edd
--- /dev/null
@@ -0,0 +1,11 @@
+using Content.Shared.Kitchen;
+
+namespace Content.Server.Kitchen.Components;
+
+/// <summary>
+/// Attached to an object that's actively being microwaved
+/// </summary>
+[RegisterComponent]
+public sealed partial class ActivelyMicrowavedComponent : Component
+{
+}
index 38965a19d5534823e5afe993027d9ec0d06d1258..930318609bef54c47b560ffd8a6bbfd15d40975f 100644 (file)
@@ -59,6 +59,8 @@ namespace Content.Server.Kitchen.EntitySystems
             SubscribeLocalEvent<MicrowaveComponent, ComponentInit>(OnInit);
             SubscribeLocalEvent<MicrowaveComponent, MapInitEvent>(OnMapInit);
             SubscribeLocalEvent<MicrowaveComponent, SolutionContainerChangedEvent>(OnSolutionChange);
+            SubscribeLocalEvent<MicrowaveComponent, EntInsertedIntoContainerMessage>(OnContentUpdate);
+            SubscribeLocalEvent<MicrowaveComponent, EntRemovedFromContainerMessage>(OnContentUpdate);
             SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
             SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
             SubscribeLocalEvent<MicrowaveComponent, PowerChangedEvent>(OnPowerChanged);
@@ -76,6 +78,10 @@ namespace Content.Server.Kitchen.EntitySystems
 
             SubscribeLocalEvent<ActiveMicrowaveComponent, ComponentStartup>(OnCookStart);
             SubscribeLocalEvent<ActiveMicrowaveComponent, ComponentShutdown>(OnCookStop);
+            SubscribeLocalEvent<ActiveMicrowaveComponent, EntInsertedIntoContainerMessage>(OnActiveMicrowaveInsert);
+            SubscribeLocalEvent<ActiveMicrowaveComponent, EntRemovedFromContainerMessage>(OnActiveMicrowaveRemove);
+
+            SubscribeLocalEvent<ActivelyMicrowavedComponent, OnConstructionTemperatureEvent>(OnConstructionTemp);
         }
 
         private void OnCookStart(Entity<ActiveMicrowaveComponent> ent, ref ComponentStartup args)
@@ -97,6 +103,22 @@ namespace Content.Server.Kitchen.EntitySystems
             microwaveComponent.PlayingStream = _audio.Stop(microwaveComponent.PlayingStream);
         }
 
+        private void OnActiveMicrowaveInsert(Entity<ActiveMicrowaveComponent> ent, ref EntInsertedIntoContainerMessage args)
+        {
+            AddComp<ActivelyMicrowavedComponent>(args.Entity);
+        }
+
+        private void OnActiveMicrowaveRemove(Entity<ActiveMicrowaveComponent> ent, ref EntRemovedFromContainerMessage args)
+        {
+            EntityManager.RemoveComponentDeferred<ActivelyMicrowavedComponent>(args.Entity);
+        }
+
+        private void OnConstructionTemp(Entity<ActivelyMicrowavedComponent> ent, ref OnConstructionTemperatureEvent args)
+        {
+            args.Result = HandleResult.False;
+            return;
+        }
+
         /// <summary>
         ///     Adds temperature to every item in the microwave,
         ///     based on the time it took to microwave.
@@ -239,6 +261,11 @@ namespace Content.Server.Kitchen.EntitySystems
             UpdateUserInterfaceState(ent, ent.Comp);
         }
 
+        private void OnContentUpdate(EntityUid uid, MicrowaveComponent component, ContainerModifiedMessage args) // For some reason ContainerModifiedMessage just can't be used at all with Entity<T>. TODO: replace with Entity<T> syntax once that's possible
+        {
+            UpdateUserInterfaceState(uid, component);
+        }
+
         private void OnInteractUsing(Entity<MicrowaveComponent> ent, ref InteractUsingEvent args)
         {
             if (args.Handled)
@@ -390,6 +417,8 @@ namespace Content.Server.Kitchen.EntitySystems
                     QueueDel(item);
                 }
 
+                AddComp<ActivelyMicrowavedComponent>(item);
+
                 var metaData = MetaData(item); //this simply begs for cooking refactor
                 if (metaData.EntityPrototype == null)
                     continue;
@@ -490,6 +519,9 @@ namespace Content.Server.Kitchen.EntitySystems
                 //this means the microwave has finished cooking.
                 AddTemperature(microwave, Math.Max(frameTime + active.CookTimeRemaining, 0)); //Though there's still a little bit more heat to pump out
 
+                foreach (var solid in microwave.Storage.ContainedEntities)
+                    EntityManager.RemoveComponentDeferred<ActivelyMicrowavedComponent>(solid);
+
                 if (active.PortionedRecipe.Item1 != null)
                 {
                     var coords = Transform(uid).Coordinates;