FloorTileItem station extension/new grid creation (#2500)
* FloorTileItemComponent can now extend the station, or create new grids. * Fixes wrong interaction system EntityCoordinates check. Needed for all this to work.
This commit is contained in:
committed by
GitHub
parent
6a469508ca
commit
bb3aee90b2
@@ -1,4 +1,5 @@
|
|||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Content.Shared.Utility;
|
using Content.Shared.Utility;
|
||||||
@@ -8,6 +9,7 @@ using Robust.Shared.GameObjects.Systems;
|
|||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Items
|
namespace Content.Server.GameObjects.Components.Items
|
||||||
@@ -33,23 +35,52 @@ namespace Content.Server.GameObjects.Components.Items
|
|||||||
Owner.EnsureComponent<StackComponent>();
|
Owner.EnsureComponent<StackComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool HasBaseTurf(ContentTileDefinition tileDef, string baseTurf)
|
||||||
|
{
|
||||||
|
foreach (var tileBaseTurf in tileDef.BaseTurfs)
|
||||||
|
{
|
||||||
|
if (baseTurf == tileBaseTurf)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlaceAt(IMapGrid mapGrid, EntityCoordinates location, ushort tileId, float offset = 0)
|
||||||
|
{
|
||||||
|
mapGrid.SetTile(location.Offset(new Vector2(offset, offset)), new Tile(tileId));
|
||||||
|
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Items/genhit.ogg", location, AudioHelpers.WithVariation(0.125f));
|
||||||
|
}
|
||||||
|
|
||||||
public void AfterInteract(AfterInteractEventArgs eventArgs)
|
public void AfterInteract(AfterInteractEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
|
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
|
||||||
if (!Owner.TryGetComponent(out StackComponent stack)) return;
|
if (!Owner.TryGetComponent(out StackComponent stack)) return;
|
||||||
|
|
||||||
var attacked = eventArgs.Target;
|
var location = eventArgs.ClickLocation.AlignWithClosestGridTile();
|
||||||
var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager));
|
var locationMap = location.ToMap(Owner.EntityManager);
|
||||||
var tile = mapGrid.GetTileRef(eventArgs.ClickLocation);
|
|
||||||
var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
|
||||||
|
|
||||||
if (tileDef.IsSubFloor && attacked == null && stack.Use(1))
|
var desiredTile = (ContentTileDefinition)_tileDefinitionManager[_outputTile];
|
||||||
|
|
||||||
|
if (_mapManager.TryGetGrid(location.GetGridId(Owner.EntityManager), out var mapGrid))
|
||||||
{
|
{
|
||||||
var desiredTile = _tileDefinitionManager[_outputTile];
|
var tile = mapGrid.GetTileRef(location);
|
||||||
mapGrid.SetTile(eventArgs.ClickLocation, new Tile(desiredTile.TileId));
|
var baseTurf = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId];
|
||||||
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Items/genhit.ogg", eventArgs.ClickLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (HasBaseTurf(desiredTile, baseTurf.Name) && eventArgs.Target == null && stack.Use(1))
|
||||||
|
{
|
||||||
|
PlaceAt(mapGrid, location, desiredTile.TileId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(HasBaseTurf(desiredTile, "space"))
|
||||||
|
{
|
||||||
|
mapGrid = _mapManager.CreateGrid(locationMap.MapId);
|
||||||
|
mapGrid.WorldPosition = locationMap.Position;
|
||||||
|
location = new EntityCoordinates(mapGrid.GridEntityId, Vector2.Zero);
|
||||||
|
PlaceAt(mapGrid, location, desiredTile.TileId, mapGrid.TileSize/2f);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
|
|||||||
private bool HandleWideAttack(ICommonSession session, EntityCoordinates coords, EntityUid uid)
|
private bool HandleWideAttack(ICommonSession session, EntityCoordinates coords, EntityUid uid)
|
||||||
{
|
{
|
||||||
// client sanitization
|
// client sanitization
|
||||||
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
|
if (!coords.IsValid(_entityManager))
|
||||||
{
|
{
|
||||||
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
||||||
return true;
|
return true;
|
||||||
@@ -211,7 +211,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
|
|||||||
private bool HandleClientUseItemInHand(ICommonSession session, EntityCoordinates coords, EntityUid uid)
|
private bool HandleClientUseItemInHand(ICommonSession session, EntityCoordinates coords, EntityUid uid)
|
||||||
{
|
{
|
||||||
// client sanitization
|
// client sanitization
|
||||||
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
|
if (!coords.IsValid(_entityManager))
|
||||||
{
|
{
|
||||||
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
|
||||||
return true;
|
return true;
|
||||||
@@ -242,7 +242,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
|
|||||||
private bool HandleTryPullObject(ICommonSession session, EntityCoordinates coords, EntityUid uid)
|
private bool HandleTryPullObject(ICommonSession session, EntityCoordinates coords, EntityUid uid)
|
||||||
{
|
{
|
||||||
// client sanitization
|
// client sanitization
|
||||||
if (!_mapManager.GridExists(coords.GetGridId(_entityManager)))
|
if (!coords.IsValid(_entityManager))
|
||||||
{
|
{
|
||||||
Logger.InfoS("system.interaction", $"Invalid Coordinates for pulling: client={session}, coords={coords}");
|
Logger.InfoS("system.interaction", $"Invalid Coordinates for pulling: client={session}, coords={coords}");
|
||||||
return false;
|
return false;
|
||||||
@@ -303,7 +303,7 @@ namespace Content.Server.GameObjects.EntitySystems.Click
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify player is on the same map as the entity he clicked on
|
// Verify player is on the same map as the entity he clicked on
|
||||||
if (_mapManager.GetGrid(coordinates.GetGridId(EntityManager)).ParentMapId != playerTransform.MapID)
|
if (coordinates.GetMapId(_entityManager) != playerTransform.MapID)
|
||||||
{
|
{
|
||||||
Logger.WarningS("system.interaction",
|
Logger.WarningS("system.interaction",
|
||||||
$"Player named {player.Name} clicked on a map he isn't located on");
|
$"Player named {player.Name} clicked on a map he isn't located on");
|
||||||
|
|||||||
Reference in New Issue
Block a user