Miasma improvements (#9022)

This commit is contained in:
Rane
2022-06-24 04:20:52 -04:00
committed by GitHub
parent 2b6c352aff
commit a1affccc84
15 changed files with 191 additions and 26 deletions

View File

@@ -0,0 +1,8 @@
using Content.Shared.Atmos.Miasma;
using Robust.Shared.GameStates;
namespace Content.Client.Atmos.Miasma;
[NetworkedComponent, RegisterComponent]
public sealed class FliesComponent : SharedFliesComponent
{ }

View File

@@ -0,0 +1,41 @@
using Robust.Client.GameObjects;
using Robust.Shared.Utility;
namespace Content.Client.Atmos.Miasma;
public sealed class FliesSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<FliesComponent, ComponentStartup>(FliesAdded);
SubscribeLocalEvent<FliesComponent, ComponentShutdown>(FliesRemoved);
}
private void FliesRemoved(EntityUid uid, FliesComponent component, ComponentShutdown args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;
if (!sprite.LayerMapTryGet(FliesKey.Key, out var layer))
return;
sprite.RemoveLayer(layer);
}
private void FliesAdded(EntityUid uid, FliesComponent component, ComponentStartup args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;
if (sprite.LayerMapTryGet(FliesKey.Key, out var _))
return;
var layer = sprite.AddLayer(new SpriteSpecifier.Rsi(new ResourcePath("Objects/Misc/flies.rsi"), "flies"));
sprite.LayerMapSet(FliesKey.Key, layer);
}
private enum FliesKey
{
Key,
}
}

View File

@@ -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);
}
}
}

View 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;
}

View File

@@ -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);
}
}
}

View File

@@ -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>

View File

@@ -0,0 +1,5 @@
namespace Content.Shared.Atmos.Miasma;
public abstract class SharedFliesComponent : Component
{
}

Binary file not shown.

View File

@@ -0,0 +1 @@
flies.ogg taken from https://freesound.org/people/telezon/sounds/321870/ licensed under CC-0

View File

@@ -78,7 +78,7 @@
sprite: Mobs/Animals/cow.rsi
state: cow
product: CrateNPCCow
cost: 1000
cost: 3200
category: Livestock
group: market

View File

@@ -0,0 +1,12 @@
- type: entity
id: AmbientSoundSourceFlies
noSpawn: true
components:
- type: AmbientSound
volume: -5
range: 3
sound:
path: /Audio/Ambience/Temporary/flies.ogg
- type: Tag
tags:
- HideContextMenu

View File

@@ -76,6 +76,7 @@
- type: Construction
graph: CrateGenericSteel
node: crategenericsteel
- type: AntiRottingContainer
- type: entity
id: CrateHydroponics

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

View File

@@ -0,0 +1,23 @@
{
"version": 1,
"license": "CC-BY-NC-SA-3.0",
"copyright": "Created by github user @elijahrane",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "flies",
"directions": 1,
"delays": [
[
0.2,
0.2,
0.2,
0.2
]
]
}
]
}