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
This commit is contained in:
corentt
2022-11-15 12:51:30 +01:00
committed by GitHub
parent 172e8eb931
commit f9bf24f903
5 changed files with 29 additions and 1 deletions

View File

@@ -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<StaticPriceComponent, PriceCalculationEvent>(CalculateStaticPrice);
SubscribeLocalEvent<StackPriceComponent, PriceCalculationEvent>(CalculateStackPrice);
SubscribeLocalEvent<MobPriceComponent, PriceCalculationEvent>(CalculateMobPrice);
SubscribeLocalEvent<SolutionContainerManagerComponent, PriceCalculationEvent>(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<ReagentPrototype>(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;

View File

@@ -84,6 +84,9 @@ namespace Content.Shared.Chemistry.Reagent
[DataField("plantMetabolism", serverOnly: true)]
public readonly List<ReagentEffect> PlantMetabolisms = new(0);
[DataField("pricePerUnit")]
public float PricePerUnit { get; }
/// <summary>
/// If the substance color is too dark we user a lighter version to make the text color readable when the user examines a solution.
/// </summary>

View File

@@ -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.

View File

@@ -389,6 +389,8 @@
- Trash
- type: Recyclable
- type: SpaceGarbage
- type: StaticPrice
price: 0
- type: entity
noSpawn: true

View File

@@ -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