Fix griddrag and tethergun (#10510)
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
using Content.Client.Administration.Managers;
|
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
@@ -24,6 +23,23 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
|
|||||||
private Vector2 _localPosition;
|
private Vector2 _localPosition;
|
||||||
private MapCoordinates? _lastMousePosition;
|
private MapCoordinates? _lastMousePosition;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeNetworkEvent<GridDragToggleMessage>(OnToggleMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnToggleMessage(GridDragToggleMessage ev)
|
||||||
|
{
|
||||||
|
if (Enabled == ev.Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Enabled = ev.Enabled;
|
||||||
|
|
||||||
|
if (!Enabled)
|
||||||
|
StopDragging();
|
||||||
|
}
|
||||||
|
|
||||||
private void StartDragging(EntityUid grid, Vector2 localPosition)
|
private void StartDragging(EntityUid grid, Vector2 localPosition)
|
||||||
{
|
{
|
||||||
_dragging = grid;
|
_dragging = grid;
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeNetworkEvent<PredictTetherEvent>(OnPredictTether);
|
SubscribeNetworkEvent<PredictTetherEvent>(OnPredictTether);
|
||||||
|
SubscribeNetworkEvent<TetherGunToggleMessage>(OnTetherGun);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTetherGun(TetherGunToggleMessage ev)
|
||||||
|
{
|
||||||
|
Enabled = ev.Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPredictTether(PredictTetherEvent ev)
|
private void OnPredictTether(PredictTetherEvent ev)
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
|
using Content.Server.Administration;
|
||||||
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
namespace Content.Client.Maps;
|
namespace Content.Server.Maps;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Toggles GridDragging on the system.
|
/// Toggles GridDragging on the system.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[AdminCommand(AdminFlags.Fun)]
|
||||||
public sealed class GridDraggingCommand : IConsoleCommand
|
public sealed class GridDraggingCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
public string Command => SharedGridDraggingSystem.CommandName;
|
public string Command => SharedGridDraggingSystem.CommandName;
|
||||||
@@ -13,10 +16,16 @@ public sealed class GridDraggingCommand : IConsoleCommand
|
|||||||
public string Help => $"{Command}";
|
public string Help => $"{Command}";
|
||||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
{
|
||||||
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<GridDraggingSystem>();
|
if (shell.Player == null)
|
||||||
system.Enabled ^= true;
|
{
|
||||||
|
shell.WriteError("shell-server-cannot");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (system.Enabled)
|
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<GridDraggingSystem>();
|
||||||
|
system.Toggle(shell.Player);
|
||||||
|
|
||||||
|
if (system.IsEnabled(shell.Player))
|
||||||
shell.WriteLine("Grid dragging toggled on");
|
shell.WriteLine("Grid dragging toggled on");
|
||||||
else
|
else
|
||||||
shell.WriteLine("Grid dragging toggled off");
|
shell.WriteLine("Grid dragging toggled off");
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Robust.Server.Console;
|
using Robust.Server.Console;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Players;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Maps;
|
namespace Content.Server.Maps;
|
||||||
|
|
||||||
@@ -9,6 +11,8 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IConGroupController _admin = default!;
|
[Dependency] private readonly IConGroupController _admin = default!;
|
||||||
|
|
||||||
|
private readonly HashSet<ICommonSession> _draggers = new();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -16,6 +20,31 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
|
|||||||
SubscribeNetworkEvent<GridDragVelocityRequest>(OnRequestVelocity);
|
SubscribeNetworkEvent<GridDragVelocityRequest>(OnRequestVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsEnabled(ICommonSession session) => _draggers.Contains(session);
|
||||||
|
|
||||||
|
public void Toggle(ICommonSession session)
|
||||||
|
{
|
||||||
|
if (session is not IPlayerSession pSession)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DebugTools.Assert(_admin.CanCommand(pSession, CommandName));
|
||||||
|
|
||||||
|
// Weird but it's a toggle
|
||||||
|
if (_draggers.Add(session))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_draggers.Remove(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
RaiseNetworkEvent(new GridDragToggleMessage()
|
||||||
|
{
|
||||||
|
Enabled = _draggers.Contains(session),
|
||||||
|
}, session.ConnectedClient);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnRequestVelocity(GridDragVelocityRequest ev, EntitySessionEventArgs args)
|
private void OnRequestVelocity(GridDragVelocityRequest ev, EntitySessionEventArgs args)
|
||||||
{
|
{
|
||||||
if (args.SenderSession is not IPlayerSession playerSession ||
|
if (args.SenderSession is not IPlayerSession playerSession ||
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Linq;
|
||||||
using Content.Server.Ghost.Components;
|
using Content.Server.Ghost.Components;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Content.Shared.Weapons.Ranged.Systems;
|
using Content.Shared.Weapons.Ranged.Systems;
|
||||||
@@ -20,7 +21,8 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
|||||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||||
[Dependency] private readonly SharedJointSystem _joints = default!;
|
[Dependency] private readonly SharedJointSystem _joints = default!;
|
||||||
|
|
||||||
private Dictionary<ICommonSession, (EntityUid Entity, EntityUid Tether, Joint Joint)> _tethered = new();
|
private readonly Dictionary<ICommonSession, (EntityUid Entity, EntityUid Tether, Joint Joint)> _tethered = new();
|
||||||
|
private readonly HashSet<ICommonSession> _draggers = new();
|
||||||
|
|
||||||
private const string JointId = "tether-joint";
|
private const string JointId = "tether-joint";
|
||||||
|
|
||||||
@@ -46,6 +48,35 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
|||||||
_playerManager.PlayerStatusChanged -= OnStatusChange;
|
_playerManager.PlayerStatusChanged -= OnStatusChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Toggle(ICommonSession? session)
|
||||||
|
{
|
||||||
|
if (session == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_draggers.Add(session))
|
||||||
|
{
|
||||||
|
RaiseNetworkEvent(new TetherGunToggleMessage()
|
||||||
|
{
|
||||||
|
Enabled = true,
|
||||||
|
}, session.ConnectedClient);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_draggers.Remove(session);
|
||||||
|
RaiseNetworkEvent(new TetherGunToggleMessage()
|
||||||
|
{
|
||||||
|
Enabled = false,
|
||||||
|
}, session.ConnectedClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnabled(ICommonSession? session)
|
||||||
|
{
|
||||||
|
if (session == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return _draggers.Contains(session);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnStartTether(StartTetherEvent msg, EntitySessionEventArgs args)
|
private void OnStartTether(StartTetherEvent msg, EntitySessionEventArgs args)
|
||||||
{
|
{
|
||||||
if (args.SenderSession is not IPlayerSession playerSession ||
|
if (args.SenderSession is not IPlayerSession playerSession ||
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
using Content.Client.Weapons.Ranged.Systems;
|
using Content.Server.Administration;
|
||||||
|
using Content.Server.Weapon.Ranged.Systems;
|
||||||
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.Weapons.Ranged.Systems;
|
||||||
using Robust.Shared.Console;
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
namespace Content.Client.Weapons.Ranged;
|
namespace Content.Server.Weapons.Ranged.Commands;
|
||||||
|
|
||||||
|
[AdminCommand(AdminFlags.Fun)]
|
||||||
public sealed class TetherGunCommand : IConsoleCommand
|
public sealed class TetherGunCommand : IConsoleCommand
|
||||||
{
|
{
|
||||||
public string Command => "tethergun";
|
public string Command => SharedTetherGunSystem.CommandName;
|
||||||
public string Description => "Allows you to drag mobs around with your mouse.";
|
public string Description => "Allows you to drag mobs around with your mouse.";
|
||||||
public string Help => $"{Command}";
|
public string Help => $"{Command}";
|
||||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
{
|
{
|
||||||
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<TetherGunSystem>();
|
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<TetherGunSystem>();
|
||||||
system.Enabled ^= true;
|
system.Toggle(shell.Player);
|
||||||
|
|
||||||
if (system.Enabled)
|
if (system.IsEnabled(shell.Player))
|
||||||
shell.WriteLine("Tether gun toggled on");
|
shell.WriteLine("Tether gun toggled on");
|
||||||
else
|
else
|
||||||
shell.WriteLine("Tether gun toggled off");
|
shell.WriteLine("Tether gun toggled off");
|
||||||
@@ -3,7 +3,7 @@ using Robust.Shared.Serialization;
|
|||||||
namespace Content.Shared.Maps;
|
namespace Content.Shared.Maps;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper system to allow you to move grids with a mouse.
|
/// Helper system to allow you to move entities with a mouse.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class SharedGridDraggingSystem : EntitySystem
|
public abstract class SharedGridDraggingSystem : EntitySystem
|
||||||
{
|
{
|
||||||
@@ -11,6 +11,15 @@ public abstract class SharedGridDraggingSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sent from server to client if grid dragging is toggled on.
|
||||||
|
/// </summary>
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class GridDragToggleMessage : EntityEventArgs
|
||||||
|
{
|
||||||
|
public bool Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised on the client to request a grid move to a specific position.
|
/// Raised on the client to request a grid move to a specific position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,7 +5,16 @@ namespace Content.Shared.Weapons.Ranged.Systems;
|
|||||||
|
|
||||||
public abstract class SharedTetherGunSystem : EntitySystem
|
public abstract class SharedTetherGunSystem : EntitySystem
|
||||||
{
|
{
|
||||||
protected const string CommandName = "tethergun";
|
public const string CommandName = "tethergun";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sent from server to client if tether gun is toggled on.
|
||||||
|
/// </summary>
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class TetherGunToggleMessage : EntityEventArgs
|
||||||
|
{
|
||||||
|
public bool Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
@@ -57,11 +57,6 @@
|
|||||||
- nodevis
|
- nodevis
|
||||||
- nodevisfilter
|
- nodevisfilter
|
||||||
|
|
||||||
- Flags: FUN
|
|
||||||
Commands:
|
|
||||||
- tethergun
|
|
||||||
- griddrag
|
|
||||||
|
|
||||||
- Flags: ADMIN
|
- Flags: ADMIN
|
||||||
Commands:
|
Commands:
|
||||||
- togglehealthoverlay
|
- togglehealthoverlay
|
||||||
|
|||||||
Reference in New Issue
Block a user