Fix griddrag and tethergun (#10510)

This commit is contained in:
metalgearsloth
2022-09-01 13:11:45 +10:00
committed by GitHub
parent a44c5a447e
commit a0f2e7ac92
9 changed files with 126 additions and 18 deletions

View File

@@ -1,4 +1,3 @@
using Content.Client.Administration.Managers;
using Content.Shared.Maps;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
@@ -24,6 +23,23 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
private Vector2 _localPosition;
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)
{
_dragging = grid;

View File

@@ -31,6 +31,12 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
{
base.Initialize();
SubscribeNetworkEvent<PredictTetherEvent>(OnPredictTether);
SubscribeNetworkEvent<TetherGunToggleMessage>(OnTetherGun);
}
private void OnTetherGun(TetherGunToggleMessage ev)
{
Enabled = ev.Enabled;
}
private void OnPredictTether(PredictTetherEvent ev)

View File

@@ -1,11 +1,14 @@
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Maps;
using Robust.Shared.Console;
namespace Content.Client.Maps;
namespace Content.Server.Maps;
/// <summary>
/// Toggles GridDragging on the system.
/// </summary>
[AdminCommand(AdminFlags.Fun)]
public sealed class GridDraggingCommand : IConsoleCommand
{
public string Command => SharedGridDraggingSystem.CommandName;
@@ -13,10 +16,16 @@ public sealed class GridDraggingCommand : IConsoleCommand
public string Help => $"{Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<GridDraggingSystem>();
system.Enabled ^= true;
if (shell.Player == null)
{
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");
else
shell.WriteLine("Grid dragging toggled off");

View File

@@ -1,6 +1,8 @@
using Content.Shared.Maps;
using Robust.Server.Console;
using Robust.Server.Player;
using Robust.Shared.Players;
using Robust.Shared.Utility;
namespace Content.Server.Maps;
@@ -9,6 +11,8 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
{
[Dependency] private readonly IConGroupController _admin = default!;
private readonly HashSet<ICommonSession> _draggers = new();
public override void Initialize()
{
base.Initialize();
@@ -16,6 +20,31 @@ public sealed class GridDraggingSystem : SharedGridDraggingSystem
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)
{
if (args.SenderSession is not IPlayerSession playerSession ||

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Ghost.Components;
using Content.Shared.Administration;
using Content.Shared.Weapons.Ranged.Systems;
@@ -20,7 +21,8 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
[Dependency] private readonly SharedContainerSystem _container = 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";
@@ -46,6 +48,35 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
_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)
{
if (args.SenderSession is not IPlayerSession playerSession ||

View File

@@ -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;
namespace Content.Client.Weapons.Ranged;
namespace Content.Server.Weapons.Ranged.Commands;
[AdminCommand(AdminFlags.Fun)]
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 Help => $"{Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
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");
else
shell.WriteLine("Tether gun toggled off");

View File

@@ -3,7 +3,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Maps;
/// <summary>
/// Helper system to allow you to move grids with a mouse.
/// Helper system to allow you to move entities with a mouse.
/// </summary>
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>
/// Raised on the client to request a grid move to a specific position.
/// </summary>

View File

@@ -5,7 +5,16 @@ namespace Content.Shared.Weapons.Ranged.Systems;
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]

View File

@@ -57,11 +57,6 @@
- nodevis
- nodevisfilter
- Flags: FUN
Commands:
- tethergun
- griddrag
- Flags: ADMIN
Commands:
- togglehealthoverlay