using Content.Shared.Kitchen.Components;
using Robust.Shared.Serialization;
namespace Content.Shared.Kitchen.EntitySystems;
public abstract partial class MicrowaveSystem
{
///
/// Subscribe to UI-related events for microwaves.
///
private void InitializeUI()
{
SubscribeLocalEvent((e, ref m) => StartCooking(e, m.Actor));
}
///
/// Ejects all ingredients from the microwave.
///
[SubscribeLocalEvent]
private void OnEjectAll(Entity ent, ref MicrowaveEjectMessage args)
{
if (!HasContents(ent.AsNullable()) || IsActiveMicrowave(ent.AsNullable()))
return;
Container.EmptyContainer(ent.Comp.Storage);
var audioParams = ent.Comp.ClickSound.Params;
audioParams = audioParams.AddVolume(-2);
Audio.PlayPredicted(ent.Comp.ClickSound, ent, args.Actor, audioParams);
}
///
/// Ejects an ingredient entity from the microwave.
///
[SubscribeLocalEvent]
private void OnEjectSolidIndexed(Entity ent, ref MicrowaveEjectSolidIndexedMessage args)
{
if (!HasContents(ent.AsNullable()) || IsActiveMicrowave(ent.AsNullable()))
return;
Container.Remove(GetEntity(args.EntityId), ent.Comp.Storage);
var audioParams = ent.Comp.ClickSound.Params;
Audio.PlayPredicted(ent.Comp.ClickSound, ent, args.Actor, audioParams);
}
///
/// Change the cook time of the microwave by selecting a new button index.
///
[SubscribeLocalEvent]
private void OnSelectCookTime(Entity ent, ref MicrowaveSelectCookTimeMessage args)
{
if (IsActiveMicrowave(ent.AsNullable())
|| !_power.IsPowered(ent.Owner))
return;
// some validation to prevent trollage
if (args.NewCookTime % 5 != 0 || args.NewCookTime > ent.Comp.MaxCookTime)
return;
ent.Comp.CurrentCookTimeButtonIndex = args.ButtonIndex;
ent.Comp.CurrentCookTimerTime = args.NewCookTime;
Dirty(ent);
var audioParams = ent.Comp.ClickSound.Params;
Audio.PlayPredicted(ent.Comp.ClickSound, ent, args.Actor, audioParams);
UpdateUI(ent.AsNullable());
}
///
/// Update the UI state of the microwave, including the microwave's current contents, cook time,
/// and whether or not it is actively cooking.
///
/// The microwave to update.
public virtual void UpdateUI(Entity microwave)
{
}
}
///
/// Sent from client to server to request the microwave to start cooking.
///
[Serializable, NetSerializable]
public sealed class MicrowaveStartCookMessage : BoundUserInterfaceMessage;
///
/// Sent from client to server to request ejecting all contents of the microwave.
///
[Serializable, NetSerializable]
public sealed class MicrowaveEjectMessage : BoundUserInterfaceMessage;
///
/// Sent from client to server to request ejecting an entity from the microwave.
///
[Serializable, NetSerializable]
public sealed class MicrowaveEjectSolidIndexedMessage(NetEntity entityId) : BoundUserInterfaceMessage
{
///
/// The entity to eject from the microwave.
///
public NetEntity EntityId = entityId;
}
///
/// Sent from client to server to request changing the selected cook time button of the microwave.
///
[Serializable, NetSerializable]
public sealed class MicrowaveSelectCookTimeMessage(int buttonIndex, uint inputTime) : BoundUserInterfaceMessage
{
///
/// The index of the cook time button to select.
///
public int ButtonIndex = buttonIndex;
///
/// The cooking time associated with the newly-selected button.
///
public uint NewCookTime = inputTime;
}