From fd9698617e3222d5e63e278eb74625fa8f2991cf Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 11 Jan 2022 18:17:54 +1100 Subject: [PATCH] Shuttle modes verb (#6096) --- .../Physics/Controllers/MoverController.cs | 9 ++- .../EntitySystems/ShuttleConsoleSystem.cs | 59 ++++++++++++++++++- Resources/Locale/en-US/shuttles/console.ftl | 5 +- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/Content.Server/Physics/Controllers/MoverController.cs b/Content.Server/Physics/Controllers/MoverController.cs index cd4f04e1eb..93be6e8fd5 100644 --- a/Content.Server/Physics/Controllers/MoverController.cs +++ b/Content.Server/Physics/Controllers/MoverController.cs @@ -178,7 +178,7 @@ namespace Content.Server.Physics.Controllers var angle = linearInput.ToWorldAngle(); var linearDir = angle.GetDir(); var dockFlag = linearDir.AsFlag(); - var shuttleNorth = EntityManager.GetComponent((body).Owner).WorldRotation.ToWorldVec(); + var shuttleNorth = EntityManager.GetComponent(body.Owner).WorldRotation.ToWorldVec(); // Won't just do cardinal directions. foreach (DirectionFlag dir in Enum.GetValues(typeof(DirectionFlag))) @@ -202,20 +202,25 @@ namespace Content.Server.Physics.Controllers } float length; + Angle thrustAngle; switch (dir) { case DirectionFlag.North: length = linearInput.Y; + thrustAngle = new Angle(MathF.PI); break; case DirectionFlag.South: length = -linearInput.Y; + thrustAngle = new Angle(0f); break; case DirectionFlag.East: length = linearInput.X; + thrustAngle = new Angle(MathF.PI / 2f); break; case DirectionFlag.West: length = -linearInput.X; + thrustAngle = new Angle(-MathF.PI / 2f); break; default: throw new ArgumentOutOfRangeException(); @@ -232,7 +237,7 @@ namespace Content.Server.Physics.Controllers } body.ApplyLinearImpulse( - angle.RotateVec(shuttleNorth) * + thrustAngle.RotateVec(shuttleNorth) * speed * frameTime); } diff --git a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs index 348b9825d7..6971ee6c45 100644 --- a/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/EntitySystems/ShuttleConsoleSystem.cs @@ -1,4 +1,5 @@ using System; +using Content.Server.Popups; using Content.Server.Power.Components; using Content.Server.Shuttles.Components; using Content.Shared.ActionBlocker; @@ -8,26 +9,80 @@ using Content.Shared.Popups; using Content.Shared.Shuttles; using Content.Shared.Shuttles.Components; using Content.Shared.Tag; +using Content.Shared.Verbs; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; +using Robust.Shared.Map; +using Robust.Shared.Player; using Robust.Shared.Utility; namespace Content.Server.Shuttles.EntitySystems { internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem { + [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly ActionBlockerSystem _blocker = default!; [Dependency] private readonly AlertsSystem _alertsSystem = default!; + [Dependency] private readonly PopupSystem _popup = default!; public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(HandleConsoleShutdown); - SubscribeLocalEvent(HandlePilotShutdown); SubscribeLocalEvent(HandleConsoleInteract); - SubscribeLocalEvent(HandlePilotMove); SubscribeLocalEvent(HandlePowerChange); + SubscribeLocalEvent(OnConsoleInteract); + + SubscribeLocalEvent(HandlePilotShutdown); + SubscribeLocalEvent(HandlePilotMove); + } + + private void OnConsoleInteract(EntityUid uid, ShuttleConsoleComponent component, GetInteractionVerbsEvent args) + { + if (!args.CanAccess || + !args.CanInteract) + return; + + var xform = EntityManager.GetComponent(uid); + + // Maybe move mode onto the console instead? + if (!_mapManager.TryGetGrid(xform.GridID, out var grid) || + !EntityManager.TryGetComponent(grid.GridEntityId, out ShuttleComponent? shuttle)) return; + + Verb verb = new() + { + Text = Loc.GetString("shuttle-mode-toggle"), + Act = () => ToggleShuttleMode(args.User, component, shuttle), + Disabled = !xform.Anchored || EntityManager.TryGetComponent(uid, out ApcPowerReceiverComponent? receiver) && !receiver.Powered, + }; + + args.Verbs.Add(verb); + } + + private void ToggleShuttleMode(EntityUid user, ShuttleConsoleComponent consoleComponent, ShuttleComponent shuttleComponent, TransformComponent? consoleXform = null) + { + // Re-validate + if (EntityManager.TryGetComponent(consoleComponent.Owner, out ApcPowerReceiverComponent? receiver) && !receiver.Powered) return; + + if (!Resolve(consoleComponent.Owner, ref consoleXform)) return; + + if (!consoleXform.Anchored || consoleXform.GridID != EntityManager.GetComponent(shuttleComponent.Owner).GridID) return; + + switch (shuttleComponent.Mode) + { + case ShuttleMode.Cruise: + shuttleComponent.Mode = ShuttleMode.Docking; + _popup.PopupEntity(Loc.GetString("shuttle-mode-docking"), consoleComponent.Owner, Filter.Entities(user)); + break; + case ShuttleMode.Docking: + shuttleComponent.Mode = ShuttleMode.Cruise; + _popup.PopupEntity(Loc.GetString("shuttle-mode-cruise"), consoleComponent.Owner, Filter.Entities(user)); + break; + default: + throw new ArgumentOutOfRangeException(); + } } public override void Update(float frameTime) diff --git a/Resources/Locale/en-US/shuttles/console.ftl b/Resources/Locale/en-US/shuttles/console.ftl index dfd8b6734c..32254244f8 100644 --- a/Resources/Locale/en-US/shuttles/console.ftl +++ b/Resources/Locale/en-US/shuttles/console.ftl @@ -1,2 +1,5 @@ shuttle-pilot-start = Piloting ship -shuttle-pilot-end = Stopped piloting \ No newline at end of file +shuttle-pilot-end = Stopped piloting +shuttle-mode-cruise = Cruise mode +shuttle-mode-docking = Docking mode +shuttle-mode-toggle = Toggle mode