Fixes construction graphs proccing while being microwaved (#23835)
* Fixes construction graphs proccing while being microwaved * git those indents in line * We knew we were missing something!
This commit is contained in:
@@ -380,6 +380,13 @@ namespace Content.Server.Construction
|
|||||||
if (ev is not OnTemperatureChangeEvent)
|
if (ev is not OnTemperatureChangeEvent)
|
||||||
break;
|
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.
|
// prefer using InternalTemperature since that's more accurate for cooking.
|
||||||
float temp;
|
float temp;
|
||||||
if (TryComp<InternalTemperatureComponent>(uid, out var internalTemp))
|
if (TryComp<InternalTemperatureComponent>(uid, out var internalTemp))
|
||||||
@@ -588,11 +595,12 @@ namespace Content.Server.Construction
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
Completed
|
Completed
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the result after attempting to handle a specific step with an event.
|
/// Specifies the result after attempting to handle a specific step with an event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private enum HandleResult : byte
|
public enum HandleResult : byte
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The interaction wasn't handled or validated.
|
/// The interaction wasn't handled or validated.
|
||||||
@@ -617,5 +625,9 @@ namespace Content.Server.Construction
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public sealed class OnConstructionTemperatureEvent : HandledEntityEventArgs
|
||||||
|
{
|
||||||
|
public HandleResult? Result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -59,6 +59,8 @@ namespace Content.Server.Kitchen.EntitySystems
|
|||||||
SubscribeLocalEvent<MicrowaveComponent, ComponentInit>(OnInit);
|
SubscribeLocalEvent<MicrowaveComponent, ComponentInit>(OnInit);
|
||||||
SubscribeLocalEvent<MicrowaveComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<MicrowaveComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<MicrowaveComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
SubscribeLocalEvent<MicrowaveComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
||||||
|
SubscribeLocalEvent<MicrowaveComponent, EntInsertedIntoContainerMessage>(OnContentUpdate);
|
||||||
|
SubscribeLocalEvent<MicrowaveComponent, EntRemovedFromContainerMessage>(OnContentUpdate);
|
||||||
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
|
SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
|
||||||
SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
|
SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
|
||||||
SubscribeLocalEvent<MicrowaveComponent, PowerChangedEvent>(OnPowerChanged);
|
SubscribeLocalEvent<MicrowaveComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
@@ -76,6 +78,10 @@ namespace Content.Server.Kitchen.EntitySystems
|
|||||||
|
|
||||||
SubscribeLocalEvent<ActiveMicrowaveComponent, ComponentStartup>(OnCookStart);
|
SubscribeLocalEvent<ActiveMicrowaveComponent, ComponentStartup>(OnCookStart);
|
||||||
SubscribeLocalEvent<ActiveMicrowaveComponent, ComponentShutdown>(OnCookStop);
|
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)
|
private void OnCookStart(Entity<ActiveMicrowaveComponent> ent, ref ComponentStartup args)
|
||||||
@@ -97,6 +103,22 @@ namespace Content.Server.Kitchen.EntitySystems
|
|||||||
microwaveComponent.PlayingStream = _audio.Stop(microwaveComponent.PlayingStream);
|
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>
|
/// <summary>
|
||||||
/// Adds temperature to every item in the microwave,
|
/// Adds temperature to every item in the microwave,
|
||||||
/// based on the time it took to microwave.
|
/// based on the time it took to microwave.
|
||||||
@@ -239,6 +261,11 @@ namespace Content.Server.Kitchen.EntitySystems
|
|||||||
UpdateUserInterfaceState(ent, ent.Comp);
|
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)
|
private void OnInteractUsing(Entity<MicrowaveComponent> ent, ref InteractUsingEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled)
|
if (args.Handled)
|
||||||
@@ -390,6 +417,8 @@ namespace Content.Server.Kitchen.EntitySystems
|
|||||||
QueueDel(item);
|
QueueDel(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddComp<ActivelyMicrowavedComponent>(item);
|
||||||
|
|
||||||
var metaData = MetaData(item); //this simply begs for cooking refactor
|
var metaData = MetaData(item); //this simply begs for cooking refactor
|
||||||
if (metaData.EntityPrototype == null)
|
if (metaData.EntityPrototype == null)
|
||||||
continue;
|
continue;
|
||||||
@@ -490,6 +519,9 @@ namespace Content.Server.Kitchen.EntitySystems
|
|||||||
//this means the microwave has finished cooking.
|
//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
|
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)
|
if (active.PortionedRecipe.Item1 != null)
|
||||||
{
|
{
|
||||||
var coords = Transform(uid).Coordinates;
|
var coords = Transform(uid).Coordinates;
|
||||||
|
|||||||
Reference in New Issue
Block a user