diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 4618420..2ec8fa4 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -2434,80 +2434,138 @@ func _terra_count_for_card(card: Dictionary) -> int: return 1 -func _valid_move_tiles(unit: Dictionary) -> Array: +## BFS reachable set — returns all coords reachable within max_mp steps, +## treating blocked_coords as impassable walls (destination included in check). +## Mirrors Pathfinding.GetReachableWithCost on the server. +func _bfs_reachable(fx: int, fy: int, max_mp: int, blocked_coords: Dictionary) -> Array: + var bw := Game.board_width() + var bh := Game.board_height() + var DIRS : Array[Vector2i] = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1)] + var cost : Dictionary = { Vector2i(fx, fy): 0 } + var queue : Array = [Vector2i(fx, fy)] + while not queue.is_empty(): + var cur : Vector2i = queue.pop_front() + var cur_cost : int = cost[cur] + if cur_cost >= max_mp: continue + for d : Vector2i in DIRS: + var nxt := cur + d + if nxt.x < 0 or nxt.x >= bw or nxt.y < 0 or nxt.y >= bh: continue + if not _tile_bodies.has("%d,%d" % [nxt.x, nxt.y]): continue + if cost.has(nxt): continue + if blocked_coords.has(nxt): continue + cost[nxt] = cur_cost + 1 + queue.append(nxt) var results : Array = [] + for coord in cost.keys(): + if coord != Vector2i(fx, fy): + results.append(coord) + return results + + +func _valid_move_tiles(unit: Dictionary) -> Array: var pos : Dictionary = unit.get("position", {}) - if pos.is_empty(): return results - var ux : int = pos.get("x", 0) - var uy : int = pos.get("y", 0) - var mp : int = unit.get("currentMp", 0) + if pos.is_empty(): return [] + var ux : int = pos.get("x", 0) + var uy : int = pos.get("y", 0) + var mp : int = unit.get("currentMp", 0) + var mov : String = str(unit.get("movementType", "Walk")).to_lower() + if mp <= 0: return [] + var bw : int = Game.board_width() var bh : int = Game.board_height() - if mp <= 0: return results + + # Walk / Flight: BFS — can't pass through blocked tiles + if mov == "walk" or mov == "flight": + # Build blocked set from all occupants, excluding this unit. + var blocked : Dictionary = {} + for unit_dict : Dictionary in Game.get_field(): + var up : Dictionary = unit_dict.get("position", {}) + if up.is_empty(): continue + var cx : int = up.get("x", 0) + var cy : int = up.get("y", 0) + if cx == ux and cy == uy: continue # don't block own tile + # Flight is only blocked by other Flight units; Walk is blocked by all. + if mov == "flight": + if str(unit_dict.get("movementType", "Walk")).to_lower() != "flight": + continue + blocked[Vector2i(cx, cy)] = true + return _bfs_reachable(ux, uy, mp, blocked) + + # Jump / Teleport: Manhattan range, land on any unoccupied tile. + var results : Array = [] for tx in range(bw): for ty in range(bh): if not _tile_bodies.has("%d,%d" % [tx, ty]): continue var dist : int = abs(tx - ux) + abs(ty - uy) if dist == 0 or dist > mp: continue if Game.get_tile(tx, ty).get("occupantId"): continue + # Teleport additionally requires LOS to the destination. + if mov == "teleport" and not _client_has_los(ux, uy, tx, ty): continue results.append(Vector2i(tx, ty)) return results func _valid_attack_target_coords(unit: Dictionary) -> Array: - var results : Array = [] - var pos : Dictionary = unit.get("position", {}) + var results : Array = [] + var pos : Dictionary = unit.get("position", {}) if pos.is_empty(): return results - var ux : int = pos.get("x", 0) - var uy : int = pos.get("y", 0) - var min_r : int = unit.get("minAttackRange", 1) - var max_r : int = unit.get("maxAttackRange", 1) + var ux : int = pos.get("x", 0) + var uy : int = pos.get("y", 0) + var min_r : int = unit.get("minAttackRange", 1) + var max_r : int = unit.get("maxAttackRange", 1) + var needs_los : bool = bool(unit.get("attackRequiresLos", false)) if unit.get("isExhausted", false) and unit.get("extraAttacksRemaining", 0) == 0: return results - var to_check : Array = Game.get_all_enemy_units() - for t: Dictionary in to_check: + for t: Dictionary in Game.get_all_enemy_units(): if not t.get("canBeAttacked", true): continue var _tpos = t.get("position") - if not (_tpos is Dictionary): continue # null when unit removed from board + if not (_tpos is Dictionary): continue var tp : Dictionary = _tpos if tp.is_empty(): continue - var dist : int = abs(tp.get("x", 0) - ux) + abs(tp.get("y", 0) - uy) - if dist >= min_r and dist <= max_r: - results.append(tp) + var tx : int = tp.get("x", 0) + var ty : int = tp.get("y", 0) + var dist : int = abs(tx - ux) + abs(ty - uy) + if dist < min_r or dist > max_r: continue + if needs_los and not _client_has_los(ux, uy, tx, ty): continue + results.append(tp) return results func _valid_attack_target_ids(unit: Dictionary) -> Array: - var results : Array = [] - var pos : Dictionary = unit.get("position", {}) + var results : Array = [] + var pos : Dictionary = unit.get("position", {}) if pos.is_empty(): return results - var ux : int = pos.get("x", 0) - var uy : int = pos.get("y", 0) - var min_r : int = unit.get("minAttackRange", 1) - var max_r : int = unit.get("maxAttackRange", 1) + var ux : int = pos.get("x", 0) + var uy : int = pos.get("y", 0) + var min_r : int = unit.get("minAttackRange", 1) + var max_r : int = unit.get("maxAttackRange", 1) + var needs_los : bool = bool(unit.get("attackRequiresLos", false)) if unit.get("isExhausted", false) and unit.get("extraAttacksRemaining", 0) == 0: return results - var to_check : Array = Game.get_all_enemy_units() - for t: Dictionary in to_check: + for t: Dictionary in Game.get_all_enemy_units(): if not t.get("canBeAttacked", true): continue var tp : Dictionary = t.get("position", {}) if tp.is_empty(): continue - var dist : int = abs(tp.get("x", 0) - ux) + abs(tp.get("y", 0) - uy) - if dist >= min_r and dist <= max_r: - results.append(t.get("instanceId", "")) + var tx : int = tp.get("x", 0) + var ty : int = tp.get("y", 0) + var dist : int = abs(tx - ux) + abs(ty - uy) + if dist < min_r or dist > max_r: continue + if needs_los and not _client_has_los(ux, uy, tx, ty): continue + results.append(t.get("instanceId", "")) return results ## All tiles within a unit's attack range (regardless of occupancy). ## Used to show the orange reach area for ranged units. func _attack_range_tiles(unit: Dictionary) -> Array: - var results : Array = [] - var pos : Dictionary = unit.get("position", {}) + var results : Array = [] + var pos : Dictionary = unit.get("position", {}) if pos.is_empty(): return results - var ux : int = pos.get("x", 0) - var uy : int = pos.get("y", 0) - var min_r : int = unit.get("minAttackRange", 1) - var max_r : int = unit.get("maxAttackRange", 1) + var ux : int = pos.get("x", 0) + var uy : int = pos.get("y", 0) + var min_r : int = unit.get("minAttackRange", 1) + var max_r : int = unit.get("maxAttackRange", 1) + var needs_los : bool = bool(unit.get("attackRequiresLos", false)) if max_r <= 1: return results # skip melee — no separate range indicator needed var bw : int = Game.board_width() var bh : int = Game.board_height() @@ -2515,8 +2573,9 @@ func _attack_range_tiles(unit: Dictionary) -> Array: for ty in range(bh): if not _tile_bodies.has("%d,%d" % [tx, ty]): continue var dist : int = abs(tx - ux) + abs(ty - uy) - if dist >= min_r and dist <= max_r: - results.append(Vector2i(tx, ty)) + if dist < min_r or dist > max_r: continue + if needs_los and not _client_has_los(ux, uy, tx, ty): continue + results.append(Vector2i(tx, ty)) return results diff --git a/Server/src/SOR.Game/GameEngine.cs b/Server/src/SOR.Game/GameEngine.cs index 9d65720..c30b498 100644 --- a/Server/src/SOR.Game/GameEngine.cs +++ b/Server/src/SOR.Game/GameEngine.cs @@ -1473,6 +1473,7 @@ public static class GameEngine MaxAttackRange : c.MaxAttackRange, CanMove : c.CanMove, CanAttack : c.CanAttack, + AttackRequiresLos : c.RequiresLos, ExtraAttacksRemaining : c.ExtraAttacksRemaining, CanBeAttacked : c.CanBeAttacked, AbilitiesJson : c.AbilitiesJson, diff --git a/Server/src/SOR.Game/GameMessages.cs b/Server/src/SOR.Game/GameMessages.cs index 2fc777d..bf872a1 100644 --- a/Server/src/SOR.Game/GameMessages.cs +++ b/Server/src/SOR.Game/GameMessages.cs @@ -638,6 +638,7 @@ public sealed record CardInstanceDto( int? MaxAttackRange, bool CanMove, bool CanAttack, + bool AttackRequiresLos, int ExtraAttacksRemaining, bool CanBeAttacked, string? AbilitiesJson,