From b8d18433359c5973a36ed954b6fef913572036f4 Mon Sep 17 00:00:00 2001 From: Mervill Date: Wed, 14 Sep 2022 10:15:54 -0700 Subject: [PATCH] Adds a new SolutionExplosionBehavior for the benefit of fuel tanks and future exploding canisters (#11260) --- .../Destructible/DestructibleSystem.cs | 4 ++ .../Behaviors/SolutionExplosionBehavior.cs | 46 +++++++++++++++++++ .../Storage/Tanks/base_structuretanks.yml | 8 ++-- 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 Content.Server/Destructible/Thresholds/Behaviors/SolutionExplosionBehavior.cs diff --git a/Content.Server/Destructible/DestructibleSystem.cs b/Content.Server/Destructible/DestructibleSystem.cs index 39578f9d95..a751e85945 100644 --- a/Content.Server/Destructible/DestructibleSystem.cs +++ b/Content.Server/Destructible/DestructibleSystem.cs @@ -11,6 +11,8 @@ using Robust.Server.GameObjects; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Content.Shared.Destructible; +using Content.Server.Chemistry.EntitySystems; +using Content.Server.Fluids.EntitySystems; namespace Content.Server.Destructible { @@ -25,6 +27,8 @@ namespace Content.Server.Destructible [Dependency] public readonly ExplosionSystem ExplosionSystem = default!; [Dependency] public readonly StackSystem StackSystem = default!; [Dependency] public readonly TriggerSystem TriggerSystem = default!; + [Dependency] public readonly SolutionContainerSystem SolutionContainerSystem = default!; + [Dependency] public readonly SpillableSystem SpillableSystem = default!; [Dependency] public readonly IPrototypeManager PrototypeManager = default!; [Dependency] public readonly IComponentFactory ComponentFactory = default!; diff --git a/Content.Server/Destructible/Thresholds/Behaviors/SolutionExplosionBehavior.cs b/Content.Server/Destructible/Thresholds/Behaviors/SolutionExplosionBehavior.cs new file mode 100644 index 0000000000..4f94efe76f --- /dev/null +++ b/Content.Server/Destructible/Thresholds/Behaviors/SolutionExplosionBehavior.cs @@ -0,0 +1,46 @@ +using Content.Server.Chemistry.EntitySystems; +using Content.Server.Fluids.Components; +using Content.Server.Fluids.EntitySystems; +using Content.Server.Explosion.Components; +using JetBrains.Annotations; + +namespace Content.Server.Destructible.Thresholds.Behaviors +{ + /// + /// Works like a SpillBehavior combined with an ExplodeBehavior + /// + [UsedImplicitly] + [DataDefinition] + public sealed class SolutionExplosionBehavior : IThresholdBehavior + { + [DataField("solution", required: true)] + public string Solution = default!; + + public void Execute(EntityUid owner, DestructibleSystem system) + { + if (system.SolutionContainerSystem.TryGetSolution(owner, Solution, out var explodingSolution) + && system.EntityManager.TryGetComponent(owner, out ExplosiveComponent? explosiveComponent)) + { + // Don't explode if there's no solution + if (explodingSolution.CurrentVolume == 0) + return; + + // Scale the explosion intensity based on the remaining volume of solution + var explosionScaleFactor = (explodingSolution.CurrentVolume.Float() / explodingSolution.MaxVolume.Float()); + + // 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(owner).Coordinates; + system.SpillableSystem.SpillAt(explodingSolution, coordinates, "PuddleSmear", combine: true); + + // 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); + } + } + } +} diff --git a/Resources/Prototypes/Entities/Structures/Storage/Tanks/base_structuretanks.yml b/Resources/Prototypes/Entities/Structures/Storage/Tanks/base_structuretanks.yml index f29c361ee0..ea312dfb06 100644 --- a/Resources/Prototypes/Entities/Structures/Storage/Tanks/base_structuretanks.yml +++ b/Resources/Prototypes/Entities/Structures/Storage/Tanks/base_structuretanks.yml @@ -30,17 +30,17 @@ damageType: Heat damage: 5 behaviors: - #spill BEFORE exploding, so that one day explosions can ignite puddles - - !type:SpillBehavior + - !type:SolutionExplosionBehavior solution: tank - - !type:ExplodeBehavior - #note: only actually explodes if entity has ExplosiveComponent. - trigger: !type:DamageTrigger damage: 10 behaviors: - !type:SpillBehavior solution: tank + - !type:PlaySoundBehavior + sound: + path: /Audio/Effects/metalbreak.ogg - !type:DoActsBehavior acts: ["Destruction"] - type: SolutionContainerManager