IReagentEffect and some chemistry stuff uses EntityUid

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 11:51:17 +01:00
parent 222541f1a2
commit c5fda6daca
7 changed files with 36 additions and 26 deletions

View File

@@ -10,11 +10,11 @@ namespace Content.Server.Chemistry.EntitySystems
{ {
public class ChemicalReactionSystem : SharedChemicalReactionSystem 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);
} }
} }
} }

View File

@@ -128,8 +128,7 @@ namespace Content.Server.Chemistry.EntitySystems
// Process reactions // Process reactions
if (needsReactionsProcessing && solutionHolder.CanReact) if (needsReactionsProcessing && solutionHolder.CanReact)
{ {
_chemistrySystem _chemistrySystem.FullyReactSolution(solutionHolder, uid, solutionHolder.MaxVolume);
.FullyReactSolution(solutionHolder, EntityManager.GetEntity(uid), solutionHolder.MaxVolume);
} }
UpdateAppearance(uid, solutionHolder); UpdateAppearance(uid, solutionHolder);

View File

@@ -89,9 +89,9 @@ namespace Content.Server.Chemistry.ReactionEffects
IoCManager.InjectDependencies(this); 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<SolutionContainerSystem>().SplitSolution(solutionEntity.Uid, solution, solution.MaxVolume); var splitSolution = EntitySystem.Get<SolutionContainerSystem>().SplitSolution(solutionEntity, solution, solution.MaxVolume);
// We take the square root so it becomes harder to reach higher amount values // 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(intensity));
amount = Math.Min(amount, _maxRange); amount = Math.Min(amount, _maxRange);
@@ -117,11 +117,13 @@ namespace Content.Server.Chemistry.ReactionEffects
splitSolution.RemoveSolution(splitSolution.TotalVolume * solutionFraction); splitSolution.RemoveSolution(splitSolution.TotalVolume * solutionFraction);
} }
if (!_mapManager.TryFindGridAt(solutionEntity.Transform.MapPosition, out var grid)) return; var transform = entityManager.GetComponent<TransformComponent>(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); var areaEffectComponent = GetAreaEffectComponent(ent);

View File

@@ -28,11 +28,11 @@ namespace Content.Server.Chemistry.ReactionEffects
/// </summary> /// </summary>
[DataField("maxScale")] private float _maxScale = 1; [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; var floatIntensity = (float) intensity;
if (!solutionEntity.HasComponent<SolutionContainerManagerComponent>()) if (!entityManager.HasComponent<SolutionContainerManagerComponent>(solutionEntity))
return; return;
//Handle scaling //Handle scaling

View File

@@ -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<IEntityManager>();
SpawnExplosion(entityManager.GetEntity(uid), devastationRange, heavyImpactRange, lightImpactRange, flashRange);
}
public static void SpawnExplosion(this IEntity entity, int devastationRange = 0, int heavyImpactRange = 0, public static void SpawnExplosion(this IEntity entity, int devastationRange = 0, int heavyImpactRange = 0,
int lightImpactRange = 0, int flashRange = 0) int lightImpactRange = 0, int flashRange = 0)
{ {

View File

@@ -8,6 +8,6 @@ namespace Content.Shared.Chemistry.Reaction
/// </summary> /// </summary>
public interface IReactionEffect public interface IReactionEffect
{ {
void React(Solution solution, IEntity solutionEntity, double intensity); void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager);
} }
} }

View File

@@ -56,7 +56,7 @@ namespace Content.Shared.Chemistry.Reaction
/// Perform a reaction on a solution. This assumes all reaction criteria are met. /// 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. /// Removes the reactants from the solution, then returns a solution with all products.
/// </summary> /// </summary>
private Solution PerformReaction(Solution solution, IEntity owner, ReactionPrototype reaction, FixedPoint2 unitReactions) private Solution PerformReaction(Solution solution, EntityUid ownerUid, ReactionPrototype reaction, FixedPoint2 unitReactions)
{ {
//Remove reactants //Remove reactants
foreach (var reactant in reaction.Reactants) foreach (var reactant in reaction.Reactants)
@@ -76,16 +76,16 @@ namespace Content.Shared.Chemistry.Reaction
} }
// Trigger reaction effects // Trigger reaction effects
OnReaction(solution, reaction, owner, unitReactions); OnReaction(solution, reaction, ownerUid, unitReactions);
return products; 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) 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. /// Removes the reactants from the solution, then returns a solution with all products.
/// WARNING: Does not trigger reactions between solution and new products. /// WARNING: Does not trigger reactions between solution and new products.
/// </summary> /// </summary>
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 //TODO: make a hashmap at startup and then look up reagents in the contents for a reaction
var overallProducts = new Solution(); var overallProducts = new Solution();
@@ -102,7 +102,7 @@ namespace Content.Shared.Chemistry.Reaction
{ {
if (CanReact(solution, reaction, out var unitReactions)) if (CanReact(solution, reaction, out var unitReactions))
{ {
var reactionProducts = PerformReaction(solution, owner, reaction, unitReactions); var reactionProducts = PerformReaction(solution, ownerUid, reaction, unitReactions);
overallProducts.AddSolution(reactionProducts); overallProducts.AddSolution(reactionProducts);
break; break;
} }
@@ -113,29 +113,29 @@ namespace Content.Shared.Chemistry.Reaction
/// <summary> /// <summary>
/// Continually react a solution until no more reactions occur. /// Continually react a solution until no more reactions occur.
/// </summary> /// </summary>
public void FullyReactSolution(Solution solution, IEntity owner) public void FullyReactSolution(Solution solution, EntityUid ownerUid)
{ {
for (var i = 0; i < MaxReactionIterations; i++) for (var i = 0; i < MaxReactionIterations; i++)
{ {
var products = ProcessReactions(solution, owner); var products = ProcessReactions(solution, ownerUid);
if (products.TotalVolume <= 0) if (products.TotalVolume <= 0)
return; return;
solution.AddSolution(products); 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.");
} }
/// <summary> /// <summary>
/// Continually react a solution until no more reactions occur, with a volume constraint. /// 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. /// If a reaction's products would exceed the max volume, some product is deleted.
/// </summary> /// </summary>
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++) for (var i = 0; i < MaxReactionIterations; i++)
{ {
var products = ProcessReactions(solution, owner); var products = ProcessReactions(solution, ownerUid);
if (products.TotalVolume <= 0) if (products.TotalVolume <= 0)
return; return;
@@ -150,7 +150,7 @@ namespace Content.Shared.Chemistry.Reaction
solution.AddSolution(products); 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.");
} }
} }
} }