From e3784bc23742f5f90e14333fe91b5c998610c7d2 Mon Sep 17 00:00:00 2001 From: Arthur <14136326+Morb0@users.noreply.github.com> Date: Mon, 11 Jul 2022 16:41:35 +0300 Subject: [PATCH] Complete spawn beam command --- .../Icarus/Commands/SpawnIcarusCommand.cs | 25 +++++++++++- Content.Server/Icarus/IcarusTerminalSystem.cs | 40 ++++++++++++------- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/Content.Server/Icarus/Commands/SpawnIcarusCommand.cs b/Content.Server/Icarus/Commands/SpawnIcarusCommand.cs index f732a911d6..eda379590c 100644 --- a/Content.Server/Icarus/Commands/SpawnIcarusCommand.cs +++ b/Content.Server/Icarus/Commands/SpawnIcarusCommand.cs @@ -2,6 +2,7 @@ using Content.Shared.Administration; using JetBrains.Annotations; using Robust.Shared.Console; +using Robust.Shared.Map; namespace Content.Server.Icarus.Commands; @@ -10,15 +11,35 @@ namespace Content.Server.Icarus.Commands; public sealed class SpawnIcarusCommand : IConsoleCommand { public string Command => "spawnicarus"; - public string Description => "Spawn Icarus beam."; + public string Description => "Spawn Icarus beam and direct to specified grid center."; public string Help => "spawnicarus "; public void Execute(IConsoleShell shell, string argStr, string[] args) { - if (args.Length < 1) + if (args.Length != 1) { shell.WriteError("Incorrect number of arguments. " + Help); return; } + + if (!int.TryParse(args[0], out var id)) + { + shell.WriteLine($"{args[0]} is not a valid integer."); + return; + } + + var gridId = new GridId(int.Parse(args[0])); + var mapManager = IoCManager.Resolve(); + + if (mapManager.TryGetGrid(gridId, out var grid)) + { + var icarusSystem = EntitySystem.Get(); + var coords = icarusSystem.FireBeam(grid.WorldAABB); + shell.WriteLine($"Icarus was spawned: {coords.ToString()}"); + } + else + { + shell.WriteError($"No grid exists with id {id}"); + } } } diff --git a/Content.Server/Icarus/IcarusTerminalSystem.cs b/Content.Server/Icarus/IcarusTerminalSystem.cs index cf9d2e1dd5..25aed6d006 100644 --- a/Content.Server/Icarus/IcarusTerminalSystem.cs +++ b/Content.Server/Icarus/IcarusTerminalSystem.cs @@ -165,43 +165,55 @@ public sealed class IcarusTerminalSystem : EntitySystem if (component.RemainingTime <= 0) { component.RemainingTime = 0; - ActivateBeam(component); + ActivateBeamOnStation(component); } UpdateUserInterface(component); } - private void ActivateBeam(IcarusTerminalComponent component) + private void ActivateBeamOnStation(IcarusTerminalComponent component) { component.Status = IcarusTerminalStatus.COOLDOWN; component.CooldownTime = component.Cooldown; SoundSystem.Play(component.FireSound.GetSound(), Filter.Broadcast()); - TryGetBeamSpawnLocation(component, out var coords, out var offset); + FireBeam(GetStationArea()); + } + + public MapCoordinates FireBeam(Box2 area) + { + TryGetBeamSpawnLocation(area, out var coords, out var offset); Logger.DebugS("icarus", $"Try spawn beam on coords: {coords.ToString()}"); var entUid = Spawn(IcarusBeamPrototypeId, coords); _icarusSystem.LaunchInDirection(entUid, -offset.Normalized); + return coords; } - private void TryGetBeamSpawnLocation(IcarusTerminalComponent component, out MapCoordinates coords, + private void TryGetBeamSpawnLocation(Box2 area, out MapCoordinates coords, out Vector2 offset) { coords = MapCoordinates.Nullspace; offset = Vector2.Zero; - var areas = _stationSystem.Stations.SelectMany(x => - Comp(x).Grids.Select(x => _mapManager.GetGridComp(x).Grid.WorldAABB)).ToArray(); - var playableArea = areas[0]; - for (var i = 1; i < areas.Length; i++) - { - playableArea.Union(areas[i]); - } - - var center = playableArea.Center; - var distance = (playableArea.TopRight - center).Length; + var center = area.Center; + var distance = (area.TopRight - center).Length; var angle = new Angle(_robustRandom.NextFloat() * MathF.Tau); offset = angle.RotateVec(new Vector2(distance, 0)); coords = new MapCoordinates(center + offset, _gameTicker.DefaultMap); } + + private Box2 GetStationArea() + { + var areas = _stationSystem.Stations.SelectMany(x => + Comp(x).Grids.Select(x => _mapManager.GetGridComp(x).Grid.WorldAABB)).ToArray(); + var stationArea = areas[0]; + + for (var i = 1; i < areas.Length; i++) + { + stationArea.Union(areas[i]); + } + + return stationArea; + } }