* Update RobustToolbox * Transition direct type usages * More updates * Fix invalid use of to map * Update RobustToolbox * Fix dropping items * Rename name usages of "GridCoordinates" to "EntityCoordinates" * Revert "Update RobustToolbox" This reverts commit 9f334a17c5908ded0043a63158bb671e4aa3f346. * Revert "Update RobustToolbox" This reverts commit 3a9c8cfa3606fa501aa84407796d2ad920853a09. # Conflicts: # RobustToolbox * Fix cursed IMapGrid method usage. * GridTileLookupTest now uses EntityCoordinates Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
162 lines
5.1 KiB
C#
162 lines
5.1 KiB
C#
#nullable enable
|
|
using System.Linq;
|
|
using Content.Shared.Maps;
|
|
using JetBrains.Annotations;
|
|
using Robust.Server.Interfaces.Console;
|
|
using Robust.Server.Interfaces.GameObjects;
|
|
using Robust.Server.Interfaces.Player;
|
|
using Robust.Shared.Interfaces.Map;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.Server.GameObjects.Components.Interactable
|
|
{
|
|
/// <summary>
|
|
/// <see cref="TilePryingComponent.TryPryTile"/>
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
class TilePryCommand : IClientCommand
|
|
{
|
|
public string Command => "tilepry";
|
|
public string Description => "Pries up all tiles in a radius around the user.";
|
|
public string Help => $"Usage: {Command} <radius>";
|
|
|
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
|
{
|
|
if (player?.AttachedEntity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (args.Length != 1)
|
|
{
|
|
shell.SendText(player, Help);
|
|
return;
|
|
}
|
|
|
|
if (!int.TryParse(args[0], out var radius))
|
|
{
|
|
shell.SendText(player, $"{args[0]} isn't a valid integer.");
|
|
return;
|
|
}
|
|
|
|
if (radius < 0)
|
|
{
|
|
shell.SendText(player, "Radius must be positive.");
|
|
return;
|
|
}
|
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
|
var playerGrid = player.AttachedEntity.Transform.GridID;
|
|
var mapGrid = mapManager.GetGrid(playerGrid);
|
|
var playerPosition = player.AttachedEntity.Transform.Coordinates;
|
|
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
|
|
|
|
for (var i = -radius; i <= radius; i++)
|
|
{
|
|
for (var j = -radius; j <= radius; j++)
|
|
{
|
|
var tile = mapGrid.GetTileRef(playerPosition.Offset((i, j)));
|
|
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
|
|
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.Tile.TypeId];
|
|
|
|
if (!tileDef.CanCrowbar) continue;
|
|
|
|
var underplating = tileDefinitionManager["underplating"];
|
|
mapGrid.SetTile(coordinates, new Tile(underplating.TileId));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[UsedImplicitly]
|
|
class AnchorCommand : IClientCommand
|
|
{
|
|
public string Command => "anchor";
|
|
public string Description => "Anchors all entities in a radius around the user";
|
|
public string Help => $"Usage: {Command} <radius>";
|
|
|
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
|
{
|
|
if (player?.AttachedEntity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (args.Length != 1)
|
|
{
|
|
shell.SendText(player, Help);
|
|
return;
|
|
}
|
|
|
|
if (!int.TryParse(args[0], out var radius))
|
|
{
|
|
shell.SendText(player, $"{args[0]} isn't a valid integer.");
|
|
return;
|
|
}
|
|
|
|
if (radius < 0)
|
|
{
|
|
shell.SendText(player, "Radius must be positive.");
|
|
return;
|
|
}
|
|
|
|
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
|
var entities = serverEntityManager.GetEntitiesInRange(player.AttachedEntity, radius).ToList();
|
|
|
|
foreach (var entity in entities)
|
|
{
|
|
if (entity.TryGetComponent(out AnchorableComponent? anchorable))
|
|
{
|
|
anchorable.TryAnchor(player.AttachedEntity, force: true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[UsedImplicitly]
|
|
class UnAnchorCommand : IClientCommand
|
|
{
|
|
public string Command => "unanchor";
|
|
public string Description => "Unanchors all anchorable entities in a radius around the user";
|
|
public string Help => $"Usage: {Command} <radius>";
|
|
|
|
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
|
{
|
|
if (player?.AttachedEntity == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (args.Length != 1)
|
|
{
|
|
shell.SendText(player, Help);
|
|
return;
|
|
}
|
|
|
|
if (!int.TryParse(args[0], out var radius))
|
|
{
|
|
shell.SendText(player, $"{args[0]} isn't a valid integer.");
|
|
return;
|
|
}
|
|
|
|
if (radius < 0)
|
|
{
|
|
shell.SendText(player, "Radius must be positive.");
|
|
return;
|
|
}
|
|
|
|
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
|
|
var entities = serverEntityManager.GetEntitiesInRange(player.AttachedEntity, radius).ToList();
|
|
|
|
foreach (var entity in entities)
|
|
{
|
|
if (entity.TryGetComponent(out AnchorableComponent? anchorable))
|
|
{
|
|
anchorable.TryUnAnchor(player.AttachedEntity, force: true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|