Turn ReagentEffects into generic EntityEffects (#28168)
* Oh the possibilities * Merge fixes * Forgot to remote LavaSystem oops * Changed EntityEffectArgs to EntityEffectBaseArgs and EntityEffectReagentArgs * Throw exception for unimplemented effectargs * Remove Json and overrideable datafields * Fix test issues * Actually fix the compiling issue * Fix comments and remove EntityEffectArgs (no longer used, replaced with EntityEffectBaseArgs)
This commit is contained in:
@@ -3,102 +3,107 @@ using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.EntityEffects;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Chemistry
|
||||
namespace Content.Shared.Chemistry;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class ReactiveSystem : EntitySystem
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class ReactiveSystem : EntitySystem
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
|
||||
public void DoEntityReaction(EntityUid uid, Solution solution, ReactionMethod method)
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
|
||||
public void DoEntityReaction(EntityUid uid, Solution solution, ReactionMethod method)
|
||||
foreach (var reagent in solution.Contents.ToArray())
|
||||
{
|
||||
foreach (var reagent in solution.Contents.ToArray())
|
||||
{
|
||||
ReactionEntity(uid, method, reagent, solution);
|
||||
}
|
||||
ReactionEntity(uid, method, reagent, solution);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReactionEntity(EntityUid uid, ReactionMethod method, ReagentQuantity reagentQuantity, Solution? source)
|
||||
public void ReactionEntity(EntityUid uid, ReactionMethod method, ReagentQuantity reagentQuantity, Solution? source)
|
||||
{
|
||||
// We throw if the reagent specified doesn't exist.
|
||||
var proto = _prototypeManager.Index<ReagentPrototype>(reagentQuantity.Reagent.Prototype);
|
||||
ReactionEntity(uid, method, proto, reagentQuantity, source);
|
||||
}
|
||||
|
||||
public void ReactionEntity(EntityUid uid, ReactionMethod method, ReagentPrototype proto,
|
||||
ReagentQuantity reagentQuantity, Solution? source)
|
||||
{
|
||||
if (!TryComp(uid, out ReactiveComponent? reactive))
|
||||
return;
|
||||
|
||||
// If we have a source solution, use the reagent quantity we have left. Otherwise, use the reaction volume specified.
|
||||
var args = new EntityEffectReagentArgs(uid, EntityManager, null, source, source?.GetReagentQuantity(reagentQuantity.Reagent) ?? reagentQuantity.Quantity, proto, method, 1f);
|
||||
|
||||
// First, check if the reagent wants to apply any effects.
|
||||
if (proto.ReactiveEffects != null && reactive.ReactiveGroups != null)
|
||||
{
|
||||
// We throw if the reagent specified doesn't exist.
|
||||
var proto = _prototypeManager.Index<ReagentPrototype>(reagentQuantity.Reagent.Prototype);
|
||||
ReactionEntity(uid, method, proto, reagentQuantity, source);
|
||||
}
|
||||
|
||||
public void ReactionEntity(EntityUid uid, ReactionMethod method, ReagentPrototype proto,
|
||||
ReagentQuantity reagentQuantity, Solution? source)
|
||||
{
|
||||
if (!TryComp(uid, out ReactiveComponent? reactive))
|
||||
return;
|
||||
|
||||
// If we have a source solution, use the reagent quantity we have left. Otherwise, use the reaction volume specified.
|
||||
var args = new ReagentEffectArgs(uid, null, source, proto,
|
||||
source?.GetReagentQuantity(reagentQuantity.Reagent) ?? reagentQuantity.Quantity, EntityManager, method, 1f);
|
||||
|
||||
// First, check if the reagent wants to apply any effects.
|
||||
if (proto.ReactiveEffects != null && reactive.ReactiveGroups != null)
|
||||
foreach (var (key, val) in proto.ReactiveEffects)
|
||||
{
|
||||
foreach (var (key, val) in proto.ReactiveEffects)
|
||||
if (!val.Methods.Contains(method))
|
||||
continue;
|
||||
|
||||
if (!reactive.ReactiveGroups.ContainsKey(key))
|
||||
continue;
|
||||
|
||||
if (!reactive.ReactiveGroups[key].Contains(method))
|
||||
continue;
|
||||
|
||||
foreach (var effect in val.Effects)
|
||||
{
|
||||
if (!val.Methods.Contains(method))
|
||||
if (!effect.ShouldApply(args, _robustRandom))
|
||||
continue;
|
||||
|
||||
if (!reactive.ReactiveGroups.ContainsKey(key))
|
||||
continue;
|
||||
|
||||
if (!reactive.ReactiveGroups[key].Contains(method))
|
||||
continue;
|
||||
|
||||
foreach (var effect in val.Effects)
|
||||
if (effect.ShouldLog)
|
||||
{
|
||||
if (!effect.ShouldApply(args, _robustRandom))
|
||||
continue;
|
||||
|
||||
if (effect.ShouldLog)
|
||||
{
|
||||
var entity = args.SolutionEntity;
|
||||
_adminLogger.Add(LogType.ReagentEffect, effect.LogImpact,
|
||||
$"Reactive effect {effect.GetType().Name:effect} of reagent {proto.ID:reagent} with method {method} applied on entity {ToPrettyString(entity):entity} at {Transform(entity).Coordinates:coordinates}");
|
||||
}
|
||||
|
||||
effect.Effect(args);
|
||||
var entity = args.TargetEntity;
|
||||
_adminLogger.Add(LogType.ReagentEffect, effect.LogImpact,
|
||||
$"Reactive effect {effect.GetType().Name:effect} of reagent {proto.ID:reagent} with method {method} applied on entity {ToPrettyString(entity):entity} at {Transform(entity).Coordinates:coordinates}");
|
||||
}
|
||||
|
||||
effect.Effect(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then, check if the prototype has any effects it can apply as well.
|
||||
if (reactive.Reactions != null)
|
||||
// Then, check if the prototype has any effects it can apply as well.
|
||||
if (reactive.Reactions != null)
|
||||
{
|
||||
foreach (var entry in reactive.Reactions)
|
||||
{
|
||||
foreach (var entry in reactive.Reactions)
|
||||
if (!entry.Methods.Contains(method))
|
||||
continue;
|
||||
|
||||
if (entry.Reagents != null && !entry.Reagents.Contains(proto.ID))
|
||||
continue;
|
||||
|
||||
foreach (var effect in entry.Effects)
|
||||
{
|
||||
if (!entry.Methods.Contains(method))
|
||||
if (!effect.ShouldApply(args, _robustRandom))
|
||||
continue;
|
||||
|
||||
if (entry.Reagents != null && !entry.Reagents.Contains(proto.ID))
|
||||
continue;
|
||||
|
||||
foreach (var effect in entry.Effects)
|
||||
if (effect.ShouldLog)
|
||||
{
|
||||
if (!effect.ShouldApply(args, _robustRandom))
|
||||
continue;
|
||||
|
||||
if (effect.ShouldLog)
|
||||
{
|
||||
var entity = args.SolutionEntity;
|
||||
_adminLogger.Add(LogType.ReagentEffect, effect.LogImpact,
|
||||
$"Reactive effect {effect.GetType().Name:effect} of {ToPrettyString(entity):entity} using reagent {proto.ID:reagent} with method {method} at {Transform(entity).Coordinates:coordinates}");
|
||||
}
|
||||
|
||||
effect.Effect(args);
|
||||
var entity = args.TargetEntity;
|
||||
_adminLogger.Add(LogType.ReagentEffect, effect.LogImpact,
|
||||
$"Reactive effect {effect.GetType().Name:effect} of {ToPrettyString(entity):entity} using reagent {proto.ID:reagent} with method {method} at {Transform(entity).Coordinates:coordinates}");
|
||||
}
|
||||
|
||||
effect.Effect(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public enum ReactionMethod
|
||||
{
|
||||
Touch,
|
||||
Injection,
|
||||
Ingestion,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user