diff --git a/Content.Server/Construction/ConstructionSystem.Interactions.cs b/Content.Server/Construction/ConstructionSystem.Interactions.cs index 6112dd13ad2a39..a19ee8df6d9acb 100644 --- a/Content.Server/Construction/ConstructionSystem.Interactions.cs +++ b/Content.Server/Construction/ConstructionSystem.Interactions.cs @@ -380,6 +380,13 @@ private HandleResult HandleInteraction(EntityUid uid, object ev, ConstructionGra 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(uid, out var internalTemp)) @@ -588,34 +595,39 @@ private enum DoAfterState : byte /// Completed } + } + /// + /// Specifies the result after attempting to handle a specific step with an event. + /// + public enum HandleResult : byte + { /// - /// Specifies the result after attempting to handle a specific step with an event. + /// The interaction wasn't handled or validated. /// - private enum HandleResult : byte - { - /// - /// The interaction wasn't handled or validated. - /// - False, + False, - /// - /// The interaction would be handled successfully. Nothing was modified. - /// - Validated, + /// + /// The interaction would be handled successfully. Nothing was modified. + /// + Validated, - /// - /// The interaction was handled successfully. - /// - True, + /// + /// The interaction was handled successfully. + /// + True, - /// - /// The interaction is waiting on a DoAfter now. - /// This means the interaction started the DoAfter. - /// - DoAfter, - } + /// + /// The interaction is waiting on a DoAfter now. + /// This means the interaction started the DoAfter. + /// + 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 index 00000000000000..54a7edd745497f --- /dev/null +++ b/Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs @@ -0,0 +1,11 @@ +using Content.Shared.Kitchen; + +namespace Content.Server.Kitchen.Components; + +/// +/// Attached to an object that's actively being microwaved +/// +[RegisterComponent] +public sealed partial class ActivelyMicrowavedComponent : Component +{ +} diff --git a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs index 38965a19d55348..930318609bef54 100644 --- a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs @@ -59,6 +59,8 @@ public override void Initialize() SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnSolutionChange); + SubscribeLocalEvent(OnContentUpdate); + SubscribeLocalEvent(OnContentUpdate); SubscribeLocalEvent(OnInteractUsing, after: new[] { typeof(AnchorableSystem) }); SubscribeLocalEvent(OnBreak); SubscribeLocalEvent(OnPowerChanged); @@ -76,6 +78,10 @@ public override void Initialize() SubscribeLocalEvent(OnCookStart); SubscribeLocalEvent(OnCookStop); + SubscribeLocalEvent(OnActiveMicrowaveInsert); + SubscribeLocalEvent(OnActiveMicrowaveRemove); + + SubscribeLocalEvent(OnConstructionTemp); } private void OnCookStart(Entity ent, ref ComponentStartup args) @@ -97,6 +103,22 @@ private void OnCookStop(Entity ent, ref ComponentShutd microwaveComponent.PlayingStream = _audio.Stop(microwaveComponent.PlayingStream); } + private void OnActiveMicrowaveInsert(Entity ent, ref EntInsertedIntoContainerMessage args) + { + AddComp(args.Entity); + } + + private void OnActiveMicrowaveRemove(Entity ent, ref EntRemovedFromContainerMessage args) + { + EntityManager.RemoveComponentDeferred(args.Entity); + } + + private void OnConstructionTemp(Entity ent, ref OnConstructionTemperatureEvent args) + { + args.Result = HandleResult.False; + return; + } + /// /// Adds temperature to every item in the microwave, /// based on the time it took to microwave. @@ -239,6 +261,11 @@ private void OnSolutionChange(Entity ent, ref SolutionContai 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. TODO: replace with Entity syntax once that's possible + { + UpdateUserInterfaceState(uid, component); + } + private void OnInteractUsing(Entity ent, ref InteractUsingEvent args) { if (args.Handled) @@ -390,6 +417,8 @@ public void Wzhzhzh(EntityUid uid, MicrowaveComponent component, EntityUid? user QueueDel(item); } + AddComp(item); + var metaData = MetaData(item); //this simply begs for cooking refactor if (metaData.EntityPrototype == null) continue; @@ -490,6 +519,9 @@ public override void Update(float frameTime) //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(solid); + if (active.PortionedRecipe.Item1 != null) { var coords = Transform(uid).Coordinates;