|
|
|
@@ -140,11 +140,16 @@ var _ability_unit_id : String = ""
|
|
|
|
|
var _ability_idx : int = -1
|
|
|
|
|
var _ability_panel : Control = null
|
|
|
|
|
var _ability_def : Array = [] # Actions array from parsed ability JSON
|
|
|
|
|
var _ability_range : Dictionary = {} # Top-level range {min, max} from ability definition
|
|
|
|
|
var _ability_range : Dictionary = {} # Top-level range {min, max, linearonly, requireslos}
|
|
|
|
|
var _ability_targets : Array = [] # collected AbilityTarget dicts to send
|
|
|
|
|
var _ability_cur_action_idx : int = 0 # which Action we are currently collecting for
|
|
|
|
|
var _ability_card_id : String = "" # non-empty when targeting for a card's active ability
|
|
|
|
|
var _ability_target_conditions: Array = [] # target-side ActivationConditions from card ability
|
|
|
|
|
var _ability_target_n : int = 1 # count.N for current action
|
|
|
|
|
var _ability_target_up_to : bool = false # count.upTo for current action
|
|
|
|
|
var _ability_targets_this_action : int = 0 # targets collected for current action so far
|
|
|
|
|
var _ability_confirm_btn : Control = null # "Done" button shown for UpTo selections
|
|
|
|
|
var _ability_branch_panel : Control = null # ChooseOne branch selector panel
|
|
|
|
|
var _player_panel : Control = null
|
|
|
|
|
|
|
|
|
|
# ── Unit ownership lookup ─────────────────────────────────────────────────────
|
|
|
|
@@ -2431,23 +2436,30 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
|
|
|
|
|
_confirm_sacrifice(unit_id, unit.get("name", "this spirit"))
|
|
|
|
|
|
|
|
|
|
Mode.ABILITY_TARGET:
|
|
|
|
|
# Collect the clicked board target then advance the targeting flow.
|
|
|
|
|
# Collect the clicked board target; advance only when N targets have been gathered.
|
|
|
|
|
var _collected := false
|
|
|
|
|
if not unit_id.is_empty():
|
|
|
|
|
_ability_targets.append({
|
|
|
|
|
"actionIndex": _ability_cur_action_idx,
|
|
|
|
|
"instanceId": unit_id
|
|
|
|
|
})
|
|
|
|
|
_ability_cur_action_idx += 1
|
|
|
|
|
_advance_ability_targeting()
|
|
|
|
|
_ability_targets_this_action += 1
|
|
|
|
|
_collected = true
|
|
|
|
|
elif coord.x >= 0:
|
|
|
|
|
_ability_targets.append({
|
|
|
|
|
"actionIndex": _ability_cur_action_idx,
|
|
|
|
|
"coord": { "x": coord.x, "y": coord.y }
|
|
|
|
|
})
|
|
|
|
|
_ability_targets_this_action += 1
|
|
|
|
|
_collected = true
|
|
|
|
|
|
|
|
|
|
if not _collected:
|
|
|
|
|
_set_mode(Mode.NONE)
|
|
|
|
|
elif _ability_targets_this_action >= _ability_target_n:
|
|
|
|
|
# All required targets for this action collected — advance.
|
|
|
|
|
_ability_cur_action_idx += 1
|
|
|
|
|
_advance_ability_targeting()
|
|
|
|
|
else:
|
|
|
|
|
_set_mode(Mode.NONE)
|
|
|
|
|
# else: more targets needed (or UpTo: confirm button lets player finish early)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _select_unit(unit_id: String) -> void:
|
|
|
|
@@ -2505,6 +2517,11 @@ func _set_mode(new_mode: Mode) -> void:
|
|
|
|
|
_ability_cur_action_idx = 0
|
|
|
|
|
_ability_card_id = ""
|
|
|
|
|
_ability_target_conditions = []
|
|
|
|
|
_ability_target_n = 1
|
|
|
|
|
_ability_target_up_to = false
|
|
|
|
|
_ability_targets_this_action = 0
|
|
|
|
|
_hide_ability_confirm_btn()
|
|
|
|
|
_hide_branch_panel()
|
|
|
|
|
_clear_highlights()
|
|
|
|
|
_hide_ability_panel()
|
|
|
|
|
_hide_player_panel()
|
|
|
|
@@ -2769,12 +2786,24 @@ func _start_ability_targeting() -> void:
|
|
|
|
|
if _ability_def[_ability_cur_action_idx] is Dictionary:
|
|
|
|
|
action = _ability_def[_ability_cur_action_idx] as Dictionary
|
|
|
|
|
|
|
|
|
|
# ChooseOne — present branch buttons; no board highlights needed.
|
|
|
|
|
if action.has("chooseone"):
|
|
|
|
|
_set_mode(Mode.ABILITY_TARGET)
|
|
|
|
|
_clear_highlights()
|
|
|
|
|
_show_branch_panel(action)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
var target_sel : Dictionary = action.get("target", {})
|
|
|
|
|
var scope : String = target_sel.get("scope", "Battlefield")
|
|
|
|
|
var ownership : String = target_sel.get("ownership", "Any")
|
|
|
|
|
var count_dict : Dictionary = target_sel.get("count", {})
|
|
|
|
|
var count_all : bool = count_dict.get("all", false)
|
|
|
|
|
|
|
|
|
|
# Read target count for this action (used by the input handler for multi-target collection).
|
|
|
|
|
_ability_target_n = maxi(1, int(count_dict.get("n", 1)))
|
|
|
|
|
_ability_target_up_to = bool(count_dict.get("upto", false))
|
|
|
|
|
_ability_targets_this_action = 0
|
|
|
|
|
|
|
|
|
|
# Actions auto-resolved by the server need no player input.
|
|
|
|
|
# "Target" means "owner of the last targeted card" — resolved server-side from ctx.ResolvedTargets.
|
|
|
|
|
var auto_ownerships := ["Self", "ExactSelf", "Random", "Target"]
|
|
|
|
@@ -2796,11 +2825,18 @@ func _start_ability_targeting() -> void:
|
|
|
|
|
_clear_highlights()
|
|
|
|
|
_highlight_ability_targets(action)
|
|
|
|
|
|
|
|
|
|
# When the player may select fewer than N targets, show a confirm button.
|
|
|
|
|
if _ability_target_up_to and _ability_target_n > 1:
|
|
|
|
|
_show_ability_confirm_btn()
|
|
|
|
|
|
|
|
|
|
## Called after each target is collected; advances to the next action or sends.
|
|
|
|
|
|
|
|
|
|
## Called after each target (or set of targets) is collected; advances to the next action or sends.
|
|
|
|
|
func _advance_ability_targeting() -> void:
|
|
|
|
|
_hide_ability_confirm_btn()
|
|
|
|
|
_hide_branch_panel()
|
|
|
|
|
_hide_player_panel()
|
|
|
|
|
_clear_highlights()
|
|
|
|
|
_ability_targets_this_action = 0
|
|
|
|
|
_start_ability_targeting()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2812,16 +2848,29 @@ func _highlight_ability_targets(action: Dictionary) -> void:
|
|
|
|
|
var ownership : String = target_sel.get("ownership", "Any")
|
|
|
|
|
var filters : Array = target_sel.get("filters", [])
|
|
|
|
|
|
|
|
|
|
# Tile target — paint tiles that pass spatial filters blue.
|
|
|
|
|
var linear_only : bool = _ability_range.get("linearonly", false)
|
|
|
|
|
var requires_los : bool = _ability_range.get("requireslos", false)
|
|
|
|
|
|
|
|
|
|
# Source position — needed for range, linear, and LOS checks.
|
|
|
|
|
var src_pos_ab : Dictionary = {}
|
|
|
|
|
if not _ability_range.is_empty() or linear_only or requires_los:
|
|
|
|
|
src_pos_ab = Game.get_unit_by_id(_ability_unit_id).get("position", {})
|
|
|
|
|
|
|
|
|
|
# Tile target — paint tiles that pass spatial and range/LOS 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):
|
|
|
|
|
if not src_pos_ab.is_empty():
|
|
|
|
|
var sx := int(src_pos_ab.get("x", 0))
|
|
|
|
|
var sy := int(src_pos_ab.get("y", 0))
|
|
|
|
|
if linear_only and not _is_linear(sx, sy, tx, ty): continue
|
|
|
|
|
if requires_los and not _client_has_los(sx, sy, tx, ty): continue
|
|
|
|
|
if _tile_passes_filters(tx, ty, filters):
|
|
|
|
|
_add_highlight(tx, ty, "ability")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Unit-type target — highlight the board position of each matching unit.
|
|
|
|
|
var include_enemy : bool = ownership in ["Enemy", "Any"]
|
|
|
|
|
var include_friendly : bool = ownership in ["Owner", "Ally", "Any"]
|
|
|
|
@@ -2838,10 +2887,6 @@ func _highlight_ability_targets(action: Dictionary) -> void:
|
|
|
|
|
if not my_arch.is_empty():
|
|
|
|
|
targets.append(my_arch)
|
|
|
|
|
|
|
|
|
|
var src_pos_ab : Dictionary = {}
|
|
|
|
|
if not _ability_range.is_empty():
|
|
|
|
|
src_pos_ab = Game.get_unit_by_id(_ability_unit_id).get("position", {})
|
|
|
|
|
|
|
|
|
|
for u: Dictionary in targets:
|
|
|
|
|
if type_ == "Spirit" || type_ == "ArchSpirit" || type_ == "SpiritToken" || type_ == "Ruin":
|
|
|
|
|
if u.get("cardType", "").to_lower() != type_.to_lower() : continue
|
|
|
|
@@ -2854,6 +2899,12 @@ func _highlight_ability_targets(action: Dictionary) -> void:
|
|
|
|
|
absi(int(pos.get("y", 0)) - int(src_pos_ab.get("y", 0))))
|
|
|
|
|
if dist < int(_ability_range.get("min", 0)) or dist > int(_ability_range.get("max", 999)):
|
|
|
|
|
continue
|
|
|
|
|
# Linear and LOS checks — applied independently of the distance range check.
|
|
|
|
|
if not src_pos_ab.is_empty():
|
|
|
|
|
var ux := int(pos.get("x", 0)); var uy := int(pos.get("y", 0))
|
|
|
|
|
var sx := int(src_pos_ab.get("x", 0)); var sy := int(src_pos_ab.get("y", 0))
|
|
|
|
|
if linear_only and not _is_linear(sx, sy, ux, uy): continue
|
|
|
|
|
if requires_los and not _client_has_los(sx, sy, ux, uy): continue
|
|
|
|
|
_add_highlight(pos.get("x", 0), pos.get("y", 0), "ability")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -2909,6 +2960,108 @@ func _tile_passes_filters(tx: int, ty: int, filters: Array) -> bool:
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Returns true if (tx, ty) lies on the same row, column, or diagonal as (sx, sy).
|
|
|
|
|
## Matches the server's AbilityRange.LinearOnly validation.
|
|
|
|
|
func _is_linear(sx: int, sy: int, tx: int, ty: int) -> bool:
|
|
|
|
|
return sx == tx or sy == ty or absi(tx - sx) == absi(ty - sy)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Returns true if there is an unobstructed line of sight from (sx, sy) to (tx, ty).
|
|
|
|
|
## Uses the same supercover DDA algorithm as the server's LineOfSight.HasLos.
|
|
|
|
|
## Any unit occupying an intermediate tile blocks LOS (source and destination excluded).
|
|
|
|
|
func _client_has_los(sx: int, sy: int, tx: int, ty: int) -> bool:
|
|
|
|
|
if sx == tx and sy == ty: return true
|
|
|
|
|
var dx := tx - sx; var dy := ty - sy
|
|
|
|
|
var nx := absi(dx); var ny := absi(dy)
|
|
|
|
|
var sign_x := 1 if dx > 0 else -1
|
|
|
|
|
var sign_y := 1 if dy > 0 else -1
|
|
|
|
|
var ix := 0; var iy := 0
|
|
|
|
|
var cx := sx; var cy := sy
|
|
|
|
|
while ix < nx or iy < ny:
|
|
|
|
|
var t_x := (float(ix) + 0.5) / nx if nx > 0 else 1e9
|
|
|
|
|
var t_y := (float(iy) + 0.5) / ny if ny > 0 else 1e9
|
|
|
|
|
if t_x < t_y:
|
|
|
|
|
cx += sign_x; ix += 1
|
|
|
|
|
else:
|
|
|
|
|
cy += sign_y; iy += 1
|
|
|
|
|
if cx == tx and cy == ty: break
|
|
|
|
|
var tile := Game.get_tile(cx, cy)
|
|
|
|
|
if not tile.is_empty() and str(tile.get("occupantId", "")) != "":
|
|
|
|
|
return false
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Show a "Done" button so the player can finish an UpTo selection with fewer than N targets.
|
|
|
|
|
func _show_ability_confirm_btn() -> void:
|
|
|
|
|
_hide_ability_confirm_btn()
|
|
|
|
|
var btn := Button.new()
|
|
|
|
|
btn.text = "Done Selecting"
|
|
|
|
|
btn.add_theme_font_size_override("font_size", 12)
|
|
|
|
|
btn.modulate = Color(0.4, 1.0, 0.5)
|
|
|
|
|
btn.position = Vector2(8, 330)
|
|
|
|
|
btn.size = Vector2(150, 30)
|
|
|
|
|
btn.pressed.connect(func():
|
|
|
|
|
_hide_ability_confirm_btn()
|
|
|
|
|
_ability_cur_action_idx += 1
|
|
|
|
|
_advance_ability_targeting())
|
|
|
|
|
_hud.add_child(btn)
|
|
|
|
|
_ability_confirm_btn = btn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _hide_ability_confirm_btn() -> void:
|
|
|
|
|
if is_instance_valid(_ability_confirm_btn):
|
|
|
|
|
_ability_confirm_btn.queue_free()
|
|
|
|
|
_ability_confirm_btn = null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Show a panel of labelled branch buttons for a ChooseOne action.
|
|
|
|
|
func _show_branch_panel(action: Dictionary) -> void:
|
|
|
|
|
_hide_branch_panel()
|
|
|
|
|
var co : Dictionary = action.get("chooseone", {})
|
|
|
|
|
var branches : Array = co.get("branches", [])
|
|
|
|
|
if branches.is_empty(): return
|
|
|
|
|
|
|
|
|
|
var panel := PanelContainer.new()
|
|
|
|
|
panel.position = Vector2(8, 120)
|
|
|
|
|
var vbox := VBoxContainer.new()
|
|
|
|
|
vbox.add_theme_constant_override("separation", 8)
|
|
|
|
|
vbox.custom_minimum_size = Vector2(190, 0)
|
|
|
|
|
|
|
|
|
|
var title := Label.new()
|
|
|
|
|
title.text = "Choose One:"
|
|
|
|
|
title.add_theme_font_size_override("font_size", 13)
|
|
|
|
|
title.add_theme_color_override("font_color", Color(1.0, 0.9, 0.3))
|
|
|
|
|
vbox.add_child(title)
|
|
|
|
|
vbox.add_child(HSeparator.new())
|
|
|
|
|
|
|
|
|
|
for i in branches.size():
|
|
|
|
|
var branch : Dictionary = branches[i] as Dictionary
|
|
|
|
|
var label_text : String = str(branch.get("label", "Option %d" % (i + 1)))
|
|
|
|
|
var btn := Button.new()
|
|
|
|
|
btn.text = label_text
|
|
|
|
|
btn.add_theme_font_size_override("font_size", 12)
|
|
|
|
|
var cap_idx : int = i
|
|
|
|
|
btn.pressed.connect(func():
|
|
|
|
|
_ability_targets.append({
|
|
|
|
|
"actionIndex": _ability_cur_action_idx,
|
|
|
|
|
"branchIndex": cap_idx
|
|
|
|
|
})
|
|
|
|
|
_ability_cur_action_idx += 1
|
|
|
|
|
_hide_branch_panel()
|
|
|
|
|
_advance_ability_targeting())
|
|
|
|
|
vbox.add_child(btn)
|
|
|
|
|
|
|
|
|
|
panel.add_child(vbox)
|
|
|
|
|
_hud.add_child(panel)
|
|
|
|
|
_ability_branch_panel = panel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _hide_branch_panel() -> void:
|
|
|
|
|
if is_instance_valid(_ability_branch_panel):
|
|
|
|
|
_ability_branch_panel.queue_free()
|
|
|
|
|
_ability_branch_panel = null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Fire the ability request with all collected targets.
|
|
|
|
|
func _send_ability() -> void:
|
|
|
|
|
if not _ability_card_id.is_empty():
|
|
|
|
|