Fix SummonToken tile-filter validation: reject bad picks before costs are paid

Three bugs fixed for abilities like Demonate Leviathan (SummonToken + TileFilter):

1. Server: AbilityUsesThisTurn was incremented (and costs paid) before effect-level
   TileFilter validation ran. Added PreValidateClientTileTargets() called before the
   use-count increment so an invalid tile pick wastes no uses and no sacrificed tokens.

2. Server: SummonToken silently break'd when TileFilter or token-affinity check failed,
   giving the client no error. Changed both to throw GameException("INVALID_TILE").

3. Client: tile_passes_filters() only checked the target selector's filters, not the
   effect-level TileFilter (e.g. SummonToken.tileFilter). Added _collect_effect_tile_filters()
   and TileAffinityMatches handling so invalid tiles are never highlighted or accepted.

Also includes: Art2dUrl/ModelUrl deltas in GameStateDiffer/GameMessages/GameEngine,
unit_mesh_builder token-model URL fallback + shader/tint helpers, ModelCache v3 bump,
Game.gd unit delta merging for art2dUrl/modelUrl.

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-05-12 07:06:54 -04:00
co-authored by Claude Happy
parent 3bbf419836
commit f3e5363c13
10 changed files with 210 additions and 37 deletions
@@ -297,6 +297,9 @@ func highlight_ability_targets(action: Dictionary) -> void:
# Tile target.
if type_ == "Tile":
# Gather effect-level tile filters (e.g. SummonToken.tileFilter) in addition to
# the target selector's filters so invalid tiles are never highlighted.
var effect_tile_filters: Array = _collect_effect_tile_filters(action)
var bw: int = Game.board_width()
var bh: int = Game.board_height()
for tx: int in range(bw):
@@ -308,8 +311,11 @@ func highlight_ability_targets(action: Dictionary) -> void:
continue
if requires_los and pathfinder != null and not pathfinder.client_has_los(sx, sy, tx, ty):
continue
if tile_passes_filters(tx, ty, filters):
emit_signal("highlight_add_requested", tx, ty, "ability")
if not tile_passes_filters(tx, ty, filters):
continue
if not tile_passes_filters(tx, ty, effect_tile_filters):
continue
emit_signal("highlight_add_requested", tx, ty, "ability")
return
# Unit-type target.
@@ -370,7 +376,10 @@ func is_valid_board_target(coord: Vector2i, unit_id: String) -> bool:
var filters: Array = filters_v as Array if filters_v is Array else []
if type_ == "Tile":
return coord.x >= 0 and tile_passes_filters(coord.x, coord.y, filters) \
var effect_tile_filters: Array = _collect_effect_tile_filters(action)
return coord.x >= 0 \
and tile_passes_filters(coord.x, coord.y, filters) \
and tile_passes_filters(coord.x, coord.y, effect_tile_filters) \
and _target_coord_passes_range(coord)
if unit_id.is_empty():
@@ -471,6 +480,19 @@ func unit_passes_filters(unit: Dictionary, filters: Array) -> bool:
return true
## Collects all effect-level tile filters from a single action's effects array.
## Currently supports SummonToken.tileFilter.
func _collect_effect_tile_filters(action: Dictionary) -> Array:
var result: Array = []
var effects_v: Variant = action.get("effects", [])
var effects: Array = effects_v as Array if effects_v is Array else []
for fx: Dictionary in effects:
var tile_filter_v: Variant = fx.get("tilefilter", [])
var tile_filter: Array = tile_filter_v as Array if tile_filter_v is Array else []
result.append_array(tile_filter)
return result
func tile_passes_filters(tx: int, ty: int, filters: Array) -> bool:
if filters.is_empty():
return true
@@ -486,6 +508,10 @@ func tile_passes_filters(tx: int, ty: int, filters: Array) -> bool:
int(src_pos.get("x", 0)), int(src_pos.get("y", 0)))
if dist < int(f.get("min", 0)) or dist > int(f.get("max", 999)):
return false
"tileaffinitymatches":
var tile: Dictionary = Game.get_tile(tx, ty)
if tile.get("affinity", "") != f.get("affinity", ""):
return false
return true