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 = board.HexSides > 0 ? HexGrid.Distance(attackerPos, targetPos, board.HexSides) : attackerPos.ManhattanDistance(targetPos); if (dist < minRange || dist > maxRange) return false; if (requiresLos && !LineOfSight.HasLos(board, attackerPos, targetPos, unitsByCoord, board.HexSides)) 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) { if (board.HexSides > 0) { foreach (var tile in board.Tiles.Values) { if (CanAttack(attackerPos, tile.Coord, minRange, maxRange, requiresLos, board, unitsByCoord)) yield return tile.Coord; } yield break; } 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; } } }