From 6850bb6e1dff45af2f300c80097c42db66a3484a Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Wed, 18 Dec 2024 02:38:20 +0000
Subject: [PATCH] surface-level refactor of deep fryer component
---
.../Kitchen/Components/DeepFryerComponent.cs | 402 ++++++++----------
.../EntitySystems/DeepFryerSystem.Results.cs | 25 +-
.../Kitchen/EntitySystems/DeepFryerSystem.cs | 9 -
3 files changed, 193 insertions(+), 243 deletions(-)
diff --git a/Content.Server/Nyanotrasen/Kitchen/Components/DeepFryerComponent.cs b/Content.Server/Nyanotrasen/Kitchen/Components/DeepFryerComponent.cs
index d77bec6b1ae..faf27484ce9 100644
--- a/Content.Server/Nyanotrasen/Kitchen/Components/DeepFryerComponent.cs
+++ b/Content.Server/Nyanotrasen/Kitchen/Components/DeepFryerComponent.cs
@@ -11,230 +11,184 @@
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
-namespace Content.Server.Nyanotrasen.Kitchen.Components
+namespace Content.Server.Nyanotrasen.Kitchen.Components;
+
+// TODO: move to shared and get rid of SharedDeepFryerComponent
+[RegisterComponent, Access(typeof(SharedDeepfryerSystem))]
+public sealed partial class DeepFryerComponent : SharedDeepFryerComponent
{
- [RegisterComponent]
- [Access(typeof(SharedDeepfryerSystem))]
- // This line appears to be depracted: [ComponentReference(typeof(SharedDeepFryerComponent))]
- public sealed partial class DeepFryerComponent : SharedDeepFryerComponent
- {
- // There are three levels to how the deep fryer treats entities.
- //
- // 1. An entity can be rejected by the blacklist and be untouched by
- // anything other than heat damage.
- //
- // 2. An entity can be deep-fried but not turned into an edible. The
- // change will be mostly cosmetic. Any entity that does not match
- // the blacklist will fall into this category.
- //
- // 3. An entity can be deep-fried and turned into something edible. The
- // change will permit the item to be permanently destroyed by eating
- // it.
-
- ///
- /// When will the deep fryer layer on the next stage of crispiness?
- ///
- [DataField("nextFryTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
- public TimeSpan NextFryTime { get; set; }
-
- ///
- /// How much waste needs to be added at the next update interval?
- ///
- public FixedPoint2 WasteToAdd { get; set; } = FixedPoint2.Zero;
-
- ///
- /// How often are items in the deep fryer fried?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("fryInterval")]
- public TimeSpan FryInterval { get; set; } = TimeSpan.FromSeconds(5);
-
- ///
- /// What entities cannot be deep-fried no matter what?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("blacklist")]
- public EntityWhitelist? Blacklist { get; set; }
-
- ///
- /// What entities can be deep-fried into being edible?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("whitelist")]
- public EntityWhitelist? Whitelist { get; set; }
-
- ///
- /// What are over-cooked and burned entities turned into?
- ///
- ///
- /// To prevent unwanted destruction of items, only food can be turned
- /// into this.
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("charredPrototype", customTypeSerializer: typeof(PrototypeIdSerializer))]
- public string? CharredPrototype { get; set; }
-
- ///
- /// What reagents are considered valid cooking oils?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("fryingOils", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
- public HashSet FryingOils { get; set; } = new();
-
- ///
- /// What reagents are added to tasty deep-fried food?
- /// JJ Comment: I removed Solution from this. Unsure if I need to replace it with something.
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("goodReagents")]
- public List GoodReagents { get; set; } = new();
-
- ///
- /// What reagents are added to terrible deep-fried food?
- /// JJ Comment: I removed Solution from this. Unsure if I need to replace it with something.
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("badReagents")]
- public List BadReagents { get; set; } = new();
-
- ///
- /// What reagents replace every 1 unit of oil spent on frying?
- /// JJ Comment: I removed Solution from this. Unsure if I need to replace it with something.
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("wasteReagents")]
- public List WasteReagents { get; set; } = new();
-
- ///
- /// What flavors go well with deep frying?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("goodFlavors", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
- public HashSet GoodFlavors { get; set; } = new();
-
- ///
- /// What flavors don't go well with deep frying?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("badFlavors", customTypeSerializer: typeof(PrototypeIdHashSetSerializer))]
- public HashSet BadFlavors { get; set; } = new();
-
- ///
- /// How much is the price coefficiency of a food changed for each good flavor?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("goodFlavorPriceBonus")]
- public float GoodFlavorPriceBonus { get; set; } = 0.2f;
-
- ///
- /// How much is the price coefficiency of a food changed for each bad flavor?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("badFlavorPriceMalus")]
- public float BadFlavorPriceMalus { get; set; } = -0.3f;
-
- ///
- /// What is the name of the solution container for the fryer's oil?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("solution")]
- public string SolutionName { get; set; } = "vat_oil";
-
- public Solution Solution { get; set; } = default!;
-
- ///
- /// What is the name of the entity container for items inside the deep fryer?
- ///
- [DataField("storage")]
- public string StorageName { get; set; } = "vat_entities";
-
- public BaseContainer Storage { get; set; } = default!;
-
- ///
- /// How much solution should be imparted based on an item's size?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("solutionSizeCoefficient")]
- public FixedPoint2 SolutionSizeCoefficient { get; set; } = 1f;
-
- ///
- /// What's the maximum amount of solution that should ever be imparted?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("solutionSplitMax")]
- public FixedPoint2 SolutionSplitMax { get; set; } = 10f;
-
- ///
- /// What percent of the fryer's solution has to be oil in order for it to fry?
- ///
- ///
- /// The chef will have to clean it out occasionally, and if too much
- /// non-oil reagents are added, the vat will have to be drained.
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("fryingOilThreshold")]
- public FixedPoint2 FryingOilThreshold { get; set; } = 0.5f;
-
- ///
- /// What is the bare minimum number of oil units to prevent the fryer
- /// from unsafe operation?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("safeOilVolume")]
- public FixedPoint2 SafeOilVolume { get; set; } = 10f;
-
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("unsafeOilVolumeEffects")]
- public List UnsafeOilVolumeEffects = new();
-
- ///
- /// What is the temperature of the vat when the deep fryer is powered?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("poweredTemperature")]
- public float PoweredTemperature = 550.0f;
-
- ///
- /// How many entities can this deep fryer hold?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- public int StorageMaxEntities = 4;
-
- ///
- /// How many entities can be held, at a minimum?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("baseStorageMaxEntities")]
- public int BaseStorageMaxEntities = 4;
-
- // ///
- // /// What upgradeable machine part dictates the quality of the storage size?
- // ///
- // [DataField("machinePartStorageMax", customTypeSerializer: typeof(PrototypeIdSerializer))]
- // public string MachinePartStorageMax = "MatterBin";
-
- ///
- /// How much extra storage is added per part rating?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("storagePerPartRating")]
- public int StoragePerPartRating = 4;
-
- ///
- /// What sound is played when an item is inserted into hot oil?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("soundInsertItem")]
- public SoundSpecifier SoundInsertItem = new SoundPathSpecifier("/Audio/Nyanotrasen/Machines/deepfryer_basket_add_item.ogg");
-
- ///
- /// What sound is played when an item is removed?
- ///
- [ViewVariables(VVAccess.ReadWrite)]
- [DataField("soundRemoveItem")]
- public SoundSpecifier SoundRemoveItem = new SoundPathSpecifier("/Audio/Nyanotrasen/Machines/deepfryer_basket_remove_item.ogg");
- }
+ // There are three levels to how the deep fryer treats entities.
+ //
+ // 1. An entity can be rejected by the blacklist and be untouched by
+ // anything other than heat damage.
+ //
+ // 2. An entity can be deep-fried but not turned into an edible. The
+ // change will be mostly cosmetic. Any entity that does not match
+ // the blacklist will fall into this category.
+ //
+ // 3. An entity can be deep-fried and turned into something edible. The
+ // change will permit the item to be permanently destroyed by eating
+ // it.
+
+ ///
+ /// When will the deep fryer layer on the next stage of crispiness?
+ ///
+ [DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
+ public TimeSpan NextFryTime;
+
+ ///
+ /// How much waste needs to be added at the next update interval?
+ ///
+ [DataField]
+ public FixedPoint2 WasteToAdd = FixedPoint2.Zero;
+
+ ///
+ /// How often are items in the deep fryer fried?
+ ///
+ [DataField]
+ public TimeSpan FryInterval = TimeSpan.FromSeconds(5);
+
+ ///
+ /// What entities cannot be deep-fried no matter what?
+ ///
+ [DataField]
+ public EntityWhitelist? Blacklist;
+
+ ///
+ /// What entities can be deep-fried into being edible?
+ ///
+ [DataField]
+ public EntityWhitelist? Whitelist;
+
+ ///
+ /// What are over-cooked and burned entities turned into?
+ ///
+ ///
+ /// To prevent unwanted destruction of items, only food can be turned
+ /// into this.
+ ///
+ [DataField]
+ public EntProtoId? CharredPrototype;
+
+ ///
+ /// What reagents are considered valid cooking oils?
+ ///
+ [DataField]
+ public HashSet> FryingOils = new();
+
+ ///
+ /// What reagents are added to tasty deep-fried food?
+ ///
+ [DataField]
+ public List GoodReagents = new();
+
+ ///
+ /// What reagents are added to terrible deep-fried food?
+ ///
+ [DataField]
+ public List BadReagents = new();
+
+ ///
+ /// What reagents replace every 1 unit of oil spent on frying?
+ ///
+ [DataField]
+ public List WasteReagents = new();
+
+ ///
+ /// What flavors go well with deep frying?
+ ///
+ [DataField]
+ public HashSet> GoodFlavors = new();
+
+ ///
+ /// What flavors don't go well with deep frying?
+ ///
+ [DataField]
+ public HashSet> BadFlavors = new();
+
+ ///
+ /// How much is the price coefficiency of a food changed for each good flavor?
+ ///
+ [DataField]
+ public float GoodFlavorPriceBonus = 0.2f;
+
+ ///
+ /// How much is the price coefficiency of a food changed for each bad flavor?
+ ///
+ [DataField]
+ public float BadFlavorPriceMalus = -0.3f;
+
+ ///
+ /// What is the name of the solution container for the fryer's oil?
+ ///
+ [DataField]
+ public string SolutionName = "vat_oil";
+
+ // TODO: Entity
+ public Solution Solution = default!;
+
+ ///
+ /// What is the name of the entity container for items inside the deep fryer?
+ ///
+ [DataField("storage")]
+ public string StorageName = "vat_entities";
+
+ public BaseContainer Storage = default!;
+
+ ///
+ /// How much solution should be imparted based on an item's size?
+ ///
+ [DataField]
+ public FixedPoint2 SolutionSizeCoefficient = 1f;
+
+ ///
+ /// What's the maximum amount of solution that should ever be imparted?
+ ///
+ [DataField]
+ public FixedPoint2 SolutionSplitMax = 10f;
+
+ ///
+ /// What percent of the fryer's solution has to be oil in order for it to fry?
+ ///
+ ///
+ /// The chef will have to clean it out occasionally, and if too much
+ /// non-oil reagents are added, the vat will have to be drained.
+ ///
+ [DataField]
+ public FixedPoint2 FryingOilThreshold = 0.5f;
+
+ ///
+ /// What is the bare minimum number of oil units to prevent the fryer
+ /// from unsafe operation?
+ ///
+ [DataField]
+ public FixedPoint2 SafeOilVolume = 10f;
+
+ [DataField]
+ public List UnsafeOilVolumeEffects = new();
+
+ ///
+ /// What is the temperature of the vat when the deep fryer is powered?
+ ///
+ [DataField]
+ public float PoweredTemperature = 550.0f;
+
+ ///
+ /// How many entities can this deep fryer hold?
+ ///
+ [DataField]
+ public int StorageMaxEntities = 4;
+
+ ///
+ /// What sound is played when an item is inserted into hot oil?
+ ///
+ [DataField]
+ public SoundSpecifier SoundInsertItem = new SoundPathSpecifier("/Audio/Nyanotrasen/Machines/deepfryer_basket_add_item.ogg");
+
+ ///
+ /// What sound is played when an item is removed?
+ ///
+ [DataField]
+ public SoundSpecifier SoundRemoveItem = new SoundPathSpecifier("/Audio/Nyanotrasen/Machines/deepfryer_basket_remove_item.ogg");
}
diff --git a/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.Results.cs b/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.Results.cs
index 3f93787934c..fa2807509a6 100644
--- a/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.Results.cs
+++ b/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.Results.cs
@@ -11,15 +11,20 @@
using Content.Shared.FixedPoint;
using Content.Shared.Mobs.Components;
using Content.Shared.NPC;
+using Content.Shared.Nutrition;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nyanotrasen.Kitchen.Components;
using Content.Shared.Paper;
+using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Nyanotrasen.Kitchen.EntitySystems;
public sealed partial class DeepFryerSystem
{
+ private HashSet> _badFlavors = new();
+ private HashSet> _goodFlavors = new();
+
///
/// Make an item look deep-fried.
///
@@ -129,33 +134,33 @@ private void MakeEdible(EntityUid uid, DeepFryerComponent component, EntityUid i
var extraSolution = new Solution();
if (TryComp(item, out FlavorProfileComponent? flavorProfileComponent))
{
- HashSet goodFlavors = new(flavorProfileComponent.Flavors);
- goodFlavors.IntersectWith(component.GoodFlavors);
+ _goodFlavors.Clear();
+ _goodFlavors.IntersectWith(component.GoodFlavors);
- HashSet badFlavors = new(flavorProfileComponent.Flavors);
- badFlavors.IntersectWith(component.BadFlavors);
+ _badFlavors.Clear();
+ _badFlavors.IntersectWith(component.BadFlavors);
deepFriedComponent.PriceCoefficient = Math.Max(0.01f,
1.0f
- + goodFlavors.Count * component.GoodFlavorPriceBonus
- - badFlavors.Count * component.BadFlavorPriceMalus);
+ + _goodFlavors.Count * component.GoodFlavorPriceBonus
+ - _badFlavors.Count * component.BadFlavorPriceMalus);
- if (goodFlavors.Count > 0)
+ if (_goodFlavors.Count > 0)
{
foreach (var reagent in component.GoodReagents)
{
- extraSolution.AddReagent(reagent.Reagent.ToString(), reagent.Quantity * goodFlavors.Count);
+ extraSolution.AddReagent(reagent.Reagent.ToString(), reagent.Quantity * _goodFlavors.Count);
// Mask the taste of "medicine."
flavorProfileComponent.IgnoreReagents.Add(reagent.Reagent.ToString());
}
}
- if (badFlavors.Count > 0)
+ if (_badFlavors.Count > 0)
{
foreach (var reagent in component.BadReagents)
{
- extraSolution.AddReagent(reagent.Reagent.ToString(), reagent.Quantity * badFlavors.Count);
+ extraSolution.AddReagent(reagent.Reagent.ToString(), reagent.Quantity * _badFlavors.Count);
}
}
}
diff --git a/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.cs b/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.cs
index 40a658f0c44..4ac8684a7a3 100644
--- a/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.cs
+++ b/Content.Server/Nyanotrasen/Kitchen/EntitySystems/DeepFryerSystem.cs
@@ -105,7 +105,6 @@ public override void Initialize()
SubscribeLocalEvent(OnInitDeepFryer);
SubscribeLocalEvent(OnPowerChange);
- // SubscribeLocalEvent(OnRefreshParts);
SubscribeLocalEvent(OnDeconstruct);
SubscribeLocalEvent(OnDestruction);
SubscribeLocalEvent(OnThrowHitBy);
@@ -437,14 +436,6 @@ private void OnDestruction(EntityUid uid, DeepFryerComponent component, Destruct
_containerSystem.EmptyContainer(component.Storage, true);
}
- // private void OnRefreshParts(EntityUid uid, DeepFryerComponent component, RefreshPartsEvent args)
- // {
- // var ratingStorage = args.PartRatings[component.MachinePartStorageMax];
- //
- // component.StorageMaxEntities = component.BaseStorageMaxEntities +
- // (int) (component.StoragePerPartRating * (ratingStorage - 1));
- // }
-
///
/// Allow thrown items to land in a basket.
///