From e0836311f1f66e8825bec550fc1789d34d081a8c Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Sun, 7 Aug 2022 18:49:06 -0700 Subject: [PATCH] Add prices for gas canisters (#10129) --- .../Unary/EntitySystems/GasCanisterSystem.cs | 23 +++++++++++++++++++ .../Atmos/Prototypes/GasPrototype.cs | 3 +++ Resources/Prototypes/Atmospherics/gases.yml | 9 ++++++++ .../Catalog/Cargo/cargo_atmospherics.yml | 14 +++++------ .../Storage/Canisters/gas_canisters.yml | 2 ++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs index cc1bbd7b9a..2c43a7dd8d 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasCanisterSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.Piping.Components; using Content.Server.Atmos.Piping.Unary.Components; +using Content.Server.Cargo.Systems; using Content.Server.NodeContainer; using Content.Server.NodeContainer.NodeGroups; using Content.Server.NodeContainer.Nodes; @@ -23,6 +24,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly PricingSystem _pricing = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; public override void Initialize() @@ -36,6 +38,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems SubscribeLocalEvent(OnCanisterInteractUsing); SubscribeLocalEvent(OnCanisterContainerInserted); SubscribeLocalEvent(OnCanisterContainerRemoved); + SubscribeLocalEvent(CalculateCanisterPrice); // Bound UI subscriptions SubscribeLocalEvent(OnHoldingTankEjectMessage); SubscribeLocalEvent(OnCanisterChangeReleasePressure); @@ -292,5 +295,25 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems _atmosphereSystem.Merge(containerAir, buffer); containerAir.Multiply(containerAir.Volume / buffer.Volume); } + + private void CalculateCanisterPrice(EntityUid uid, GasCanisterComponent component, ref PriceCalculationEvent args) + { + float basePrice = 0; // moles of gas * price/mole + float totalMoles = 0; // total number of moles in can + float maxComponent = 0; // moles of the dominant gas + for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++) + { + basePrice += component.Air.Moles[i] * _atmosphereSystem.GetGas(i).PricePerMole; + totalMoles += component.Air.Moles[i]; + maxComponent = Math.Max(maxComponent, component.Air.Moles[i]); + } + + // Pay more for gas canisters that are more pure + float purity = 1; + if (totalMoles > 0) { + purity = maxComponent / totalMoles; + } + args.Price += basePrice * purity; + } } } diff --git a/Content.Shared/Atmos/Prototypes/GasPrototype.cs b/Content.Shared/Atmos/Prototypes/GasPrototype.cs index 7f42951e0b..6047728d4a 100644 --- a/Content.Shared/Atmos/Prototypes/GasPrototype.cs +++ b/Content.Shared/Atmos/Prototypes/GasPrototype.cs @@ -80,5 +80,8 @@ namespace Content.Shared.Atmos.Prototypes public string? Reagent { get; } = default!; [DataField("color")] public string Color { get; } = string.Empty; + + [DataField("pricePerMole")] + public float PricePerMole { get; set; } = 0; } } diff --git a/Resources/Prototypes/Atmospherics/gases.yml b/Resources/Prototypes/Atmospherics/gases.yml index b4e0af02ba..39c6324878 100644 --- a/Resources/Prototypes/Atmospherics/gases.yml +++ b/Resources/Prototypes/Atmospherics/gases.yml @@ -6,6 +6,7 @@ molarMass: 32 color: 2887E8 reagent: Oxygen + pricePerMole: 0.3 - type: gas id: 1 @@ -15,6 +16,7 @@ molarMass: 28 color: DA1010 reagent: Nitrogen + pricePerMole: 0.6 - type: gas id: 2 @@ -24,6 +26,7 @@ molarMass: 44 color: 4e4e4e reagent: CarbonDioxide + pricePerMole: 0.4 - type: gas id: 3 @@ -35,6 +38,7 @@ gasOverlayState: plasma color: FF3300 reagent: Plasma + pricePerMole: 2.5 - type: gas id: 4 @@ -46,6 +50,7 @@ gasOverlayState: tritium color: 13FF4B reagent: Tritium + pricePerMole: 5 - type: gas id: 5 @@ -57,6 +62,7 @@ gasOverlayState: water_vapor color: bffffd reagent: Water + pricePerMole: 0.4 - type: gas id: 6 @@ -70,6 +76,7 @@ gasVisbilityFactor: 3.5 color: 56941E reagent: Miasma + pricePerMole: 0.15 - type: gas id: 7 @@ -79,6 +86,7 @@ molarMass: 44 color: 2887E8 reagent: NitrousOxide + pricePerMole: 2.5 - type: gas id: 8 @@ -91,3 +99,4 @@ gasMolesVisible: 0.6 color: 3a758c reagent: Frezon + pricePerMole: 7.5 diff --git a/Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml b/Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml index aaa65e9348..9b6b02ff45 100644 --- a/Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml +++ b/Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml @@ -6,7 +6,7 @@ sprite: Structures/Storage/canister.rsi state: grey product: AirCanister - cost: 1000 + cost: 2700 category: Atmospherics group: market @@ -18,7 +18,7 @@ sprite: Structures/Storage/canister.rsi state: blue product: OxygenCanister - cost: 1000 + cost: 2300 category: Atmospherics group: market @@ -30,7 +30,7 @@ sprite: Structures/Storage/canister.rsi state: red product: NitrogenCanister - cost: 1000 + cost: 3200 category: Atmospherics group: market @@ -42,7 +42,7 @@ sprite: Structures/Storage/canister.rsi state: black product: CarbonDioxideCanister - cost: 1000 + cost: 2600 category: Atmospherics group: market @@ -54,7 +54,7 @@ # sprite: Structures/Storage/canister.rsi # state: water_vapor # product: WaterVaporCanister -# cost: 1000 +# cost: 2600 # category: Atmospherics # group: market @@ -66,7 +66,7 @@ # sprite: Structures/Storage/canister.rsi # state: orange # product: PlasmaCanister -# cost: 2000 +# cost: 8500 # category: Atmospherics # group: market @@ -78,6 +78,6 @@ # sprite: Structures/Storage/canister.rsi # state: green # product: TritiumCanister -# cost: 2000 +# cost: 15500 # category: Atmospherics # group: market diff --git a/Resources/Prototypes/Entities/Structures/Storage/Canisters/gas_canisters.yml b/Resources/Prototypes/Entities/Structures/Storage/Canisters/gas_canisters.yml index d7a40a2e21..06e1fd16d8 100644 --- a/Resources/Prototypes/Entities/Structures/Storage/Canisters/gas_canisters.yml +++ b/Resources/Prototypes/Entities/Structures/Storage/Canisters/gas_canisters.yml @@ -80,6 +80,8 @@ volume: 1 - type: GasPortable - type: GasCanister + - type: StaticPrice + price: 1000 - type: entity parent: GasCanister