Miasma improvements (#9022)
This commit is contained in:
8
Content.Client/Atmos/Miasma/FliesComponent.cs
Normal file
8
Content.Client/Atmos/Miasma/FliesComponent.cs
Normal 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
|
||||
{ }
|
||||
41
Content.Client/Atmos/Miasma/FliesSystem.cs
Normal file
41
Content.Client/Atmos/Miasma/FliesSystem.cs
Normal 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,
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
5
Content.Shared/Atmos/Miasma/SharedFliesComponent.cs
Normal file
5
Content.Shared/Atmos/Miasma/SharedFliesComponent.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Content.Shared.Atmos.Miasma;
|
||||
public abstract class SharedFliesComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
BIN
Resources/Audio/Ambience/Temporary/flies.ogg
Normal file
BIN
Resources/Audio/Ambience/Temporary/flies.ogg
Normal file
Binary file not shown.
1
Resources/Audio/Ambience/Temporary/license.txt
Normal file
1
Resources/Audio/Ambience/Temporary/license.txt
Normal file
@@ -0,0 +1 @@
|
||||
flies.ogg taken from https://freesound.org/people/telezon/sounds/321870/ licensed under CC-0
|
||||
@@ -78,7 +78,7 @@
|
||||
sprite: Mobs/Animals/cow.rsi
|
||||
state: cow
|
||||
product: CrateNPCCow
|
||||
cost: 1000
|
||||
cost: 3200
|
||||
category: Livestock
|
||||
group: market
|
||||
|
||||
|
||||
12
Resources/Prototypes/Entities/Effects/ambient_sounds.yml
Normal file
12
Resources/Prototypes/Entities/Effects/ambient_sounds.yml
Normal 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
|
||||
@@ -76,6 +76,7 @@
|
||||
- type: Construction
|
||||
graph: CrateGenericSteel
|
||||
node: crategenericsteel
|
||||
- type: AntiRottingContainer
|
||||
|
||||
- type: entity
|
||||
id: CrateHydroponics
|
||||
|
||||
BIN
Resources/Textures/Objects/Misc/flies.rsi/flies.png
Normal file
BIN
Resources/Textures/Objects/Misc/flies.rsi/flies.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 585 B |
23
Resources/Textures/Objects/Misc/flies.rsi/meta.json
Normal file
23
Resources/Textures/Objects/Misc/flies.rsi/meta.json
Normal 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
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user