Shuttle modes verb (#6096)
This commit is contained in:
@@ -178,7 +178,7 @@ namespace Content.Server.Physics.Controllers
|
|||||||
var angle = linearInput.ToWorldAngle();
|
var angle = linearInput.ToWorldAngle();
|
||||||
var linearDir = angle.GetDir();
|
var linearDir = angle.GetDir();
|
||||||
var dockFlag = linearDir.AsFlag();
|
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.
|
// Won't just do cardinal directions.
|
||||||
foreach (DirectionFlag dir in Enum.GetValues(typeof(DirectionFlag)))
|
foreach (DirectionFlag dir in Enum.GetValues(typeof(DirectionFlag)))
|
||||||
@@ -202,20 +202,25 @@ namespace Content.Server.Physics.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
float length;
|
float length;
|
||||||
|
Angle thrustAngle;
|
||||||
|
|
||||||
switch (dir)
|
switch (dir)
|
||||||
{
|
{
|
||||||
case DirectionFlag.North:
|
case DirectionFlag.North:
|
||||||
length = linearInput.Y;
|
length = linearInput.Y;
|
||||||
|
thrustAngle = new Angle(MathF.PI);
|
||||||
break;
|
break;
|
||||||
case DirectionFlag.South:
|
case DirectionFlag.South:
|
||||||
length = -linearInput.Y;
|
length = -linearInput.Y;
|
||||||
|
thrustAngle = new Angle(0f);
|
||||||
break;
|
break;
|
||||||
case DirectionFlag.East:
|
case DirectionFlag.East:
|
||||||
length = linearInput.X;
|
length = linearInput.X;
|
||||||
|
thrustAngle = new Angle(MathF.PI / 2f);
|
||||||
break;
|
break;
|
||||||
case DirectionFlag.West:
|
case DirectionFlag.West:
|
||||||
length = -linearInput.X;
|
length = -linearInput.X;
|
||||||
|
thrustAngle = new Angle(-MathF.PI / 2f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
@@ -232,7 +237,7 @@ namespace Content.Server.Physics.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
body.ApplyLinearImpulse(
|
body.ApplyLinearImpulse(
|
||||||
angle.RotateVec(shuttleNorth) *
|
thrustAngle.RotateVec(shuttleNorth) *
|
||||||
speed *
|
speed *
|
||||||
frameTime);
|
frameTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Content.Server.Popups;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.Shuttles.Components;
|
using Content.Server.Shuttles.Components;
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
@@ -8,26 +9,80 @@ using Content.Shared.Popups;
|
|||||||
using Content.Shared.Shuttles;
|
using Content.Shared.Shuttles;
|
||||||
using Content.Shared.Shuttles.Components;
|
using Content.Shared.Shuttles.Components;
|
||||||
using Content.Shared.Tag;
|
using Content.Shared.Tag;
|
||||||
|
using Content.Shared.Verbs;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Shuttles.EntitySystems
|
namespace Content.Server.Shuttles.EntitySystems
|
||||||
{
|
{
|
||||||
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
|
||||||
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
||||||
|
[Dependency] private readonly PopupSystem _popup = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<ShuttleConsoleComponent, ComponentShutdown>(HandleConsoleShutdown);
|
SubscribeLocalEvent<ShuttleConsoleComponent, ComponentShutdown>(HandleConsoleShutdown);
|
||||||
SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
|
|
||||||
SubscribeLocalEvent<ShuttleConsoleComponent, ActivateInWorldEvent>(HandleConsoleInteract);
|
SubscribeLocalEvent<ShuttleConsoleComponent, ActivateInWorldEvent>(HandleConsoleInteract);
|
||||||
SubscribeLocalEvent<PilotComponent, MoveEvent>(HandlePilotMove);
|
|
||||||
SubscribeLocalEvent<ShuttleConsoleComponent, PowerChangedEvent>(HandlePowerChange);
|
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)
|
public override void Update(float frameTime)
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
shuttle-pilot-start = Piloting ship
|
shuttle-pilot-start = Piloting ship
|
||||||
shuttle-pilot-end = Stopped piloting
|
shuttle-pilot-end = Stopped piloting
|
||||||
|
shuttle-mode-cruise = Cruise mode
|
||||||
|
shuttle-mode-docking = Docking mode
|
||||||
|
shuttle-mode-toggle = Toggle mode
|
||||||
|
|||||||
Reference in New Issue
Block a user