Merge branch 'master' into 2020-08-19-firelocks
# Conflicts: # Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs # Content.Shared/Maps/TurfHelpers.cs # SpaceStation14.sln.DotSettings
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
@@ -61,6 +63,59 @@ namespace Content.Shared.Maps
|
||||
return tile;
|
||||
}
|
||||
|
||||
public static bool TryGetTileRef(this GridCoordinates coordinates, [NotNullWhen(true)] out TileRef? turf)
|
||||
{
|
||||
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));
|
||||
|
||||
var half = mapGrid.TileSize / 2f;
|
||||
|
||||
//Actually spawn the relevant tile item at the right position and give it some random offset.
|
||||
var tileItem = entityManager.SpawnEntity(tileDef.ItemDropPrototypeName, indices.ToGridCoordinates(mapManager, tileRef.GridIndex).Offset(new Vector2(half, half)));
|
||||
tileItem.RandomOffset(0.25f);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper that returns all entities in a turf.
|
||||
/// </summary>
|
||||
@@ -121,6 +176,11 @@ namespace Content.Shared.Maps
|
||||
return false;
|
||||
}
|
||||
|
||||
public static GridCoordinates GridPosition(this TileRef turf)
|
||||
{
|
||||
return new GridCoordinates(turf.X, turf.Y, turf.GridIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a box the size of a tile, at the same position in the world as the tile.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user