Files
tbd-station-14/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs
Tyler Young de274de9e3 use CannyFastMath in various places even where it might not be any different
also update a bunch of packages

clean up redundant YamlDotNet references
2020-06-14 09:36:53 -04:00

71 lines
2.6 KiB
C#

using System;
using Content.Server.Explosions;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Interfaces;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;
namespace Content.Server.Chemistry.ReactionEffects
{
class ExplosionReactionEffect : IReactionEffect
{
private float _devastationRange;
private float _heavyImpactRange;
private float _lightImpactRange;
private float _flashRange;
/// <summary>
/// If true, then scale ranges by intensity. If not, the ranges are the same regardless of reactant amount.
/// </summary>
private bool _scaled;
/// <summary>
/// Maximum scaling on ranges. For example, if it equals 5, then it won't scaled anywhere past
/// 5 times the minimum reactant amount.
/// </summary>
private float _maxScale;
public void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref _devastationRange, "devastationRange", 1);
serializer.DataField(ref _heavyImpactRange, "heavyImpactRange", 2);
serializer.DataField(ref _lightImpactRange, "lightImpactRange", 3);
serializer.DataField(ref _flashRange, "flashRange", 0);
serializer.DataField(ref _scaled, "scaled", false);
serializer.DataField(ref _maxScale, "maxScale", 1);
}
public void React(IEntity solutionEntity, double intensity)
{
float floatIntensity = (float)intensity;
if (solutionEntity == null)
return;
if(!solutionEntity.TryGetComponent(out SolutionComponent solution))
return;
//Handle scaling
if (_scaled)
{
floatIntensity = MathF.Min(floatIntensity, _maxScale);
}
else
{
floatIntensity = 1;
}
//Calculate intensities
int finalDevastationRange = (int)MathF.Round(_devastationRange * floatIntensity);
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.GridPosition, finalDevastationRange,
finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
}
}
}