From 14609428e643ce4beacf8c09d5dbfe42403b2521 Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 23 Mar 2026 12:23:39 -0400 Subject: [PATCH] Fix three bugs blocking SetAffinity on tile targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug 1 — SetAffinityEffect silently ignored for Coord targets: ExecuteEffect had no tile case for SetAffinityEffect (only handled CardInstance). Added case that writes to Base2 and tracks the original value for duration reversal using a "tile:X,Y" target ref. Bug 2 — ApplyReversal couldn't find tile targets: The reversal lookup only searched players' card zones. Added parsing of the "tile:X,Y" ref format to produce the Coord used to re-execute the SetBaseAffinity2 reversal effect. Bug 3 — TileIsOccupied / TileIsUnoccupied / TileAffinityMatches conditions not implemented in EvaluateCondition: All three tile condition types fell through to the default (return true), so conditions like TileIsOccupied were silently no-ops. Implemented all three with proper tile lookup and occupant/affinity checks. Wavecrasher (SetAffinity Lake on occupied tiles, ForNTurns:2) now correctly selects only occupied tiles, changes their affinity, and reverts them automatically after two turns. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../src/SOR.Game/Abilities/AbilitySystem.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 2b279ec..f6c066e 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -992,6 +992,20 @@ public static class AbilitySystem if (tile is not null) tile.Base2 = ResolveAffinity(pfa.Affinity, ctx); break; } + case SetAffinityEffect sa when target is Coord coord: + { + // SetAffinity on a tile overrides Base2 (the dominant slot) and tracks the + // original value for duration-based reversal. + var tile = ctx.State.Board?.GetTile(coord); + if (tile is null) break; + var origBase2 = tile.Base2; + tile.Base2 = ResolveAffinity(sa.Affinity, ctx); + TrackEffect( + new SetBaseAffinity2Effect { Affinity = new AffinityExpr { Fixed = origBase2 } }, + $"tile:{coord.X},{coord.Y}", + duration, ctx); + break; + } // ── §5.7 Zone / card operations ─────────────────────────────────── case DrawCardsEffect dc: @@ -1576,6 +1590,26 @@ public static class AbilitySystem }; } + // ── Tile conditions (§6.3) ─────────────────────────────────────── + case TileIsOccupiedCondition tioc when subject is Coord coord: + { + var tile = ctx.State.Board?.GetTile(coord); + if (tile is null || tile.IsEmpty) return false; + if (tioc.UnitType is null or "Unit") return true; + return FindUnitType(ctx.State, tile.OccupantId!) == tioc.UnitType; + } + case TileIsUnoccupiedCondition when subject is Coord coord: + { + var tile = ctx.State.Board?.GetTile(coord); + return tile is not null && tile.IsEmpty; + } + case TileAffinityMatchesCondition tamc when subject is Coord coord: + { + var tile = ctx.State.Board?.GetTile(coord); + return tile is not null + && AffinitySystem.Resolve(tile.Base1, tile.Base2) == tamc.Affinity; + } + default: return true; } @@ -2031,6 +2065,15 @@ public static class AbilitySystem if (tgt is not null) break; if (p.AccountId == ae.TargetRef) { tgt = p; break; } } + // Tile target: reference format is "tile:X,Y". + if (tgt is null && ae.TargetRef.StartsWith("tile:")) + { + var parts = ae.TargetRef[5..].Split(','); + if (parts.Length == 2 + && int.TryParse(parts[0], out var tx) + && int.TryParse(parts[1], out var ty)) + tgt = new Coord(tx, ty); + } if (tgt is null) return; var src = state.Players.Values