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);
}
}
}

View File

@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Resources;
using Content.Shared.Alert;
using Robust.Shared.Exceptions;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
@@ -107,6 +103,33 @@ namespace Content.Shared.StatusEffect
return false;
}
public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, string component,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
{
if (!Resolve(uid, ref status, false))
return false;
Resolve(uid, ref alerts, false);
if (TryAddStatusEffect(uid, key, time, status, alerts))
{
// If they already have the comp, we just won't bother updating anything.
if (!EntityManager.HasComponent(uid, _componentFactory.GetRegistration(component).Type))
{
// Fuck this shit I hate it
var newComponent = (Component) _componentFactory.GetComponent(component);
newComponent.Owner = EntityManager.GetEntity(uid);
EntityManager.AddComponent(uid, newComponent);
status.ActiveEffects[key].RelevantComponent = component;
}
return true;
}
return false;
}
/// <summary>
/// Tries to add a status effect to an entity with a certain timer.
/// </summary>
@@ -140,11 +163,10 @@ namespace Content.Shared.StatusEffect
(TimeSpan, TimeSpan) cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + time);
// If they already have this status effect, just bulldoze its cooldown in favor of the new one
// and keep the relevant component the same.
// If they already have this status effect, add the time onto it's cooldown rather than anything else.
if (HasStatusEffect(uid, key, status))
{
status.ActiveEffects[key] = new StatusEffectState(cooldown, status.ActiveEffects[key].RelevantComponent);
status.ActiveEffects[key].Cooldown.Item2 += time;
}
else
{