1
0

ExplosionCommand.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using Content.Server.Administration.UI;
  2. using Content.Server.EUI;
  3. using Content.Server.Explosion.EntitySystems;
  4. using Content.Shared.Administration;
  5. using Content.Shared.Explosion;
  6. using Robust.Shared.Console;
  7. using Robust.Shared.Map;
  8. using Robust.Shared.Prototypes;
  9. using System.Linq;
  10. using System.Numerics;
  11. using Robust.Server.GameObjects;
  12. namespace Content.Server.Administration.Commands;
  13. [AdminCommand(AdminFlags.Fun)]
  14. public sealed class OpenExplosionEui : IConsoleCommand
  15. {
  16. public string Command => "explosionui";
  17. public string Description => "Opens a window for easy access to station destruction";
  18. public string Help => $"Usage: {Command}";
  19. public void Execute(IConsoleShell shell, string argStr, string[] args)
  20. {
  21. var player = shell.Player;
  22. if (player == null)
  23. {
  24. shell.WriteError("This does not work from the server console.");
  25. return;
  26. }
  27. var eui = IoCManager.Resolve<EuiManager>();
  28. var ui = new SpawnExplosionEui();
  29. eui.OpenEui(ui, player);
  30. }
  31. }
  32. [AdminCommand(AdminFlags.Fun)] // for the admin. Not so much for anyone else.
  33. public sealed class ExplosionCommand : IConsoleCommand
  34. {
  35. public string Command => "explosion";
  36. public string Description => "Train go boom";
  37. // Note that if you change the arguments, you should also update the client-side SpawnExplosionWindow, as that just
  38. // uses this command.
  39. public string Help => "Usage: explosion [intensity] [slope] [maxIntensity] [x y] [mapId] [prototypeId]";
  40. public void Execute(IConsoleShell shell, string argStr, string[] args)
  41. {
  42. if (args.Length == 0 || args.Length == 4 || args.Length > 7)
  43. {
  44. shell.WriteError("Wrong number of arguments.");
  45. return;
  46. }
  47. if (!float.TryParse(args[0], out var intensity))
  48. {
  49. shell.WriteError($"Failed to parse intensity: {args[0]}");
  50. return;
  51. }
  52. float slope = 5;
  53. if (args.Length > 1 && !float.TryParse(args[1], out slope))
  54. {
  55. shell.WriteError($"Failed to parse float: {args[1]}");
  56. return;
  57. }
  58. float maxIntensity = 100;
  59. if (args.Length > 2 && !float.TryParse(args[2], out maxIntensity))
  60. {
  61. shell.WriteError($"Failed to parse float: {args[2]}");
  62. return;
  63. }
  64. float x = 0, y = 0;
  65. if (args.Length > 4)
  66. {
  67. if (!float.TryParse(args[3], out x) ||
  68. !float.TryParse(args[4], out y))
  69. {
  70. shell.WriteError($"Failed to parse coordinates: {(args[3], args[4])}");
  71. return;
  72. }
  73. }
  74. MapCoordinates coords;
  75. if (args.Length > 5)
  76. {
  77. if (!int.TryParse(args[5], out var parsed))
  78. {
  79. shell.WriteError($"Failed to parse map ID: {args[5]}");
  80. return;
  81. }
  82. coords = new MapCoordinates(new Vector2(x, y), new(parsed));
  83. }
  84. else
  85. {
  86. // attempt to find the player's current position
  87. var entMan = IoCManager.Resolve<IEntityManager>();
  88. if (!entMan.TryGetComponent(shell.Player?.AttachedEntity, out TransformComponent? xform))
  89. {
  90. shell.WriteError($"Failed get default coordinates/map via player's transform. Need to specify explicitly.");
  91. return;
  92. }
  93. if (args.Length > 4)
  94. coords = new MapCoordinates(new Vector2(x, y), xform.MapID);
  95. else
  96. coords = entMan.System<TransformSystem>().GetMapCoordinates(shell.Player.AttachedEntity.Value, xform: xform);
  97. }
  98. ExplosionPrototype? type;
  99. var protoMan = IoCManager.Resolve<IPrototypeManager>();
  100. if (args.Length > 6)
  101. {
  102. if (!protoMan.TryIndex(args[6], out type))
  103. {
  104. shell.WriteError($"Unknown explosion prototype: {args[6]}");
  105. return;
  106. }
  107. }
  108. else if (!protoMan.TryIndex(ExplosionSystem.DefaultExplosionPrototypeId, out type))
  109. {
  110. // no prototype was specified, so lets default to whichever one was defined first
  111. type = protoMan.EnumeratePrototypes<ExplosionPrototype>().FirstOrDefault();
  112. if (type == null)
  113. {
  114. shell.WriteError($"Prototype manager has no explosion prototypes?");
  115. return;
  116. }
  117. }
  118. var sysMan = IoCManager.Resolve<IEntitySystemManager>();
  119. sysMan.GetEntitySystem<ExplosionSystem>().QueueExplosion(coords, type.ID, intensity, slope, maxIntensity, null);
  120. }
  121. }