Add TryPryTile

This commit is contained in:
zumorica
2020-05-19 14:50:24 +02:00
parent 312e8f17a5
commit be6eba4f75

View File

@@ -153,28 +153,34 @@ namespace Content.Server.GameObjects.Components.Interactable
public void AfterAttack(AfterAttackEventArgs eventArgs) public void AfterAttack(AfterAttackEventArgs eventArgs)
{ {
if (Qualities != ToolQuality.Prying) TryPryTile(eventArgs.User, eventArgs.ClickLocation);
return; }
var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); public bool TryPryTile(IEntity user, GridCoordinates clickLocation)
var tile = mapGrid.GetTileRef(eventArgs.ClickLocation); {
if (HasQuality(ToolQuality.Prying))
return false;
var mapGrid = _mapManager.GetGrid(clickLocation.GridID);
var tile = mapGrid.GetTileRef(clickLocation);
var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); var coordinates = mapGrid.GridTileToLocal(tile.GridIndices);
if (!_interactionSystem.InRangeUnobstructed(eventArgs.User.Transform.MapPosition, coordinates.ToMapPos(_mapManager), ignoredEnt:eventArgs.User)) if (!_interactionSystem.InRangeUnobstructed(user.Transform.MapPosition, coordinates.ToMapPos(_mapManager), ignoredEnt:user))
return; return false;
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
if (!tileDef.CanCrowbar) return; if (!tileDef.CanCrowbar) return false;
var underplating = _tileDefinitionManager["underplating"]; var underplating = _tileDefinitionManager["underplating"];
mapGrid.SetTile(eventArgs.ClickLocation, new Tile(underplating.TileId)); mapGrid.SetTile(clickLocation, new Tile(underplating.TileId));
PlayUseSound(); PlayUseSound();
//Actually spawn the relevant tile item at the right position and give it some offset to the corner. //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); var tileItem = Owner.EntityManager.SpawnEntity(tileDef.ItemDropPrototypeName, coordinates);
tileItem.Transform.WorldPosition += (0.2f, 0.2f); tileItem.Transform.WorldPosition += (0.2f, 0.2f);
return true;
} }
} }
} }