Shuttle modes verb (#6096)

This commit is contained in:
metalgearsloth
2022-01-11 18:17:54 +11:00
committed by GitHub
parent 951bdabcd0
commit fd9698617e
3 changed files with 68 additions and 5 deletions

View File

@@ -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<TransformComponent>((body).Owner).WorldRotation.ToWorldVec();
var shuttleNorth = EntityManager.GetComponent<TransformComponent>(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);
}

View File

@@ -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<ShuttleConsoleComponent, ComponentShutdown>(HandleConsoleShutdown);
SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
SubscribeLocalEvent<ShuttleConsoleComponent, ActivateInWorldEvent>(HandleConsoleInteract);
SubscribeLocalEvent<PilotComponent, MoveEvent>(HandlePilotMove);
SubscribeLocalEvent<ShuttleConsoleComponent, PowerChangedEvent>(HandlePowerChange);
SubscribeLocalEvent<ShuttleConsoleComponent, GetInteractionVerbsEvent>(OnConsoleInteract);
SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
SubscribeLocalEvent<PilotComponent, MoveEvent>(HandlePilotMove);
}
private void OnConsoleInteract(EntityUid uid, ShuttleConsoleComponent component, GetInteractionVerbsEvent args)
{
if (!args.CanAccess ||
!args.CanInteract)
return;
var xform = EntityManager.GetComponent<TransformComponent>(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<TransformComponent>(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)

View File

@@ -1,2 +1,5 @@
shuttle-pilot-start = Piloting ship
shuttle-pilot-end = Stopped piloting
shuttle-mode-cruise = Cruise mode
shuttle-mode-docking = Docking mode
shuttle-mode-toggle = Toggle mode