Files
tbd-station-14/Content.Server/Destructible/Thresholds/Behaviors/SolutionExplosionBehavior.cs
deltanedas 1c839da604 move TriggerExplosion to shared (#30227)
* move component to shared

* add fake systems

* update server explosion system and remove duplicate transform query

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
2024-09-19 10:01:40 +10:00

44 lines
2.0 KiB
C#

using Content.Shared.Explosion.Components;
using JetBrains.Annotations;
namespace Content.Server.Destructible.Thresholds.Behaviors
{
/// <summary>
/// Works like a SpillBehavior combined with an ExplodeBehavior
/// </summary>
[UsedImplicitly]
[DataDefinition]
public sealed partial class SolutionExplosionBehavior : IThresholdBehavior
{
[DataField(required: true)]
public string Solution = default!;
public void Execute(EntityUid owner, DestructibleSystem system, EntityUid? cause = null)
{
if (system.SolutionContainerSystem.TryGetSolution(owner, Solution, out _, out var explodingSolution)
&& system.EntityManager.TryGetComponent(owner, out ExplosiveComponent? explosiveComponent))
{
// Don't explode if there's no solution
if (explodingSolution.Volume == 0)
return;
// Scale the explosion intensity based on the remaining volume of solution
var explosionScaleFactor = explodingSolution.FillFraction;
// TODO: Perhaps some of the liquid should be discarded as if it's being consumed by the explosion
// Spill the solution out into the world
// Spill before exploding in anticipation of a future where the explosion can light the solution on fire.
var coordinates = system.EntityManager.GetComponent<TransformComponent>(owner).Coordinates;
system.PuddleSystem.TrySpillAt(coordinates, explodingSolution, out _);
// Explode
// Don't delete the object here - let other processes like physical damage from the
// explosion clean up the exploding object(s)
var explosiveTotalIntensity = explosiveComponent.TotalIntensity * explosionScaleFactor;
system.ExplosionSystem.TriggerExplosive(owner, explosiveComponent, false, explosiveTotalIntensity, user:cause);
}
}
}
}