From 200c061dd3bce8ca2173e46f89ff30ce9196e835 Mon Sep 17 00:00:00 2001 From: dingo Date: Tue, 10 Mar 2026 12:47:30 -0400 Subject: [PATCH] Fix: enforce WithinRange/IsAdjacentToSource filters in client targeting UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _highlight_ability_targets was ignoring the target selector's filters array entirely — it showed all ownership-matched units as clickable regardless of spatial constraints. The server correctly rejected out-of-range selections (after the previous fix) but the UI still offered them. Added _unit_passes_filters() and _tile_passes_filters() which evaluate the withinrange and isadjacenttosource filters using Manhattan distance from the ability source unit before adding a tile highlight. Other filters (HasFlag, AffinityMatches, etc.) are left as pass-through for now since they didn't affect visibility in any reported case. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../origin-client/scenes/game/game_screen.gd | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index db6a122..b45127f 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -1313,14 +1313,16 @@ func _highlight_ability_targets(action: Dictionary) -> void: var target_sel : Dictionary = action.get("target", {}) var type_ : String = target_sel.get("type", "Unit") var ownership : String = target_sel.get("ownership", "Any") + var filters : Array = target_sel.get("filters", []) - # Tile target — paint the whole board blue. + # Tile target — paint tiles that pass spatial filters blue. if type_ == "Tile": var bw := Game.board_width() var bh := Game.board_height() for tx in range(bw): for ty in range(bh): - _add_highlight(tx, ty, HI_BLUE) + if _tile_passes_filters(tx, ty, filters): + _add_highlight(tx, ty, HI_BLUE) return # Unit-type target — highlight the board position of each matching unit. @@ -1345,9 +1347,53 @@ func _highlight_ability_targets(action: Dictionary) -> void: for u: Dictionary in targets: var pos : Dictionary = u.get("position", {}) if pos.is_empty(): continue + if not _unit_passes_filters(u, filters): continue _add_highlight(pos.get("x", 0), pos.get("y", 0), HI_BLUE) +## Returns true if the unit passes all client-evaluable filters. +## Spatial filters (withinrange, isadjacenttosource) are checked here so the +## highlight matches what the server will accept. +func _unit_passes_filters(unit: Dictionary, filters: Array) -> bool: + if filters.is_empty(): return true + var src := Game.get_unit_by_id(_ability_unit_id) + var src_pos := src.get("position", {}) + for f: Dictionary in filters: + match f.get("$type", ""): + "withinrange": + if src_pos.is_empty(): return false + var tgt_pos := unit.get("position", {}) + if tgt_pos.is_empty(): return false + var dist := (absi(int(tgt_pos.get("x", 0)) - int(src_pos.get("x", 0))) + + absi(int(tgt_pos.get("y", 0)) - int(src_pos.get("y", 0)))) + if dist < int(f.get("min", 0)) or dist > int(f.get("max", 999)): + return false + "isadjacenttosource": + if src_pos.is_empty(): return false + var tgt_pos := unit.get("position", {}) + if tgt_pos.is_empty(): return false + var dist := (absi(int(tgt_pos.get("x", 0)) - int(src_pos.get("x", 0))) + + absi(int(tgt_pos.get("y", 0)) - int(src_pos.get("y", 0)))) + if dist != 1: return false + return true + + +## Returns true if the tile at (tx, ty) passes all client-evaluable tile filters. +func _tile_passes_filters(tx: int, ty: int, filters: Array) -> bool: + if filters.is_empty(): return true + var src := Game.get_unit_by_id(_ability_unit_id) + var src_pos := src.get("position", {}) + for f: Dictionary in filters: + match f.get("$type", ""): + "tilewithinrange": + if src_pos.is_empty(): return false + var dist := (absi(tx - int(src_pos.get("x", 0))) + + absi(ty - int(src_pos.get("y", 0)))) + if dist < int(f.get("min", 0)) or dist > int(f.get("max", 999)): + return false + return true + + ## Fire the ability request with all collected targets. func _send_ability() -> void: Game.send_activate_ability(_ability_unit_id, _ability_idx, _ability_targets)