Add prices for gas canisters (#10129)

This commit is contained in:
Kevin Zheng
2022-08-07 18:49:06 -07:00
committed by GitHub
parent 193b9f467d
commit e0836311f1
5 changed files with 44 additions and 7 deletions

View File

@@ -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<GasCanisterComponent, InteractUsingEvent>(OnCanisterInteractUsing);
SubscribeLocalEvent<GasCanisterComponent, EntInsertedIntoContainerMessage>(OnCanisterContainerInserted);
SubscribeLocalEvent<GasCanisterComponent, EntRemovedFromContainerMessage>(OnCanisterContainerRemoved);
SubscribeLocalEvent<GasCanisterComponent, PriceCalculationEvent>(CalculateCanisterPrice);
// Bound UI subscriptions
SubscribeLocalEvent<GasCanisterComponent, GasCanisterHoldingTankEjectMessage>(OnHoldingTankEjectMessage);
SubscribeLocalEvent<GasCanisterComponent, GasCanisterChangeReleasePressureMessage>(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;
}
}
}