Make ExplosionHelper methods extensions (#2373)

This commit is contained in:
DrSmugleaf
2020-10-25 12:11:23 +01:00
committed by GitHub
parent ab537a0f56
commit 4c46c7afce
5 changed files with 13 additions and 9 deletions

View File

@@ -58,7 +58,7 @@ namespace Content.Server.Chemistry.ReactionEffects
int finalHeavyImpactRange = (int)MathF.Round(_heavyImpactRange * floatIntensity);
int finalLightImpactRange = (int)MathF.Round(_lightImpactRange * floatIntensity);
int finalFlashRange = (int)MathF.Round(_flashRange * floatIntensity);
ExplosionHelper.SpawnExplosion(solutionEntity.Transform.Coordinates, finalDevastationRange,
solutionEntity.SpawnExplosion(finalDevastationRange,
finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
}
}

View File

@@ -24,9 +24,9 @@ namespace Content.Server.Explosions
/// Distance used for camera shake when distance from explosion is (0.0, 0.0).
/// Avoids getting NaN values down the line from doing math on (0.0, 0.0).
/// </summary>
private static Vector2 _epicenterDistance = (0.1f, 0.1f);
private static readonly Vector2 EpicenterDistance = (0.1f, 0.1f);
public static void SpawnExplosion(EntityCoordinates coords, int devastationRange, int heavyImpactRange, int lightImpactRange, int flashRange)
public static void SpawnExplosion(this EntityCoordinates coords, int devastationRange, int heavyImpactRange, int lightImpactRange, int flashRange)
{
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
@@ -151,7 +151,7 @@ namespace Content.Server.Explosions
var delta = coords.ToMapPos(entityManager) - playerPos;
//Change if zero. Will result in a NaN later breaking camera shake if not changed
if (delta.EqualsApprox((0.0f, 0.0f)))
delta = _epicenterDistance;
delta = EpicenterDistance;
var distance = delta.LengthSquared;
var effect = 10 * (1 / (1 + distance));
@@ -162,5 +162,11 @@ namespace Content.Server.Explosions
}
}
}
public static void SpawnExplosion(this IEntity entity, int devastationRange, int heavyImpactRange,
int lightImpactRange, int flashRange)
{
entity.Transform.Coordinates.SpawnExplosion(devastationRange, heavyImpactRange, lightImpactRange, flashRange);
}
}
}

View File

@@ -34,7 +34,7 @@ namespace Content.Server.GameObjects.Components.Explosion
if (_beingExploded) return true;
_beingExploded = true;
ExplosionHelper.SpawnExplosion(Owner.Transform.Coordinates, DevastationRange, HeavyImpactRange, LightImpactRange, FlashRange);
Owner.SpawnExplosion(DevastationRange, HeavyImpactRange, LightImpactRange, FlashRange);
Owner.Delete();
return true;

View File

@@ -143,9 +143,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
intensity = Math.Min(intensity, 8);
ExplosionHelper.SpawnExplosion(epicenter.Owner.Transform.Coordinates, intensity / 2, intensity, intensity * 2, intensity * 3);
epicenter.Owner.SpawnExplosion(intensity / 2, intensity, intensity * 2, intensity * 3);
}
}
}

View File

@@ -127,7 +127,7 @@ namespace Content.Server.GameObjects.Components.Pointing
return;
}
ExplosionHelper.SpawnExplosion(Owner.Transform.Coordinates, 0, 2, 1, 1);
Owner.SpawnExplosion(0, 2, 1, 1);
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Effects/explosion.ogg", Owner);
Owner.Delete();