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

@@ -1,18 +1,23 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Content.Shared.Body.Metabolism;
using Content.Shared.Body.Networks;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
namespace Content.Server.Body.Metabolism
{
/// <summary>
/// Handles metabolizing various reagents with given effects.
/// </summary>
[RegisterComponent]
[RegisterComponent, Friend(typeof(MetabolizerSystem))]
public class MetabolizerComponent : Component
{
public override string Name => "Metabolizer";
@@ -27,33 +32,44 @@ namespace Content.Server.Body.Metabolism
public float UpdateFrequency = 1.0f;
/// <summary>
/// From which solution will this metabolizer attempt to metabolize chemicals in its parent bodies' bloodstream,
/// as opposed to a solution container on the metabolizing entity itself.
/// From which solution will this metabolizer attempt to metabolize chemicals
/// </summary>
[DataField("solution")]
public string SolutionName { get; set; } = SharedBloodstreamComponent.DefaultSolutionName;
/// <summary>
/// A dictionary mapping reagent string IDs to a list of effects & associated metabolism rate.
/// Does this component use a solution on it's parent entity (the body) or itself
/// </summary>
/// <returns></returns>
[DataField("metabolisms", required: true, customTypeSerializer:typeof(PrototypeIdDictionarySerializer<ReagentEffectsEntry, ReagentPrototype>))]
public Dictionary<string, ReagentEffectsEntry> Metabolisms = default!;
/// <remarks>
/// Most things will use the parent entity (bloodstream).
/// </remarks>
[DataField("solutionOnBody")]
public bool SolutionOnBody = true;
/// <summary>
/// List of metabolizer types that this organ is. ex. Human, Slime, Felinid, w/e.
/// </summary>
[DataField("metabolizerTypes", customTypeSerializer:typeof(PrototypeIdHashSetSerializer<MetabolizerTypePrototype>))]
public HashSet<string>? MetabolizerTypes = null;
/// <summary>
/// A list of metabolism groups that this metabolizer will act on, in order of precedence.
/// </summary>
[DataField("groups", required: true)]
public List<MetabolismGroupEntry> MetabolismGroups = default!;
}
/// <summary>
/// Contains data about how a metabolizer will metabolize a single group.
/// This allows metabolizers to remove certain groups much faster, or not at all.
/// </summary>
[DataDefinition]
public class ReagentEffectsEntry
public class MetabolismGroupEntry
{
/// <summary>
/// Amount of reagent to metabolize, per metabolism cycle.
/// </summary>
[DataField("metabolismRate")]
public FixedPoint2 MetabolismRate = FixedPoint2.New(1.0f);
[DataField("id", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<MetabolismGroupPrototype>))]
public string Id = default!;
/// <summary>
/// A list of effects to apply when these reagents are metabolized.
/// </summary>
[DataField("effects", required: true)]
public ReagentEffect[] Effects = default!;
[DataField("rateModifier")]
public FixedPoint2 MetabolismRateModifier = 1.0;
}
}

View File

@@ -1,5 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.Body.Circulatory;
using Content.Server.Body.Mechanism;
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Body.Components;
using Content.Shared.Body.Mechanism;
@@ -9,6 +12,7 @@ using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Body.Metabolism
{
@@ -16,9 +20,8 @@ namespace Content.Server.Body.Metabolism
[UsedImplicitly]
public class MetabolizerSystem : EntitySystem
{
[Dependency]
private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override void Initialize()
{
@@ -29,7 +32,20 @@ namespace Content.Server.Body.Metabolism
private void OnMetabolizerInit(EntityUid uid, MetabolizerComponent component, ComponentInit args)
{
_solutionContainerSystem.EnsureSolution(uid, component.SolutionName);
if (!component.SolutionOnBody)
{
_solutionContainerSystem.EnsureSolution(uid, component.SolutionName);
}
else
{
if (EntityManager.TryGetComponent<MechanismComponent>(uid, out var mech))
{
if (mech.Body != null)
{
_solutionContainerSystem.EnsureSolution(mech.Body.OwnerUid, component.SolutionName);
}
}
}
}
public override void Update(float frameTime)
@@ -43,80 +59,96 @@ namespace Content.Server.Body.Metabolism
// Only update as frequently as it should
if (metab.AccumulatedFrametime >= metab.UpdateFrequency)
{
metab.AccumulatedFrametime = 0.0f;
TryMetabolize(metab);
metab.AccumulatedFrametime -= metab.UpdateFrequency;
TryMetabolize(metab.OwnerUid, metab);
}
}
}
private void TryMetabolize(MetabolizerComponent comp)
private void TryMetabolize(EntityUid uid, MetabolizerComponent? meta=null, MechanismComponent? mech=null)
{
var owner = comp.Owner;
IReadOnlyList<Solution.ReagentQuantity> reagentList = new List<Solution.ReagentQuantity>();
Solution? solution = null;
SharedBodyComponent? body = null;
if (!Resolve(uid, ref meta))
return;
// if this field is passed we should try and take from the bloodstream over anything else
if (owner.TryGetComponent<SharedMechanismComponent>(out var mech))
Resolve(uid, ref mech, false);
// First step is get the solution we actually care about
Solution? solution = null;
EntityUid? solutionEntityUid = null;
SolutionContainerManagerComponent? manager = null;
if (meta.SolutionOnBody)
{
body = mech.Body;
if (body != null)
if (mech != null)
{
if (body.Owner.HasComponent<BloodstreamComponent>()
&& _solutionContainerSystem.TryGetSolution(body.OwnerUid, comp.SolutionName, out solution)
&& solution.CurrentVolume >= FixedPoint2.Zero)
var body = mech.Body;
if (body != null)
{
reagentList = solution.Contents;
if (!Resolve(body.OwnerUid, ref manager, false))
return;
_solutionContainerSystem.TryGetSolution(body.OwnerUid, meta.SolutionName, out solution, manager);
solutionEntityUid = body.OwnerUid;
}
}
}
if (solution == null || reagentList.Count == 0)
else
{
// We're all outta ideas on where to metabolize from
return;
if (!Resolve(uid, ref manager, false))
return;
_solutionContainerSystem.TryGetSolution(uid, meta.SolutionName, out solution, manager);
solutionEntityUid = uid;
}
List<Solution.ReagentQuantity> removeReagents = new(5);
var ent = body?.Owner ?? owner;
// Run metabolism for each reagent, remove metabolized reagents
foreach (var reagent in reagentList)
if (solutionEntityUid == null || solution == null)
return;
// we found our guy
foreach (var reagent in solution.Contents.ToArray())
{
if (!comp.Metabolisms.ContainsKey(reagent.ReagentId))
if (!_prototypeManager.TryIndex<ReagentPrototype>(reagent.ReagentId, out var proto))
continue;
var metabolism = comp.Metabolisms[reagent.ReagentId];
// Run metabolism code for each reagent
foreach (var effect in metabolism.Effects)
{
var conditionsMet = true;
if (effect.Conditions != null)
{
// yes this is 3 nested for loops, but all of these lists are
// basically guaranteed to be small or empty
foreach (var condition in effect.Conditions)
{
if (!condition.Condition(ent, reagent))
{
conditionsMet = false;
break;
}
}
}
if (proto.Metabolisms == null)
continue;
if (!conditionsMet)
// loop over all our groups and see which ones apply
FixedPoint2 mostToRemove = FixedPoint2.Zero;
foreach (var group in meta.MetabolismGroups)
{
if (!proto.Metabolisms.Keys.Contains(group.Id))
continue;
// If we're part of a body, pass that entity to Metabolize
// Otherwise, just pass our owner entity, maybe we're a plant or something
effect.Metabolize(ent, reagent);
var entry = proto.Metabolisms[group.Id];
// we don't remove reagent for every group, just whichever had the biggest rate
if (entry.MetabolismRate > mostToRemove)
mostToRemove = entry.MetabolismRate;
// do all effects, if conditions apply
foreach (var effect in entry.Effects)
{
bool failed = false;
var quant = new Solution.ReagentQuantity(reagent.ReagentId, reagent.Quantity);
if (effect.Conditions != null)
{
foreach (var cond in effect.Conditions)
{
if (!cond.Condition(solutionEntityUid.Value, meta.OwnerUid, quant, EntityManager))
failed = true;
}
if (failed)
continue;
}
effect.Metabolize(solutionEntityUid.Value, meta.OwnerUid, quant, EntityManager);
}
}
removeReagents.Add(new Solution.ReagentQuantity(reagent.ReagentId, metabolism.MetabolismRate));
// remove a certain amount of reagent
if (mostToRemove > FixedPoint2.Zero)
_solutionContainerSystem.TryRemoveReagent(solutionEntityUid.Value, solution, reagent.ReagentId, mostToRemove);
}
_solutionContainerSystem.TryRemoveAllReagents(ent.Uid, solution, removeReagents);
}
}
}

View File

@@ -10,6 +10,7 @@ using Content.Server.Popups;
using Content.Shared.ActionBlocker;
using Content.Shared.Audio;
using Content.Shared.Botany;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
@@ -561,11 +562,11 @@ namespace Content.Server.Botany.Components
}
else
{
var one = FixedPoint2.New(1);
foreach (var reagent in solutionSystem.RemoveEachReagent(Owner.Uid, solution, one))
var amt = FixedPoint2.New(1);
foreach (var reagent in solutionSystem.RemoveEachReagent(OwnerUid, solution, amt))
{
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent);
reagentProto.ReactionPlant(Owner);
reagentProto.ReactionPlant(OwnerUid, new Solution.ReagentQuantity(reagent, amt));
}
}

View File

@@ -1,18 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustHealth : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp))
return;
plantHolderComp.Health += Amount;
plantHolderComp.CheckHealth();
}
}
}

View File

@@ -1,17 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustMutationLevel : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, false))
return;
plantHolderComp.MutationLevel += Amount * plantHolderComp.MutationMod * customPlantMetabolism;
}
}
}

View File

@@ -1,17 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustMutationMod : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp))
return;
plantHolderComp.MutationMod += Amount;
}
}
}

View File

@@ -1,18 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustNutrition : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, false))
return;
plantHolderComp.AdjustNutrient(Amount);
return;
}
}
}

View File

@@ -1,17 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustPests : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp))
return;
plantHolderComp.PestLevel += Amount;
}
}
}

View File

@@ -1,17 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustToxins : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, false))
return;
plantHolderComp.Toxins += Amount;
}
}
}

View File

@@ -1,17 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustWater : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, false))
return;
plantHolderComp.AdjustWater(Amount);
}
}
}

View File

@@ -1,17 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AdjustWeeds : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp, false))
return;
plantHolderComp.WeedLevel += Amount;
}
}
}

View File

@@ -1,17 +0,0 @@
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.Chemistry.PlantMetabolism
{
[UsedImplicitly]
public class AffectGrowth : AdjustAttribute
{
public override void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
{
if (!CanMetabolize(plantHolder, out var plantHolderComp))
return;
plantHolderComp.AffectGrowth((int) Amount);
}
}
}

View File

@@ -0,0 +1,34 @@
using Content.Server.Body.Metabolism;
using Content.Shared.Body.Metabolism;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Chemistry.ReagentEffectConditions
{
/// <summary>
/// Requires that the metabolizing organ is or is not tagged with a certain MetabolizerType
/// </summary>
public class OrganType : ReagentEffectCondition
{
[DataField("type", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<MetabolizerTypePrototype>))]
public string Type = default!;
/// <summary>
/// Does this condition pass when the organ has the type, or when it doesn't have the type?
/// </summary>
[DataField("shouldHave")]
public bool ShouldHave = true;
public override bool Condition(EntityUid solutionEntity, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (entityManager.TryGetComponent<MetabolizerComponent>(organEntity, out var metabolizer)
&& metabolizer.MetabolizerTypes != null
&& metabolizer.MetabolizerTypes.Contains(Type))
return ShouldHave;
return !ShouldHave;
}
}
}

View File

@@ -18,7 +18,7 @@ namespace Content.Server.Chemistry.ReagentEffectConditions
[DataField("max")]
public FixedPoint2 Max = FixedPoint2.MaxValue;
public override bool Condition(IEntity solutionEntity, Solution.ReagentQuantity reagent)
public override bool Condition(EntityUid solutionEntity, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
return reagent.Quantity >= Min && reagent.Quantity < Max;
}

View File

@@ -19,9 +19,9 @@ namespace Content.Server.Chemistry.ReagentEffects
[DataField("damage", required: true)]
public DamageSpecifier Damage = default!;
public override void Metabolize(IEntity solutionEntity, Solution.ReagentQuantity amount)
public override void Metabolize(EntityUid solutionEntity, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
EntitySystem.Get<DamageableSystem>().TryChangeDamage(solutionEntity.Uid, Damage, true);
EntitySystem.Get<DamageableSystem>().TryChangeDamage(solutionEntity, Damage, true);
}
}
}

View File

@@ -37,9 +37,9 @@ namespace Content.Server.Chemistry.ReagentEffects
/// <summary>
/// Remove reagent at set rate, changes the movespeed modifiers and adds a MovespeedModifierMetabolismComponent if not already there.
/// </summary>
public override void Metabolize(IEntity solutionEntity, Solution.ReagentQuantity amount)
public override void Metabolize(EntityUid solutionEntity, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
solutionEntity.EnsureComponent(out MovespeedModifierMetabolismComponent status);
var status = entityManager.EnsureComponent<MovespeedModifierMetabolismComponent>(solutionEntity);
// Only refresh movement if we need to.
var modified = !status.WalkSpeedModifier.Equals(WalkSpeedModifier) ||
@@ -48,10 +48,10 @@ namespace Content.Server.Chemistry.ReagentEffects
status.WalkSpeedModifier = WalkSpeedModifier;
status.SprintSpeedModifier = SprintSpeedModifier;
IncreaseTimer(status, StatusLifetime * amount.Quantity.Float());
IncreaseTimer(status, StatusLifetime * reagent.Quantity.Float());
if (modified)
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(solutionEntity.Uid);
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(solutionEntity);
}
public void IncreaseTimer(MovespeedModifierMetabolismComponent status, float time)

View File

@@ -1,15 +1,17 @@
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.PlantMetabolism
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[ImplicitDataDefinitionForInheritors]
public abstract class AdjustAttribute : IPlantMetabolizable
public abstract class PlantAdjustAttribute : ReagentEffect
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
@@ -21,13 +23,16 @@ namespace Content.Server.Chemistry.PlantMetabolism
/// </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(IEntity plantHolder, [NotNullWhen(true)] out PlantHolderComponent? plantHolderComponent, bool mustHaveAlivePlant = true)
public bool CanMetabolize(EntityUid plantHolder, [NotNullWhen(true)] out PlantHolderComponent? plantHolderComponent,
IEntityManager entityManager,
bool mustHaveAlivePlant = true)
{
plantHolderComponent = null;
if (plantHolder.Deleted || !plantHolder.TryGetComponent(out plantHolderComponent)
if (!entityManager.TryGetComponent(plantHolder, out plantHolderComponent)
|| mustHaveAlivePlant && (plantHolderComponent.Seed == null || plantHolderComponent.Dead))
return false;
@@ -36,7 +41,5 @@ namespace Content.Server.Chemistry.PlantMetabolism
return !(Prob <= 0f) && _robustRandom.Prob(Prob);
}
public abstract void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f);
}
}

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

@@ -1,21 +1,23 @@
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.PlantMetabolism
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
[DataDefinition]
public class Clonexadone : IPlantMetabolizable
public class PlantClonexadone : ReagentEffect
{
public void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1)
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (plantHolder.Deleted || !plantHolder.TryGetComponent(out PlantHolderComponent? plantHolderComp)
if (!entityManager.TryGetComponent(plantHolder, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null || plantHolderComp.Dead)
return;

View File

@@ -1,5 +1,7 @@
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;
@@ -7,29 +9,29 @@ using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Chemistry.PlantMetabolism
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
[DataDefinition]
public class Diethylamine : IPlantMetabolizable
public class PlantDiethylamine : ReagentEffect
{
public void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1)
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (plantHolder.Deleted || !plantHolder.TryGetComponent(out PlantHolderComponent? plantHolderComp)
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 * customPlantMetabolism;
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 * customPlantMetabolism;
chance = MathHelper.Lerp(15f, 125f, plantHolderComp.Seed.Endurance) * 2f;
if (random.Prob(chance))
{
plantHolderComp.CheckForDivergence(true);

View File

@@ -1,5 +1,7 @@
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;
@@ -7,22 +9,22 @@ using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Chemistry.PlantMetabolism
namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
{
[UsedImplicitly]
[DataDefinition]
public class RobustHarvest : IPlantMetabolizable
public class RobustHarvest : ReagentEffect
{
public void Metabolize(IEntity plantHolder, float customPlantMetabolism = 1f)
public override void Metabolize(EntityUid plantHolder, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (plantHolder.Deleted || !plantHolder.TryGetComponent(out PlantHolderComponent? plantHolderComp)
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 * customPlantMetabolism;
var chance = MathHelper.Lerp(15f, 150f, plantHolderComp.Seed.Potency) * 3.5f;
if (random.Prob(chance))
{
@@ -30,7 +32,7 @@ namespace Content.Server.Chemistry.PlantMetabolism
plantHolderComp.Seed.Potency++;
}
chance = MathHelper.Lerp(6f, 2f, plantHolderComp.Seed.Yield) * 0.15f * customPlantMetabolism;
chance = MathHelper.Lerp(6f, 2f, plantHolderComp.Seed.Yield) * 0.15f;
if (random.Prob(chance))
{

View File

@@ -15,12 +15,12 @@ namespace Content.Server.Chemistry.ReagentEffects
/// <summary>
/// How much hunger is satiated when 1u of the reagent is metabolized
/// </summary>
[DataField("nutritionFactor")] public float NutritionFactor { get; set; } = 3.0f;
[DataField("factor")] public float NutritionFactor { get; set; } = 3.0f;
//Remove reagent at set rate, satiate hunger if a HungerComponent can be found
public override void Metabolize(IEntity solutionEntity, Solution.ReagentQuantity amount)
public override void Metabolize(EntityUid solutionEntity, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (solutionEntity.TryGetComponent(out HungerComponent? hunger))
if (entityManager.TryGetComponent(solutionEntity, out HungerComponent? hunger))
hunger.UpdateFood(NutritionFactor);
}
}

View File

@@ -14,13 +14,13 @@ namespace Content.Server.Chemistry.ReagentEffects
{
/// How much thirst is satiated each metabolism tick. Not currently tied to
/// rate or anything.
[DataField("hydrationFactor")]
[DataField("factor")]
public float HydrationFactor { get; set; } = 3.0f;
/// Satiate thirst if a ThirstComponent can be found
public override void Metabolize(IEntity solutionEntity, Solution.ReagentQuantity amount)
public override void Metabolize(EntityUid solutionEntity, EntityUid organEntity, Solution.ReagentQuantity reagent, IEntityManager entityManager)
{
if (solutionEntity.TryGetComponent(out ThirstComponent? thirst))
if (entityManager.TryGetComponent(solutionEntity, out ThirstComponent? thirst))
thirst.UpdateThirst(HydrationFactor);
}
}