GridCoordinates API changes.

This commit is contained in:
Acruid
2020-01-25 01:39:14 -08:00
parent a86363a6d2
commit a692899f5b
8 changed files with 14 additions and 19 deletions

View File

@@ -109,9 +109,8 @@ namespace Content.Client.State
public IList<IEntity> GetEntitiesUnderPosition(GridCoordinates coordinates) public IList<IEntity> GetEntitiesUnderPosition(GridCoordinates coordinates)
{ {
// Find all the entities intersecting our click // Find all the entities intersecting our click
var worldCoords = coordinates.ToWorld(_mapManager); var mapCoords = coordinates.ToMap(_mapManager);
var entities = _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(coordinates.GridID).ParentMapId, var entities = _entityManager.GetEntitiesIntersecting(mapCoords.MapId, mapCoords.Position);
worldCoords.Position);
// Check the entities against whether or not we can click them // Check the entities against whether or not we can click them
var foundEntities = new List<(IEntity clicked, int drawDepth)>(); var foundEntities = new List<(IEntity clicked, int drawDepth)>();

View File

@@ -119,8 +119,6 @@ namespace Content.Server.Explosions
// Knock back cameras of all players in the area. // Knock back cameras of all players in the area.
var playerManager = IoCManager.Resolve<IPlayerManager>(); var playerManager = IoCManager.Resolve<IPlayerManager>();
//var selfPos = Owner.Transform.WorldPosition; //vec2
var selfPos = coords.ToWorld(mapManager).Position;
foreach (var player in playerManager.GetAllPlayers()) foreach (var player in playerManager.GetAllPlayers())
{ {
if (player.AttachedEntity == null if (player.AttachedEntity == null
@@ -131,7 +129,7 @@ namespace Content.Server.Explosions
} }
var playerPos = player.AttachedEntity.Transform.WorldPosition; var playerPos = player.AttachedEntity.Transform.WorldPosition;
var delta = selfPos - playerPos; var delta = coords.ToMapPos(mapManager) - playerPos;
var distance = delta.LengthSquared; var distance = delta.LengthSquared;
var effect = 1 / (1 + 0.2f * distance); var effect = 1 / (1 + 0.2f * distance);

View File

@@ -86,8 +86,7 @@ namespace Content.Server.GameObjects.Components.Movement
{ {
if (_teleporterType == TeleporterType.Directed) if (_teleporterType == TeleporterType.Directed)
{ {
var userTarget = eventArgs.ClickLocation.ToWorld(_mapManager); TryDirectedTeleport(eventArgs.User, eventArgs.ClickLocation.ToMap(_mapManager));
TryDirectedTeleport(eventArgs.User, userTarget);
} }
if (_teleporterType == TeleporterType.Random) if (_teleporterType == TeleporterType.Random)
@@ -96,10 +95,10 @@ namespace Content.Server.GameObjects.Components.Movement
} }
} }
public void TryDirectedTeleport(IEntity user, GridCoordinates grid) public void TryDirectedTeleport(IEntity user, MapCoordinates mapCoords)
{ {
// Checks // Checks
if (user.Transform.GridPosition.Distance(_mapManager, grid) > _range) if ((user.Transform.WorldPosition - mapCoords.Position).LengthSquared > (_range * _range))
{ {
return; return;
} }
@@ -110,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Movement
} }
if (_avoidCollidable) if (_avoidCollidable)
{ {
foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(grid)) foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(mapCoords))
{ {
// Added this component to avoid stacking portals and causing shenanigans // Added this component to avoid stacking portals and causing shenanigans
// TODO: Doesn't do a great job of stopping stacking portals for directed // TODO: Doesn't do a great job of stopping stacking portals for directed
@@ -132,7 +131,7 @@ namespace Content.Server.GameObjects.Components.Movement
return; return;
} }
Timer.Spawn(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, new Vector2(grid.X, grid.Y))); Timer.Spawn(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, mapCoords.Position));
StartCooldown(); StartCooldown();
} }

View File

@@ -28,7 +28,7 @@ namespace Content.Server.GameObjects.Components.Power
if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GridID, out var grid)) if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GridID, out var grid))
return; return;
var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation.ToWorld(_mapManager), SnapGridOffset.Center); var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center); var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center);
if(grid.GetTileRef(snapPos).Tile.IsEmpty) if(grid.GetTileRef(snapPos).Tile.IsEmpty)

View File

@@ -83,8 +83,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
return; return;
} }
var location = eventArgs.User.Transform.GridPosition; var location = eventArgs.User.Transform.GridPosition;
var angle = new Angle(eventArgs.ClickLocation.ToWorld(_mapManager).Position - var angle = new Angle(eventArgs.ClickLocation.ToMapPos(_mapManager) - location.ToMapPos(_mapManager));
location.ToWorld(_mapManager).Position);
// This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes. // This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes.
var entities = ArcRayCast(eventArgs.User.Transform.WorldPosition, angle, eventArgs.User); var entities = ArcRayCast(eventArgs.User.Transform.WorldPosition, angle, eventArgs.User);

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Timing; using Content.Server.GameObjects.Components.Timing;
@@ -408,7 +408,7 @@ namespace Content.Server.GameObjects.EntitySystems
// Check if ClickLocation is in object bounds here, if not lets log as warning and see why // Check if ClickLocation is in object bounds here, if not lets log as warning and see why
if (attacked.TryGetComponent(out ICollidableComponent collideComp)) if (attacked.TryGetComponent(out ICollidableComponent collideComp))
{ {
if (!collideComp.WorldAABB.Contains(coordinates.ToWorld(_mapManager).Position)) if (!collideComp.WorldAABB.Contains(coordinates.ToMapPos(_mapManager)))
{ {
Logger.WarningS("system.interaction", Logger.WarningS("system.interaction",
$"Player {player.Name} clicked {attacked.Name} outside of its bounding box component somehow"); $"Player {player.Name} clicked {attacked.Name} outside of its bounding box component somehow");

View File

@@ -198,7 +198,7 @@ namespace Content.Server.GameObjects.EntitySystems
projComp.IgnoreEntity(plyEnt); projComp.IgnoreEntity(plyEnt);
var transform = plyEnt.Transform; var transform = plyEnt.Transform;
var dirVec = (coords.ToWorld(_mapManager).Position - transform.WorldPosition).Normalized; var dirVec = (coords.ToMapPos(_mapManager) - transform.WorldPosition).Normalized;
if (!throwEnt.TryGetComponent(out PhysicsComponent physComp)) if (!throwEnt.TryGetComponent(out PhysicsComponent physComp))
physComp = throwEnt.AddComponent<PhysicsComponent>(); physComp = throwEnt.AddComponent<PhysicsComponent>();