Metabolism 3.0 (#5157)

* basic system + convert all plantmetabolism

* stragglers

* convert all old metabolisms over

* fix YAML errors + dumb serialization issue

* remove unused thingy

* reimplement

* add organ type condition

* organtype condition but real

* cleanups + test fix

* metabolismtype -> metabolizertype

* solution resilience

* fixes

* serializer + use entityuid + hashset

* this is apparently an entirely different thing

* turns out it just works

* oops
This commit is contained in:
mirrorcult
2021-11-08 15:33:45 -07:00
committed by GitHub
parent f5b11d6af8
commit 31d622f941
53 changed files with 969 additions and 912 deletions

View File

@@ -0,0 +1,45 @@
using System.Diagnostics.CodeAnalysis;
using Content.Server.Botany.Components;
using Content.Shared.Botany;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[ImplicitDataDefinitionForInheritors]
public abstract class PlantAdjustAttribute : ReagentEffect
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[DataField("amount")] public float Amount { get; protected set; } = 1;
[DataField("prob")] public float Prob { get; protected set; } = 1; // = (80);
/// <summary>
/// Checks if the plant holder can metabolize the reagent or not. Checks if it has an alive plant by default.
/// </summary>
/// <param name="plantHolder">The entity holding the plant</param>
/// <param name="plantHolderComponent">The plant holder component</param>
/// <param name="entityManager">The entity manager</param>
/// <param name="mustHaveAlivePlant">Whether to check if it has an alive plant or not</param>
/// <returns></returns>
public bool CanMetabolize(EntityUid plantHolder, [NotNullWhen(true)] out PlantHolderComponent? plantHolderComponent,
IEntityManager entityManager,
bool mustHaveAlivePlant = true)
{
plantHolderComponent = null;
if (!entityManager.TryGetComponent(plantHolder, out plantHolderComponent)
|| mustHaveAlivePlant && (plantHolderComponent.Seed == null || plantHolderComponent.Dead))
return false;
if (Prob >= 1f)
return true;
return !(Prob <= 0f) && _robustRandom.Prob(Prob);
}
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
public class PlantAdjustHealth : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.Health += Amount;
plantHolderComp.CheckHealth();
}
}
}

View File

@@ -0,0 +1,17 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
public class PlantAdjustMutationLevel : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.MutationLevel += Amount * plantHolderComp.MutationMod;
}
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
public class PlantAdjustMutationMod : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.MutationMod += Amount;
}
}
}

View File

@@ -0,0 +1,19 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
public class PlantAdjustNutrition : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.AdjustNutrient(Amount);
return;
}
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
public class PlantAdjustPests : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.PestLevel += Amount;
}
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
public class PlantAdjustToxins : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.Toxins += Amount;
}
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
public class PlantAdjustWater : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.AdjustWater(Amount);
}
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
public class PlantAdjustWeeds : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.WeedLevel += Amount;
}
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
public class PlantAffectGrowth : PlantAdjustAttribute
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, entityManager))
return;
plantHolderComp.AffectGrowth((int) Amount);
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using Content.Server.Botany.Components;
using Content.Shared.Botany;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
[DataDefinition]
public class PlantClonexadone : ReagentEffect
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!entityManager.TryGetComponent(plantHolder, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null || plantHolderComp.Dead)
return;
var deviation = 0;
var seed = plantHolderComp.Seed;
var random = IoCManager.Resolve<IRobustRandom>();
if (plantHolderComp.Age > seed.Maturation)
deviation = (int) Math.Max(seed.Maturation - 1, plantHolderComp.Age - random.Next(7, 10));
else
deviation = (int) (seed.Maturation / seed.GrowthStages);
plantHolderComp.Age -= deviation;
plantHolderComp.SkipAging++;
plantHolderComp.ForceUpdate = true;
}
}
}

View File

@@ -0,0 +1,42 @@
using Content.Server.Botany.Components;
using Content.Shared.Botany;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
[DataDefinition]
public class PlantDiethylamine : ReagentEffect
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!entityManager.TryGetComponent(plantHolder, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null || plantHolderComp.Dead ||
plantHolderComp.Seed.Immutable)
return;
var random = IoCManager.Resolve<IRobustRandom>();
var chance = MathHelper.Lerp(15f, 125f, plantHolderComp.Seed.Lifespan) * 2f;
if (random.Prob(chance))
{
plantHolderComp.CheckForDivergence(true);
plantHolderComp.Seed.Lifespan++;
}
chance = MathHelper.Lerp(15f, 125f, plantHolderComp.Seed.Endurance) * 2f;
if (random.Prob(chance))
{
plantHolderComp.CheckForDivergence(true);
plantHolderComp.Seed.Endurance++;
}
}
}
}

View File

@@ -0,0 +1,44 @@
using Content.Server.Botany.Components;
using Content.Shared.Botany;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
[DataDefinition]
public class RobustHarvest : ReagentEffect
{
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (!entityManager.TryGetComponent(plantHolder, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null || plantHolderComp.Dead ||
plantHolderComp.Seed.Immutable)
return;
var random = IoCManager.Resolve<IRobustRandom>();
var chance = MathHelper.Lerp(15f, 150f, plantHolderComp.Seed.Potency) * 3.5f;
if (random.Prob(chance))
{
plantHolderComp.CheckForDivergence(true);
plantHolderComp.Seed.Potency++;
}
chance = MathHelper.Lerp(6f, 2f, plantHolderComp.Seed.Yield) * 0.15f;
if (random.Prob(chance))
{
plantHolderComp.CheckForDivergence(true);
plantHolderComp.Seed.Yield--;
}
}
}
}