Skip to content

Commit

Permalink
2023 12 22 deep fryer fixes (#740)
Browse files Browse the repository at this point in the history
* Deepfryer missing import

* deep frier slice fix (#581)

* move SliceFoodEvent into a deltav file, move raising into Slice()

* import deltav event

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>

* Fix unlocalized name deep-fried-burnt-item (#535)

Fix unlocalized name

WHEW.

* Update SliceableFoodSystem.cs

* Deep

---------

Co-authored-by: deltanedas <[email protected]>
Co-authored-by: Loonessia <[email protected]>
  • Loading branch information
3 people authored Dec 24, 2023
1 parent 426ac36 commit b6c5d67
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 69 deletions.
34 changes: 34 additions & 0 deletions Content.Server/DeltaV/Nutrition/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Content.Server.Nutrition;

/// <summary>
/// Raised on a food being sliced.
/// Used by deep frier to apply friedness to slices (e.g. deep fried pizza)
/// </summary>
public sealed class SliceFoodEvent : EntityEventArgs
{
/// <summary>
/// Who did the slicing?
/// <summary>
public EntityUid User;

/// <summary>
/// What has been sliced?
/// <summary>
/// <remarks>
/// This could soon be deleted if there was not enough food left to
/// continue slicing.
/// </remarks>
public EntityUid Food;

/// <summary>
/// What is the slice?
/// <summary>
public EntityUid Slice;

public SliceFoodEvent(EntityUid user, EntityUid food, EntityUid slice)
{
User = user;
Food = food;
Slice = slice;
}
}
93 changes: 30 additions & 63 deletions Content.Server/Nutrition/EntitySystems/SliceableFoodSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Nutrition; // DeltaV
using Content.Server.Nutrition.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
Expand All @@ -7,16 +8,18 @@
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Robust.Shared.Audio;
//using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Player;
//using Robust.Shared.Player;

namespace Content.Server.Nutrition.EntitySystems
{
internal sealed class SliceableFoodSystem : EntitySystem
public sealed class SliceableFoodSystem : EntitySystem
{
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -55,28 +58,15 @@ private bool TrySliceFood(EntityUid uid, EntityUid user, EntityUid usedItem,
return false;
}

var sliceUid = Spawn(component.Slice, transform.Coordinates);
var sliceUid = Slice(uid, user, component, transform);

var lostSolution = _solutionContainerSystem.SplitSolution(uid, solution,
solution.Volume / FixedPoint2.New(component.Count));

// Fill new slice
FillSlice(sliceUid, lostSolution);

var inCont = _containerSystem.IsEntityInContainer(component.Owner);
if (inCont)
{
_handsSystem.PickupOrDrop(user, sliceUid);
}
else
{
var xform = Transform(sliceUid);
_containerSystem.AttachParentToContainerOrGrid((sliceUid, xform));
xform.LocalRotation = 0;
}

SoundSystem.Play(component.Sound.GetSound(), Filter.Pvs(uid),
transform.Coordinates, AudioParams.Default.WithVolume(-2));
_audio.PlayPvs(component.Sound, transform.Coordinates, AudioParams.Default.WithVolume(-2));

// Decrease size of item based on count - Could implement in the future
// Bug with this currently is the size in a container is not updated
Expand All @@ -87,12 +77,6 @@ private bool TrySliceFood(EntityUid uid, EntityUid user, EntityUid usedItem,

component.Count--;

//Nyano - Summary: Begin Nyano Code to tell us we've sliced something for Fryer --

var sliceEvent = new SliceFoodEvent(user, usedItem, uid, sliceUid);
RaiseLocalEvent(uid, sliceEvent);
//Nyano - End Nyano Code.

// If someone makes food proto with 1 slice...
if (component.Count < 1)
{
Expand All @@ -104,11 +88,26 @@ private bool TrySliceFood(EntityUid uid, EntityUid user, EntityUid usedItem,
if (component.Count > 1)
return true;

sliceUid = Spawn(component.Slice, transform.Coordinates);
sliceUid = Slice(uid, user, component, transform);

// Fill last slice with the rest of the solution
FillSlice(sliceUid, solution);

DeleteFood(uid, user);
return true;
}

/// <summary>
/// Create a new slice in the world and returns its entity.
/// The solutions must be set afterwards.
/// </summary>
private EntityUid Slice(EntityUid uid, EntityUid user, SliceableFoodComponent? comp = null, TransformComponent? transform = null) // Frontier - Public to private
{
if (!Resolve(uid, ref comp, ref transform))
return EntityUid.Invalid;

var sliceUid = Spawn(comp.Slice, transform.Coordinates);
var inCont = _containerSystem.IsEntityInContainer(uid);
if (inCont)
{
_handsSystem.PickupOrDrop(user, sliceUid);
Expand All @@ -120,8 +119,12 @@ private bool TrySliceFood(EntityUid uid, EntityUid user, EntityUid usedItem,
xform.LocalRotation = 0;
}

DeleteFood(uid, user);
return true;
// DeltaV - Begin deep frier related code
var sliceEvent = new SliceFoodEvent(user, uid, sliceUid);
RaiseLocalEvent(uid, sliceEvent);
// DeltaV - End deep frier related code

return sliceUid;
}

private void DeleteFood(EntityUid uid, EntityUid user)
Expand Down Expand Up @@ -163,40 +166,4 @@ private void OnExamined(EntityUid uid, SliceableFoodComponent component, Examine
args.PushMarkup(Loc.GetString("sliceable-food-component-on-examine-remaining-slices-text", ("remainingCount", component.Count)));
}
}
//Nyano - Summary: Begin Nyano Code for the sliced food event.
public sealed class SliceFoodEvent : EntityEventArgs
{
/// <summary>
/// Who did the slicing?
/// <summary>
public EntityUid User;

/// <summary>
/// What did the slicing?
/// <summary>
public EntityUid Tool;

/// <summary>
/// What has been sliced?
/// <summary>
/// <remarks>
/// This could soon be deleted if there was not enough food left to
/// continue slicing.
/// </remarks>
public EntityUid Food;

/// <summary>
/// What is the slice?
/// <summary>
public EntityUid Slice;

public SliceFoodEvent(EntityUid user, EntityUid tool, EntityUid food, EntityUid slice)
{
User = user;
Tool = tool;
Food = food;
Slice = slice;
}
}
//End Nyano Code.
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Content.Server.Ghost.Roles.Components;
using Content.Server.Kitchen.Components;
using Content.Server.NPC.Components;
using Content.Server.Nutrition;
using Content.Server.Nutrition.Components;
using Content.Server.Nutrition.EntitySystems;
using Content.Server.Paper;
Expand Down Expand Up @@ -62,6 +63,8 @@
using FastAccessors;
using Content.Shared.NPC;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Construction;
//using Robust.Shared.Audio.Systems;

namespace Content.Server.Kitchen.EntitySystems
{
Expand All @@ -86,7 +89,7 @@ public sealed class DeepFryerSystem : EntitySystem
[Dependency] private readonly TemperatureSystem _temperature = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly AmbientSoundSystem _ambientSoundSystem = default!;
[Dependency] private readonly MetaDataSystem _meta = default!;
[Dependency] private readonly MetaDataSystem _metaDataSystem = default!;

private static readonly string CookingDamageType = "Heat";
private static readonly float CookingDamageAmount = 10.0f;
Expand Down Expand Up @@ -512,11 +515,11 @@ private void UpdateDeepFriedName(EntityUid uid, DeepFriedComponent component)
// Already handled at OnInitDeepFried.
break;
case 1:
_meta.SetEntityName(uid, Loc.GetString("deep-fried-fried-item",
_metaDataSystem.SetEntityName(uid, Loc.GetString("deep-fried-crispy-item",
("entity", component.OriginalName)));
break;
default:
_meta.SetEntityName(uid, Loc.GetString("deep-fried-burned-item",
_metaDataSystem.SetEntityName(uid, Loc.GetString("deep-fried-burned-item",
("entity", component.OriginalName)));
break;
}
Expand Down Expand Up @@ -819,8 +822,9 @@ private void OnBeforeActivatableUIOpen(EntityUid uid, DeepFryerComponent compone

private void OnRemoveItem(EntityUid uid, DeepFryerComponent component, DeepFryerRemoveItemMessage args)
{
var removedItem = EntityManager.GetEntity( args.Item );
if (removedItem.Valid) { //JJ Comment - This line should be unnecessary. Some issue is keeping the UI from updating when converting straight to a Burned Mess while the UI is still open. To replicate, put a Raw Meat in the fryer with no oil in it. Wait until it sputters with no effect. It should transform to Burned Mess, but doesn't.
var removedItem = EntityManager.GetEntity(args.Item);
if (removedItem.Valid)
{ //JJ Comment - This line should be unnecessary. Some issue is keeping the UI from updating when converting straight to a Burned Mess while the UI is still open. To replicate, put a Raw Meat in the fryer with no oil in it. Wait until it sputters with no effect. It should transform to Burned Mess, but doesn't.
if (!component.Storage.Remove(removedItem))
return;

Expand Down Expand Up @@ -990,7 +994,7 @@ private void OnInitDeepFried(EntityUid uid, DeepFriedComponent component, Compon
{
var meta = MetaData(uid);
component.OriginalName = meta.EntityName;
_meta.SetEntityName(uid, Loc.GetString("deep-fried-crispy-item", ("entity", meta.EntityName)));
_metaDataSystem.SetEntityName(uid, Loc.GetString("deep-fried-crispy-item", ("entity", meta.EntityName)));
}

private void OnExamineFried(EntityUid uid, DeepFriedComponent component, ExaminedEvent args)
Expand Down

0 comments on commit b6c5d67

Please sign in to comment.