Miasma improvements (#9022)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Atmos.Miasma;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Disease.Components;
|
||||
@@ -89,15 +90,13 @@ namespace Content.Server.Administration.Commands
|
||||
sys.TryModifyBloodLevel(target, bloodStream.BloodSolution.AvailableVolume, bloodStream);
|
||||
}
|
||||
|
||||
if (entMan.HasComponent<JitteringComponent>(target))
|
||||
{
|
||||
entMan.RemoveComponent<JitteringComponent>(target);
|
||||
}
|
||||
|
||||
if (entMan.TryGetComponent<DiseaseCarrierComponent>(target, out var carrier))
|
||||
{
|
||||
EntitySystem.Get<DiseaseSystem>().CureAllDiseases(target, carrier);
|
||||
}
|
||||
|
||||
entMan.RemoveComponent<JitteringComponent>(target);
|
||||
entMan.RemoveComponent<RottingComponent>(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
Content.Server/Atmos/Miasma/FliesComponent.cs
Normal file
11
Content.Server/Atmos/Miasma/FliesComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Content.Shared.Atmos.Miasma;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Server.Atmos.Miasma;
|
||||
|
||||
[NetworkedComponent, RegisterComponent]
|
||||
public sealed class FliesComponent : SharedFliesComponent
|
||||
{
|
||||
/// Need something to hold the ambient sound, at least until that system becomes more robust
|
||||
public EntityUid VirtFlies;
|
||||
}
|
||||
@@ -2,12 +2,10 @@ 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.Temperature.Systems;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Examine;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Atmos.Miasma
|
||||
{
|
||||
@@ -15,8 +13,8 @@ namespace Content.Server.Atmos.Miasma
|
||||
{
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
/// Feel free to weak this if there are perf concerns
|
||||
private float UpdateRate = 5f;
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
@@ -26,18 +24,17 @@ namespace Content.Server.Atmos.Miasma
|
||||
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)
|
||||
if (perishable.RotAccumulator < UpdateRate) // This is where it starts to get noticable on larger animals, no need to run every second
|
||||
continue;
|
||||
|
||||
perishable.RotAccumulator -= 1f;
|
||||
perishable.RotAccumulator -= UpdateRate;
|
||||
|
||||
EnsureComp<FliesComponent>(perishable.Owner);
|
||||
|
||||
DamageSpecifier damage = new();
|
||||
damage.DamageDict.Add("Blunt", 0.3); // Slowly accumulate enough to gib after like half an hour
|
||||
@@ -49,21 +46,45 @@ namespace Content.Server.Atmos.Miasma
|
||||
continue;
|
||||
// We need a way to get the mass of the mob alone without armor etc in the future
|
||||
|
||||
float molRate = perishable.MolsPerSecondPerUnitMass * UpdateRate;
|
||||
|
||||
var tileMix = _atmosphereSystem.GetTileMixture(Transform(perishable.Owner).Coordinates);
|
||||
if (tileMix != null)
|
||||
tileMix.AdjustMoles(Gas.Miasma, perishable.MolsPerSecondPerUnitMass * physics.FixturesMass);
|
||||
tileMix.AdjustMoles(Gas.Miasma, molRate * physics.FixturesMass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
// Core rotting stuff
|
||||
SubscribeLocalEvent<RottingComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<RottingComponent, OnTemperatureChangeEvent>(OnTempChange);
|
||||
SubscribeLocalEvent<PerishableComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||
SubscribeLocalEvent<PerishableComponent, BeingGibbedEvent>(OnGibbed);
|
||||
SubscribeLocalEvent<PerishableComponent, ExaminedEvent>(OnExamined);
|
||||
// Containers
|
||||
SubscribeLocalEvent<AntiRottingContainerComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
|
||||
SubscribeLocalEvent<AntiRottingContainerComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
|
||||
// Fly audiovisual stuff
|
||||
SubscribeLocalEvent<FliesComponent, ComponentInit>(OnFliesInit);
|
||||
SubscribeLocalEvent<FliesComponent, ComponentShutdown>(OnFliesShutdown);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, RottingComponent component, ComponentShutdown args)
|
||||
{
|
||||
RemComp<FliesComponent>(uid);
|
||||
if (TryComp<PerishableComponent>(uid, out var perishable))
|
||||
{
|
||||
perishable.DeathAccumulator = 0;
|
||||
perishable.RotAccumulator = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTempChange(EntityUid uid, RottingComponent component, OnTemperatureChangeEvent args)
|
||||
{
|
||||
bool decompose = (args.CurrentTemperature > 274f);
|
||||
ToggleDecomposition(uid, decompose);
|
||||
}
|
||||
|
||||
private void OnMobStateChanged(EntityUid uid, PerishableComponent component, MobStateChangedEvent args)
|
||||
@@ -77,7 +98,7 @@ namespace Content.Server.Atmos.Miasma
|
||||
if (!TryComp<PhysicsComponent>(uid, out var physics))
|
||||
return;
|
||||
|
||||
if (component.DeathAccumulator <= component.RotAfter.TotalSeconds)
|
||||
if (!component.Rotting)
|
||||
return;
|
||||
|
||||
var molsToDump = (component.MolsPerSecondPerUnitMass * physics.FixturesMass) * component.DeathAccumulator;
|
||||
@@ -85,28 +106,69 @@ namespace Content.Server.Atmos.Miasma
|
||||
if (tileMix != null)
|
||||
tileMix.AdjustMoles(Gas.Miasma, molsToDump);
|
||||
|
||||
// Waste of entities to let these through
|
||||
foreach (var part in args.GibbedParts)
|
||||
{
|
||||
EntityManager.QueueDeleteEntity(part);
|
||||
}
|
||||
EntityManager.DeleteEntity(part);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, PerishableComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (component.DeathAccumulator >= component.RotAfter.TotalSeconds)
|
||||
if (component.Rotting)
|
||||
args.PushMarkup(Loc.GetString("miasma-rotting"));
|
||||
}
|
||||
|
||||
/// Containers
|
||||
|
||||
private void OnEntInserted(EntityUid uid, AntiRottingContainerComponent component, EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (TryComp<PerishableComponent>(args.Entity, out var perishable))
|
||||
perishable.Progressing = false;
|
||||
ToggleDecomposition(args.Entity, false, perishable);
|
||||
}
|
||||
|
||||
private void OnEntRemoved(EntityUid uid, AntiRottingContainerComponent component, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (TryComp<PerishableComponent>(args.Entity, out var perishable))
|
||||
ToggleDecomposition(args.Entity, true, perishable);
|
||||
}
|
||||
|
||||
|
||||
/// Fly stuff
|
||||
|
||||
private void OnFliesInit(EntityUid uid, FliesComponent component, ComponentInit args)
|
||||
{
|
||||
component.VirtFlies = EntityManager.SpawnEntity("AmbientSoundSourceFlies", Transform(uid).Coordinates);
|
||||
Transform(component.VirtFlies).AttachParent(uid);
|
||||
}
|
||||
|
||||
private void OnFliesShutdown(EntityUid uid, FliesComponent component, ComponentShutdown args)
|
||||
{
|
||||
EntityManager.DeleteEntity(component.VirtFlies);
|
||||
}
|
||||
|
||||
/// Public functions
|
||||
|
||||
public void ToggleDecomposition(EntityUid uid, bool decompose, PerishableComponent? perishable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref perishable))
|
||||
return;
|
||||
|
||||
if (decompose == perishable.Progressing) // Saved a few cycles
|
||||
return;
|
||||
|
||||
if (!HasComp<RottingComponent>(uid))
|
||||
return;
|
||||
|
||||
if (!perishable.Rotting)
|
||||
return;
|
||||
|
||||
if (decompose)
|
||||
{
|
||||
perishable.Progressing = true;
|
||||
EnsureComp<FliesComponent>(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
perishable.Progressing = false;
|
||||
RemComp<FliesComponent>(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Content.Server.Atmos.Miasma
|
||||
/// </summary>
|
||||
public TimeSpan RotAfter = TimeSpan.FromMinutes(5);
|
||||
|
||||
public bool Rotting => (DeathAccumulator > RotAfter.TotalSeconds);
|
||||
|
||||
/// <summary>
|
||||
/// Gasses are released every second.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user