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)