Refactor reaction effects to use reagent effects (#5426)
* reaction effect refactor * works now
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user