public Backend.Coords ClosestEnemy(Coords coords, int radius = 4, bool includePlayer = true, bool includeNPC = true, bool includeEnemy = true)
{
for (int distance = 0; distance <= radius; ++distance)
{
for (int x = Math.Max(coords.x - distance, 0); x <= Math.Min(coords.x + distance, _width); ++x)
{
if ((((includePlayer && this[x, coords.y - distance].hasPlayer))
// ||((includeNPC&&this[coords.x-distance,y].hasNPC))
|| ((includeEnemy && this[x, coords.y - distance].hasEnemy)))
&& ((x != coords.x) || (distance != 0)))
{
//System.Diagnostics.Debug.WriteLine(coords.x + "/" + coords.y + "->" + x + "/" + (coords.y - distance).ToString() + " = " + (this[x, coords.y - distance].hasPlayer ? "Player" : "Enemy"));
return new Backend.Coords(x, coords.y - distance);
}
if ((((includePlayer && this[x, coords.y + distance].hasPlayer))
// ||((includeNPC&&this[coords.x-distance,y].hasNPC))
|| ((includeEnemy && this[x, coords.y + distance].hasEnemy)))
&& ((x != coords.x) || (distance != 0)))
{
// System.Diagnostics.Debug.WriteLine(coords.x + "/" + coords.y + "->" + x + "/" + (coords.y + distance).ToString() + " = " + (this[x, coords.y + distance].hasPlayer ? "Player" : "Enemy"));
return new Backend.Coords(x, coords.y + distance);
}
}
for (int y = Math.Max(coords.y - distance, 0); y <= Math.Min(coords.y + distance, _height); ++y)
{
if ((((includePlayer && this[coords.x - distance, y].hasPlayer))
// ||((includeNPC&&this[coords.x-distance,y].hasNPC))
|| ((includeEnemy && this[coords.x - distance, y].hasEnemy)))
&& ((y != coords.y) || (distance != 0)))
{
// System.Diagnostics.Debug.WriteLine(coords.x + "/" + coords.y + "->" + (coords.x - distance) + "/" + y.ToString() + " = " + (this[coords.x - distance, y].hasPlayer ? "Player" : "Enemy"));
return new Backend.Coords(coords.x - distance, y);
}
if ((((includePlayer && this[coords.x + distance, y].hasPlayer))
// ||((includeNPC&&this[coords.x-distance,y].hasNPC))
|| ((includeEnemy && this[coords.x + distance, y].hasEnemy)))
&& ((y != coords.y) || (distance != 0)))
{
// System.Diagnostics.Debug.WriteLine(coords.x + "/" + coords.y + "->" + (coords.x + distance) + "/" + y.ToString() + " = " + (this[coords.x + distance, y].hasPlayer ? "Player" : "Enemy"));
return new Backend.Coords(coords.x + distance, y);
}
}
}
return new Backend.Coords(-1, -1);
}