diff --git a/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs index 1a376e5f65..d1a032b77f 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemicalReactionSystem.cs @@ -10,11 +10,11 @@ namespace Content.Server.Chemistry.EntitySystems { public class ChemicalReactionSystem : SharedChemicalReactionSystem { - protected override void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, FixedPoint2 unitReactions) + protected override void OnReaction(Solution solution, ReactionPrototype reaction, EntityUid ownerUid, FixedPoint2 unitReactions) { - base.OnReaction(solution, reaction, owner, unitReactions); + base.OnReaction(solution, reaction, ownerUid, unitReactions); - SoundSystem.Play(Filter.Pvs(owner), reaction.Sound.GetSound(), owner); + SoundSystem.Play(Filter.Pvs(ownerUid, entityManager:EntityManager), reaction.Sound.GetSound(), ownerUid); } } } diff --git a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs index 530402eef6..e1835481da 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionContainerSystem.cs @@ -128,8 +128,7 @@ namespace Content.Server.Chemistry.EntitySystems // Process reactions if (needsReactionsProcessing && solutionHolder.CanReact) { - _chemistrySystem - .FullyReactSolution(solutionHolder, EntityManager.GetEntity(uid), solutionHolder.MaxVolume); + _chemistrySystem.FullyReactSolution(solutionHolder, uid, solutionHolder.MaxVolume); } UpdateAppearance(uid, solutionHolder); diff --git a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs index 6605363fbf..07e5ed169a 100644 --- a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs @@ -89,9 +89,9 @@ namespace Content.Server.Chemistry.ReactionEffects IoCManager.InjectDependencies(this); } - public void React(Solution solution, IEntity solutionEntity, double intensity) + public void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager) { - var splitSolution = EntitySystem.Get().SplitSolution(solutionEntity.Uid, solution, solution.MaxVolume); + var splitSolution = EntitySystem.Get().SplitSolution(solutionEntity, solution, solution.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)); amount = Math.Min(amount, _maxRange); @@ -117,11 +117,13 @@ namespace Content.Server.Chemistry.ReactionEffects splitSolution.RemoveSolution(splitSolution.TotalVolume * solutionFraction); } - if (!_mapManager.TryFindGridAt(solutionEntity.Transform.MapPosition, out var grid)) return; + var transform = entityManager.GetComponent(solutionEntity); - var coords = grid.MapToGrid(solutionEntity.Transform.MapPosition); + if (!_mapManager.TryFindGridAt(transform.MapPosition, out var grid)) return; - var ent = solutionEntity.EntityManager.SpawnEntity(_prototypeId, coords.SnapToGrid()); + var coords = grid.MapToGrid(transform.MapPosition); + + var ent = entityManager.SpawnEntity(_prototypeId, coords.SnapToGrid()); var areaEffectComponent = GetAreaEffectComponent(ent); diff --git a/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs index 8dda50a59a..1d6423345a 100644 --- a/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs @@ -28,11 +28,11 @@ namespace Content.Server.Chemistry.ReactionEffects /// [DataField("maxScale")] private float _maxScale = 1; - public void React(Solution solution, IEntity solutionEntity, double intensity) + public void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager) { var floatIntensity = (float) intensity; - - if (!solutionEntity.HasComponent()) + + if (!entityManager.HasComponent(solutionEntity)) return; //Handle scaling diff --git a/Content.Server/Explosion/ExplosionHelper.cs b/Content.Server/Explosion/ExplosionHelper.cs index 5cf1d9f5f6..f4c051937e 100644 --- a/Content.Server/Explosion/ExplosionHelper.cs +++ b/Content.Server/Explosion/ExplosionHelper.cs @@ -273,6 +273,15 @@ namespace Content.Server.Explosion } } + // TODO: remove this shit + public static void SpawnExplosion(this EntityUid uid, int devastationRange = 0, int heavyImpactRange = 0, + int lightImpactRange = 0, int flashRange = 0, IEntityManager? entityManager = null) + { + entityManager ??= IoCManager.Resolve(); + + SpawnExplosion(entityManager.GetEntity(uid), devastationRange, heavyImpactRange, lightImpactRange, flashRange); + } + public static void SpawnExplosion(this IEntity entity, int devastationRange = 0, int heavyImpactRange = 0, int lightImpactRange = 0, int flashRange = 0) { diff --git a/Content.Shared/Chemistry/Reaction/IReactionEffect.cs b/Content.Shared/Chemistry/Reaction/IReactionEffect.cs index 995e1ccbb1..9e0ac78ddf 100644 --- a/Content.Shared/Chemistry/Reaction/IReactionEffect.cs +++ b/Content.Shared/Chemistry/Reaction/IReactionEffect.cs @@ -8,6 +8,6 @@ namespace Content.Shared.Chemistry.Reaction /// public interface IReactionEffect { - void React(Solution solution, IEntity solutionEntity, double intensity); + void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager); } } diff --git a/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs b/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs index 4835a996b6..408af8d1cc 100644 --- a/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs +++ b/Content.Shared/Chemistry/Reaction/SharedChemicalReactionSystem.cs @@ -56,7 +56,7 @@ namespace Content.Shared.Chemistry.Reaction /// Perform a reaction on a solution. This assumes all reaction criteria are met. /// Removes the reactants from the solution, then returns a solution with all products. /// - private Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, FixedPoint2 unitReactions) + private Solution PerformReaction(Solution solution, EntityUid ownerUid, ReactionPrototype reaction, FixedPoint2 unitReactions) { //Remove reactants foreach (var reactant in reaction.Reactants) @@ -76,16 +76,16 @@ namespace Content.Shared.Chemistry.Reaction } // Trigger reaction effects - OnReaction(solution, reaction, owner, unitReactions); + OnReaction(solution, reaction, ownerUid, unitReactions); return products; } - protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, IEntity owner, FixedPoint2 unitReactions) + protected virtual void OnReaction(Solution solution, ReactionPrototype reaction, EntityUid ownerUid, FixedPoint2 unitReactions) { foreach (var effect in reaction.Effects) { - effect.React(solution, owner, unitReactions.Double()); + effect.React(solution, ownerUid, unitReactions.Double(), EntityManager); } } @@ -94,7 +94,7 @@ namespace Content.Shared.Chemistry.Reaction /// Removes the reactants from the solution, then returns a solution with all products. /// WARNING: Does not trigger reactions between solution and new products. /// - private Solution ProcessReactions(Solution solution, IEntity owner) + private Solution ProcessReactions(Solution solution, EntityUid ownerUid) { //TODO: make a hashmap at startup and then look up reagents in the contents for a reaction var overallProducts = new Solution(); @@ -102,7 +102,7 @@ namespace Content.Shared.Chemistry.Reaction { if (CanReact(solution, reaction, out var unitReactions)) { - var reactionProducts = PerformReaction(solution, owner, reaction, unitReactions); + var reactionProducts = PerformReaction(solution, ownerUid, reaction, unitReactions); overallProducts.AddSolution(reactionProducts); break; } @@ -113,29 +113,29 @@ namespace Content.Shared.Chemistry.Reaction /// /// Continually react a solution until no more reactions occur. /// - public void FullyReactSolution(Solution solution, IEntity owner) + public void FullyReactSolution(Solution solution, EntityUid ownerUid) { for (var i = 0; i < MaxReactionIterations; i++) { - var products = ProcessReactions(solution, owner); + var products = ProcessReactions(solution, ownerUid); if (products.TotalVolume <= 0) return; solution.AddSolution(products); } - Logger.Error($"{nameof(Solution)} on {owner} (Uid: {owner.Uid}) could not finish reacting in under {MaxReactionIterations} loops."); + Logger.Error($"{nameof(Solution)} {ownerUid} could not finish reacting in under {MaxReactionIterations} loops."); } /// /// Continually react a solution until no more reactions occur, with a volume constraint. /// If a reaction's products would exceed the max volume, some product is deleted. /// - public void FullyReactSolution(Solution solution, IEntity owner, FixedPoint2 maxVolume) + public void FullyReactSolution(Solution solution, EntityUid ownerUid, FixedPoint2 maxVolume) { for (var i = 0; i < MaxReactionIterations; i++) { - var products = ProcessReactions(solution, owner); + var products = ProcessReactions(solution, ownerUid); if (products.TotalVolume <= 0) return; @@ -150,7 +150,7 @@ namespace Content.Shared.Chemistry.Reaction solution.AddSolution(products); } - Logger.Error($"{nameof(Solution)} on {owner} (Uid: {owner.Uid}) could not finish reacting in under {MaxReactionIterations} loops."); + Logger.Error($"{nameof(Solution)} {ownerUid} could not finish reacting in under {MaxReactionIterations} loops."); } } }