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

@@ -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);
}
}
}