CatStation/Content.Shared/Atmos/EntitySystems/SharedGasMinerSystem.cs
Samuka e16a77768d
Stinky Smite (#44394)
* needs to be anchored datafield

* add verb

* improve description

* Use Captalization

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

* remove redudant thing

* remove redudant check

* update examine text

* make stinkt person not show examine text of a gas miner

* Update Content.Shared/Atmos/Components/GasMinerComponent.cs

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2026-07-02 22:18:14 +00:00

71 lines
2.9 KiB
C#

using Content.Shared.Atmos.Components;
using Content.Shared.Examine;
using Content.Shared.Temperature;
namespace Content.Shared.Atmos.EntitySystems;
public abstract partial class SharedGasMinerSystem : EntitySystem
{
[Dependency] private SharedAtmosphereSystem _sharedAtmosphereSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GasMinerComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<GasMinerComponent, AnchorStateChangedEvent>(OnMinerAnchorChanged);
}
private void OnExamine(Entity<GasMinerComponent> ent, ref ExaminedEvent args)
{
var component = ent.Comp;
if (!component.ShowExamineText)
return;
using (args.PushGroup(nameof(GasMinerComponent)))
{
args.PushMarkup(Loc.GetString("gas-miner-mines-text",
("gas", Loc.GetString(_sharedAtmosphereSystem.GetGas(component.SpawnGas).Name))));
args.PushText(Loc.GetString("gas-miner-amount-text",
("moles", $"{component.SpawnAmount:0.#}")));
args.PushText(Loc.GetString("gas-miner-temperature-text",
("tempK", $"{component.SpawnTemperature:0.#}"),
("tempC", $"{TemperatureHelpers.KelvinToCelsius(component.SpawnTemperature):0.#}")));
if (component.MaxExternalAmount < float.PositiveInfinity)
{
args.PushText(Loc.GetString("gas-miner-moles-cutoff-text",
("moles", $"{component.MaxExternalAmount:0.#}")));
}
if (component.MaxExternalPressure < float.PositiveInfinity)
{
args.PushText(Loc.GetString("gas-miner-pressure-cutoff-text",
("pressure", $"{component.MaxExternalPressure:0.#}")));
}
args.AddMarkup(component.MinerState switch
{
GasMinerState.Disabled => Loc.GetString("gas-miner-state-disabled-text"),
GasMinerState.Idle => Loc.GetString("gas-miner-state-idle-text"),
GasMinerState.Working => Loc.GetString("gas-miner-state-working-text"),
// C# pattern matching is not exhaustive for enums
_ => throw new IndexOutOfRangeException(nameof(component.MinerState)),
});
}
}
// This is merely to update the examine text.
// when a gas miner with RequireAnchored (in the atmos device comp) set to true is unanchored,
// it leaves the atmosphere and stops receiving AtmosDeviceUpdateEvent which spawns the gas
private void OnMinerAnchorChanged(Entity<GasMinerComponent> entity, ref AnchorStateChangedEvent args)
{
if (!TryComp<AtmosDeviceComponent>(entity, out var atmosDevice))
return;
if (!args.Anchored && atmosDevice.RequireAnchored)
entity.Comp.MinerState = GasMinerState.Disabled;
}
}