Grid infrastructure (SOR.Game/Grid/): - Coord — immutable (X,Y) struct with Manhattan distance, adjacency, BFS helpers - Tile — mutable affinity slots (Base1/Base2) + occupancy tracking - Board — 8×8 (configurable) grid, PlaceUnit/RemoveUnit/MoveUnit/BuildOccupancyMap - Pathfinding — Walk/Flight BFS (GetReachableWithCost), Jump/Teleport range (GetJumpRange) - LineOfSight — supercover DDA; occupied intermediate tiles block LOS - AffinitySystem — full Resolve table for all 20+ affinities per affinity.md, PushAffinity, ApplyPlacementAffinity, IsAffinityValid (basic vs non-basic rules) Combat (SOR.Game/Combat/): - AttackSystem — Manhattan range + optional LOS validation (§6.10) - SacrificeSystem — exact ST return formula from gameplay.md §6.15 Abilities (SOR.Game/Abilities/): - AbilitySystem stub — future pass per abilities.md Game engine / state changes: - GamePhase: added Placement phase (before Draw) - GameRuleSet + GameRules: added BoardWidth/BoardHeight (default 8×8) - GameState: added Board, PlayerOneAccountId; CardInstance gains MovementType, MaxMp, MinAttackRange, MaxAttackRange, RequiresLos, MinChannelRange, MaxChannelRange, IsLeader (moved from FieldCard); FieldCard adds Position + CurrentMp - [JsonPolymorphic] on CardInstance so FieldCard survives JSONB round-trip - JsonStringEnumConverter added to GameEngine serializer options - GameEngine.Initialize: creates Board + sets Placement phase; no opening draw yet - GameEngine.PlaceArchSpirit: validates row, pushes affinity, triggers opening draw and SP gain when both players placed - GameEngine.ChannelCard (was PlayCard): validates channeling range + affinity for Spirits - GameEngine.MoveUnit: Walk/Flight BFS, Jump (1 MP/landing), Teleport (LOS + 1 MP) - GameEngine.Attack: adds range+LOS validation via AttackSystem - GameEngine.Sacrifice: adjacency + SacrificeSystem ST formula - GameEngine.EndTurn: now also restores MP (§6.0 step 1) for next player - ToDto: includes Board tiles with resolved affinities; CardInstanceDto gets Position, CurrentMp, MaxMp, MovementType New handlers: game.place_arch_spirit, game.move_unit, game.sacrifice Updated handlers: game.play_card (target tile), GameReadyHandler (new Initialize sig) Migration: AddBoardDimensions (board_width/board_height on game_rule_sets) 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>
55 lines
1.7 KiB
C#
55 lines
1.7 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 = attackerPos.ManhattanDistance(targetPos);
|
|
if (dist < minRange || dist > maxRange) return false;
|
|
|
|
if (requiresLos && !LineOfSight.HasLos(board, attackerPos, targetPos, unitsByCoord))
|
|
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)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|