From 87cf078d428a580eefbeba0e8cd12594bd5d32c8 Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Sat, 2 Jul 2022 22:25:31 -0400 Subject: [PATCH] Miasma outbreaks give every mob the same disease (#9232) --- Content.Server/Atmos/Miasma/MiasmaSystem.cs | 79 +++++++++++++++++-- .../ReagentEffects/ChemCauseRandomDisease.cs | 2 +- .../ReagentEffects/ChemMiasmaPoolSource.cs | 23 ++++++ .../en-US/reagents/meta/physical-desc.ftl | 1 + .../Locale/en-US/reagents/meta/toxins.ftl | 3 + Resources/Prototypes/Diseases/infectious.yml | 2 +- .../Entities/Mobs/NPCs/regalrat.yml | 4 +- .../Objects/Consumable/Food/Baked/bread.yml | 2 +- .../Objects/Consumable/Food/Baked/pizza.yml | 2 +- Resources/Prototypes/Reagents/gases.yml | 11 +-- Resources/Prototypes/Reagents/toxins.yml | 27 +++++++ 11 files changed, 135 insertions(+), 21 deletions(-) create mode 100644 Content.Server/Chemistry/ReagentEffects/ChemMiasmaPoolSource.cs diff --git a/Content.Server/Atmos/Miasma/MiasmaSystem.cs b/Content.Server/Atmos/Miasma/MiasmaSystem.cs index 73d1168ae3..c8fe1418fb 100644 --- a/Content.Server/Atmos/Miasma/MiasmaSystem.cs +++ b/Content.Server/Atmos/Miasma/MiasmaSystem.cs @@ -6,6 +6,7 @@ using Content.Server.Temperature.Systems; using Content.Server.Body.Components; using Content.Shared.Examine; using Robust.Shared.Containers; +using Robust.Shared.Random; namespace Content.Server.Atmos.Miasma { @@ -13,12 +14,70 @@ namespace Content.Server.Atmos.Miasma { [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly DamageableSystem _damageableSystem = default!; - /// Feel free to weak this if there are perf concerns - private float UpdateRate = 5f; + + [Dependency] private readonly IRobustRandom _random = default!; + + /// System Variables + + /// Rotting + + /// + /// How often the rotting ticks. + /// Feel free to weak this if there are perf concerns. + /// + private float _rotUpdateRate = 5f; + + /// Miasma Disease Pool + /// Miasma outbreaks are not per-entity, + /// so this ensures that each entity in the same incident + /// receives the same disease. + + public readonly IReadOnlyList MiasmaDiseasePool = new[] + { + "VentCough", + "AMIV", + "SpaceCold", + "SpaceFlu", + "BirdFlew", + "VanAusdallsRobovirus", + "BleedersBite", + "Plague" + }; + + /// + /// The current pool disease. + /// + private string _poolDisease = ""; + + /// + /// The list of diseases in the pool. + /// + + /// + /// This ticks up to PoolRepickTime. + /// After that, it resets to 0. + /// Any infection will also reset it to 0. + /// + private float _poolAccumulator = 0f; + + /// + /// How long without an infection before we pick a new disease. + /// + private TimeSpan _poolRepickTime = TimeSpan.FromMinutes(5); public override void Update(float frameTime) { base.Update(frameTime); + // Disease pool + _poolAccumulator += frameTime; + + if (_poolAccumulator > _poolRepickTime.TotalSeconds) + { + _poolAccumulator = 0f; + _poolDisease = _random.Pick(MiasmaDiseasePool); + } + + // Rotting foreach (var (rotting, perishable) in EntityQuery()) { if (!perishable.Progressing) @@ -29,10 +88,10 @@ namespace Content.Server.Atmos.Miasma continue; perishable.RotAccumulator += frameTime; - if (perishable.RotAccumulator < UpdateRate) // This is where it starts to get noticable on larger animals, no need to run every second + if (perishable.RotAccumulator < _rotUpdateRate) // This is where it starts to get noticable on larger animals, no need to run every second continue; - perishable.RotAccumulator -= UpdateRate; + perishable.RotAccumulator -= _rotUpdateRate; EnsureComp(perishable.Owner); @@ -46,7 +105,7 @@ 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; + float molRate = perishable.MolsPerSecondPerUnitMass * _rotUpdateRate; var tileMix = _atmosphereSystem.GetTileMixture(Transform(perishable.Owner).Coordinates); if (tileMix != null) @@ -69,6 +128,9 @@ namespace Content.Server.Atmos.Miasma // Fly audiovisual stuff SubscribeLocalEvent(OnFliesInit); SubscribeLocalEvent(OnFliesShutdown); + + // Init disease pool + _poolDisease = _random.Pick(MiasmaDiseasePool); } private void OnShutdown(EntityUid uid, RottingComponent component, ComponentShutdown args) @@ -170,5 +232,12 @@ namespace Content.Server.Atmos.Miasma perishable.Progressing = false; RemComp(uid); } + + public string RequestPoolDisease() + { + // We reset the current time on this outbreak so people don't get unlucky at the transition time + _poolAccumulator = 0f; + return _poolDisease; + } } } diff --git a/Content.Server/Chemistry/ReagentEffects/ChemCauseRandomDisease.cs b/Content.Server/Chemistry/ReagentEffects/ChemCauseRandomDisease.cs index acb3b87b3f..c53796dd94 100644 --- a/Content.Server/Chemistry/ReagentEffects/ChemCauseRandomDisease.cs +++ b/Content.Server/Chemistry/ReagentEffects/ChemCauseRandomDisease.cs @@ -7,7 +7,7 @@ using JetBrains.Annotations; namespace Content.Server.Chemistry.ReagentEffects { /// - /// Default metabolism for medicine reagents. + /// Causes a random disease from a list, if the user is not already diseased. /// [UsedImplicitly] public sealed class ChemCauseRandomDisease : ReagentEffect diff --git a/Content.Server/Chemistry/ReagentEffects/ChemMiasmaPoolSource.cs b/Content.Server/Chemistry/ReagentEffects/ChemMiasmaPoolSource.cs new file mode 100644 index 0000000000..f964a1be9e --- /dev/null +++ b/Content.Server/Chemistry/ReagentEffects/ChemMiasmaPoolSource.cs @@ -0,0 +1,23 @@ +using Content.Shared.Chemistry.Reagent; +using JetBrains.Annotations; +using Content.Server.Atmos.Miasma; +using Content.Server.Disease; + +namespace Content.Server.Chemistry.ReagentEffects +{ + /// + /// The miasma system rotates between 1 disease at a time. + /// This gives all entities the disease the miasme system is currently on. + /// For things ingested by one person, you probably want ChemCauseRandomDisease instead. + /// + [UsedImplicitly] + public sealed class ChemMiasmaPoolSource : ReagentEffect + { + public override void Effect(ReagentEffectArgs args) + { + string disease = EntitySystem.Get().RequestPoolDisease(); + + EntitySystem.Get().TryAddDisease(args.SolutionEntity, disease); + } + } +} diff --git a/Resources/Locale/en-US/reagents/meta/physical-desc.ftl b/Resources/Locale/en-US/reagents/meta/physical-desc.ftl index 7e2d88e9ae..ddbbcfd1ad 100644 --- a/Resources/Locale/en-US/reagents/meta/physical-desc.ftl +++ b/Resources/Locale/en-US/reagents/meta/physical-desc.ftl @@ -13,6 +13,7 @@ reagent-physical-desc-cold = cold reagent-physical-desc-bee-guts = bee guts reagent-physical-desc-tangy = tangy reagent-physical-desc-fizzy = fizzy +reagent-physical-desc-fuzzy = fuzzy reagent-physical-desc-spicy = spicy reagent-physical-desc-abrasive = abrasive reagent-physical-desc-chalky = chalky diff --git a/Resources/Locale/en-US/reagents/meta/toxins.ftl b/Resources/Locale/en-US/reagents/meta/toxins.ftl index 1f980ad6e7..3d73bb0e23 100644 --- a/Resources/Locale/en-US/reagents/meta/toxins.ftl +++ b/Resources/Locale/en-US/reagents/meta/toxins.ftl @@ -4,6 +4,9 @@ reagent-desc-toxin = A toxic chemical. reagent-name-carpotoxin = carpotoxin reagent-desc-carpotoxin = Toxic secretions of a space carp. Causes a painful burning sensation. +reagent-name-mold = mold +reagent-desc-mold = Often found in dark, humid places or on old bread. + reagent-name-polytrinic-acid = polytrinic acid reagent-desc-polytrinic-acid = An extremely corrosive chemical substance. The slightest touch of it will melt off most masks and headgear, and it deals extreme damage to anyone who comes directly into contact with it. diff --git a/Resources/Prototypes/Diseases/infectious.yml b/Resources/Prototypes/Diseases/infectious.yml index 58f222c1f3..c24fd5a2ce 100644 --- a/Resources/Prototypes/Diseases/infectious.yml +++ b/Resources/Prototypes/Diseases/infectious.yml @@ -71,7 +71,7 @@ maxLength: 100 - type: disease - id: Bird Flew + id: BirdFlew name: bird flew cureResist: 0.08 effects: diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/regalrat.yml b/Resources/Prototypes/Entities/Mobs/NPCs/regalrat.yml index a420531783..7d7b11f4c7 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/regalrat.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/regalrat.yml @@ -110,7 +110,7 @@ - AMIV - SpaceCold - SpaceFlu - - Bird Flew + - BirdFlew - VanAusdallsRobovirus - BleedersBite - Plague @@ -192,7 +192,7 @@ - AMIV - SpaceCold - SpaceFlu - - Bird Flew + - BirdFlew - VanAusdallsRobovirus - BleedersBite - Plague diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/bread.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/bread.yml index 2588cca586..c86c544612 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/bread.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/bread.yml @@ -434,7 +434,7 @@ reagents: - ReagentId: Nutriment Quantity: 4 - - ReagentId: Amatoxin + - ReagentId: Mold Quantity: 7 # Tastes like decaying fungus. diff --git a/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pizza.yml b/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pizza.yml index 1e5cd50478..ef2d59f253 100644 --- a/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pizza.yml +++ b/Resources/Prototypes/Entities/Objects/Consumable/Food/Baked/pizza.yml @@ -350,7 +350,7 @@ reagents: - ReagentId: Nutriment Quantity: 2 - - ReagentId: Amatoxin + - ReagentId: Mold Quantity: 2 - ReagentId: Vitamin Quantity: 1 diff --git a/Resources/Prototypes/Reagents/gases.yml b/Resources/Prototypes/Reagents/gases.yml index dfcf5ad8cc..82d5c57175 100644 --- a/Resources/Prototypes/Reagents/gases.yml +++ b/Resources/Prototypes/Reagents/gases.yml @@ -163,7 +163,7 @@ metabolisms: Gas: effects: - - !type:ChemCauseRandomDisease + - !type:ChemMiasmaPoolSource conditions: - !type:OrganType type: Rat @@ -171,15 +171,6 @@ - !type:ReagentThreshold reagent: Miasma min: 1 - diseases: - - VentCough - - AMIV - - SpaceCold - - SpaceFlu - - Bird Flew - - VanAusdallsRobovirus - - BleedersBite - - Plague - !type:HealthChange conditions: - !type:OrganType diff --git a/Resources/Prototypes/Reagents/toxins.yml b/Resources/Prototypes/Reagents/toxins.yml index 2042f1e4b8..eb60f3ea27 100644 --- a/Resources/Prototypes/Reagents/toxins.yml +++ b/Resources/Prototypes/Reagents/toxins.yml @@ -42,6 +42,33 @@ messages: [ "generic-reagent-effect-burning-insides" ] probability: 0.33 + +- type: reagent + id: Mold + name: reagent-name-mold + group: Toxins + desc: reagent-desc-mold + color: "#8a9a5b" + physicalDesc: reagent-physical-desc-fuzzy + metabolisms: + Poison: + effects: + - !type:HealthChange + damage: + types: + Poison: 1 + - !type:ChemCauseRandomDisease + conditions: + - !type:ReagentThreshold + reagent: Mold + min: 1 + diseases: + - VentCough + - SpaceCold + - SpaceFlu + - BirdFlew + - Plague + - type: reagent id: PolytrinicAcid name: reagent-name-polytrinic-acid