Skip to content

Commit f5c40c3

Browse files
authored
Fixes construction graphs proccing while being microwaved (space-wizards#23835)
* Fixes construction graphs proccing while being microwaved * git those indents in line * We knew we were missing something!
1 parent 1c3c596 commit f5c40c3

File tree

3 files changed

+77
-22
lines changed

3 files changed

+77
-22
lines changed

‎Content.Server/Construction/ConstructionSystem.Interactions.cs‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ private HandleResult HandleInteraction(EntityUid uid, object ev, ConstructionGra
380380
if (ev is not OnTemperatureChangeEvent)
381381
break;
382382

383+
// Some things, like microwaves, might need to block the temperature construction step from kicking in, or override it entirely.
384+
var tempEvent = new OnConstructionTemperatureEvent();
385+
RaiseLocalEvent(uid, tempEvent, true);
386+
387+
if (tempEvent.Result is not null)
388+
return tempEvent.Result.Value;
389+
383390
// prefer using InternalTemperature since that's more accurate for cooking.
384391
float temp;
385392
if (TryComp<InternalTemperatureComponent>(uid, out var internalTemp))
@@ -588,34 +595,39 @@ private enum DoAfterState : byte
588595
/// </summary>
589596
Completed
590597
}
598+
}
591599

600+
/// <summary>
601+
/// Specifies the result after attempting to handle a specific step with an event.
602+
/// </summary>
603+
public enum HandleResult : byte
604+
{
592605
/// <summary>
593-
/// Specifies the result after attempting to handle a specific step with an event.
606+
/// The interaction wasn't handled or validated.
594607
/// </summary>
595-
private enum HandleResult : byte
596-
{
597-
/// <summary>
598-
/// The interaction wasn't handled or validated.
599-
/// </summary>
600-
False,
608+
False,
601609

602-
/// <summary>
603-
/// The interaction would be handled successfully. Nothing was modified.
604-
/// </summary>
605-
Validated,
610+
/// <summary>
611+
/// The interaction would be handled successfully. Nothing was modified.
612+
/// </summary>
613+
Validated,
606614

607-
/// <summary>
608-
/// The interaction was handled successfully.
609-
/// </summary>
610-
True,
615+
/// <summary>
616+
/// The interaction was handled successfully.
617+
/// </summary>
618+
True,
611619

612-
/// <summary>
613-
/// The interaction is waiting on a DoAfter now.
614-
/// This means the interaction started the DoAfter.
615-
/// </summary>
616-
DoAfter,
617-
}
620+
/// <summary>
621+
/// The interaction is waiting on a DoAfter now.
622+
/// This means the interaction started the DoAfter.
623+
/// </summary>
624+
DoAfter,
625+
}
618626

619-
#endregion
627+
#endregion
628+
629+
public sealed class OnConstructionTemperatureEvent : HandledEntityEventArgs
630+
{
631+
public HandleResult? Result;
620632
}
621633
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Content.Shared.Kitchen;
2+
3+
namespace Content.Server.Kitchen.Components;
4+
5+
/// <summary>
6+
/// Attached to an object that's actively being microwaved
7+
/// </summary>
8+
[RegisterComponent]
9+
public sealed partial class ActivelyMicrowavedComponent : Component
10+
{
11+
}

‎Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public override void Initialize()
5959
SubscribeLocalEvent<MicrowaveComponent, ComponentInit>(OnInit);
6060
SubscribeLocalEvent<MicrowaveComponent, MapInitEvent>(OnMapInit);
6161
SubscribeLocalEvent<MicrowaveComponent, SolutionContainerChangedEvent>(OnSolutionChange);
62+
SubscribeLocalEvent<MicrowaveComponent, EntInsertedIntoContainerMessage>(OnContentUpdate);
63+
SubscribeLocalEvent<MicrowaveComponent, EntRemovedFromContainerMessage>(OnContentUpdate);
6264
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
6365
SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
6466
SubscribeLocalEvent<MicrowaveComponent, PowerChangedEvent>(OnPowerChanged);
@@ -76,6 +78,10 @@ public override void Initialize()
7678

7779
SubscribeLocalEvent<ActiveMicrowaveComponent, ComponentStartup>(OnCookStart);
7880
SubscribeLocalEvent<ActiveMicrowaveComponent, ComponentShutdown>(OnCookStop);
81+
SubscribeLocalEvent<ActiveMicrowaveComponent, EntInsertedIntoContainerMessage>(OnActiveMicrowaveInsert);
82+
SubscribeLocalEvent<ActiveMicrowaveComponent, EntRemovedFromContainerMessage>(OnActiveMicrowaveRemove);
83+
84+
SubscribeLocalEvent<ActivelyMicrowavedComponent, OnConstructionTemperatureEvent>(OnConstructionTemp);
7985
}
8086

8187
private void OnCookStart(Entity<ActiveMicrowaveComponent> ent, ref ComponentStartup args)
@@ -97,6 +103,22 @@ private void OnCookStop(Entity<ActiveMicrowaveComponent> ent, ref ComponentShutd
97103
microwaveComponent.PlayingStream = _audio.Stop(microwaveComponent.PlayingStream);
98104
}
99105

106+
private void OnActiveMicrowaveInsert(Entity<ActiveMicrowaveComponent> ent, ref EntInsertedIntoContainerMessage args)
107+
{
108+
AddComp<ActivelyMicrowavedComponent>(args.Entity);
109+
}
110+
111+
private void OnActiveMicrowaveRemove(Entity<ActiveMicrowaveComponent> ent, ref EntRemovedFromContainerMessage args)
112+
{
113+
EntityManager.RemoveComponentDeferred<ActivelyMicrowavedComponent>(args.Entity);
114+
}
115+
116+
private void OnConstructionTemp(Entity<ActivelyMicrowavedComponent> ent, ref OnConstructionTemperatureEvent args)
117+
{
118+
args.Result = HandleResult.False;
119+
return;
120+
}
121+
100122
/// <summary>
101123
/// Adds temperature to every item in the microwave,
102124
/// based on the time it took to microwave.
@@ -239,6 +261,11 @@ private void OnSolutionChange(Entity<MicrowaveComponent> ent, ref SolutionContai
239261
UpdateUserInterfaceState(ent, ent.Comp);
240262
}
241263

264+
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
265+
{
266+
UpdateUserInterfaceState(uid, component);
267+
}
268+
242269
private void OnInteractUsing(Entity<MicrowaveComponent> ent, ref InteractUsingEvent args)
243270
{
244271
if (args.Handled)
@@ -390,6 +417,8 @@ public void Wzhzhzh(EntityUid uid, MicrowaveComponent component, EntityUid? user
390417
QueueDel(item);
391418
}
392419

420+
AddComp<ActivelyMicrowavedComponent>(item);
421+
393422
var metaData = MetaData(item); //this simply begs for cooking refactor
394423
if (metaData.EntityPrototype == null)
395424
continue;
@@ -490,6 +519,9 @@ public override void Update(float frameTime)
490519
//this means the microwave has finished cooking.
491520
AddTemperature(microwave, Math.Max(frameTime + active.CookTimeRemaining, 0)); //Though there's still a little bit more heat to pump out
492521

522+
foreach (var solid in microwave.Storage.ContainedEntities)
523+
EntityManager.RemoveComponentDeferred<ActivelyMicrowavedComponent>(solid);
524+
493525
if (active.PortionedRecipe.Item1 != null)
494526
{
495527
var coords = Transform(uid).Coordinates;

0 commit comments

Comments
 (0)