IReagentEffect and some chemistry stuff uses EntityUid
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<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
|
||||
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<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);
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
/// </summary>
|
||||
[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<SolutionContainerManagerComponent>())
|
||||
if (!entityManager.HasComponent<SolutionContainerManagerComponent>(solutionEntity))
|
||||
return;
|
||||
|
||||
//Handle scaling
|
||||
|
||||
@@ -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,
|
||||
int lightImpactRange = 0, int flashRange = 0)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,6 @@ namespace Content.Shared.Chemistry.Reaction
|
||||
/// </summary>
|
||||
public interface IReactionEffect
|
||||
{
|
||||
void React(Solution solution, IEntity solutionEntity, double intensity);
|
||||
void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
/// </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
|
||||
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.
|
||||
/// </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
|
||||
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
|
||||
/// <summary>
|
||||
/// Continually react a solution until no more reactions occur.
|
||||
/// </summary>
|
||||
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.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </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++)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user