Files
sor/Server/src/SOR.Game/Combat/AttackSystem.cs
T
2cfa60c7dd Add hex grid support (sides 3–10) for boards, pathfinding, LOS, and client rendering
- New HexGrid.cs: axial coord helpers, BFS neighbors, cube-lerp LOS, jump-range
- Board: HexSides property, GetNeighbors() dispatches hex/square, IsInBounds() hex-aware
- BoardShapeGenerator: MakeHexagon() with edge-based starting zones (2–6 players);
  FromTemplate() now carries HexSides through to the Board
- Pathfinding: Walk/Flight BFS uses board.GetNeighbors() (hex+square unified)
- LineOfSight: delegates to HexGrid.HasLos when hexSides > 0
- GameRules/GameRuleSet/BoardTemplate/BoardTemplateSnapshot: GridType + HexSides fields
- GameMessages BoardDto: GridType + HexSides sent to client
- GameEngine: PlaceArchSpirit range uses HexGrid.Distance on hex boards;
  Teleport LOS passes board.HexSides; ToBoardDto emits GridType/HexSides
- EF migration 20260401000000_AddHexGridSupport: grid_type + hex_sides columns on
  game_rule_sets and board_templates; applied to pg-forge-01
- Client game_screen.gd: hex coord→world (pointy-top flat layout), CylinderMesh
  tiles (radial_segments=6), _board_distance cube metric, _bfs_reachable 6-dir,
  _client_has_los cube-lerp, highlight mesh for hex tiles; reads gridType/hexSides
  from BoardDto

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-04-01 16:44:17 -04:00

67 lines
2.1 KiB
C#

namespace SOR.Game.Combat;
using SOR.Game.Grid;
/// <summary>
/// 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.
/// </summary>
public static class AttackSystem
{
/// <summary>
/// Returns true if the attacker can legally target the given position.
/// </summary>
public static bool CanAttack(
Coord attackerPos,
Coord targetPos,
int minRange,
int maxRange,
bool requiresLos,
Board board,
IReadOnlyDictionary<Coord, string> 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;
}
/// <summary>
/// Enumerate all in-bounds tiles the attacker can target from its current position.
/// </summary>
public static IEnumerable<Coord> GetAttackableCoords(
Board board,
Coord attackerPos,
int minRange,
int maxRange,
bool requiresLos,
IReadOnlyDictionary<Coord, string> 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;
}
}
}