Makes InRangeUnobstructed use MapCoordinates. Fixes #1003

(Also updates Submoduke)
This commit is contained in:
Víctor Aguilera Puerto
2020-05-26 14:23:25 +02:00
parent 0108126c43
commit 8a81f54a45
10 changed files with 21 additions and 32 deletions

View File

@@ -39,31 +39,20 @@ namespace Content.Server.GameObjects.EntitySystems
/// <param name="predicate">.</param>
/// <param name="insideBlockerValid">if coordinates inside obstructions count as obstructed or not</param>
/// <returns>True if the two points are within a given range without being obstructed.</returns>
public bool InRangeUnobstructed(MapCoordinates coords, Vector2 otherCoords, float range = InteractionRange,
public bool InRangeUnobstructed(MapCoordinates coords, MapCoordinates otherCoords, float range = InteractionRange,
int collisionMask = (int)CollisionGroup.Impassable, Func<IEntity, bool> predicate = null, bool insideBlockerValid = false)
{
var dir = otherCoords - coords.Position;
if (!coords.InRange(otherCoords, range))
return false;
var dir = otherCoords.Position - coords.Position;
if (dir.LengthSquared.Equals(0f)) return true;
if (range > 0f && !(dir.LengthSquared <= range * range)) return false;
var ray = new CollisionRay(coords.Position, dir.Normalized, collisionMask);
var rayResults = _physicsManager.IntersectRayWithPredicate(coords.MapId, ray, dir.Length, predicate).ToList();
if(rayResults.Count == 0 || (insideBlockerValid && rayResults.Count > 0 && (rayResults[0].HitPos - otherCoords).Length < 1f))
{
if (_mapManager.TryFindGridAt(coords, out var mapGrid) && mapGrid != null)
{
var srcPos = mapGrid.MapToGrid(coords);
var destPos = new GridCoordinates(otherCoords, mapGrid);
if (srcPos.InRange(_mapManager, destPos, range))
{
return true;
}
}
}
return false;
return rayResults.Count == 0 || (insideBlockerValid && rayResults.Count > 0 && (rayResults[0].HitPos - otherCoords.Position).Length < 1f);
}
/// <summary>
@@ -79,7 +68,7 @@ namespace Content.Server.GameObjects.EntitySystems
/// <param name="ignoredEnt">the entity to be ignored when checking for collisions.</param>
/// <param name="insideBlockerValid">if coordinates inside obstructions count as obstructed or not</param>
/// <returns>True if the two points are within a given range without being obstructed.</returns>
public bool InRangeUnobstructed(MapCoordinates coords, Vector2 otherCoords, float range = InteractionRange,
public bool InRangeUnobstructed(MapCoordinates coords, MapCoordinates otherCoords, float range = InteractionRange,
int collisionMask = (int)CollisionGroup.Impassable, IEntity ignoredEnt = null, bool insideBlockerValid = false) =>
InRangeUnobstructed(coords, otherCoords, range, collisionMask,
ignoredEnt == null ? null : (Func<IEntity, bool>)(entity => ignoredEnt == entity), insideBlockerValid);