Add square grid system, positional combat, sacrifice, and Placement phase

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>
This commit is contained in:
dingo
2026-02-26 11:22:30 -05:00
co-authored by Claude Happy
parent 7ab11e6f46
commit 9b6b7191f0
27 changed files with 1739 additions and 127 deletions
@@ -0,0 +1,296 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SOR.Database.Contexts;
#nullable disable
namespace SOR.Database.Migrations.Game
{
[DbContext(typeof(GameDbContext))]
[Migration("20260226162145_AddBoardDimensions")]
partial class AddBoardDimensions
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("game")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SOR.Database.Entities.Game.CustomLobby", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int?>("DrawPerTurnOverride")
.HasColumnType("integer");
b.Property<bool?>("FirstPlayerSkipsDrawOverride")
.HasColumnType("boolean");
b.Property<Guid?>("GameSessionId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestAccountId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestDeckId")
.HasColumnType("uuid");
b.Property<Guid>("HostAccountId")
.HasColumnType("uuid");
b.Property<Guid>("HostDeckId")
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("OpeningHandSizeOverride")
.HasColumnType("integer");
b.Property<int?>("SpAccumulationPerTurnOverride")
.HasColumnType("integer");
b.Property<int?>("SpCapOverride")
.HasColumnType("integer");
b.Property<bool?>("SpHasCapOverride")
.HasColumnType("boolean");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("HostAccountId");
b.HasIndex("Status", "CreatedAt");
b.ToTable("custom_lobbies", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ActionType")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ActorAccountId")
.HasColumnType("uuid");
b.Property<Guid>("GameSessionId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("OccurredAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("PayloadJson")
.HasColumnType("jsonb")
.HasColumnName("payload");
b.Property<int>("SequenceNumber")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ActorAccountId");
b.HasIndex("GameSessionId", "SequenceNumber")
.IsUnique();
b.ToTable("action_logs", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameRuleSet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("BoardHeight")
.HasColumnType("integer");
b.Property<int>("BoardWidth")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("DrawPerTurn")
.HasColumnType("integer");
b.Property<bool>("FirstPlayerSkipsDraw")
.HasColumnType("boolean");
b.Property<bool>("IsCustomDefault")
.HasColumnType("boolean");
b.Property<bool>("IsRankedDefault")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OpeningHandSize")
.HasColumnType("integer");
b.Property<int>("SpAccumulationPerTurn")
.HasColumnType("integer");
b.Property<int>("SpCap")
.HasColumnType("integer");
b.Property<bool>("SpHasCap")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("IsCustomDefault");
b.HasIndex("IsRankedDefault");
b.ToTable("game_rule_sets", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("EndedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("PlayerOneAccountId")
.HasColumnType("uuid");
b.Property<Guid>("PlayerOneDeckId")
.HasColumnType("uuid");
b.Property<bool>("PlayerOneReady")
.HasColumnType("boolean");
b.Property<Guid>("PlayerTwoAccountId")
.HasColumnType("uuid");
b.Property<Guid>("PlayerTwoDeckId")
.HasColumnType("uuid");
b.Property<bool>("PlayerTwoReady")
.HasColumnType("boolean");
b.Property<string>("RuleSnapshotJson")
.HasColumnType("jsonb")
.HasColumnName("rule_snapshot");
b.Property<DateTimeOffset?>("StartedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("StateJson")
.HasColumnType("jsonb")
.HasColumnName("state");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<string>("WinCondition")
.HasColumnType("text");
b.Property<Guid?>("WinnerAccountId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("PlayerOneAccountId");
b.HasIndex("PlayerTwoAccountId");
b.HasIndex("Status", "CreatedAt");
b.ToTable("game_sessions", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.MatchmakingEntry", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AccountId")
.HasColumnType("uuid");
b.Property<Guid>("DeckId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("JoinedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("MatchedGameSessionId")
.HasColumnType("uuid");
b.Property<int>("RankScore")
.HasColumnType("integer");
b.Property<DateTimeOffset?>("ResolvedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AccountId", "Status");
b.HasIndex("Status", "RankScore");
b.ToTable("matchmaking_entries", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
{
b.HasOne("SOR.Database.Entities.Game.GameSession", "Session")
.WithMany("ActionLog")
.HasForeignKey("GameSessionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Session");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
{
b.Navigation("ActionLog");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,114 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SOR.Database.Migrations.Game
{
/// <inheritdoc />
public partial class AddBoardDimensions : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "rule_snapshot",
schema: "game",
table: "game_sessions",
type: "jsonb",
nullable: true);
migrationBuilder.CreateTable(
name: "custom_lobbies",
schema: "game",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Status = table.Column<string>(type: "text", nullable: false),
HostAccountId = table.Column<Guid>(type: "uuid", nullable: false),
HostDeckId = table.Column<Guid>(type: "uuid", nullable: false),
GuestAccountId = table.Column<Guid>(type: "uuid", nullable: true),
GuestDeckId = table.Column<Guid>(type: "uuid", nullable: true),
GameSessionId = table.Column<Guid>(type: "uuid", nullable: true),
OpeningHandSizeOverride = table.Column<int>(type: "integer", nullable: true),
FirstPlayerSkipsDrawOverride = table.Column<bool>(type: "boolean", nullable: true),
SpAccumulationPerTurnOverride = table.Column<int>(type: "integer", nullable: true),
DrawPerTurnOverride = table.Column<int>(type: "integer", nullable: true),
SpHasCapOverride = table.Column<bool>(type: "boolean", nullable: true),
SpCapOverride = table.Column<int>(type: "integer", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_custom_lobbies", x => x.Id);
});
migrationBuilder.CreateTable(
name: "game_rule_sets",
schema: "game",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
IsRankedDefault = table.Column<bool>(type: "boolean", nullable: false),
IsCustomDefault = table.Column<bool>(type: "boolean", nullable: false),
OpeningHandSize = table.Column<int>(type: "integer", nullable: false),
FirstPlayerSkipsDraw = table.Column<bool>(type: "boolean", nullable: false),
SpAccumulationPerTurn = table.Column<int>(type: "integer", nullable: false),
DrawPerTurn = table.Column<int>(type: "integer", nullable: false),
SpHasCap = table.Column<bool>(type: "boolean", nullable: false),
SpCap = table.Column<int>(type: "integer", nullable: false),
BoardWidth = table.Column<int>(type: "integer", nullable: false),
BoardHeight = table.Column<int>(type: "integer", nullable: false),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_game_rule_sets", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_custom_lobbies_HostAccountId",
schema: "game",
table: "custom_lobbies",
column: "HostAccountId");
migrationBuilder.CreateIndex(
name: "IX_custom_lobbies_Status_CreatedAt",
schema: "game",
table: "custom_lobbies",
columns: new[] { "Status", "CreatedAt" });
migrationBuilder.CreateIndex(
name: "IX_game_rule_sets_IsCustomDefault",
schema: "game",
table: "game_rule_sets",
column: "IsCustomDefault");
migrationBuilder.CreateIndex(
name: "IX_game_rule_sets_IsRankedDefault",
schema: "game",
table: "game_rule_sets",
column: "IsRankedDefault");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "custom_lobbies",
schema: "game");
migrationBuilder.DropTable(
name: "game_rule_sets",
schema: "game");
migrationBuilder.DropColumn(
name: "rule_snapshot",
schema: "game",
table: "game_sessions");
}
}
}
@@ -23,6 +23,65 @@ namespace SOR.Database.Migrations.Game
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SOR.Database.Entities.Game.CustomLobby", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int?>("DrawPerTurnOverride")
.HasColumnType("integer");
b.Property<bool?>("FirstPlayerSkipsDrawOverride")
.HasColumnType("boolean");
b.Property<Guid?>("GameSessionId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestAccountId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestDeckId")
.HasColumnType("uuid");
b.Property<Guid>("HostAccountId")
.HasColumnType("uuid");
b.Property<Guid>("HostDeckId")
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("OpeningHandSizeOverride")
.HasColumnType("integer");
b.Property<int?>("SpAccumulationPerTurnOverride")
.HasColumnType("integer");
b.Property<int?>("SpCapOverride")
.HasColumnType("integer");
b.Property<bool?>("SpHasCapOverride")
.HasColumnType("boolean");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("HostAccountId");
b.HasIndex("Status", "CreatedAt");
b.ToTable("custom_lobbies", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
{
b.Property<Guid>("Id")
@@ -59,6 +118,61 @@ namespace SOR.Database.Migrations.Game
b.ToTable("action_logs", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameRuleSet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("BoardHeight")
.HasColumnType("integer");
b.Property<int>("BoardWidth")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("DrawPerTurn")
.HasColumnType("integer");
b.Property<bool>("FirstPlayerSkipsDraw")
.HasColumnType("boolean");
b.Property<bool>("IsCustomDefault")
.HasColumnType("boolean");
b.Property<bool>("IsRankedDefault")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OpeningHandSize")
.HasColumnType("integer");
b.Property<int>("SpAccumulationPerTurn")
.HasColumnType("integer");
b.Property<int>("SpCap")
.HasColumnType("integer");
b.Property<bool>("SpHasCap")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("IsCustomDefault");
b.HasIndex("IsRankedDefault");
b.ToTable("game_rule_sets", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
{
b.Property<Guid>("Id")
@@ -89,6 +203,10 @@ namespace SOR.Database.Migrations.Game
b.Property<bool>("PlayerTwoReady")
.HasColumnType("boolean");
b.Property<string>("RuleSnapshotJson")
.HasColumnType("jsonb")
.HasColumnName("rule_snapshot");
b.Property<DateTimeOffset?>("StartedAt")
.HasColumnType("timestamp with time zone");