Fix griddrag and tethergun (#10510)
This commit is contained in:
33
Content.Server/Maps/GridDraggingCommand.cs
Normal file
33
Content.Server/Maps/GridDraggingCommand.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Maps;
|
||||
|
||||
/// <summary>
|
||||
/// Toggles GridDragging on the system.
|
||||
/// </summary>
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public sealed class GridDraggingCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => SharedGridDraggingSystem.CommandName;
|
||||
public string Description => $"Allows someone with permissions to drag grids around.";
|
||||
public string Help => $"{Command}";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (shell.Player == null)
|
||||
{
|
||||
shell.WriteError("shell-server-cannot");
|
||||
return;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -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 ||
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
25
Content.Server/Weapons/Ranged/Commands/TetherGunCommand.cs
Normal file
25
Content.Server/Weapons/Ranged/Commands/TetherGunCommand.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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.Server.Weapons.Ranged.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public sealed class TetherGunCommand : IConsoleCommand
|
||||
{
|
||||
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.Toggle(shell.Player);
|
||||
|
||||
if (system.IsEnabled(shell.Player))
|
||||
shell.WriteLine("Tether gun toggled on");
|
||||
else
|
||||
shell.WriteLine("Tether gun toggled off");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user