Port miasma from nyano (#8926)
Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
92
Content.Server/Atmos/Miasma/MiasmaSystem.cs
Normal file
92
Content.Server/Atmos/Miasma/MiasmaSystem.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Server.Body.Components;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Atmos.Miasma
|
||||
{
|
||||
public sealed class MiasmaSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
foreach (var (rotting, perishable) in EntityQuery<RottingComponent, PerishableComponent>())
|
||||
{
|
||||
if (!perishable.Progressing)
|
||||
continue;
|
||||
|
||||
if (TryComp<TemperatureComponent>(perishable.Owner, out var temp) && temp.CurrentTemperature < 274f)
|
||||
continue;
|
||||
|
||||
perishable.DeathAccumulator += frameTime;
|
||||
if (perishable.DeathAccumulator < perishable.RotAfter.TotalSeconds)
|
||||
continue;
|
||||
|
||||
perishable.RotAccumulator += frameTime;
|
||||
if (perishable.RotAccumulator < 1f)
|
||||
continue;
|
||||
|
||||
perishable.RotAccumulator -= 1f;
|
||||
|
||||
DamageSpecifier damage = new();
|
||||
damage.DamageDict.Add("Blunt", 0.25); // Slowly accumulate enough to gib after like half an hour
|
||||
damage.DamageDict.Add("Cellular", 0.25); // Cloning rework might use this eventually
|
||||
|
||||
_damageableSystem.TryChangeDamage(perishable.Owner, damage, true, true);
|
||||
|
||||
if (!TryComp<PhysicsComponent>(perishable.Owner, out var physics))
|
||||
continue;
|
||||
// We need a way to get the mass of the mob alone without armor etc in the future
|
||||
|
||||
var tileMix = _atmosphereSystem.GetTileMixture(Transform(perishable.Owner).Coordinates);
|
||||
if (tileMix != null)
|
||||
tileMix.AdjustMoles(Gas.Miasma, perishable.MolsPerSecondPerUnitMass * physics.FixturesMass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PerishableComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||
SubscribeLocalEvent<PerishableComponent, BeingGibbedEvent>(OnGibbed);
|
||||
SubscribeLocalEvent<AntiRottingContainerComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
|
||||
SubscribeLocalEvent<AntiRottingContainerComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
}
|
||||
|
||||
private void OnMobStateChanged(EntityUid uid, PerishableComponent component, MobStateChangedEvent args)
|
||||
{
|
||||
if (args.Component.IsDead())
|
||||
EnsureComp<RottingComponent>(uid);
|
||||
}
|
||||
|
||||
private void OnGibbed(EntityUid uid, PerishableComponent component, BeingGibbedEvent args)
|
||||
{
|
||||
if (!TryComp<PhysicsComponent>(uid, out var physics))
|
||||
return;
|
||||
|
||||
var molsToDump = (component.MolsPerSecondPerUnitMass * physics.FixturesMass) * component.DeathAccumulator;
|
||||
var tileMix = _atmosphereSystem.GetTileMixture(Transform(uid).Coordinates);
|
||||
if (tileMix != null)
|
||||
tileMix.AdjustMoles(Gas.Miasma, molsToDump);
|
||||
}
|
||||
|
||||
private void OnEntInserted(EntityUid uid, AntiRottingContainerComponent component, EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (TryComp<PerishableComponent>(args.Entity, out var perishable))
|
||||
perishable.Progressing = false;
|
||||
}
|
||||
|
||||
private void OnEntRemoved(EntityUid uid, AntiRottingContainerComponent component, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (TryComp<PerishableComponent>(args.Entity, out var perishable))
|
||||
perishable.Progressing = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Content.Server/Atmos/Miasma/NoRotContainerComponent.cs
Normal file
9
Content.Server/Atmos/Miasma/NoRotContainerComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Content.Server.Atmos.Miasma
|
||||
{
|
||||
[RegisterComponent]
|
||||
/// <summary>
|
||||
/// Entities inside this container will not rot.
|
||||
/// </summary>
|
||||
public sealed class AntiRottingContainerComponent : Component
|
||||
{}
|
||||
}
|
||||
42
Content.Server/Atmos/Miasma/PerishableComponent.cs
Normal file
42
Content.Server/Atmos/Miasma/PerishableComponent.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace Content.Server.Atmos.Miasma
|
||||
{
|
||||
[RegisterComponent]
|
||||
/// <summary>
|
||||
/// This makes mobs eventually start rotting when they die.
|
||||
/// It may be expanded to food at some point, but it's just for mobs right now.
|
||||
/// </summary>
|
||||
public sealed class PerishableComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Is this progressing?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Progressing = true;
|
||||
|
||||
/// <summary>
|
||||
/// How long this creature has been dead.
|
||||
/// </summary>
|
||||
[DataField("deathAccumulator")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float DeathAccumulator = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// When DeathAccumulator is greater than this, start rotting.
|
||||
/// </summary>
|
||||
public TimeSpan RotAfter = TimeSpan.FromMinutes(3);
|
||||
|
||||
/// <summary>
|
||||
/// Gasses are released every second.
|
||||
/// </summary>
|
||||
[DataField("rotAccumulator")]
|
||||
public float RotAccumulator = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// How many moles of gas released per second, adjusted for mass.
|
||||
/// Humans have a mass of 70. I am aiming for ten mols a minute, so
|
||||
/// 1/6 of a minute, divided by 70 as a baseline.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MolsPerSecondPerUnitMass = 0.0025f;
|
||||
}
|
||||
}
|
||||
9
Content.Server/Atmos/Miasma/RottingComponent.cs
Normal file
9
Content.Server/Atmos/Miasma/RottingComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Content.Server.Atmos.Miasma
|
||||
{
|
||||
[RegisterComponent]
|
||||
/// <summary>
|
||||
/// Tracking component for stuff that has started to rot.
|
||||
/// </summary>
|
||||
public sealed class RottingComponent : Component
|
||||
{}
|
||||
}
|
||||
Reference in New Issue
Block a user