Refactor reaction effects to use reagent effects (#5426)
* reaction effect refactor * works now
This commit is contained in:
@@ -158,7 +158,7 @@ namespace Content.Server.Body.Systems
|
||||
if (!effect.ShouldApply(args, _random))
|
||||
continue;
|
||||
|
||||
effect.Metabolize(args);
|
||||
effect.Effect(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Content.Server.Chemistry.EntitySystems
|
||||
{
|
||||
public class ChemicalReactionSystem : SharedChemicalReactionSystem
|
||||
{
|
||||
protected override void OnReaction(Solution solution, ReactionPrototype reaction, EntityUid ownerUid, FixedPoint2 unitReactions)
|
||||
protected override void OnReaction(Solution solution, ReactionPrototype reaction, ReagentPrototype randomReagent, EntityUid ownerUid, FixedPoint2 unitReactions)
|
||||
{
|
||||
base.OnReaction(solution, reaction, ownerUid, unitReactions);
|
||||
base.OnReaction(solution, reaction, randomReagent, ownerUid, unitReactions);
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(ownerUid, entityManager:EntityManager), reaction.Sound.GetSound(), ownerUid);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.Coordinates.Helpers;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Sound;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -23,7 +24,7 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public abstract class AreaReactionEffect : IReactionEffect, ISerializationHooks
|
||||
public abstract class AreaReactionEffect : ReagentEffect, ISerializationHooks
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
@@ -89,11 +90,14 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
var splitSolution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(solutionEntity, solution, solution.MaxVolume);
|
||||
if (args.Source == null)
|
||||
return;
|
||||
|
||||
var splitSolution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(args.SolutionEntity, args.Source, args.Source.MaxVolume);
|
||||
// We take the square root so it becomes harder to reach higher amount values
|
||||
var amount = (int) Math.Round(_rangeConstant + _rangeMultiplier*Math.Sqrt(intensity));
|
||||
var amount = (int) Math.Round(_rangeConstant + _rangeMultiplier*Math.Sqrt(args.Quantity.Float()));
|
||||
amount = Math.Min(amount, _maxRange);
|
||||
|
||||
if (_diluteReagents)
|
||||
@@ -117,13 +121,13 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
splitSolution.RemoveSolution(splitSolution.TotalVolume * solutionFraction);
|
||||
}
|
||||
|
||||
var transform = entityManager.GetComponent<TransformComponent>(solutionEntity);
|
||||
var transform = args.EntityManager.GetComponent<TransformComponent>(args.SolutionEntity);
|
||||
|
||||
if (!_mapManager.TryFindGridAt(transform.MapPosition, out var grid)) return;
|
||||
|
||||
var coords = grid.MapToGrid(transform.MapPosition);
|
||||
|
||||
var ent = entityManager.SpawnEntity(_prototypeId, coords.SnapToGrid());
|
||||
var ent = args.EntityManager.SpawnEntity(_prototypeId, coords.SnapToGrid());
|
||||
|
||||
var areaEffectComponent = GetAreaEffectComponent(ent);
|
||||
|
||||
@@ -137,7 +141,7 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
areaEffectComponent.TryAddSolution(splitSolution);
|
||||
areaEffectComponent.Start(amount, _duration, _spreadDelay, _removeDelay);
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(solutionEntity), _sound.GetSound(), solutionEntity, AudioHelpers.WithVariation(0.125f));
|
||||
SoundSystem.Play(Filter.Pvs(args.SolutionEntity), _sound.GetSound(), args.SolutionEntity, AudioHelpers.WithVariation(0.125f));
|
||||
}
|
||||
|
||||
protected abstract SolutionAreaEffectComponent? GetAreaEffectComponent(IEntity entity);
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
using System;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Chemistry.ReactionEffects
|
||||
{
|
||||
[DataDefinition]
|
||||
public class ExplosionReactionEffect : IReactionEffect
|
||||
public class ExplosionReactionEffect : ReagentEffect
|
||||
{
|
||||
[DataField("devastationRange")] private float _devastationRange = 1;
|
||||
[DataField("heavyImpactRange")] private float _heavyImpactRange = 2;
|
||||
@@ -27,11 +26,11 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
/// </summary>
|
||||
[DataField("maxScale")] private float _maxScale = 1;
|
||||
|
||||
public void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
var floatIntensity = (float) intensity;
|
||||
var floatIntensity = (float) args.Quantity;
|
||||
|
||||
if (!entityManager.HasComponent<SolutionContainerManagerComponent>(solutionEntity))
|
||||
if (!args.EntityManager.HasComponent<SolutionContainerManagerComponent>(args.SolutionEntity))
|
||||
return;
|
||||
|
||||
//Handle scaling
|
||||
@@ -49,7 +48,7 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
var finalHeavyImpactRange = (int)MathF.Round(_heavyImpactRange * floatIntensity);
|
||||
var finalLightImpactRange = (int)MathF.Round(_lightImpactRange * floatIntensity);
|
||||
var finalFlashRange = (int)MathF.Round(_flashRange * floatIntensity);
|
||||
EntitySystem.Get<ExplosionSystem>().SpawnExplosion(solutionEntity, finalDevastationRange,
|
||||
EntitySystem.Get<ExplosionSystem>().SpawnExplosion(args.SolutionEntity, finalDevastationRange,
|
||||
finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace Content.Server.Chemistry.ReagentEffectConditions
|
||||
|
||||
public override bool Condition(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.Reagent == null)
|
||||
return false;
|
||||
|
||||
if (Reagent == null)
|
||||
Reagent = args.Reagent.ID;
|
||||
|
||||
|
||||
@@ -16,15 +16,18 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[DataField("solution")]
|
||||
private string _solution = "reagents";
|
||||
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.Reagent == null)
|
||||
return;
|
||||
|
||||
// TODO see if this is correct
|
||||
if (!EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryGetSolution(args.SolutionEntity, _solution, out var solutionContainer))
|
||||
return;
|
||||
|
||||
if (EntitySystem.Get<SolutionContainerSystem>()
|
||||
.TryAddReagent(args.SolutionEntity, solutionContainer, args.Reagent.ID, args.Metabolizing, out var accepted))
|
||||
.TryAddReagent(args.SolutionEntity, solutionContainer, args.Reagent.ID, args.Quantity, out var accepted))
|
||||
args.Source?.RemoveReagent(args.Reagent.ID, accepted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[DataField("amount")]
|
||||
public float Amount;
|
||||
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent(args.SolutionEntity, out TemperatureComponent temp))
|
||||
{
|
||||
|
||||
@@ -14,13 +14,13 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[UsedImplicitly]
|
||||
public class ExtinguishReaction : ReagentEffect
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!args.EntityManager.TryGetComponent(args.SolutionEntity, out FlammableComponent? flammable)) return;
|
||||
|
||||
var flammableSystem = EntitySystem.Get<FlammableSystem>();
|
||||
flammableSystem.Extinguish(args.SolutionEntity, flammable);
|
||||
flammableSystem.AdjustFireStacks(args.SolutionEntity, -1.5f * (float) args.Metabolizing, flammable);
|
||||
flammableSystem.AdjustFireStacks(args.SolutionEntity, -1.5f * (float) args.Quantity, flammable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[UsedImplicitly]
|
||||
public class FlammableReaction : ReagentEffect
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!args.EntityManager.TryGetComponent(args.SolutionEntity, out FlammableComponent? flammable)) return;
|
||||
|
||||
EntitySystem.Get<FlammableSystem>().AdjustFireStacks(args.SolutionEntity, args.Metabolizing.Float() / 5f, flammable);
|
||||
args.Source?.RemoveReagent(args.Reagent.ID, args.Metabolizing);
|
||||
EntitySystem.Get<FlammableSystem>().AdjustFireStacks(args.SolutionEntity, args.Quantity.Float() / 5f, flammable);
|
||||
args.Source?.RemoveReagent(args.Reagent.ID, args.Quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[DataField("damage", required: true)]
|
||||
public DamageSpecifier Damage = default!;
|
||||
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
EntitySystem.Get<DamageableSystem>().TryChangeDamage(args.SolutionEntity, Damage * args.Metabolizing, true);
|
||||
EntitySystem.Get<DamageableSystem>().TryChangeDamage(args.SolutionEntity, Damage * args.Quantity, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ 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(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
var status = args.EntityManager.EnsureComponent<MovespeedModifierMetabolismComponent>(args.SolutionEntity);
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
status.WalkSpeedModifier = WalkSpeedModifier;
|
||||
status.SprintSpeedModifier = SprintSpeedModifier;
|
||||
|
||||
IncreaseTimer(status, StatusLifetime * args.Metabolizing.Float());
|
||||
IncreaseTimer(status, StatusLifetime * args.Quantity.Float());
|
||||
|
||||
if (modified)
|
||||
EntitySystem.Get<MovementSpeedModifierSystem>().RefreshMovementSpeedModifiers(args.SolutionEntity);
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
{
|
||||
public class PlantAdjustHealth : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
{
|
||||
public class PlantAdjustMutationLevel : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[UsedImplicitly]
|
||||
public class PlantAdjustMutationMod : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[UsedImplicitly]
|
||||
public class PlantAdjustNutrition : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[UsedImplicitly]
|
||||
public class PlantAdjustPests : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[UsedImplicitly]
|
||||
public class PlantAdjustToxins : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[UsedImplicitly]
|
||||
public class PlantAdjustWater : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[UsedImplicitly]
|
||||
public class PlantAdjustWeeds : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[UsedImplicitly]
|
||||
public class PlantAffectGrowth : PlantAdjustAttribute
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!CanMetabolize(args.SolutionEntity, out var plantHolderComp, args.EntityManager))
|
||||
return;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[DataDefinition]
|
||||
public class PlantClonexadone : ReagentEffect
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!args.EntityManager.TryGetComponent(args.SolutionEntity, out PlantHolderComponent? plantHolderComp)
|
||||
|| plantHolderComp.Seed == null || plantHolderComp.Dead)
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[DataDefinition]
|
||||
public class PlantDiethylamine : ReagentEffect
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!args.EntityManager.TryGetComponent(args.SolutionEntity, out PlantHolderComponent? plantHolderComp)
|
||||
|| plantHolderComp.Seed == null || plantHolderComp.Dead ||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Content.Server.Chemistry.ReagentEffects.PlantMetabolism
|
||||
[DataDefinition]
|
||||
public class RobustHarvest : ReagentEffect
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!args.EntityManager.TryGetComponent(args.SolutionEntity, out PlantHolderComponent? plantHolderComp)
|
||||
|| plantHolderComp.Seed == null || plantHolderComp.Dead ||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[DataField("type")]
|
||||
public PopupType Type = PopupType.Local;
|
||||
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
var popupSys = args.EntityManager.EntitySysManager.GetEntitySystem<SharedPopupSystem>();
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[DataField("amount", required: true)]
|
||||
public FixedPoint2 Amount = default!;
|
||||
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.Source != null)
|
||||
{
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[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(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent(args.SolutionEntity, out HungerComponent? hunger))
|
||||
hunger.UpdateFood(NutritionFactor * (float) args.Metabolizing);
|
||||
hunger.UpdateFood(NutritionFactor * (float) args.Quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
public float HydrationFactor { get; set; } = 3.0f;
|
||||
|
||||
/// Satiate thirst if a ThirstComponent can be found
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.EntityManager.TryGetComponent(args.SolutionEntity, out ThirstComponent? thirst))
|
||||
thirst.UpdateThirst(HydrationFactor * (float) args.Metabolizing);
|
||||
thirst.UpdateThirst(HydrationFactor * (float) args.Quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Content.Server.Chemistry.ReagentEffects.StatusEffects
|
||||
[DataField("type")]
|
||||
public StatusEffectMetabolismType Type = StatusEffectMetabolismType.Add;
|
||||
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
var statusSys = args.EntityManager.EntitySysManager.GetEntitySystem<StatusEffectsSystem>();
|
||||
if (Type == StatusEffectMetabolismType.Add && Component != String.Empty)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Chemistry.ReagentEffects.StatusEffects
|
||||
[DataField("time")]
|
||||
public float Time = 2.0f;
|
||||
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
args.EntityManager.EntitySysManager.GetEntitySystem<SharedJitteringSystem>()
|
||||
.DoJitter(args.SolutionEntity, TimeSpan.FromSeconds(Time), Amplitude, Frequency);
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
[UsedImplicitly]
|
||||
public class WashCreamPieReaction : ReagentEffect
|
||||
{
|
||||
public override void Metabolize(ReagentEffectArgs args)
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (!args.EntityManager.TryGetComponent(args.SolutionEntity, out CreamPiedComponent? creamPied)) return;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Content.Shared.Chemistry
|
||||
if (!effect.ShouldApply(args, _robustRandom))
|
||||
continue;
|
||||
|
||||
effect.Metabolize(args);
|
||||
effect.Effect(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Chemistry.Reaction
|
||||
{
|
||||
/// <summary>
|
||||
/// Chemical reaction effect on the world such as an explosion, EMP, or fire.
|
||||
/// </summary>
|
||||
public interface IReactionEffect
|
||||
{
|
||||
void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager);
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,6 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
[Prototype("reaction")]
|
||||
public class ReactionPrototype : IPrototype
|
||||
{
|
||||
[DataField("reactants")] private Dictionary<string, ReactantPrototype> _reactants = new();
|
||||
[DataField("products")] private Dictionary<string, FixedPoint2> _products = new();
|
||||
[DataField("effects", serverOnly: true)] private List<IReactionEffect> _effects = new();
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("id", required: true)]
|
||||
public string ID { get; } = default!;
|
||||
@@ -28,15 +24,17 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
/// <summary>
|
||||
/// Reactants required for the reaction to occur.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, ReactantPrototype> Reactants => _reactants;
|
||||
[DataField("reactants")] public Dictionary<string, ReactantPrototype> Reactants = new();
|
||||
|
||||
/// <summary>
|
||||
/// Reagents created when the reaction occurs.
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, FixedPoint2> Products => _products;
|
||||
[DataField("products")] public Dictionary<string, FixedPoint2> Products = new();
|
||||
|
||||
/// <summary>
|
||||
/// Effects to be triggered when the reaction occurs.
|
||||
/// </summary>
|
||||
public IReadOnlyList<IReactionEffect> Effects => _effects;
|
||||
[DataField("effects", serverOnly: true)] public List<ReagentEffect> Effects = new();
|
||||
|
||||
// TODO SERV3: Empty on the client, (de)serialize on the server with module manager is server module
|
||||
[DataField("sound", serverOnly: true)] public SoundSpecifier Sound { get; private set; } = new SoundPathSpecifier("/Audio/Effects/Chemistry/bubbles.ogg");
|
||||
|
||||
@@ -6,6 +6,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Chemistry.Reaction
|
||||
{
|
||||
@@ -16,6 +17,7 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
private const int MaxReactionIterations = 20;
|
||||
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -58,6 +60,9 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
/// </summary>
|
||||
private Solution PerformReaction(Solution solution, EntityUid ownerUid, ReactionPrototype reaction, FixedPoint2 unitReactions)
|
||||
{
|
||||
// We do this so that ReagentEffect can have something to work with, even if it's
|
||||
// a little meaningless.
|
||||
var randomReagent = _prototypeManager.Index<ReagentPrototype>(_random.Pick(reaction.Reactants).Key);
|
||||
//Remove reactants
|
||||
foreach (var reactant in reaction.Reactants)
|
||||
{
|
||||
@@ -76,16 +81,23 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
}
|
||||
|
||||
// Trigger reaction effects
|
||||
OnReaction(solution, reaction, ownerUid, unitReactions);
|
||||
OnReaction(solution, reaction, randomReagent, ownerUid, unitReactions);
|
||||
|
||||
return products;
|
||||
}
|
||||
|
||||
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, EntityUid ownerUid, FixedPoint2 unitReactions)
|
||||
protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, ReagentPrototype randomReagent, EntityUid ownerUid, FixedPoint2 unitReactions)
|
||||
{
|
||||
var args = new ReagentEffectArgs(ownerUid, null, solution,
|
||||
randomReagent,
|
||||
unitReactions, EntityManager, null);
|
||||
|
||||
foreach (var effect in reaction.Effects)
|
||||
{
|
||||
effect.React(solution, ownerUid, unitReactions.Double(), EntityManager);
|
||||
if (!effect.ShouldApply(args))
|
||||
continue;
|
||||
|
||||
effect.Effect(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
[DataField("probability")]
|
||||
public float Probability = 1.0f;
|
||||
|
||||
public abstract void Metabolize(ReagentEffectArgs args);
|
||||
public abstract void Effect(ReagentEffectArgs args);
|
||||
}
|
||||
|
||||
public static class ReagentEffectExt
|
||||
@@ -41,11 +41,6 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
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;
|
||||
|
||||
@@ -74,7 +69,7 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
EntityUid? OrganEntity,
|
||||
Solution? Source,
|
||||
ReagentPrototype Reagent,
|
||||
FixedPoint2 Metabolizing,
|
||||
FixedPoint2 Quantity,
|
||||
IEntityManager EntityManager,
|
||||
ReactionMethod? Method
|
||||
);
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Content.Shared.Chemistry.Reagent
|
||||
if (!plantMetabolizable.ShouldApply(args, random))
|
||||
continue;
|
||||
|
||||
plantMetabolizable.Metabolize(args);
|
||||
plantMetabolizable.Effect(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user