Files
tbd-station-14/Content.Server/Administration/Commands/ExplosionCommand.cs
Leon Friedrich 56168e592e Explosion refactor (#5230)
* Explosions

* fix yaml typo

and prevent silly UI inputs

* oop

* Use modified contains() checks

And remove IEnumerable

* Buff nuke, nerf meteors

* optimize the entity lookup stuff a bit

* fix tile (0,0) error

forgot to do an initial Enumerator.MoveNext(), so the first tile was always the "null" tile.

* remove celebration

* byte -> int

* remove diag edge tile dict

* fix one bug

but there is another

* fix the other bug

turns out dividing a ushort leads to rounding errors.  Why TF is the grid tile size even a ushort in the first place.

* improve edge map

* fix minor bug

If the initial-explosion tile had an airtight entity on it, the tile was processed twice.

* some reviews (transform queries, eye.mapid, and tilesizes in overlays)

* Apply suggestions from code review

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* is map paused

* GetAllTiles ignores space by default

* WriteLine -> WriteError

* First -> FirstOrDefault()

* default prototype const string

* entity query

* misc review changes

* grid edge max distance

* fix fire texture defn

bad use of type serializer and ioc-resolves

* Remove ExplosionLaunched

And allow nukes to throw items towards the outer part of an explosion

* no hot-reload disclaimer

* replace prototype id string with int index

* optimise damage a tiiiiny bit.

* entity queries

* comments

* misc mirror comments

* cvars

* admin logs

* move intensity-per-state to prototype

* update tile event to ECS event

* git mv

* Tweak rpg & minibomb

also fix merge bug

* you don't exist anymore go away

* Fix build

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-03-31 21:39:26 -05:00

137 lines
4.4 KiB
C#

using Content.Server.Administration.UI;
using Content.Server.EUI;
using Content.Server.Explosion.EntitySystems;
using Content.Shared.Administration;
using Content.Shared.Explosion;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.Fun)]
public sealed class OpenExplosionEui : IConsoleCommand
{
public string Command => "explosionui";
public string Description => "Opens a window for easy access to station destruction";
public string Help => $"Usage: {Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null)
{
shell.WriteError("This does not work from the server console.");
return;
}
var eui = IoCManager.Resolve<EuiManager>();
var ui = new SpawnExplosionEui();
eui.OpenEui(ui, player);
}
}
[AdminCommand(AdminFlags.Fun)] // for the admin. Not so much for anyone else.
public sealed class ExplosionCommand : IConsoleCommand
{
public string Command => "explosion";
public string Description => "Train go boom";
// Note that if you change the arguments, you should also update the client-side SpawnExplosionWindow, as that just
// uses this command.
public string Help => "Usage: explosion [intensity] [slope] [maxIntensity] [x y] [mapId] [prototypeId]";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length == 0 || args.Length == 4 || args.Length > 7)
{
shell.WriteError("Wrong number of arguments.");
return;
}
if (!float.TryParse(args[0], out var intensity))
{
shell.WriteError($"Failed to parse intensity: {args[0]}");
return;
}
float slope = 5;
if (args.Length > 1 && !float.TryParse(args[1], out slope))
{
shell.WriteError($"Failed to parse float: {args[1]}");
return;
}
float maxIntensity = 100;
if (args.Length > 2 && !float.TryParse(args[2], out maxIntensity))
{
shell.WriteError($"Failed to parse float: {args[2]}");
return;
}
float x = 0, y = 0;
if (args.Length > 4)
{
if (!float.TryParse(args[3], out x) ||
!float.TryParse(args[4], out y))
{
shell.WriteError($"Failed to parse coordinates: {(args[3], args[4])}");
return;
}
}
MapCoordinates coords;
if (args.Length > 5)
{
if (!int.TryParse(args[5], out var parsed))
{
shell.WriteError($"Failed to parse map ID: {args[5]}");
return;
}
coords = new MapCoordinates((x, y), new(parsed));
}
else
{
// attempt to find the player's current position
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.TryGetComponent(shell.Player?.AttachedEntity, out TransformComponent? xform))
{
shell.WriteError($"Failed get default coordinates/map via player's transform. Need to specify explicitly.");
return;
}
if (args.Length > 4)
coords = new MapCoordinates((x, y), xform.MapID);
else
coords = xform.MapPosition;
}
ExplosionPrototype? type;
var protoMan = IoCManager.Resolve<IPrototypeManager>();
if (args.Length > 6)
{
if (!protoMan.TryIndex(args[6], out type))
{
shell.WriteError($"Unknown explosion prototype: {args[6]}");
return;
}
}
else
{
// no prototype was specified, so lets default to whichever one was defined first
type = protoMan.EnumeratePrototypes<ExplosionPrototype>().FirstOrDefault();
if (type == null)
{
shell.WriteError($"Prototype manager has no explosion prototypes?");
return;
}
}
var sysMan = IoCManager.Resolve<IEntitySystemManager>();
sysMan.GetEntitySystem<ExplosionSystem>().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity);
}
}