2021-01-07 00:31:43 -06:00
|
|
|
using System;
|
2019-10-11 16:57:16 -04:00
|
|
|
using Content.Server.Explosions;
|
|
|
|
|
using Content.Server.GameObjects.Components.Chemistry;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.Interfaces.Chemistry;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2019-10-11 16:57:16 -04:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
2019-11-21 17:24:19 -05:00
|
|
|
namespace Content.Server.Chemistry.ReactionEffects
|
2019-10-11 16:57:16 -04:00
|
|
|
{
|
2020-11-27 01:01:56 +01:00
|
|
|
public class ExplosionReactionEffect : IReactionEffect
|
2019-10-11 16:57:16 -04:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
void IExposeData.ExposeData(ObjectSerializer serializer)
|
2019-10-11 16:57:16 -04:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-13 01:28:28 -04:00
|
|
|
public void React(IEntity solutionEntity, double intensity)
|
2019-10-11 16:57:16 -04:00
|
|
|
{
|
2020-06-13 01:28:28 -04:00
|
|
|
float floatIntensity = (float)intensity;
|
2019-10-11 16:57:16 -04:00
|
|
|
if (solutionEntity == null)
|
|
|
|
|
return;
|
2020-09-09 18:32:31 -04:00
|
|
|
if(!solutionEntity.TryGetComponent(out SolutionContainerComponent solution))
|
2019-10-11 16:57:16 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//Handle scaling
|
|
|
|
|
if (_scaled)
|
|
|
|
|
{
|
2020-06-13 01:28:28 -04:00
|
|
|
floatIntensity = MathF.Min(floatIntensity, _maxScale);
|
2019-10-11 16:57:16 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
floatIntensity = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Calculate intensities
|
2020-06-13 01:28:28 -04:00
|
|
|
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);
|
2020-10-25 12:11:23 +01:00
|
|
|
solutionEntity.SpawnExplosion(finalDevastationRange,
|
2019-10-11 16:57:16 -04:00
|
|
|
finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|