Files
tbd-station-14/Content.Server/Chemistry/ReactionEffects/ExplosionReactionEffect.cs
py01 2b195fccb9 Chemical reaction refactor (#2936)
* Moves ContainsReagent from SolutionContainer to Solution

GetMajorReagentId from SOlutionContainer to Solution

Makes capability checks use HasFlag

Moves Solution Color calculation from SolutionContainer to Solution

Replaces SolutionContainerCaps.NoExamine with CanExamine

Misc SolutionContainer.Capabilities yaml cleanup

* Moves IReactionEffect from server to shared

* Moves ReactionPrototype from server to shared

* Moves SolutionValidReaction from SolutionContainer to ChemicalReactionSystem

* Moves PerformReaction from SolutionContainer to ChemicalReactionSystem

* Moves CheckForReaction from SolutionContainer to ChemicalReactionSystem

* Removes unused SolutionContainer methods

* Removes now-unused GetMajorReagentId from SOlutionContainer

* ChemicalReactionSystem comments

* Replaces usage of SolutionContainer.ContainsReagent and replaces it with SolutionContainer.Solution.ContainsReagent

* ChemicalReactionSystem ProcessReactions

* Moves ExplosionReactionEffect to shared, comments out server code, TODO: figure out how to let ReactionEffects in shared do server stuff

* Fixes SolutionContainer.CheckForReaction infinite recursion

* Moves IReactionEffect and ExplosionReactionEffect back to server

* Moves ChemicalReactionSystem and ReactionPrototype back to server

* Uncomments out Explosion code

* namespace fixes

* Moves ReactionPrototype and IReactionEffect from Server to Shared

* Moves ChemicalReactionSystem from Server to Shared

* ChemicalReaction code partial rewrite

* Moves CanReact and PerformReaction to Solution

* Revert "Moves CanReact and PerformReaction to Solution"

This reverts commit bab791c3ebd0ff39d22f2610e27ca04f0d46d6b8.

* Moves ChemistrySystem from Server to Shared

* diff fix

* TODO warning

Co-authored-by: py01 <pyronetics01@gmail.com>
2021-01-07 17:31:43 +11:00

68 lines
2.5 KiB
C#

using System;
using Content.Server.Explosions;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.Interfaces.Chemistry;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Server.Chemistry.ReactionEffects
{
public 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 SolutionContainerComponent 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);
solutionEntity.SpawnExplosion(finalDevastationRange,
finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
}
}
}