2022-02-24 11:00:30 +11:00
|
|
|
using Content.Client.Administration.Managers;
|
2019-10-02 10:45:06 +02:00
|
|
|
using Content.Shared.Sandbox;
|
2020-08-14 09:09:58 -07:00
|
|
|
using Robust.Client.Console;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Placement;
|
2022-06-06 10:58:20 +12:00
|
|
|
using Robust.Client.Placement.Modes;
|
2022-09-04 16:17:05 -07:00
|
|
|
using Robust.Client.UserInterface;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Map;
|
2022-06-06 10:58:20 +12:00
|
|
|
using Robust.Shared.Players;
|
2019-10-02 10:45:06 +02:00
|
|
|
|
|
|
|
|
namespace Content.Client.Sandbox
|
|
|
|
|
{
|
2022-02-24 11:00:30 +11:00
|
|
|
public sealed class SandboxSystem : SharedSandboxSystem
|
2019-10-02 10:45:06 +02:00
|
|
|
{
|
2022-02-24 11:00:30 +11:00
|
|
|
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
2022-09-14 14:34:48 -07:00
|
|
|
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
|
|
|
|
[Dependency] private readonly IMapManager _map = default!;
|
|
|
|
|
[Dependency] private readonly IPlacementManager _placement = default!;
|
2022-09-04 16:17:05 -07:00
|
|
|
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
2019-10-02 10:45:06 +02:00
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
private bool _sandboxEnabled;
|
2020-02-08 20:45:02 +01:00
|
|
|
public bool SandboxAllowed { get; private set; }
|
2022-09-14 14:34:48 -07:00
|
|
|
public event Action? SandboxEnabled;
|
|
|
|
|
public event Action? SandboxDisabled;
|
2019-10-02 10:45:06 +02:00
|
|
|
|
2022-02-24 11:00:30 +11:00
|
|
|
public override void Initialize()
|
2019-10-02 10:45:06 +02:00
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
_adminManager.AdminStatusUpdated += CheckStatus;
|
2022-02-24 11:00:30 +11:00
|
|
|
SubscribeNetworkEvent<MsgSandboxStatus>(OnSandboxStatus);
|
2022-06-06 10:58:20 +12:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
private void CheckStatus()
|
2022-06-06 10:58:20 +12:00
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
var currentStatus = _sandboxEnabled || _adminManager.IsActive();
|
|
|
|
|
if (currentStatus == SandboxAllowed)
|
|
|
|
|
return;
|
|
|
|
|
SandboxAllowed = currentStatus;
|
|
|
|
|
if (SandboxAllowed)
|
2022-06-06 10:58:20 +12:00
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
SandboxEnabled?.Invoke();
|
2022-06-06 10:58:20 +12:00
|
|
|
}
|
2022-02-24 11:00:30 +11:00
|
|
|
else
|
2022-09-14 14:34:48 -07:00
|
|
|
{
|
|
|
|
|
SandboxDisabled?.Invoke();
|
|
|
|
|
}
|
2022-02-24 11:00:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
_adminManager.AdminStatusUpdated -= CheckStatus;
|
2022-02-24 11:00:30 +11:00
|
|
|
base.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSandboxStatus(MsgSandboxStatus ev)
|
|
|
|
|
{
|
|
|
|
|
SetAllowed(ev.SandboxAllowed);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
private void SetAllowed(bool sandboxEnabled)
|
2019-10-02 10:45:06 +02:00
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
_sandboxEnabled = sandboxEnabled;
|
|
|
|
|
CheckStatus();
|
2019-10-02 10:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void Respawn()
|
2019-10-02 10:45:06 +02:00
|
|
|
{
|
2022-02-24 11:00:30 +11:00
|
|
|
RaiseNetworkEvent(new MsgSandboxRespawn());
|
2019-10-02 10:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void GiveAdminAccess()
|
2020-07-17 03:38:58 -05:00
|
|
|
{
|
2022-02-24 11:00:30 +11:00
|
|
|
RaiseNetworkEvent(new MsgSandboxGiveAccess());
|
2020-07-17 03:38:58 -05:00
|
|
|
}
|
2020-08-14 09:09:58 -07:00
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void GiveAGhost()
|
2020-08-14 09:09:58 -07:00
|
|
|
{
|
2022-02-24 11:00:30 +11:00
|
|
|
RaiseNetworkEvent(new MsgSandboxGiveAghost());
|
2020-08-14 09:09:58 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void Suicide()
|
2020-08-14 09:09:58 -07:00
|
|
|
{
|
2022-02-24 11:00:30 +11:00
|
|
|
RaiseNetworkEvent(new MsgSandboxSuicide());
|
2020-08-14 09:09:58 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public bool Copy(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
2020-02-02 16:38:51 -05:00
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
if (!SandboxAllowed)
|
|
|
|
|
return false;
|
2020-08-14 09:09:58 -07:00
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
// Try copy entity.
|
|
|
|
|
if (uid.IsValid()
|
|
|
|
|
&& EntityManager.TryGetComponent(uid, out MetaDataComponent? comp)
|
|
|
|
|
&& !comp.EntityDeleted)
|
2022-02-08 13:54:41 -07:00
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
if (comp.EntityPrototype == null || comp.EntityPrototype.NoSpawn || comp.EntityPrototype.Abstract)
|
|
|
|
|
return false;
|
2022-02-24 11:00:30 +11:00
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
if (_placement.Eraser)
|
|
|
|
|
_placement.ToggleEraser();
|
2022-02-08 13:54:41 -07:00
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
_placement.BeginPlacing(new()
|
|
|
|
|
{
|
|
|
|
|
EntityType = comp.EntityPrototype.ID,
|
|
|
|
|
IsTile = false,
|
|
|
|
|
TileType = 0,
|
|
|
|
|
PlacementOption = comp.EntityPrototype.PlacementMode
|
|
|
|
|
});
|
|
|
|
|
return true;
|
2022-02-08 13:54:41 -07:00
|
|
|
}
|
2022-09-14 14:34:48 -07:00
|
|
|
|
|
|
|
|
// Try copy tile.
|
|
|
|
|
if (!_map.TryFindGridAt(coords.ToMap(EntityManager), out var grid) || !grid.TryGetTileRef(coords, out var tileRef))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (_placement.Eraser)
|
|
|
|
|
_placement.ToggleEraser();
|
|
|
|
|
|
|
|
|
|
_placement.BeginPlacing(new()
|
2022-02-08 13:54:41 -07:00
|
|
|
{
|
2022-09-14 14:34:48 -07:00
|
|
|
EntityType = null,
|
|
|
|
|
IsTile = true,
|
|
|
|
|
TileType = tileRef.Tile.TypeId,
|
|
|
|
|
PlacementOption = nameof(AlignTileAny)
|
|
|
|
|
});
|
|
|
|
|
return true;
|
2022-02-08 13:54:41 -07:00
|
|
|
}
|
|
|
|
|
|
2022-02-24 11:00:30 +11:00
|
|
|
// TODO: need to cleanup these
|
2022-09-14 14:34:48 -07:00
|
|
|
public void ToggleLight()
|
2020-08-14 09:09:58 -07:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand("togglelight");
|
2020-08-14 09:09:58 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void ToggleFov()
|
2020-09-26 06:50:14 -07:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand("togglefov");
|
2020-09-26 06:50:14 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void ToggleShadows()
|
2020-09-26 06:50:14 -07:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand("toggleshadows");
|
2020-09-26 06:50:14 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void ToggleSubFloor()
|
2020-08-14 09:09:58 -07:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand("showsubfloor");
|
2020-08-14 09:09:58 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void ShowMarkers()
|
2020-08-14 09:09:58 -07:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand("showmarkers");
|
2020-08-14 09:09:58 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void ShowBb()
|
2020-08-14 09:09:58 -07:00
|
|
|
{
|
2021-10-03 17:58:19 +11:00
|
|
|
_consoleHost.ExecuteCommand("physics shapes");
|
2020-08-14 09:09:58 -07:00
|
|
|
}
|
2020-11-03 04:14:43 -06:00
|
|
|
|
2022-09-14 14:34:48 -07:00
|
|
|
public void MachineLinking()
|
2020-11-03 04:14:43 -06:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
_consoleHost.ExecuteCommand("signallink");
|
2020-11-03 04:14:43 -06:00
|
|
|
}
|
2019-10-02 10:45:06 +02:00
|
|
|
}
|
|
|
|
|
}
|