Fix Battlefield tile targeting and SetAffinity on tiles

Bug: Battlefield/All tile targets were always empty — the tile
resolution path required client-provided coords for every case,
but board-wide abilities (Scope=Battlefield, All=true) never send
coords from the client. Added server-side enumeration of all board
tiles for this case.

Fix: SetAffinity on a tile now writes both Base1 and Base2 to
the new affinity so AffinitySystem.Resolve returns the correct
value unambiguously. Reversal tracks both slots independently so
both are restored when the duration expires.

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-03-23 12:33:03 -04:00
co-authored by Claude Happy
parent 14609428e6
commit a768f1b27c
+24 -7
View File
@@ -497,6 +497,19 @@ public static class AbilitySystem
if (selector.Type == TargetType.Tile)
{
// Battlefield scope with All=true: enumerate every board tile server-side.
// The client does not (and should not) send coords for board-wide tile effects.
if (selector.Scope == TargetScope.Battlefield && selector.Count.All
&& ctx.State.Board is { } board)
{
var allTiles = board.Tiles.Values
.Select(t => (object)t.Coord)
.ToList();
if (activationRange is not null)
allTiles = FilterTargetsByAbilityRange(allTiles, ctx, activationRange);
return allTiles;
}
if (clientTargets is null) return [];
var tiles = clientTargets
.Where(t => t.ActionIndex == actionIndex && t.Coord is not null)
@@ -994,16 +1007,20 @@ public static class AbilitySystem
}
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.
// SetAffinity on a tile writes both slots so the resolved affinity is unambiguous,
// and tracks a reversal for each slot so both are restored when the duration expires.
var tile = ctx.State.Board?.GetTile(coord);
if (tile is null) break;
var origBase1 = tile.Base1;
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);
var newAff = ResolveAffinity(sa.Affinity, ctx);
tile.Base1 = newAff;
tile.Base2 = newAff;
var tileRef = $"tile:{coord.X},{coord.Y}";
TrackEffect(new SetBaseAffinity1Effect { Affinity = new AffinityExpr { Fixed = origBase1 } },
tileRef, duration, ctx);
TrackEffect(new SetBaseAffinity2Effect { Affinity = new AffinityExpr { Fixed = origBase2 } },
tileRef, duration, ctx);
break;
}