Cooking simulator 3: Pies (#1540)

* enum -> prototype

* move sprites

* more dirt sprites

* some food data stucking fixing

* pumpkin fix

* pie move sprites

* refactor components

* pie refactor

* remove outdated proto

* new pie types

* Update SliceableFoodSystem.cs

* Refactor food cooking system and add fat flavor

Added 'Fat' to the flavor profile. Refactored food cooking logic to use CreateFoodData and UpdateFoodDataVisuals instead of CookFood and ApplyFoodVisuals. Introduced RenameCooker property to CP14FoodCookerComponent to control entity renaming during cooking. Improved separation of food data creation and visual updates.

* Update migration.yml

* Refactor food visual and sliceable logic in cooking system

Moved sliceable food logic from OnCookFinished to UpdateFoodDataVisuals for better encapsulation. Made UpdateFoodDataVisuals overridable and updated its usage in random food initialization. Added Rename field to CP14RandomFoodDataComponent and cleaned up unused BecomeSliceable field in CP14FoodCookerComponent. Updated pie_pan.yml to add SliceableFood and a new random food entity.

* Update pie_pan.yml

* fill levels
This commit is contained in:
Red
2025-07-20 15:45:59 +03:00
committed by GitHub
parent 6b98c91f73
commit 8721f736e1
79 changed files with 581 additions and 700 deletions

View File

@@ -673,11 +673,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
return false;
}
//CP14 spill event for cooking subscription
var ev = new CP14BeforeSpillEvent();
RaiseLocalEvent(uid, ev);
//CP14 end
return TrySpillAt(transformComponent.Coordinates, solution, out puddleUid, sound: sound);
}

View File

@@ -1,10 +1,11 @@
using Content.Server._CP14.Cooking;
using Content.Server.Nutrition.EntitySystems;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
namespace Content.Server.Nutrition.Components;
[RegisterComponent, Access(typeof(SliceableFoodSystem))]
[RegisterComponent, Access(typeof(SliceableFoodSystem), typeof(CP14CookingSystem))]
public sealed partial class SliceableFoodComponent : Component
{
/// <summary>

View File

@@ -85,6 +85,10 @@ public sealed class SliceableFoodSystem : EntitySystem
if (!TryComp<UtensilComponent>(usedItem, out var utensil) || (utensil.Types & UtensilType.Knife) == 0)
return false;
//CP14 transfer flavors
TryComp<FlavorProfileComponent>(uid, out var flavorProfile);
//CP14 end
var sliceVolume = solution.Volume / FixedPoint2.New(component.TotalCount);
for (int i = 0; i < component.TotalCount; i++)
{
@@ -93,6 +97,17 @@ public sealed class SliceableFoodSystem : EntitySystem
var lostSolution =
_solutionContainer.SplitSolution(soln.Value, sliceVolume);
//CP14 - transfer flavors
if (flavorProfile is not null)
{
var sliceFlavors = EnsureComp<FlavorProfileComponent>(sliceUid);
foreach (var newFlavor in flavorProfile.Flavors)
{
sliceFlavors.Flavors.Add(newFlavor);
}
}
//CP14 end
// Fill new slice
FillSlice(sliceUid, lostSolution);
}

View File

@@ -5,11 +5,12 @@
using System.Linq;
using System.Numerics;
using Content.Server.Nutrition.Components;
using Content.Server.Temperature.Systems;
using Content.Shared._CP14.Cooking;
using Content.Shared._CP14.Cooking.Components;
using Content.Shared._CP14.Temperature;
using Content.Shared.Nutrition.Components;
using Content.Shared.Chemistry.EntitySystems;
using Robust.Shared.Random;
namespace Content.Server._CP14.Cooking;
@@ -17,6 +18,7 @@ namespace Content.Server._CP14.Cooking;
public sealed class CP14CookingSystem : CP14SharedCookingSystem
{
[Dependency] private readonly TemperatureSystem _temperature = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
@@ -24,25 +26,30 @@ public sealed class CP14CookingSystem : CP14SharedCookingSystem
SubscribeLocalEvent<CP14RandomFoodDataComponent, MapInitEvent>(OnRandomFoodMapInit);
SubscribeLocalEvent<CP14FoodVisualsComponent, CP14BeforeSpillEvent>(OnSpilled);
SubscribeLocalEvent<CP14FoodHolderComponent, CP14BeforeSpillEvent>(OnHolderSpilled);
SubscribeLocalEvent<CP14FoodCookerComponent, CP14BeforeSpillEvent>(OnCookerSpilled);
SubscribeLocalEvent<CP14FoodHolderComponent, SolutionContainerChangedEvent>(OnHolderChanged);
}
private void OnCookerSpilled(Entity<CP14FoodCookerComponent> ent, ref CP14BeforeSpillEvent args)
protected override bool TryTransferFood(Entity<CP14FoodHolderComponent> target, Entity<CP14FoodHolderComponent> source)
{
ent.Comp.HoldFood = false;
Dirty(ent);
if (base.TryTransferFood(target, source))
{
//Sliceable
if (source.Comp.FoodData?.SliceProto is not null)
{
var sliceable = EnsureComp<SliceableFoodComponent>(target);
sliceable.Slice = source.Comp.FoodData.SliceProto;
sliceable.TotalCount = source.Comp.FoodData.SliceCount;
}
}
return true;
}
private void OnHolderSpilled(Entity<CP14FoodHolderComponent> ent, ref CP14BeforeSpillEvent args)
private void OnHolderChanged(Entity<CP14FoodHolderComponent> ent, ref SolutionContainerChangedEvent args)
{
ent.Comp.HoldFood = false;
Dirty(ent);
}
if (args.Solution.Volume != 0)
return;
private void OnSpilled(Entity<CP14FoodVisualsComponent> ent, ref CP14BeforeSpillEvent args)
{
ent.Comp.FoodData = null;
Dirty(ent);
}
@@ -55,26 +62,17 @@ public sealed class CP14CookingSystem : CP14SharedCookingSystem
if (!_random.Prob(ent.Comp.Prob))
return;
//TODO: Fuck this dublication logic, and randomization visual
var randomFood = _random.Pick(OrderedRecipes.Where(r => r.FoodType == holder.FoodType).ToList());
//Name and Description
if (randomFood.FoodData.Name is not null)
_metaData.SetEntityName(ent, Loc.GetString(randomFood.FoodData.Name));
if (randomFood.FoodData.Desc is not null)
_metaData.SetEntityDescription(ent, Loc.GetString(randomFood.FoodData.Desc));
var foodVisuals = EnsureComp<CP14FoodVisualsComponent>(ent);
//Visuals
foodVisuals.FoodData = randomFood.FoodData;
//Some randomize
foreach (var layer in foodVisuals.FoodData.Visuals)
var filteredRecipes = OrderedRecipes.Where(r => r.FoodType == holder.FoodType).ToList();
if (filteredRecipes.Count == 0)
{
if (_random.Prob(0.5f))
layer.Scale = new Vector2(-1, 1);
Log.Error($"No recipes found for food type {holder.FoodType}");
return;
}
var randomFood = _random.Pick(filteredRecipes);
UpdateFoodDataVisuals((ent, holder), randomFood.FoodData, ent.Comp.Rename);
Dirty(ent.Owner, holder);
}
@@ -89,6 +87,20 @@ public sealed class CP14CookingSystem : CP14SharedCookingSystem
Spawn(ent.Comp.BurntAdditionalSpawn, Transform(ent).Coordinates);
}
protected override void UpdateFoodDataVisuals(Entity<CP14FoodHolderComponent> ent, CP14FoodData data, bool rename = true)
{
base.UpdateFoodDataVisuals(ent, data, rename);
if (ent.Comp.FoodData?.SliceProto is null)
return;
if (!TryComp<SliceableFoodComponent>(ent, out var sliceable))
return;
sliceable.Slice = ent.Comp.FoodData.SliceProto;
sliceable.TotalCount = ent.Comp.FoodData.SliceCount;
}
protected override void OnCookFinished(Entity<CP14FoodCookerComponent> ent, ref CP14CookingDoAfter args)
{
if (args.Cancelled || args.Handled)
@@ -125,10 +137,3 @@ public sealed class CP14CookingSystem : CP14SharedCookingSystem
}
}
}
/// <summary>
/// It is invoked on the entity from which all reagents are spilled.
/// </summary>
public sealed class CP14BeforeSpillEvent : EntityEventArgs
{
}

View File

@@ -11,4 +11,7 @@ public sealed partial class CP14RandomFoodDataComponent : Component
/// </summary>
[DataField]
public float Prob = 0.75f;
[DataField]
public bool Rename = true;
}