Add gas selling to tanks too (#11304)
This commit is contained in:
@@ -8,6 +8,30 @@ namespace Content.Server.Atmos.EntitySystems;
|
|||||||
|
|
||||||
public partial class AtmosphereSystem
|
public partial class AtmosphereSystem
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the particular price of an air mixture.
|
||||||
|
/// </summary>
|
||||||
|
public double GetPrice(GasMixture mixture)
|
||||||
|
{
|
||||||
|
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 += mixture.Moles[i] * GetGas(i).PricePerMole;
|
||||||
|
totalMoles += mixture.Moles[i];
|
||||||
|
maxComponent = Math.Max(maxComponent, mixture.Moles[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pay more for gas canisters that are more pure
|
||||||
|
float purity = 1;
|
||||||
|
if (totalMoles > 0) {
|
||||||
|
purity = maxComponent / totalMoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
return basePrice * purity;
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void InvalidateVisuals(EntityUid gridUid, Vector2i tile)
|
public void InvalidateVisuals(EntityUid gridUid, Vector2i tile)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
using Content.Server.Atmos.Components;
|
using Content.Server.Atmos.Components;
|
||||||
using Content.Server.Body.Components;
|
using Content.Server.Body.Components;
|
||||||
using Content.Server.Body.Systems;
|
using Content.Server.Body.Systems;
|
||||||
|
using Content.Server.Cargo.Systems;
|
||||||
using Content.Server.Explosion.EntitySystems;
|
using Content.Server.Explosion.EntitySystems;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.Atmos.Components;
|
using Content.Shared.Atmos.Components;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Interaction.Events;
|
|
||||||
using Content.Shared.Toggleable;
|
using Content.Shared.Toggleable;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Inventory;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
@@ -45,6 +44,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
SubscribeLocalEvent<GasTankComponent, GasTankSetPressureMessage>(OnGasTankSetPressure);
|
SubscribeLocalEvent<GasTankComponent, GasTankSetPressureMessage>(OnGasTankSetPressure);
|
||||||
SubscribeLocalEvent<GasTankComponent, GasTankToggleInternalsMessage>(OnGasTankToggleInternals);
|
SubscribeLocalEvent<GasTankComponent, GasTankToggleInternalsMessage>(OnGasTankToggleInternals);
|
||||||
SubscribeLocalEvent<GasTankComponent, GasAnalyzerScanEvent>(OnAnalyzed);
|
SubscribeLocalEvent<GasTankComponent, GasAnalyzerScanEvent>(OnAnalyzed);
|
||||||
|
SubscribeLocalEvent<GasTankComponent, PriceCalculationEvent>(OnGasTankPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGasShutdown(EntityUid uid, GasTankComponent component, ComponentShutdown args)
|
private void OnGasShutdown(EntityUid uid, GasTankComponent component, ComponentShutdown args)
|
||||||
@@ -332,5 +332,10 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
{
|
{
|
||||||
args.GasMixtures = new Dictionary<string, GasMixture?> { {Name(uid), component.Air} };
|
args.GasMixtures = new Dictionary<string, GasMixture?> { {Name(uid), component.Air} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnGasTankPrice(EntityUid uid, GasTankComponent component, ref PriceCalculationEvent args)
|
||||||
|
{
|
||||||
|
args.Price += _atmosphereSystem.GetPrice(component.Air);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,22 +298,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
|||||||
|
|
||||||
private void CalculateCanisterPrice(EntityUid uid, GasCanisterComponent component, ref PriceCalculationEvent args)
|
private void CalculateCanisterPrice(EntityUid uid, GasCanisterComponent component, ref PriceCalculationEvent args)
|
||||||
{
|
{
|
||||||
float basePrice = 0; // moles of gas * price/mole
|
args.Price += _atmosphereSystem.GetPrice(component.Air);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user