SolutionExplosionBehavior.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Shared.Explosion.Components;
  2. using JetBrains.Annotations;
  3. namespace Content.Server.Destructible.Thresholds.Behaviors
  4. {
  5. /// <summary>
  6. /// Works like a SpillBehavior combined with an ExplodeBehavior
  7. /// </summary>
  8. [UsedImplicitly]
  9. [DataDefinition]
  10. public sealed partial class SolutionExplosionBehavior : IThresholdBehavior
  11. {
  12. [DataField(required: true)]
  13. public string Solution = default!;
  14. public void Execute(EntityUid owner, DestructibleSystem system, EntityUid? cause = null)
  15. {
  16. if (system.SolutionContainerSystem.TryGetSolution(owner, Solution, out _, out var explodingSolution)
  17. && system.EntityManager.TryGetComponent(owner, out ExplosiveComponent? explosiveComponent))
  18. {
  19. // Don't explode if there's no solution
  20. if (explodingSolution.Volume == 0)
  21. return;
  22. // Scale the explosion intensity based on the remaining volume of solution
  23. var explosionScaleFactor = explodingSolution.FillFraction;
  24. // TODO: Perhaps some of the liquid should be discarded as if it's being consumed by the explosion
  25. // Spill the solution out into the world
  26. // Spill before exploding in anticipation of a future where the explosion can light the solution on fire.
  27. var coordinates = system.EntityManager.GetComponent<TransformComponent>(owner).Coordinates;
  28. system.PuddleSystem.TrySpillAt(coordinates, explodingSolution, out _);
  29. // Explode
  30. // Don't delete the object here - let other processes like physical damage from the
  31. // explosion clean up the exploding object(s)
  32. var explosiveTotalIntensity = explosiveComponent.TotalIntensity * explosionScaleFactor;
  33. system.ExplosionSystem.TriggerExplosive(owner, explosiveComponent, false, explosiveTotalIntensity, user:cause);
  34. }
  35. }
  36. }
  37. }