Adds metabolism effects to pretty much every chem already in the game (#5349)

* pass 1

* a little more reagent effect for breakfast

* move lots of stuff around

* implements all medicines

* implement all cleaning & elements

* implement toxins/pyrotechnic

* p

* linter fixies

* fixes + narcotic balancing

* fix and standardize

* reviews

* things
This commit is contained in:
mirrorcult
2021-11-20 16:47:53 -07:00
committed by GitHub
parent 8c64450305
commit 181fd055ce
36 changed files with 1107 additions and 532 deletions

View File

@@ -6,6 +6,7 @@ using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Shared.Chemistry
{
@@ -13,6 +14,7 @@ namespace Content.Shared.Chemistry
public partial class ChemistrySystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
public void ReactionEntity(EntityUid uid, ReactionMethod method, Solution solution)
{
@@ -48,21 +50,10 @@ namespace Content.Shared.Chemistry
foreach (var effect in entry.Effects)
{
bool failed = false;
foreach (var cond in effect.Conditions ?? new ReagentEffectCondition[] { })
{
if (!cond.Condition(args))
failed = true;
}
if (failed)
if (!effect.ShouldApply(args, _robustRandom))
continue;
effect.Metabolize(args);
// Make sure we still have enough reagent to go...
if (source != null && !source.ContainsReagent(reagent.ID))
break;
}
}
}

View File

@@ -4,6 +4,8 @@ using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Chemistry.Reagent
@@ -22,9 +24,44 @@ namespace Content.Shared.Chemistry.Reagent
[DataField("conditions")]
public ReagentEffectCondition[]? Conditions;
/// <summary>
/// What's the chance, from 0 to 1, that this effect will occur?
/// </summary>
[DataField("probability")]
public float Probability = 1.0f;
public abstract void Metabolize(ReagentEffectArgs args);
}
public static class ReagentEffectExt
{
public static bool ShouldApply(this ReagentEffect effect, ReagentEffectArgs args,
IRobustRandom? random = null)
{
if (random == null)
random = IoCManager.Resolve<IRobustRandom>();
// Make sure we still have enough reagent to go...
if (args.Source != null && !args.Source.ContainsReagent(args.Reagent.ID))
return false;
if (effect.Probability < 1.0f && !random.Prob(effect.Probability))
return false;
if (effect.Conditions != null)
{
foreach (var cond in effect.Conditions)
{
if (!cond.Condition(args))
return false;
}
}
return true;
}
}
public enum ReactionMethod
{
Touch,

View File

@@ -10,6 +10,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
@@ -112,11 +113,14 @@ namespace Content.Shared.Chemistry.Reagent
return;
var entMan = IoCManager.Resolve<IEntityManager>();
var random = IoCManager.Resolve<IRobustRandom>();
var args = new ReagentEffectArgs(plantHolder.Value, null, solution, this, amount.Quantity, entMan, null);
foreach (var plantMetabolizable in _plantMetabolism)
{
plantMetabolizable.Metabolize(
new ReagentEffectArgs(plantHolder.Value, null, solution, this, amount.Quantity, entMan, null)
);
if (!plantMetabolizable.ShouldApply(args, random))
continue;
plantMetabolizable.Metabolize(args);
}
}
}