Skip to content

Commit

Permalink
Fixes construction graphs proccing while being microwaved (space-wiza…
Browse files Browse the repository at this point in the history
…rds#23835)

* Fixes construction graphs proccing while being microwaved

* git those indents in line

* We knew we were missing something!
  • Loading branch information
deathride58 authored Jan 12, 2024
1 parent 1c3c596 commit f5c40c3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 22 deletions.
56 changes: 34 additions & 22 deletions Content.Server/Construction/ConstructionSystem.Interactions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InternalTemperatureComponent>(uid, out var internalTemp))
Expand Down Expand Up @@ -588,34 +595,39 @@ private enum DoAfterState : byte
/// </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;
}
}
11 changes: 11 additions & 0 deletions Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
32 changes: 32 additions & 0 deletions Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public override void Initialize()
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);
Expand All @@ -76,6 +78,10 @@ public override void Initialize()

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)
Expand All @@ -97,6 +103,22 @@ private void OnCookStop(Entity<ActiveMicrowaveComponent> ent, ref ComponentShutd
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.
Expand Down Expand Up @@ -239,6 +261,11 @@ private void OnSolutionChange(Entity<MicrowaveComponent> 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<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)
Expand Down Expand Up @@ -390,6 +417,8 @@ public void Wzhzhzh(EntityUid uid, MicrowaveComponent component, EntityUid? user
QueueDel(item);
}

AddComp<ActivelyMicrowavedComponent>(item);

var metaData = MetaData(item); //this simply begs for cooking refactor
if (metaData.EntityPrototype == null)
continue;
Expand Down Expand Up @@ -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<ActivelyMicrowavedComponent>(solid);

if (active.PortionedRecipe.Item1 != null)
{
var coords = Transform(uid).Coordinates;
Expand Down

0 comments on commit f5c40c3

Please sign in to comment.