From f9bf24f903caa0e6aa39df275894fc5f40615a51 Mon Sep 17 00:00:00 2001 From: corentt <36075110+corentt@users.noreply.github.com> Date: Tue, 15 Nov 2022 12:51:30 +0100 Subject: [PATCH] Price of food depends on its nutritional capacity (#11752) Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> fixes https://github.com/space-wizards/space-station-14/issues/11464 --- Content.Server/Cargo/Systems/PricingSystem.cs | 20 +++++++++++++++++++ .../Chemistry/Reagent/ReagentPrototype.cs | 3 +++ .../Objects/Consumable/Food/food_base.yml | 2 +- .../Objects/Consumable/Food/snacks.yml | 2 ++ .../Reagents/Consumable/Food/food.yml | 3 +++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Content.Server/Cargo/Systems/PricingSystem.cs b/Content.Server/Cargo/Systems/PricingSystem.cs index cc6645821d..e4d7568a7c 100644 --- a/Content.Server/Cargo/Systems/PricingSystem.cs +++ b/Content.Server/Cargo/Systems/PricingSystem.cs @@ -2,9 +2,11 @@ using Content.Server.Administration; using Content.Server.Body.Systems; using Content.Server.Cargo.Components; +using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Stack; using Content.Shared.Administration; using Content.Shared.Body.Components; +using Content.Shared.Chemistry.Reagent; using Content.Shared.Materials; using Content.Shared.MobState.Components; using Robust.Shared.Console; @@ -22,6 +24,7 @@ public sealed class PricingSystem : EntitySystem { [Dependency] private readonly IConsoleHost _consoleHost = default!; [Dependency] private readonly IMapManager _mapManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly BodySystem _bodySystem = default!; @@ -31,6 +34,7 @@ public sealed class PricingSystem : EntitySystem SubscribeLocalEvent(CalculateStaticPrice); SubscribeLocalEvent(CalculateStackPrice); SubscribeLocalEvent(CalculateMobPrice); + SubscribeLocalEvent(CalculateSolutionPrice); _consoleHost.RegisterCommand("appraisegrid", "Calculates the total value of the given grids.", @@ -108,6 +112,22 @@ public sealed class PricingSystem : EntitySystem args.Price += stack.Count * component.Price; } + private void CalculateSolutionPrice(EntityUid uid, SolutionContainerManagerComponent component, ref PriceCalculationEvent args) + { + var price = 0f; + + foreach (var solution in component.Solutions.Values) + { + foreach (var reagent in solution.Contents) + { + if (!_prototypeManager.TryIndex(reagent.ReagentId, out var reagentProto)) + continue; + price += (float) reagent.Quantity * reagentProto.PricePerUnit; + } + } + args.Price += price; + } + private void CalculateStaticPrice(EntityUid uid, StaticPriceComponent component, ref PriceCalculationEvent args) { args.Price += component.Price; diff --git a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs index fabb4e11eb..3e09a6f4f5 100644 --- a/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs +++ b/Content.Shared/Chemistry/Reagent/ReagentPrototype.cs @@ -84,6 +84,9 @@ namespace Content.Shared.Chemistry.Reagent [DataField("plantMetabolism", serverOnly: true)] public readonly List PlantMetabolisms = new(0); + [DataField("pricePerUnit")] + public float PricePerUnit { get; } + /// /// If the substance color is too dark we user a lighter version to make the text color readable when the user examines a solution. /// diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/food_base.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/food_base.yml index 6142e2076e..ac6b13c301 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/food_base.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/food_base.yml @@ -15,7 +15,7 @@ - type: Sprite netsync: false - type: StaticPrice - price: 50 + price: 0 # This base type is used to cover all of the "obvious" things that should be doable to open-package food. # Practically this means injection. diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/snacks.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/snacks.yml index da18ca4b33..3b10eb6d58 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/snacks.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/snacks.yml @@ -389,6 +389,8 @@ - Trash - type: Recyclable - type: SpaceGarbage + - type: StaticPrice + price: 0 - type: entity noSpawn: true diff --git a/Resources/Prototypes/Reagents/Consumable/Food/food.yml b/Resources/Prototypes/Reagents/Consumable/Food/food.yml index 9792086bff..9c6dd6e663 100644 --- a/Resources/Prototypes/Reagents/Consumable/Food/food.yml +++ b/Resources/Prototypes/Reagents/Consumable/Food/food.yml @@ -15,6 +15,7 @@ amount: 1 - !type:PlantAdjustHealth amount: 0.5 + pricePerUnit: 2 - type: reagent id: Vitamin @@ -37,6 +38,7 @@ - !type:ModifyBleedAmount amount: -0.25 - !type:SatiateHunger #Numbers are balanced with this in mind + it helps limit how much healing you can get from food + pricePerUnit: 2.5 - type: reagent id: Protein @@ -57,4 +59,5 @@ - !type:ModifyBloodLevel amount: 1 # weaker than iron but pretty good all things considered - !type:SatiateHunger + pricePerUnit: 3