Fix inflatable position (#3788)
This commit is contained in:
@@ -36,12 +36,14 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(component.Prototype))
|
if (string.IsNullOrEmpty(component.Prototype))
|
||||||
return;
|
return;
|
||||||
if (!args.ClickLocation.TryGetTileRef(out var tileRef, EntityManager, _mapManager))
|
if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridId(EntityManager), out var grid))
|
||||||
|
return;
|
||||||
|
if (!grid.TryGetTileRef(args.ClickLocation, out var tileRef))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool IsTileClear()
|
bool IsTileClear()
|
||||||
{
|
{
|
||||||
return tileRef.Value.Tile.IsEmpty == false && args.User.InRangeUnobstructed(args.ClickLocation, popup: true);
|
return tileRef.Tile.IsEmpty == false && args.User.InRangeUnobstructed(args.ClickLocation, popup: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsTileClear())
|
if (!IsTileClear())
|
||||||
@@ -68,7 +70,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
if (component.RemoveOnInteract && component.Owner.TryGetComponent(out stack) && !stack.Use(1))
|
if (component.RemoveOnInteract && component.Owner.TryGetComponent(out stack) && !stack.Use(1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EntityManager.SpawnEntity(component.Prototype, tileRef.Value.GridPosition(_mapManager));
|
EntityManager.SpawnEntity(component.Prototype, args.ClickLocation.SnapToGrid(grid, SnapGridOffset.Center));
|
||||||
|
|
||||||
if (component.RemoveOnInteract && stack == null && !component.Owner.Deleted)
|
if (component.RemoveOnInteract && stack == null && !component.Owner.Deleted)
|
||||||
component.Owner.Delete();
|
component.Owner.Delete();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
@@ -35,5 +35,18 @@ namespace Content.Server.Utility
|
|||||||
|
|
||||||
return new EntityCoordinates(coordinates.EntityId, x, y);
|
return new EntityCoordinates(coordinates.EntityId, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EntityCoordinates SnapToGrid(this EntityCoordinates coordinates, IMapGrid grid,
|
||||||
|
SnapGridOffset offset = SnapGridOffset.Center)
|
||||||
|
{
|
||||||
|
var tileSize = grid.TileSize;
|
||||||
|
|
||||||
|
var localPos = coordinates.Position;
|
||||||
|
|
||||||
|
var x = (int)Math.Floor(localPos.X / tileSize) + tileSize / (offset == SnapGridOffset.Center ? 2f : 0f);
|
||||||
|
var y = (int)Math.Floor(localPos.Y / tileSize) + tileSize / (offset == SnapGridOffset.Center ? 2f : 0f);
|
||||||
|
|
||||||
|
return new EntityCoordinates(coordinates.EntityId, x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user