diff --git a/Content.Server/Botany/Systems/MutationSystem.cs b/Content.Server/Botany/Systems/MutationSystem.cs index 7cc5545ddb..2ac3260877 100644 --- a/Content.Server/Botany/Systems/MutationSystem.cs +++ b/Content.Server/Botany/Systems/MutationSystem.cs @@ -1,10 +1,21 @@ +using Robust.Shared.Prototypes; using Robust.Shared.Random; +using Content.Shared.Chemistry.Reagent; +using System.Linq; +using Content.Shared.Atmos; namespace Content.Server.Botany; public sealed class MutationSystem : EntitySystem { [Dependency] private readonly IRobustRandom _robustRandom = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + private List _allChemicals = default!; + + public override void Initialize() + { + _allChemicals = _prototypeManager.EnumeratePrototypes().ToList(); + } /// /// Main idea: Simulate genetic mutation using random binary flips. Each @@ -25,7 +36,7 @@ public sealed class MutationSystem : EntitySystem } // Add up everything in the bits column and put the number here. - const int totalbits = 245; + const int totalbits = 270; // Tolerances (55) MutateFloat(ref seed.NutrientConsumption , 0.05f , 1.2f , 5 , totalbits , severity); @@ -62,6 +73,13 @@ public sealed class MutationSystem : EntitySystem seed.BioluminescentColor = RandomColor(seed.BioluminescentColor, 10, totalbits, severity); // ConstantUpgade (10) MutateHarvestType(ref seed.HarvestRepeat , 10 , totalbits , severity); + + // Gas (5) + MutateGasses(ref seed.ExudeGasses, 0.01f, 0.5f, 4, totalbits, severity); + MutateGasses(ref seed.ConsumeGasses, 0.01f, 0.5f, 1, totalbits, severity); + + // Chems (20) + MutateChemicals(ref seed.Chemicals, 5, 20, totalbits, severity); } public SeedData Cross(SeedData a, SeedData b) @@ -97,6 +115,8 @@ public sealed class MutationSystem : EntitySystem CrossBool(ref result.Bioluminescent, a.Bioluminescent); CrossBool(ref result.TurnIntoKudzu, a.TurnIntoKudzu); CrossBool(ref result.CanScream, a.CanScream); + result.ExudeGasses = Random(0.5f) ? a.ExudeGasses : result.ExudeGasses; + result.ConsumeGasses = Random(0.5f) ? a.ConsumeGasses : result.ConsumeGasses; result.BioluminescentColor = Random(0.5f) ? a.BioluminescentColor : result.BioluminescentColor; // Hybrids have a high chance of being seedless. Balances very @@ -200,6 +220,59 @@ public sealed class MutationSystem : EntitySystem val = HarvestType.SelfHarvest; } + private void MutateGasses(ref Dictionary gasses, float min, float max, int bits, int totalbits, float mult) + { + float p = mult * bits / totalbits; + p = Math.Clamp(p, 0, 1); + if (!Random(p)) + return; + + // Add a random amount of a random gas to this gas dictionary + float amount = _robustRandom.NextFloat(min, max); + Gas gas = _robustRandom.Pick(Enum.GetValues(typeof(Gas)).Cast().ToList()); + if (gasses.ContainsKey(gas)) + { + gasses[gas] += amount; + } + else + { + gasses.Add(gas, amount); + } + } + + private void MutateChemicals(ref Dictionary chemicals, int max, int bits, int totalbits, float mult) + { + float p = mult * bits / totalbits; + p = Math.Clamp(p, 0, 1); + if (!Random(p)) + return; + + // Add a random amount of a random chemical to this set of chemicals + ReagentPrototype selected_chemical = _robustRandom.Pick(_allChemicals); + if (selected_chemical != null) + { + string chemical_id = selected_chemical.ID; + int amount = _robustRandom.Next(1, max); + SeedChemQuantity seed_chem_quantity = new SeedChemQuantity(); + if (chemicals.ContainsKey(chemical_id)) + { + seed_chem_quantity.Min = chemicals[chemical_id].Min; + seed_chem_quantity.Max = chemicals[chemical_id].Max + amount; + int potency = (int) Math.Ceiling(100.0f / (float) seed_chem_quantity.Max); + seed_chem_quantity.PotencyDivisor = potency; + chemicals[chemical_id] = seed_chem_quantity; + } + else + { + seed_chem_quantity.Min = 1; + seed_chem_quantity.Max = 1 + amount; + int potency = (int) Math.Ceiling(100.0f / (float) seed_chem_quantity.Max); + seed_chem_quantity.PotencyDivisor = potency; + chemicals.Add(chemical_id, seed_chem_quantity); + } + } + } + private Color RandomColor(Color color, int bits, int totalbits, float mult) { float p = mult*bits/totalbits; @@ -214,8 +287,7 @@ public sealed class MutationSystem : EntitySystem Color.Purple, Color.Pink }; - var rng = IoCManager.Resolve(); - return rng.Pick(colors); + return _robustRandom.Pick(colors); } return color; }