Tile Prying helpers
This commit is contained in:
@@ -162,16 +162,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
if (IsSpace(indices) || IsAirBlocked(indices)) return;
|
if (IsSpace(indices) || IsAirBlocked(indices)) return;
|
||||||
|
|
||||||
var mapGrid = mapGridComponent.Grid;
|
var mapGrid = mapGridComponent.Grid;
|
||||||
var tile = mapGrid.GetTileRef(indices).Tile;
|
indices.PryTile(mapGrid.Index, _mapManager, _tileDefinitionManager, _serverEntityManager);
|
||||||
|
|
||||||
var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.TypeId];
|
|
||||||
|
|
||||||
var underplating = _tileDefinitionManager["underplating"];
|
|
||||||
mapGrid.SetTile(indices, new Tile(underplating.TileId));
|
|
||||||
|
|
||||||
//Actually spawn the relevant tile item at the right position and give it some offset to the corner.
|
|
||||||
var tileItem = _serverEntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, new GridCoordinates(indices.X, indices.Y, mapGrid));
|
|
||||||
tileItem.Transform.WorldPosition += (0.2f, 0.2f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
|
|||||||
@@ -53,12 +53,7 @@ namespace Content.Server.GameObjects.Components.Interactable
|
|||||||
if (_toolComponentNeeded && !await tool!.UseTool(user, null, 0f, ToolQuality.Prying))
|
if (_toolComponentNeeded && !await tool!.UseTool(user, null, 0f, ToolQuality.Prying))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var underplating = _tileDefinitionManager["underplating"];
|
coordinates.PryTile(_mapManager, _tileDefinitionManager, Owner.EntityManager);
|
||||||
mapGrid.SetTile(clickLocation, new Tile(underplating.TileId));
|
|
||||||
|
|
||||||
//Actually spawn the relevant tile item at the right position and give it some offset to the corner.
|
|
||||||
var tileItem = Owner.EntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, coordinates);
|
|
||||||
tileItem.Transform.WorldPosition += (0.2f, 0.2f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
|
using Content.Shared.Utility;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.Interfaces.Physics;
|
using Robust.Shared.Interfaces.Physics;
|
||||||
@@ -65,6 +66,52 @@ namespace Content.Shared.Maps
|
|||||||
return (turf = coordinates.GetTileRef()) != null;
|
return (turf = coordinates.GetTileRef()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool PryTile(this GridCoordinates coordinates,
|
||||||
|
IMapManager? mapManager = null, ITileDefinitionManager? tileDefinitionManager = null, IEntityManager? entityManager = null)
|
||||||
|
{
|
||||||
|
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||||
|
|
||||||
|
return coordinates.ToMapIndices(mapManager).PryTile(coordinates.GridID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool PryTile(this MapIndices indices, GridId gridId,
|
||||||
|
IMapManager? mapManager = null, ITileDefinitionManager? tileDefinitionManager = null, IEntityManager? entityManager = null)
|
||||||
|
{
|
||||||
|
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||||
|
var grid = mapManager.GetGrid(gridId);
|
||||||
|
var tileRef = grid.GetTileRef(indices);
|
||||||
|
return tileRef.PryTile(mapManager, tileDefinitionManager, entityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool PryTile(this TileRef tileRef,
|
||||||
|
IMapManager? mapManager = null, ITileDefinitionManager? tileDefinitionManager = null, IEntityManager? entityManager = null)
|
||||||
|
{
|
||||||
|
var tile = tileRef.Tile;
|
||||||
|
var indices = tileRef.GridIndices;
|
||||||
|
|
||||||
|
// If the arguments are null, resolve the needed dependencies.
|
||||||
|
mapManager ??= IoCManager.Resolve<IMapManager>();
|
||||||
|
tileDefinitionManager ??= IoCManager.Resolve<ITileDefinitionManager>();
|
||||||
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
|
if (tile.IsEmpty) return false;
|
||||||
|
|
||||||
|
var tileDef = (ContentTileDefinition) tileDefinitionManager[tile.TypeId];
|
||||||
|
|
||||||
|
if (!tileDef.CanCrowbar) return false;
|
||||||
|
|
||||||
|
var mapGrid = mapManager.GetGrid(tileRef.GridIndex);
|
||||||
|
|
||||||
|
var plating = tileDefinitionManager[tileDef.BaseTurfs[^1]];
|
||||||
|
|
||||||
|
mapGrid.SetTile(tileRef.GridIndices, new Tile(plating.TileId));
|
||||||
|
|
||||||
|
//Actually spawn the relevant tile item at the right position and give it some random offset.
|
||||||
|
var tileItem = entityManager.SpawnEntity(tileDef.ItemDropPrototypeName, new GridCoordinates(indices.X, indices.Y, mapGrid));
|
||||||
|
tileItem.RandomOffset(0.5f);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper that returns all entities in a turf.
|
/// Helper that returns all entities in a turf.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user