2021-01-07 00:31:43 -06:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Chemistry.Components;
|
2021-10-29 13:40:15 +01:00
|
|
|
using Content.Server.Chemistry.Components.SolutionManager;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Explosion;
|
2021-09-06 15:49:44 +02:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Chemistry.Reaction;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
2019-11-21 17:24:19 -05:00
|
|
|
namespace Content.Server.Chemistry.ReactionEffects
|
2019-10-11 16:57:16 -04:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
2020-11-27 01:01:56 +01:00
|
|
|
public class ExplosionReactionEffect : IReactionEffect
|
2019-10-11 16:57:16 -04:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("devastationRange")] private float _devastationRange = 1;
|
|
|
|
|
[DataField("heavyImpactRange")] private float _heavyImpactRange = 2;
|
|
|
|
|
[DataField("lightImpactRange")] private float _lightImpactRange = 3;
|
|
|
|
|
[DataField("flashRange")] private float _flashRange;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If true, then scale ranges by intensity. If not, the ranges are the same regardless of reactant amount.
|
|
|
|
|
/// </summary>
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("scaled")] private bool _scaled;
|
|
|
|
|
|
2019-10-11 16:57:16 -04:00
|
|
|
/// <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>
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("maxScale")] private float _maxScale = 1;
|
2019-10-11 16:57:16 -04:00
|
|
|
|
2021-11-09 11:51:17 +01:00
|
|
|
public void React(Solution solution, EntityUid solutionEntity, double intensity, IEntityManager entityManager)
|
2019-10-11 16:57:16 -04:00
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
var floatIntensity = (float) intensity;
|
2021-11-09 11:51:17 +01:00
|
|
|
|
|
|
|
|
if (!entityManager.HasComponent<SolutionContainerManagerComponent>(solutionEntity))
|
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
|
2021-03-05 01:08:38 +01:00
|
|
|
var finalDevastationRange = (int)MathF.Round(_devastationRange * floatIntensity);
|
|
|
|
|
var finalHeavyImpactRange = (int)MathF.Round(_heavyImpactRange * floatIntensity);
|
|
|
|
|
var finalLightImpactRange = (int)MathF.Round(_lightImpactRange * floatIntensity);
|
|
|
|
|
var 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|