diff --git a/Content.Server/Administration/Commands/ExplosionCommand.cs b/Content.Server/Administration/Commands/ExplosionCommand.cs new file mode 100644 index 0000000000..768f01b8d5 --- /dev/null +++ b/Content.Server/Administration/Commands/ExplosionCommand.cs @@ -0,0 +1,41 @@ +using Content.Server.Explosions; +using Content.Shared.Administration; +using Robust.Server.Interfaces.Console; +using Robust.Server.Interfaces.Player; +using Robust.Shared.Map; + +#nullable enable + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Fun)] + public sealed class ExplosionCommand : IClientCommand + { + public string Command => "explode"; + public string Description => "Train go boom"; + public string Help => "Usage: explode \n" + + "The explosion happens on the same map as the user."; + + public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args) + { + if (player?.AttachedEntity == null) + { + shell.SendText(player, "You must have an attached entity."); + return; + } + + var x = float.Parse(args[0]); + var y = float.Parse(args[1]); + + var dev = int.Parse(args[2]); + var hvy = int.Parse(args[3]); + var lgh = int.Parse(args[4]); + var fla = int.Parse(args[5]); + + var mapTransform = player.AttachedEntity.Transform.GetMapTransform(); + var coords = new EntityCoordinates(mapTransform.Owner.Uid, x, y); + + ExplosionHelper.SpawnExplosion(coords, dev, hvy, lgh, fla); + } + } +} diff --git a/Content.Server/Explosions/ExplosionHelper.cs b/Content.Server/Explosions/ExplosionHelper.cs index 5479db7b3a..60962b67ec 100644 --- a/Content.Server/Explosions/ExplosionHelper.cs +++ b/Content.Server/Explosions/ExplosionHelper.cs @@ -1,33 +1,27 @@ using System; using System.Collections.Generic; using System.Linq; -using Content.Server.GameObjects.Components.Atmos; using Content.Server.GameObjects.Components.Explosion; -using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Mobs; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Maps; using Content.Shared.Physics; using Content.Shared.Utility; -using Microsoft.Extensions.Logging; using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Shared.Containers; -using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.EntitySystemMessages; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Timing; using Robust.Shared.IoC; -using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; -using Robust.Shared.Physics; using Robust.Shared.Random; -using Robust.Shared.Timing; namespace Content.Server.Explosions { @@ -151,7 +145,7 @@ namespace Content.Server.Explosions /// damage bracket [light, heavy, devastation], the distance from the epicenter and /// a probabilty bracket [, , 1.0]. /// - /// + /// private static void DamageTilesInRange(EntityCoordinates epicenter, GridId gridId, Box2 boundingBox, @@ -281,9 +275,31 @@ namespace Content.Server.Explosions } } - private static void Detonate(IEntity source, int devastationRange, int heavyImpactRange, int lightImpactRange, int flashRange) + public static void SpawnExplosion(this IEntity entity, int devastationRange = 0, int heavyImpactRange = 0, + int lightImpactRange = 0, int flashRange = 0) { - var mapId = source.Transform.MapID; + // If you want to directly set off the explosive + if (!entity.Deleted && entity.TryGetComponent(out ExplosiveComponent explosive) && !explosive.Exploding) + { + explosive.Explosion(); + } + else + { + while (entity.TryGetContainer(out var cont)) + { + entity = cont.Owner; + } + + var epicenter = entity.Transform.Coordinates; + + SpawnExplosion(epicenter, devastationRange, heavyImpactRange, lightImpactRange, flashRange); + } + } + + public static void SpawnExplosion(EntityCoordinates epicenter, int devastationRange = 0, + int heavyImpactRange = 0, int lightImpactRange = 0, int flashRange = 0) + { + var mapId = epicenter.GetMapId(IoCManager.Resolve()); if (mapId == MapId.Nullspace) { return; @@ -291,18 +307,14 @@ namespace Content.Server.Explosions var maxRange = MathHelper.Max(devastationRange, heavyImpactRange, lightImpactRange, 0); - while(source.TryGetContainer(out var cont)) - { - source = cont.Owner; - } - var epicenter = source.Transform.Coordinates; - var entityManager = IoCManager.Resolve(); var mapManager = IoCManager.Resolve(); var epicenterMapPos = epicenter.ToMapPos(entityManager); - var boundingBox = new Box2(epicenterMapPos - new Vector2(maxRange, maxRange), epicenterMapPos + new Vector2(maxRange, maxRange)); + var boundingBox = new Box2(epicenterMapPos - new Vector2(maxRange, maxRange), + epicenterMapPos + new Vector2(maxRange, maxRange)); + EntitySystem.Get().PlayAtCoords("/Audio/Effects/explosion.ogg", epicenter); DamageEntitiesInRange(epicenter, boundingBox, devastationRange, heavyImpactRange, maxRange, mapId); var mapGridsNear = mapManager.FindGridsIntersecting(mapId, boundingBox); @@ -315,18 +327,5 @@ namespace Content.Server.Explosions CameraShakeInRange(epicenter, maxRange); FlashInRange(epicenter, flashRange); } - - public static void SpawnExplosion(this IEntity entity, int devastationRange = 0, int heavyImpactRange = 0, int lightImpactRange = 0, int flashRange = 0) - { - // If you want to directly set off the explosive - if (!entity.Deleted && entity.TryGetComponent(out ExplosiveComponent explosive) && !explosive.Exploding) - { - explosive.Explosion(); - } - else - { - Detonate(entity, devastationRange, heavyImpactRange, lightImpactRange, flashRange); - } - } } }