namespace SOR.Game.Combat;
using SOR.Game.Grid;
///
/// Attack range and line-of-sight validation for Spirit/ArchSpirit attacks (ยง6.10).
///
/// Range uses Manhattan distance on the square grid.
/// LOS is required only when the attacker's RequiresLos flag is set.
///
public static class AttackSystem
{
///
/// Returns true if the attacker can legally target the given position.
///
public static bool CanAttack(
Coord attackerPos,
Coord targetPos,
int minRange,
int maxRange,
bool requiresLos,
Board board,
IReadOnlyDictionary unitsByCoord)
{
var dist = attackerPos.ManhattanDistance(targetPos);
if (dist < minRange || dist > maxRange) return false;
if (requiresLos && !LineOfSight.HasLos(board, attackerPos, targetPos, unitsByCoord))
return false;
return true;
}
///
/// Enumerate all in-bounds tiles the attacker can target from its current position.
///
public static IEnumerable GetAttackableCoords(
Board board,
Coord attackerPos,
int minRange,
int maxRange,
bool requiresLos,
IReadOnlyDictionary unitsByCoord)
{
for (int dy = -maxRange; dy <= maxRange; dy++)
for (int dx = -maxRange; dx <= maxRange; dx++)
{
var target = new Coord(attackerPos.X + dx, attackerPos.Y + dy);
if (!board.IsInBounds(target)) continue;
if (CanAttack(attackerPos, target, minRange, maxRange, requiresLos, board, unitsByCoord))
yield return target;
}
}
}