Legal docs draft and Client refactor
This commit is contained in:
@@ -0,0 +1,688 @@
|
||||
class_name AbilityTargeting
|
||||
extends Node
|
||||
|
||||
## Manages the ability targeting UI and state:
|
||||
## ability panel, branch panel, player panel, confirm button,
|
||||
## target collection, and sending ability/trigger responses.
|
||||
##
|
||||
## External refs (set by game_screen._ready):
|
||||
## selection_controller — for set_mode() and mode checks
|
||||
## unit_registry — for is_friendly / is_enemy queries
|
||||
## pathfinder — for board_distance, has_los, coord_to_world
|
||||
## hud — CanvasLayer that owns all 2D HUD children
|
||||
## unit_bodies — Dictionary instanceId → StaticBody3D
|
||||
## camera — Camera3D used for unproject_position
|
||||
|
||||
# ── Signals ───────────────────────────────────────────────────────────────────
|
||||
|
||||
signal highlight_add_requested(x: int, y: int, type_name: String)
|
||||
signal highlights_cleared()
|
||||
|
||||
# ── External refs ─────────────────────────────────────────────────────────────
|
||||
|
||||
var selection_controller: SelectionController = null
|
||||
var unit_registry: UnitRegistry = null
|
||||
var pathfinder: Pathfinder = null
|
||||
var hud: CanvasLayer = null
|
||||
var unit_bodies: Dictionary = {} # instanceId → StaticBody3D
|
||||
var camera: Camera3D = null
|
||||
|
||||
# ── Ability state ─────────────────────────────────────────────────────────────
|
||||
|
||||
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, linearonly, requireslos}
|
||||
var ability_targets: Array = [] # collected AbilityTarget dicts to send
|
||||
var ability_cur_action_idx: int = 0
|
||||
var ability_card_id: String = "" # non-empty when targeting a card's active ability
|
||||
var ability_target_conditions: Array = [] # ActivationConditions from card ability
|
||||
var ability_target_n: int = 1
|
||||
var ability_target_up_to: bool = false
|
||||
var ability_targets_this_action: int = 0
|
||||
var ability_confirm_btn: Control = null
|
||||
var ability_branch_panel: Control = null
|
||||
var player_panel: Control = null
|
||||
|
||||
# Triggered ability targeting
|
||||
var is_triggered_target: bool = false
|
||||
var triggered_request_id: String = ""
|
||||
|
||||
# Server-driven picks (shared with server_prompt_handler via direct access)
|
||||
var is_target_pick: bool = false
|
||||
var is_tile_pick: bool = false
|
||||
var pending_req_id: String = ""
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
## Resets all ability state variables to defaults (called by selection_controller on NONE).
|
||||
func reset_ability_state() -> void:
|
||||
ability_unit_id = ""
|
||||
ability_idx = -1
|
||||
ability_def = []
|
||||
ability_range = {}
|
||||
ability_targets = []
|
||||
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
|
||||
|
||||
|
||||
func show_ability_panel(unit_id: String, unit: Dictionary) -> void:
|
||||
hide_ability_panel()
|
||||
|
||||
# Collect Active abilities.
|
||||
var actives: Array = []
|
||||
var raw_abil: Variant = unit.get("abilitiesJson")
|
||||
var abil_json: String = "" if raw_abil == null else str(raw_abil)
|
||||
if not abil_json.is_empty():
|
||||
var parsed: Variant = JSON.parse_string(abil_json)
|
||||
if parsed is Array:
|
||||
var abilities: Array = normalize_keys(parsed) as Array
|
||||
for i: int in abilities.size():
|
||||
var ab: Dictionary = abilities[i] as Dictionary
|
||||
if ab.get("type", "") == "Active":
|
||||
actives.append({
|
||||
"index": i,
|
||||
"name": ab.get("name", "Ability %d" % i),
|
||||
"desc": ab.get("description", ""),
|
||||
"def": ab
|
||||
})
|
||||
|
||||
# Collect ArchSpirit actions (Sacrifice / Ascend / Transition).
|
||||
var arch_actions: Array = []
|
||||
if unit.get("cardType", "") == "ArchSpirit" \
|
||||
and selection_controller != null \
|
||||
and unit_registry != null \
|
||||
and unit_registry.friendly_unit_ids.has(unit_id):
|
||||
var sc: SelectionController = selection_controller
|
||||
if sc.tile_target_resolver != null:
|
||||
var sac_spirits: Array = sc.tile_target_resolver.valid_sacrifice_spirits()
|
||||
if not sac_spirits.is_empty():
|
||||
arch_actions.append({
|
||||
"label": "Sacrifice a Spirit",
|
||||
"fn": func() -> void: sc._start_sacrifice_mode()
|
||||
})
|
||||
var cur_tier: int = int(unit.get("tier", 1))
|
||||
var can_ascend: bool = false
|
||||
var can_trans: bool = false
|
||||
for card: Dictionary in Game.get_hand():
|
||||
if card.get("cardType", "") != "ArchSpirit":
|
||||
continue
|
||||
var t: int = int(card.get("tier", 0))
|
||||
if t == cur_tier + 1: can_ascend = true
|
||||
if t == 1: can_trans = true
|
||||
if can_ascend:
|
||||
arch_actions.append({
|
||||
"label": "Ascend",
|
||||
"fn": func() -> void: sc._pick_ascend_card()
|
||||
})
|
||||
if can_trans:
|
||||
arch_actions.append({
|
||||
"label": "Transition",
|
||||
"fn": func() -> void: sc._pick_transition_card()
|
||||
})
|
||||
|
||||
if actives.is_empty() and arch_actions.is_empty():
|
||||
return
|
||||
|
||||
# Build panel.
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 4)
|
||||
vbox.custom_minimum_size = Vector2(160, 0)
|
||||
|
||||
if not actives.is_empty():
|
||||
var title: Label = Label.new()
|
||||
title.text = "Abilities"
|
||||
title.add_theme_font_size_override("font_size", 12)
|
||||
title.add_theme_color_override("font_color", Color(0.7, 0.8, 1.0))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
for ab: Dictionary in actives:
|
||||
var btn: Button = Button.new()
|
||||
btn.text = ab.get("name", "")
|
||||
btn.tooltip_text = ab.get("desc", "")
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var idx: int = ab.get("index", 0)
|
||||
var ab_def: Dictionary = ab.get("def", {})
|
||||
btn.pressed.connect(func() -> void:
|
||||
ability_unit_id = unit_id
|
||||
ability_idx = idx
|
||||
ability_def = get_ability_actions(ab_def)
|
||||
ability_range = ab_def.get("range", {})
|
||||
ability_targets = []
|
||||
ability_cur_action_idx = 0
|
||||
start_ability_targeting())
|
||||
vbox.add_child(btn)
|
||||
|
||||
if not arch_actions.is_empty():
|
||||
if not actives.is_empty():
|
||||
vbox.add_child(HSeparator.new())
|
||||
var arch_title: Label = Label.new()
|
||||
arch_title.text = "ArchSpirit"
|
||||
arch_title.add_theme_font_size_override("font_size", 12)
|
||||
arch_title.add_theme_color_override("font_color", Color(1.0, 0.75, 0.3))
|
||||
vbox.add_child(arch_title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
for aa: Dictionary in arch_actions:
|
||||
var btn: Button = Button.new()
|
||||
btn.text = aa.get("label", "")
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var fn: Callable = aa.get("fn", Callable())
|
||||
btn.pressed.connect(func() -> void: fn.call())
|
||||
vbox.add_child(btn)
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
ability_panel = panel
|
||||
|
||||
# Position to the right of the unit.
|
||||
var body: StaticBody3D = unit_bodies.get(unit_id) as StaticBody3D
|
||||
if is_instance_valid(body) and camera != null:
|
||||
var screen_pos: Vector2 = camera.unproject_position(body.global_position)
|
||||
panel.set_deferred("position", clamp_panel_pos(screen_pos + Vector2(36, -40), panel))
|
||||
else:
|
||||
panel.position = Vector2(12, 420)
|
||||
|
||||
|
||||
func hide_ability_panel() -> void:
|
||||
if is_instance_valid(ability_panel):
|
||||
ability_panel.queue_free()
|
||||
ability_panel = null
|
||||
|
||||
|
||||
func current_target_mode() -> SelectionController.Mode:
|
||||
if is_triggered_target or is_target_pick or is_tile_pick:
|
||||
return SelectionController.Mode.ABILITY_TARGET_FORCED
|
||||
return SelectionController.Mode.ABILITY_TARGET
|
||||
|
||||
|
||||
## Advance through ability actions, entering board-target mode, player-pick, or sending.
|
||||
func start_ability_targeting() -> void:
|
||||
print("AbilityTargeting:: start_ability_targeting")
|
||||
if ability_cur_action_idx >= ability_def.size():
|
||||
send_ability()
|
||||
return
|
||||
|
||||
var action: Dictionary = {}
|
||||
if ability_def[ability_cur_action_idx] is Dictionary:
|
||||
action = ability_def[ability_cur_action_idx] as Dictionary
|
||||
|
||||
# ChooseOne — show branch buttons.
|
||||
var choose_one: Variant = action.get("chooseone")
|
||||
if choose_one is Dictionary and not (choose_one as Dictionary).get("branches", []).is_empty():
|
||||
if selection_controller != null:
|
||||
selection_controller.set_mode(current_target_mode())
|
||||
emit_signal("highlights_cleared")
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
# Auto-resolved by server — skip.
|
||||
var auto_ownerships: Array = ["Self", "ExactSelf", "Random", "Target"]
|
||||
if count_all or ownership in auto_ownerships:
|
||||
ability_cur_action_idx += 1
|
||||
start_ability_targeting()
|
||||
return
|
||||
|
||||
# Player / zone selection.
|
||||
var zone_scopes: Array = ["Player", "Hand", "Deck", "Discard", "AnyZone"]
|
||||
if scope in zone_scopes:
|
||||
if selection_controller != null:
|
||||
selection_controller.set_mode(current_target_mode())
|
||||
emit_signal("highlights_cleared")
|
||||
show_player_panel(scope, ownership)
|
||||
return
|
||||
|
||||
# Board selection.
|
||||
if selection_controller != null:
|
||||
selection_controller.set_mode(current_target_mode())
|
||||
emit_signal("highlights_cleared")
|
||||
highlight_ability_targets(action)
|
||||
|
||||
if ability_target_up_to and ability_target_n > 1:
|
||||
show_ability_confirm_btn()
|
||||
|
||||
|
||||
func advance_ability_targeting() -> void:
|
||||
hide_ability_confirm_btn()
|
||||
hide_branch_panel()
|
||||
hide_player_panel()
|
||||
emit_signal("highlights_cleared")
|
||||
ability_targets_this_action = 0
|
||||
start_ability_targeting()
|
||||
|
||||
|
||||
## Highlight valid ability targets in blue.
|
||||
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_v: Variant = target_sel.get("filters", [])
|
||||
var filters: Array = filters_v as Array if filters_v is Array else []
|
||||
|
||||
var linear_only: bool = ability_range.get("linearonly", false)
|
||||
var requires_los: bool = ability_range.get("requireslos", false)
|
||||
|
||||
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.
|
||||
if type_ == "Tile":
|
||||
var bw: int = Game.board_width()
|
||||
var bh: int = Game.board_height()
|
||||
for tx: int in range(bw):
|
||||
for ty: int in range(bh):
|
||||
if not src_pos_ab.is_empty():
|
||||
var sx: int = int(src_pos_ab.get("x", 0))
|
||||
var sy: int = int(src_pos_ab.get("y", 0))
|
||||
if linear_only and not is_linear(sx, sy, tx, ty):
|
||||
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")
|
||||
return
|
||||
|
||||
# Unit-type target.
|
||||
var include_enemy: bool = ownership in ["Enemy", "Any"]
|
||||
var include_friendly: bool = ownership in ["Owner", "Ally", "Any"]
|
||||
if not include_enemy and not include_friendly:
|
||||
include_enemy = true
|
||||
|
||||
var targets: Array = []
|
||||
if include_enemy:
|
||||
targets.append_array(Game.get_all_enemy_units())
|
||||
if include_friendly:
|
||||
targets.append_array(Game.get_field())
|
||||
var my_arch: Dictionary = Game.get_my_player().get("archSpirit", {})
|
||||
if not my_arch.is_empty():
|
||||
targets.append(my_arch)
|
||||
|
||||
for u: Dictionary in targets:
|
||||
if type_ in ["Spirit", "ArchSpirit", "SpiritToken", "Ruin"]:
|
||||
if u.get("cardType", "").to_lower() != type_.to_lower():
|
||||
continue
|
||||
var pos: Dictionary = u.get("position", {})
|
||||
if pos.is_empty():
|
||||
continue
|
||||
if not unit_passes_filters(u, filters):
|
||||
continue
|
||||
if not ability_range.is_empty():
|
||||
if src_pos_ab.is_empty():
|
||||
continue
|
||||
var dist: int = 0
|
||||
if pathfinder != null:
|
||||
dist = pathfinder.board_distance(
|
||||
int(pos.get("x", 0)), int(pos.get("y", 0)),
|
||||
int(src_pos_ab.get("x", 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
|
||||
if not src_pos_ab.is_empty():
|
||||
var ux: int = int(pos.get("x", 0)); var uy: int = int(pos.get("y", 0))
|
||||
var sx: int = int(src_pos_ab.get("x", 0)); var sy: int = int(src_pos_ab.get("y", 0))
|
||||
if linear_only and not is_linear(sx, sy, ux, uy):
|
||||
continue
|
||||
if requires_los and pathfinder != null and not pathfinder.client_has_los(sx, sy, ux, uy):
|
||||
continue
|
||||
emit_signal("highlight_add_requested", int(pos.get("x", 0)), int(pos.get("y", 0)), "ability")
|
||||
|
||||
|
||||
func unit_passes_filters(unit: Dictionary, filters: Array) -> bool:
|
||||
if filters.is_empty():
|
||||
return true
|
||||
var src: Dictionary = Game.get_unit_by_id(ability_unit_id)
|
||||
var src_pos: Dictionary = src.get("position", {})
|
||||
for f: Dictionary in filters:
|
||||
match f.get("$type", ""):
|
||||
"withinrange":
|
||||
if src_pos.is_empty(): return false
|
||||
var tgt_pos: Dictionary = unit.get("position", {})
|
||||
if tgt_pos.is_empty(): return false
|
||||
var dist: int = 0
|
||||
if pathfinder != null:
|
||||
dist = pathfinder.board_distance(
|
||||
int(tgt_pos.get("x", 0)), int(tgt_pos.get("y", 0)),
|
||||
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
|
||||
"isadjacenttosource":
|
||||
if src_pos.is_empty(): return false
|
||||
var tgt_pos: Dictionary = unit.get("position", {})
|
||||
if tgt_pos.is_empty(): return false
|
||||
var dist: int = 0
|
||||
if pathfinder != null:
|
||||
dist = pathfinder.board_distance(
|
||||
int(tgt_pos.get("x", 0)), int(tgt_pos.get("y", 0)),
|
||||
int(src_pos.get("x", 0)), int(src_pos.get("y", 0)))
|
||||
if dist != 1:
|
||||
return false
|
||||
for cond: Dictionary in ability_target_conditions:
|
||||
match cond.get("$type", ""):
|
||||
"IsOnTileWithAffinity":
|
||||
var upos: Dictionary = unit.get("position", {})
|
||||
if upos.is_empty(): return false
|
||||
var tile: Dictionary = Game.get_tile(int(upos.get("x", 0)), int(upos.get("y", 0)))
|
||||
if tile.get("affinity", "") != cond.get("affinity", ""):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func tile_passes_filters(tx: int, ty: int, filters: Array) -> bool:
|
||||
if filters.is_empty():
|
||||
return true
|
||||
var src: Dictionary = Game.get_unit_by_id(ability_unit_id)
|
||||
var src_pos: Dictionary = src.get("position", {})
|
||||
for f: Dictionary in filters:
|
||||
match f.get("$type", ""):
|
||||
"tilewithinrange":
|
||||
if src_pos.is_empty(): return false
|
||||
var dist: int = 0
|
||||
if pathfinder != null:
|
||||
dist = pathfinder.board_distance(tx, ty,
|
||||
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
|
||||
return true
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
## Show a "Done" button for UpTo selections.
|
||||
func show_ability_confirm_btn() -> void:
|
||||
hide_ability_confirm_btn()
|
||||
var btn: Button = 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() -> void:
|
||||
hide_ability_confirm_btn()
|
||||
ability_cur_action_idx += 1
|
||||
advance_ability_targeting())
|
||||
if hud != null:
|
||||
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
|
||||
|
||||
|
||||
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 = PanelContainer.new()
|
||||
panel.position = Vector2(8, 120)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
vbox.custom_minimum_size = Vector2(190, 0)
|
||||
|
||||
var title: Label = 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: int 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 = Button.new()
|
||||
btn.text = label_text
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_idx: int = i
|
||||
btn.pressed.connect(func() -> void:
|
||||
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)
|
||||
if hud != null:
|
||||
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 is_triggered_target:
|
||||
is_triggered_target = false
|
||||
var rid: String = triggered_request_id
|
||||
triggered_request_id = ""
|
||||
Game.send_triggered_target_response(rid, ability_targets)
|
||||
elif is_target_pick:
|
||||
is_target_pick = false
|
||||
var rid: String = pending_req_id
|
||||
pending_req_id = ""
|
||||
Game.send_target_pick_response(rid, ability_targets)
|
||||
elif not ability_card_id.is_empty():
|
||||
Game.send_play_card_with_targets(ability_card_id, ability_targets)
|
||||
else:
|
||||
Game.send_activate_ability(ability_unit_id, ability_idx, ability_targets)
|
||||
if selection_controller != null:
|
||||
selection_controller.set_mode(SelectionController.Mode.NONE)
|
||||
|
||||
|
||||
## Called when the server pushes a triggered_target_request for this player.
|
||||
func on_triggered_target_request(req: Dictionary) -> void:
|
||||
if selection_controller != null and selection_controller.mode != SelectionController.Mode.NONE:
|
||||
selection_controller.set_mode(SelectionController.Mode.NONE)
|
||||
|
||||
is_triggered_target = true
|
||||
triggered_request_id = str(req.get("requestId", ""))
|
||||
ability_unit_id = str(req.get("sourceInstanceId", ""))
|
||||
ability_idx = -1
|
||||
ability_card_id = ""
|
||||
ability_target_conditions = []
|
||||
|
||||
var action_json: String = str(req.get("actionJson", "{}"))
|
||||
var action_raw: Variant = JSON.parse_string(action_json)
|
||||
if action_raw is Dictionary:
|
||||
ability_def = [normalize_keys(action_raw)]
|
||||
elif action_raw is Array:
|
||||
ability_def = normalize_keys(action_raw) as Array
|
||||
else:
|
||||
ability_def = []
|
||||
|
||||
var range_json: String = str(req.get("rangeJson", ""))
|
||||
if not range_json.is_empty() and range_json != "null" and range_json != "<null>":
|
||||
var r: Variant = JSON.parse_string(range_json)
|
||||
ability_range = normalize_keys(r) as Dictionary if r is Dictionary else {}
|
||||
else:
|
||||
ability_range = {}
|
||||
|
||||
ability_targets = []
|
||||
ability_cur_action_idx = 0
|
||||
ability_target_n = 1
|
||||
ability_target_up_to = false
|
||||
ability_targets_this_action = 0
|
||||
|
||||
show_triggered_banner(str(req.get("abilityName", "Triggered Ability")))
|
||||
start_ability_targeting()
|
||||
|
||||
|
||||
## Brief top-centre banner for triggered ability targeting.
|
||||
func show_triggered_banner(ability_name: String) -> void:
|
||||
if hud == null:
|
||||
return
|
||||
var lbl: Label = Label.new()
|
||||
lbl.text = "Triggered: %s — select a target" % ability_name
|
||||
lbl.set_anchors_preset(Control.PRESET_TOP_WIDE)
|
||||
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
lbl.position = Vector2(0, 72)
|
||||
lbl.add_theme_font_size_override("font_size", 15)
|
||||
lbl.modulate = Color(1.0, 0.85, 0.2)
|
||||
hud.add_child(lbl)
|
||||
get_tree().create_timer(4.0).timeout.connect(func() -> void:
|
||||
if is_instance_valid(lbl): lbl.queue_free())
|
||||
|
||||
|
||||
## Show the player-selection panel for zone/player ability targets.
|
||||
func show_player_panel(scope: String, ownership: String) -> void:
|
||||
hide_player_panel()
|
||||
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 180)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
vbox.custom_minimum_size = Vector2(160, 0)
|
||||
|
||||
var title: Label = Label.new()
|
||||
title.text = "Choose Player"
|
||||
title.add_theme_font_size_override("font_size", 13)
|
||||
title.add_theme_color_override("font_color", Color(0.7, 0.8, 1.0))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
var my_id: String = Auth.user_id
|
||||
var my_name: String = Auth.display_name if not Auth.display_name.is_empty() else "You"
|
||||
|
||||
var show_self: bool = ownership in ["Owner", "Ally", "Any"]
|
||||
var show_enemy: bool = ownership in ["Enemy", "Any"]
|
||||
if not show_self and not show_enemy:
|
||||
show_self = true
|
||||
show_enemy = true
|
||||
|
||||
if show_self:
|
||||
add_player_option(vbox, my_name, my_id, scope)
|
||||
if show_enemy:
|
||||
for ep: Dictionary in Game.get_enemy_players():
|
||||
var eid: String = str(ep.get("accountId", ""))
|
||||
var ename: String = Game.get_display_name(eid)
|
||||
add_player_option(vbox, ename, eid, scope)
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
player_panel = panel
|
||||
|
||||
|
||||
func add_player_option(vbox: VBoxContainer, name_: String,
|
||||
account_id: String, scope: String) -> void:
|
||||
var zone_scopes: Array = ["Hand", "Deck", "Discard", "AnyZone"]
|
||||
if scope in zone_scopes:
|
||||
var lbl: Label = Label.new()
|
||||
lbl.text = name_
|
||||
lbl.add_theme_font_size_override("font_size", 12)
|
||||
vbox.add_child(lbl)
|
||||
|
||||
var zone_hbox: HBoxContainer = HBoxContainer.new()
|
||||
zone_hbox.add_theme_constant_override("separation", 4)
|
||||
var zones: Array = ["Hand", "Deck", "Discard"] if scope == "AnyZone" else [scope]
|
||||
for zone_name: String in zones:
|
||||
var zbtn: Button = Button.new()
|
||||
zbtn.text = zone_name
|
||||
zbtn.add_theme_font_size_override("font_size", 11)
|
||||
var cap_id: String = account_id
|
||||
zbtn.pressed.connect(func() -> void:
|
||||
ability_targets.append({
|
||||
"actionIndex": ability_cur_action_idx,
|
||||
"instanceId": cap_id
|
||||
})
|
||||
ability_cur_action_idx += 1
|
||||
advance_ability_targeting())
|
||||
zone_hbox.add_child(zbtn)
|
||||
vbox.add_child(zone_hbox)
|
||||
else:
|
||||
var btn: Button = Button.new()
|
||||
btn.text = name_
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_id: String = account_id
|
||||
btn.pressed.connect(func() -> void:
|
||||
ability_targets.append({
|
||||
"actionIndex": ability_cur_action_idx,
|
||||
"instanceId": cap_id
|
||||
})
|
||||
ability_cur_action_idx += 1
|
||||
advance_ability_targeting())
|
||||
vbox.add_child(btn)
|
||||
|
||||
|
||||
func hide_player_panel() -> void:
|
||||
if is_instance_valid(player_panel):
|
||||
player_panel.queue_free()
|
||||
player_panel = null
|
||||
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
## Recursively normalise all Dictionary keys to lowercase.
|
||||
func normalize_keys(value: Variant) -> Variant:
|
||||
if value is Dictionary:
|
||||
var result: Dictionary = {}
|
||||
for k: Variant in (value as Dictionary):
|
||||
result[str(k).to_lower()] = normalize_keys((value as Dictionary)[k])
|
||||
return result
|
||||
elif value is Array:
|
||||
var result: Array = []
|
||||
for item: Variant in (value as Array):
|
||||
result.append(normalize_keys(item))
|
||||
return result
|
||||
return value
|
||||
|
||||
|
||||
## Returns the flat action list from a parsed ability definition.
|
||||
func get_ability_actions(ab: Dictionary) -> Array:
|
||||
var legacy: Array = ab.get("actions", [])
|
||||
if not legacy.is_empty():
|
||||
return legacy
|
||||
var ag: Variant = ab.get("actiongroup")
|
||||
if ag is Dictionary:
|
||||
return flatten_and_group(ag as Dictionary)
|
||||
return []
|
||||
|
||||
|
||||
func flatten_and_group(ag: Dictionary) -> Array:
|
||||
var logic: String = str(ag.get("logicop", "and")).to_lower()
|
||||
var result: Array = []
|
||||
result.append_array(ag.get("actions", []))
|
||||
if logic == "and":
|
||||
for g: Variant in ag.get("groups", []):
|
||||
if g is Dictionary:
|
||||
result.append_array(flatten_and_group(g as Dictionary))
|
||||
return result
|
||||
|
||||
|
||||
## Clamp a panel's desired top-left so it stays within the viewport.
|
||||
func clamp_panel_pos(desired: Vector2, panel: Control) -> Vector2:
|
||||
var vp: Vector2 = get_viewport().get_visible_rect().size
|
||||
var sz: Vector2 = panel.size
|
||||
if sz == Vector2.ZERO:
|
||||
sz = panel.custom_minimum_size
|
||||
return Vector2(
|
||||
clampf(desired.x, 4.0, vp.x - sz.x - 4.0),
|
||||
clampf(desired.y, 4.0, vp.y - sz.y - 4.0))
|
||||
@@ -0,0 +1 @@
|
||||
uid://xf03434iiopi
|
||||
@@ -0,0 +1,558 @@
|
||||
class_name SelectionController
|
||||
extends Node
|
||||
|
||||
## Manages board selection state: which mode the player is in, what card/unit
|
||||
## is selected, and dispatches board-click events to the correct handler.
|
||||
## Emits signals for highlight changes so game_screen can drive the board visuals.
|
||||
|
||||
# ── Mode enum ─────────────────────────────────────────────────────────────────
|
||||
|
||||
enum Mode {
|
||||
NONE,
|
||||
CARD_FROM_HAND,
|
||||
TERRAMORPHA_SELECT,
|
||||
UNIT_SELECTED,
|
||||
PLACEMENT,
|
||||
SACRIFICE_SELECT,
|
||||
ABILITY_TARGET,
|
||||
ABILITY_TARGET_FORCED,
|
||||
}
|
||||
|
||||
# ── Signals ───────────────────────────────────────────────────────────────────
|
||||
|
||||
signal mode_changed(new_mode: int)
|
||||
signal highlights_cleared()
|
||||
signal highlight_add_requested(x: int, y: int, type_name: String)
|
||||
signal highlight_tiles_requested(coords: Array, type_name: String)
|
||||
signal tile_drawer_open_requested(tile_data: Dictionary)
|
||||
signal tile_drawer_close_requested()
|
||||
signal camera_follow_requested(world_pos: Vector3)
|
||||
signal hand_selection_refresh_requested()
|
||||
|
||||
# ── External refs set by game_screen ─────────────────────────────────────────
|
||||
|
||||
## Reference to AbilityTargeting component (set by game_screen._ready).
|
||||
var ability_targeting: AbilityTargeting = null
|
||||
## Reference to ServerPromptHandler component (set by game_screen._ready).
|
||||
var server_prompt_handler: ServerPromptHandler = null
|
||||
## Reference to TileTargetResolver component (set by game_screen._ready).
|
||||
var tile_target_resolver: TileTargetResolver = null
|
||||
## Reference to UnitRegistry component (set by game_screen._ready).
|
||||
var unit_registry: UnitRegistry = null
|
||||
## Reference to Pathfinder component (set by game_screen._ready).
|
||||
var pathfinder: Pathfinder = null
|
||||
## Grid type string — "Square" or "Hexagon" — set by game_screen after board load.
|
||||
var board_grid_type: String = "Square"
|
||||
## Reference to board_ctrl.tile_bodies (Dictionary ref stays in sync automatically).
|
||||
var tile_bodies: Dictionary = {}
|
||||
|
||||
# ── Selection state ───────────────────────────────────────────────────────────
|
||||
|
||||
var mode: Mode = Mode.NONE
|
||||
var sel_card_id: String = ""
|
||||
var sel_unit_id: String = ""
|
||||
var held_coord: Vector2i = Vector2i(-1, -1)
|
||||
|
||||
# Terramorpha multi-tile targeting
|
||||
var terra_targets: Array = [] # Array[Vector2i]
|
||||
var terra_count: int = 0 # total tiles needed (1/2/3)
|
||||
|
||||
# Sacrifice ArchSpirit coord (unused currently, reserved)
|
||||
var sac_arch_coord: Vector2i = Vector2i(-1, -1)
|
||||
|
||||
# Dedup tracking
|
||||
var _last_board_click_frame: int = -1
|
||||
var _last_board_click_coord: Vector2i = Vector2i(-999, -999)
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
## Central mode setter — clears stale selection state when returning to NONE.
|
||||
func set_mode(new_mode: Mode) -> void:
|
||||
print("SelectionController:: set_mode: ", new_mode)
|
||||
mode = new_mode
|
||||
terra_targets = []
|
||||
terra_count = 0
|
||||
if new_mode != Mode.NONE and new_mode != Mode.UNIT_SELECTED:
|
||||
emit_signal("tile_drawer_close_requested")
|
||||
if new_mode == Mode.NONE:
|
||||
sel_card_id = ""
|
||||
sel_unit_id = ""
|
||||
if ability_targeting != null:
|
||||
ability_targeting.reset_ability_state()
|
||||
ability_targeting.hide_ability_confirm_btn()
|
||||
ability_targeting.hide_branch_panel()
|
||||
ability_targeting.hide_ability_panel()
|
||||
ability_targeting.hide_player_panel()
|
||||
emit_signal("highlights_cleared")
|
||||
emit_signal("mode_changed", new_mode as int)
|
||||
emit_signal("hand_selection_refresh_requested")
|
||||
|
||||
|
||||
## Selects a friendly unit: sets UNIT_SELECTED mode, highlights move/attack ranges,
|
||||
## optionally pans the camera, and opens the ability panel.
|
||||
func select_unit(unit_id: String) -> void:
|
||||
if mode == Mode.ABILITY_TARGET_FORCED:
|
||||
return
|
||||
var unit: Dictionary = Game.get_unit_by_id(unit_id)
|
||||
if unit.is_empty():
|
||||
return
|
||||
if unit_registry != null and unit_registry.is_ruin_unit(unit):
|
||||
return
|
||||
|
||||
if ability_targeting != null:
|
||||
ability_targeting.hide_ability_panel()
|
||||
sel_unit_id = unit_id
|
||||
set_mode(Mode.UNIT_SELECTED)
|
||||
emit_signal("highlights_cleared")
|
||||
|
||||
# Highlight own tile and pan camera.
|
||||
var upos: Dictionary = unit.get("position", {})
|
||||
if not upos.is_empty():
|
||||
var ux: int = int(upos.get("x", 0))
|
||||
var uy: int = int(upos.get("y", 0))
|
||||
emit_signal("highlight_add_requested", ux, uy, "selector")
|
||||
if Settings.camera_follow_unit and pathfinder != null:
|
||||
var target: Vector3 = pathfinder.coord_to_world(ux, uy)
|
||||
emit_signal("camera_follow_requested", target)
|
||||
|
||||
# Movement / attack ranges.
|
||||
if tile_target_resolver != null:
|
||||
emit_signal("highlight_tiles_requested", tile_target_resolver.valid_move_tiles(unit, tile_bodies), "movement")
|
||||
emit_signal("highlight_tiles_requested", tile_target_resolver.attack_range_tiles(unit, tile_bodies), "terramorpha")
|
||||
emit_signal("highlight_tiles_requested", tile_target_resolver.valid_attack_target_coords(unit), "attack")
|
||||
|
||||
# Ability panel.
|
||||
if ability_targeting != null:
|
||||
ability_targeting.show_ability_panel(unit_id, unit)
|
||||
|
||||
|
||||
## Primary board-click dispatcher — called from game_screen when a board click arrives.
|
||||
func handle_board_click(mouse_pos: Vector2, coord: Vector2i, unit_id: String) -> void:
|
||||
var cf: int = Engine.get_process_frames()
|
||||
if cf == _last_board_click_frame and coord == _last_board_click_coord:
|
||||
return
|
||||
_last_board_click_frame = cf
|
||||
_last_board_click_coord = coord
|
||||
|
||||
# Resolve occupant when clicking a tile with no direct unit-mesh hit.
|
||||
var resolved_unit_id: String = unit_id
|
||||
|
||||
if mode == Mode.ABILITY_TARGET_FORCED:
|
||||
_handle_forced_target_click(coord, resolved_unit_id)
|
||||
return
|
||||
|
||||
match mode:
|
||||
Mode.NONE:
|
||||
_handle_none_click(coord, resolved_unit_id)
|
||||
Mode.CARD_FROM_HAND:
|
||||
_handle_card_from_hand_click(coord)
|
||||
Mode.TERRAMORPHA_SELECT:
|
||||
_handle_terramorpha_click(coord)
|
||||
Mode.UNIT_SELECTED:
|
||||
_handle_unit_selected_click(coord, resolved_unit_id)
|
||||
Mode.PLACEMENT:
|
||||
if coord.x >= 0:
|
||||
Game.send_place_arch_spirit(coord.x, coord.y)
|
||||
set_mode(Mode.NONE)
|
||||
Mode.SACRIFICE_SELECT:
|
||||
_handle_sacrifice_click(coord, resolved_unit_id)
|
||||
Mode.ABILITY_TARGET:
|
||||
_handle_ability_target_click(coord, resolved_unit_id)
|
||||
|
||||
|
||||
# ── Private click handlers ────────────────────────────────────────────────────
|
||||
|
||||
func _resolve_occupant(coord: Vector2i, existing_unit_id: String) -> String:
|
||||
if not existing_unit_id.is_empty() or coord.x < 0:
|
||||
return existing_unit_id
|
||||
var tile: Dictionary = Game.get_tile(coord.x, coord.y)
|
||||
var raw_occ: Variant = tile.get("occupantId")
|
||||
var occ: String = "" if raw_occ == null else str(raw_occ)
|
||||
if not occ.is_empty() and occ != "null":
|
||||
var occ_unit: Dictionary = Game.get_unit_by_id(occ)
|
||||
if unit_registry != null and not unit_registry.is_ruin_unit(occ_unit):
|
||||
return occ
|
||||
return existing_unit_id
|
||||
|
||||
|
||||
func _handle_forced_target_click(coord: Vector2i, unit_id: String) -> void:
|
||||
var resolved: String = _resolve_occupant(coord, unit_id)
|
||||
|
||||
# Server-driven tile pick — send directly.
|
||||
if ability_targeting != null and ability_targeting.is_tile_pick and coord.x >= 0:
|
||||
ability_targeting.is_tile_pick = false
|
||||
var rid: String = ability_targeting.pending_req_id
|
||||
ability_targeting.pending_req_id = ""
|
||||
set_mode(Mode.NONE)
|
||||
emit_signal("highlights_cleared")
|
||||
Game.send_tile_pick_response(rid, coord.x, coord.y)
|
||||
return
|
||||
|
||||
# Collect board target.
|
||||
var collected: bool = false
|
||||
if ability_targeting != null:
|
||||
if not resolved.is_empty():
|
||||
ability_targeting.ability_targets.append({
|
||||
"actionIndex": ability_targeting.ability_cur_action_idx,
|
||||
"instanceId": resolved
|
||||
})
|
||||
ability_targeting.ability_targets_this_action += 1
|
||||
collected = true
|
||||
elif coord.x >= 0:
|
||||
ability_targeting.ability_targets.append({
|
||||
"actionIndex": ability_targeting.ability_cur_action_idx,
|
||||
"coord": { "x": coord.x, "y": coord.y }
|
||||
})
|
||||
ability_targeting.ability_targets_this_action += 1
|
||||
collected = true
|
||||
|
||||
if not collected:
|
||||
set_mode(Mode.NONE)
|
||||
elif ability_targeting.ability_targets_this_action >= ability_targeting.ability_target_n:
|
||||
ability_targeting.ability_cur_action_idx += 1
|
||||
ability_targeting.advance_ability_targeting()
|
||||
|
||||
|
||||
func _handle_none_click(coord: Vector2i, unit_id: String) -> void:
|
||||
var resolved: String = _resolve_occupant(coord, unit_id)
|
||||
if coord.x >= 0:
|
||||
emit_signal("tile_drawer_open_requested", Game.get_tile(coord.x, coord.y))
|
||||
if Settings.click_to_focus_camera and pathfinder != null:
|
||||
var world: Vector3 = pathfinder.coord_to_world(coord.x, coord.y)
|
||||
emit_signal("camera_follow_requested", world)
|
||||
if not resolved.is_empty() \
|
||||
and unit_registry != null and unit_registry.friendly_unit_ids.has(resolved) \
|
||||
and Game.is_my_turn() and Game.get_phase() != "Placement":
|
||||
select_unit(resolved)
|
||||
|
||||
|
||||
func _handle_card_from_hand_click(coord: Vector2i) -> void:
|
||||
var card: Dictionary = _find_hand_card(sel_card_id)
|
||||
if card.is_empty():
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
var card_type: String = card.get("cardType", "")
|
||||
if card_type in ["Repentance", "Instinct", "Ruin"]:
|
||||
Game.send_play_card(sel_card_id, 0, 0)
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
if coord.x < 0:
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
Game.send_play_card(sel_card_id, coord.x, coord.y)
|
||||
set_mode(Mode.NONE)
|
||||
|
||||
|
||||
func _handle_terramorpha_click(coord: Vector2i) -> void:
|
||||
if coord.x < 0:
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
# Validate adjacency.
|
||||
if terra_targets.size() > 0:
|
||||
var last: Vector2i = terra_targets.back() as Vector2i
|
||||
if pathfinder != null and pathfinder.board_distance(coord.x, coord.y, last.x, last.y) != 1:
|
||||
return
|
||||
terra_targets.append(coord)
|
||||
if terra_targets.size() >= terra_count:
|
||||
var targets: Array = terra_targets.map(func(v: Vector2i) -> Dictionary:
|
||||
return { "x": v.x, "y": v.y })
|
||||
Game.send_play_card_multi(sel_card_id, targets)
|
||||
set_mode(Mode.NONE)
|
||||
else:
|
||||
# Re-highlight: orange for picked, green for valid next.
|
||||
emit_signal("highlights_cleared")
|
||||
for t: Vector2i in terra_targets:
|
||||
emit_signal("highlight_add_requested", t.x, t.y, "terramorpha")
|
||||
var last2: Vector2i = terra_targets.back() as Vector2i
|
||||
var bw2: int = Game.board_width()
|
||||
var bh2: int = Game.board_height()
|
||||
var terra_dirs: Array[Vector2i] = []
|
||||
if board_grid_type == "Hexagon":
|
||||
terra_dirs = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1),
|
||||
Vector2i(1,-1), Vector2i(-1,1)]
|
||||
else:
|
||||
terra_dirs = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1)]
|
||||
for d: Vector2i in terra_dirs:
|
||||
var nx: int = last2.x + d.x
|
||||
var ny: int = last2.y + d.y
|
||||
if nx < 0 or ny < 0 or nx >= bw2 or ny >= bh2:
|
||||
continue
|
||||
emit_signal("highlight_add_requested", nx, ny, "movement")
|
||||
|
||||
|
||||
func _handle_unit_selected_click(coord: Vector2i, unit_id: String) -> void:
|
||||
if coord.x >= 0:
|
||||
emit_signal("tile_drawer_open_requested", Game.get_tile(coord.x, coord.y))
|
||||
var resolved: String = _resolve_occupant(coord, unit_id)
|
||||
if not resolved.is_empty():
|
||||
if unit_registry != null and unit_registry.enemy_unit_ids.has(resolved):
|
||||
Game.send_attack(sel_unit_id, resolved)
|
||||
set_mode(Mode.NONE)
|
||||
elif resolved == sel_unit_id:
|
||||
# Re-click same unit → toggle ability panel.
|
||||
if ability_targeting != null:
|
||||
if is_instance_valid(ability_targeting.ability_panel):
|
||||
ability_targeting.hide_ability_panel()
|
||||
else:
|
||||
var resel_unit: Dictionary = Game.get_unit_by_id(resolved)
|
||||
if not resel_unit.is_empty():
|
||||
ability_targeting.show_ability_panel(resolved, resel_unit)
|
||||
elif unit_registry != null and unit_registry.friendly_unit_ids.has(resolved):
|
||||
select_unit(resolved)
|
||||
elif coord.x >= 0:
|
||||
Game.send_move_unit(sel_unit_id, coord.x, coord.y)
|
||||
set_mode(Mode.NONE)
|
||||
|
||||
|
||||
func _handle_sacrifice_click(coord: Vector2i, unit_id: String) -> void:
|
||||
var resolved: String = _resolve_occupant(coord, unit_id)
|
||||
if resolved.is_empty() or (unit_registry != null and not unit_registry.friendly_unit_ids.has(resolved)):
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
var unit: Dictionary = Game.get_unit_by_id(resolved)
|
||||
if unit.is_empty() or unit.get("cardType", "") == "ArchSpirit":
|
||||
set_mode(Mode.NONE)
|
||||
return
|
||||
_confirm_sacrifice(resolved, unit.get("name", "this spirit"))
|
||||
|
||||
|
||||
func _handle_ability_target_click(coord: Vector2i, unit_id: String) -> void:
|
||||
if ability_targeting == null:
|
||||
return
|
||||
# Server-driven tile pick.
|
||||
if ability_targeting.is_tile_pick and coord.x >= 0:
|
||||
ability_targeting.is_tile_pick = false
|
||||
var rid: String = ability_targeting.pending_req_id
|
||||
ability_targeting.pending_req_id = ""
|
||||
set_mode(Mode.NONE)
|
||||
emit_signal("highlights_cleared")
|
||||
Game.send_tile_pick_response(rid, coord.x, coord.y)
|
||||
return
|
||||
|
||||
var collected: bool = false
|
||||
if not unit_id.is_empty():
|
||||
ability_targeting.ability_targets.append({
|
||||
"actionIndex": ability_targeting.ability_cur_action_idx,
|
||||
"instanceId": unit_id
|
||||
})
|
||||
ability_targeting.ability_targets_this_action += 1
|
||||
collected = true
|
||||
elif coord.x >= 0:
|
||||
ability_targeting.ability_targets.append({
|
||||
"actionIndex": ability_targeting.ability_cur_action_idx,
|
||||
"coord": { "x": coord.x, "y": coord.y }
|
||||
})
|
||||
ability_targeting.ability_targets_this_action += 1
|
||||
collected = true
|
||||
|
||||
if not collected:
|
||||
set_mode(Mode.NONE)
|
||||
elif ability_targeting.ability_targets_this_action >= ability_targeting.ability_target_n:
|
||||
ability_targeting.ability_cur_action_idx += 1
|
||||
ability_targeting.advance_ability_targeting()
|
||||
|
||||
# ── ArchSpirit popup menu ─────────────────────────────────────────────────────
|
||||
|
||||
func show_arch_spirit_menu(unit_id: String, unit: Dictionary) -> void:
|
||||
var menu: PopupMenu = PopupMenu.new()
|
||||
add_child(menu)
|
||||
|
||||
var sac_spirits: Array = []
|
||||
if tile_target_resolver != null:
|
||||
sac_spirits = tile_target_resolver.valid_sacrifice_spirits()
|
||||
if not sac_spirits.is_empty():
|
||||
menu.add_item("Sacrifice a Spirit", 0)
|
||||
|
||||
var can_ascend: bool = false
|
||||
var can_transition: bool = false
|
||||
var cur_tier: int = int(unit.get("tier", 1))
|
||||
for card: Dictionary in Game.get_hand():
|
||||
if card.get("cardType", "") != "ArchSpirit":
|
||||
continue
|
||||
var t: int = int(card.get("tier", 0))
|
||||
if t == cur_tier + 1:
|
||||
can_ascend = true
|
||||
if t == 1:
|
||||
can_transition = true
|
||||
|
||||
if can_ascend:
|
||||
menu.add_item("Ascend ArchSpirit", 1)
|
||||
if can_transition:
|
||||
menu.add_item("Transition ArchSpirit", 2)
|
||||
|
||||
if menu.item_count == 0:
|
||||
menu.queue_free()
|
||||
return
|
||||
|
||||
menu.id_pressed.connect(func(id: int) -> void:
|
||||
match id:
|
||||
0: _start_sacrifice_mode()
|
||||
1: _pick_ascend_card()
|
||||
2: _pick_transition_card()
|
||||
menu.queue_free())
|
||||
menu.popup_hide.connect(func() -> void: menu.queue_free())
|
||||
menu.position = DisplayServer.mouse_get_position()
|
||||
menu.reset_size()
|
||||
menu.popup()
|
||||
|
||||
|
||||
func _start_sacrifice_mode() -> void:
|
||||
set_mode(Mode.SACRIFICE_SELECT)
|
||||
emit_signal("highlights_cleared")
|
||||
var spirits: Array = []
|
||||
if tile_target_resolver != null:
|
||||
spirits = tile_target_resolver.valid_sacrifice_spirits()
|
||||
for spirit: Dictionary in spirits:
|
||||
var sp: Dictionary = spirit.get("position", {})
|
||||
if not sp.is_empty():
|
||||
emit_signal("highlight_add_requested", int(sp.get("x", 0)), int(sp.get("y", 0)), "movement")
|
||||
|
||||
|
||||
func _confirm_sacrifice(unit_id: String, unit_name: String) -> void:
|
||||
var dlg: ConfirmationDialog = ConfirmationDialog.new()
|
||||
dlg.title = "Sacrifice"
|
||||
dlg.dialog_text = "Sacrifice %s?" % unit_name
|
||||
dlg.ok_button_text = "Sacrifice"
|
||||
dlg.cancel_button_text = "Cancel"
|
||||
dlg.min_size = Vector2(260, 90)
|
||||
add_child(dlg)
|
||||
dlg.popup_centered()
|
||||
dlg.confirmed.connect(func() -> void:
|
||||
Game.send_sacrifice(unit_id)
|
||||
dlg.queue_free()
|
||||
set_mode(Mode.NONE))
|
||||
dlg.canceled.connect(func() -> void:
|
||||
dlg.queue_free()
|
||||
set_mode(Mode.NONE))
|
||||
|
||||
# ── Ascend / Transition ───────────────────────────────────────────────────────
|
||||
|
||||
func _pick_ascend_card() -> void:
|
||||
var cur_tier: int = _get_my_arch_tier()
|
||||
var candidates: Array = Game.get_hand().filter(func(c: Dictionary) -> bool:
|
||||
return c.get("cardType", "") == "ArchSpirit" and int(c.get("tier", 0)) == cur_tier + 1)
|
||||
if candidates.is_empty():
|
||||
return
|
||||
if candidates.size() == 1:
|
||||
_confirm_ascend(candidates[0])
|
||||
else:
|
||||
_show_card_picker("Choose Ascend Card", candidates,
|
||||
func(card: Dictionary) -> void: _confirm_ascend(card))
|
||||
|
||||
|
||||
func _pick_transition_card() -> void:
|
||||
var candidates: Array = Game.get_hand().filter(func(c: Dictionary) -> bool:
|
||||
return c.get("cardType", "") == "ArchSpirit" and int(c.get("tier", 0)) == 1)
|
||||
if candidates.is_empty():
|
||||
return
|
||||
if candidates.size() == 1:
|
||||
_confirm_transition(candidates[0])
|
||||
else:
|
||||
_show_card_picker("Choose Transition Card", candidates,
|
||||
func(card: Dictionary) -> void: _confirm_transition(card))
|
||||
|
||||
|
||||
func _confirm_ascend(card: Dictionary) -> void:
|
||||
var dlg: ConfirmationDialog = ConfirmationDialog.new()
|
||||
dlg.title = "Ascend"
|
||||
dlg.dialog_text = "Ascend to %s (Tier %d)?" % [
|
||||
card.get("name", "?"), int(card.get("tier", 0))]
|
||||
dlg.ok_button_text = "Ascend"
|
||||
dlg.min_size = Vector2(280, 90)
|
||||
add_child(dlg)
|
||||
dlg.popup_centered()
|
||||
dlg.confirmed.connect(func() -> void:
|
||||
Game.send_ascend(card.get("instanceId", ""))
|
||||
dlg.queue_free())
|
||||
dlg.canceled.connect(func() -> void: dlg.queue_free())
|
||||
|
||||
|
||||
func _confirm_transition(card: Dictionary) -> void:
|
||||
var dlg: ConfirmationDialog = ConfirmationDialog.new()
|
||||
dlg.title = "Transition"
|
||||
dlg.dialog_text = "Swap to %s?" % card.get("name", "?")
|
||||
dlg.ok_button_text = "Transition"
|
||||
dlg.min_size = Vector2(280, 90)
|
||||
add_child(dlg)
|
||||
dlg.popup_centered()
|
||||
dlg.confirmed.connect(func() -> void:
|
||||
Game.send_transition(card.get("instanceId", ""))
|
||||
dlg.queue_free())
|
||||
dlg.canceled.connect(func() -> void: dlg.queue_free())
|
||||
|
||||
|
||||
func channel_ruin(card: Dictionary) -> void:
|
||||
var card_affinity: String = card.get("affinity", "")
|
||||
var board: Dictionary = Game.get_board()
|
||||
var has_valid: bool = false
|
||||
for tile: Dictionary in board.get("tiles", []):
|
||||
var ruin_id_v: Variant = tile.get("ruinId", null)
|
||||
var ruin_id: String = "" if ruin_id_v == null else str(ruin_id_v)
|
||||
if not ruin_id.is_empty() and ruin_id != "null":
|
||||
continue
|
||||
if card_affinity != "" and not _tile_matches_channel_affinity(tile, card_affinity):
|
||||
continue
|
||||
has_valid = true
|
||||
break
|
||||
|
||||
if not has_valid:
|
||||
var dlg: AcceptDialog = AcceptDialog.new()
|
||||
dlg.title = "Cannot Channel Ruin"
|
||||
dlg.dialog_text = "No valid tile available for this Ruin."
|
||||
dlg.min_size = Vector2(280, 90)
|
||||
add_child(dlg)
|
||||
dlg.popup_centered()
|
||||
dlg.confirmed.connect(func() -> void: dlg.queue_free())
|
||||
return
|
||||
_confirm_channel_ruin(card)
|
||||
|
||||
|
||||
func _confirm_channel_ruin(card: Dictionary) -> void:
|
||||
var dlg: ConfirmationDialog = ConfirmationDialog.new()
|
||||
dlg.title = "Channel Ruin"
|
||||
dlg.dialog_text = "Ruin placement is random.\nContinue?"
|
||||
dlg.ok_button_text = "Channel"
|
||||
dlg.min_size = Vector2(280, 90)
|
||||
add_child(dlg)
|
||||
dlg.popup_centered()
|
||||
dlg.confirmed.connect(func() -> void:
|
||||
Game.send_play_card(card.get("instanceId", ""), 0, 0)
|
||||
dlg.queue_free())
|
||||
dlg.canceled.connect(func() -> void: dlg.queue_free())
|
||||
|
||||
|
||||
func _tile_matches_channel_affinity(tile: Dictionary, card_affinity: String) -> bool:
|
||||
return tile.get("affinity", "") == card_affinity
|
||||
|
||||
|
||||
func _get_my_arch_tier() -> int:
|
||||
var player: Dictionary = Game.get_my_player()
|
||||
var arch: Dictionary = player.get("archSpirit", {}) as Dictionary
|
||||
return int(arch.get("tier", 1))
|
||||
|
||||
|
||||
func _show_card_picker(title: String, cards: Array, on_pick: Callable) -> void:
|
||||
var dlg: AcceptDialog = AcceptDialog.new()
|
||||
dlg.title = title
|
||||
dlg.min_size = Vector2(320, 200)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 6)
|
||||
for card: Dictionary in cards:
|
||||
var btn: Button = Button.new()
|
||||
btn.text = "%s (Tier %d)" % [card.get("name", "?"), int(card.get("tier", 0))]
|
||||
btn.pressed.connect(func() -> void:
|
||||
on_pick.call(card)
|
||||
dlg.queue_free())
|
||||
vbox.add_child(btn)
|
||||
dlg.add_child(vbox)
|
||||
add_child(dlg)
|
||||
dlg.popup_centered()
|
||||
dlg.canceled.connect(func() -> void: dlg.queue_free())
|
||||
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func _find_hand_card(iid: String) -> Dictionary:
|
||||
for card: Dictionary in Game.get_hand():
|
||||
if str(card.get("instanceId", "")) == iid:
|
||||
return card
|
||||
return {}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dvgce0i548dvn
|
||||
@@ -0,0 +1,514 @@
|
||||
class_name ServerPromptHandler
|
||||
extends Node
|
||||
|
||||
## Handles all server-driven ability-pause prompts:
|
||||
## PendingCostPick, PendingCostGroupPick, PendingActionGroupPick,
|
||||
## PendingBranchPick, PendingTargetPick, PendingTilePick,
|
||||
## PendingPlayerPick, PendingRevealChoicePick.
|
||||
##
|
||||
## External refs (set by game_screen._ready):
|
||||
## selection_controller — for set_mode() calls
|
||||
## ability_targeting — for target-pick setup and normalize_keys
|
||||
## pathfinder — for board_distance in tile-pick range checks
|
||||
## hud — CanvasLayer that owns all 2D HUD children
|
||||
|
||||
# ── Signals ───────────────────────────────────────────────────────────────────
|
||||
|
||||
signal highlight_add_requested(x: int, y: int, type_name: String)
|
||||
signal highlights_cleared()
|
||||
|
||||
# ── External refs ─────────────────────────────────────────────────────────────
|
||||
|
||||
var selection_controller: SelectionController = null
|
||||
var ability_targeting: AbilityTargeting = null
|
||||
var pathfinder: Pathfinder = null
|
||||
var hud: CanvasLayer = null
|
||||
|
||||
# ── Prompt state ──────────────────────────────────────────────────────────────
|
||||
|
||||
var pending_req_id: String = ""
|
||||
var pending_source_id: String = ""
|
||||
var pending_prompt_panel: Control = null
|
||||
|
||||
# Tile-pick constraints
|
||||
var tile_pick_max_range: int = 0
|
||||
var tile_pick_require_empty: bool = false
|
||||
var tile_pick_require_occupied: bool = false
|
||||
|
||||
# Cost-pick accumulation
|
||||
var cost_pick_selected: Array[String] = []
|
||||
var cost_pick_amount: int = 1
|
||||
|
||||
# Reveal-choice ordering
|
||||
var reveal_ordered_indices: Array = []
|
||||
var reveal_total_cards: int = 0
|
||||
var reveal_required_count: int = 1
|
||||
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func hide_pending_prompt_panel() -> void:
|
||||
if is_instance_valid(pending_prompt_panel):
|
||||
pending_prompt_panel.queue_free()
|
||||
pending_prompt_panel = null
|
||||
|
||||
|
||||
func _normalize_keys(value: Variant) -> Variant:
|
||||
if ability_targeting != null:
|
||||
return ability_targeting.normalize_keys(value)
|
||||
# Fallback inline normaliser.
|
||||
if value is Dictionary:
|
||||
var result: Dictionary = {}
|
||||
for k: Variant in (value as Dictionary):
|
||||
result[str(k).to_lower()] = _normalize_keys((value as Dictionary)[k])
|
||||
return result
|
||||
elif value is Array:
|
||||
var result: Array = []
|
||||
for item: Variant in (value as Array):
|
||||
result.append(_normalize_keys(item))
|
||||
return result
|
||||
return value
|
||||
|
||||
|
||||
func _cancel_current_mode() -> void:
|
||||
if selection_controller != null and selection_controller.mode != SelectionController.Mode.NONE:
|
||||
selection_controller.set_mode(SelectionController.Mode.NONE)
|
||||
|
||||
# ── PendingCostPick ───────────────────────────────────────────────────────────
|
||||
|
||||
func on_cost_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
pending_req_id = str(req.get("requestId", ""))
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
cost_pick_selected.clear()
|
||||
cost_pick_amount = int(req.get("amount", 1))
|
||||
var cost_type: String = str(req.get("costType", ""))
|
||||
var pick_mode: String = str(req.get("pickMode", "SelfPick"))
|
||||
|
||||
hide_pending_prompt_panel()
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 160)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 6)
|
||||
vbox.custom_minimum_size = Vector2(200, 0)
|
||||
|
||||
var title: Label = Label.new()
|
||||
title.text = "Cost: %s (select %d)" % [cost_type, cost_pick_amount]
|
||||
title.add_theme_font_size_override("font_size", 13)
|
||||
title.add_theme_color_override("font_color", Color(1.0, 0.75, 0.2))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
var candidates_raw: Variant = JSON.parse_string(str(req.get("candidatesJson", "[]")))
|
||||
var candidates: Array = candidates_raw as Array if candidates_raw is Array else []
|
||||
if candidates.is_empty():
|
||||
var lbl: Label = Label.new()
|
||||
lbl.text = "(no candidates)"
|
||||
lbl.add_theme_font_size_override("font_size", 11)
|
||||
vbox.add_child(lbl)
|
||||
else:
|
||||
for cand: Variant in candidates:
|
||||
var card_d: Dictionary = cand as Dictionary
|
||||
var iid: String = str(card_d.get("instanceId", ""))
|
||||
var name_: String = str(card_d.get("name", iid))
|
||||
var btn: Button = Button.new()
|
||||
btn.text = name_
|
||||
btn.add_theme_font_size_override("font_size", 11)
|
||||
var cap_iid: String = iid
|
||||
btn.pressed.connect(func() -> void:
|
||||
if not cap_iid in cost_pick_selected:
|
||||
cost_pick_selected.append(cap_iid)
|
||||
btn.modulate = Color(0.4, 1.0, 0.4)
|
||||
if cost_pick_selected.size() >= cost_pick_amount:
|
||||
finish_cost_pick())
|
||||
vbox.add_child(btn)
|
||||
|
||||
if pick_mode == "SelfPick":
|
||||
var confirm: Button = Button.new()
|
||||
confirm.text = "Confirm"
|
||||
confirm.add_theme_font_size_override("font_size", 12)
|
||||
confirm.pressed.connect(finish_cost_pick)
|
||||
vbox.add_child(confirm)
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
pending_prompt_panel = panel
|
||||
|
||||
|
||||
func finish_cost_pick() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id
|
||||
pending_req_id = ""
|
||||
Game.send_cost_pick_response(rid, cost_pick_selected)
|
||||
cost_pick_selected.clear()
|
||||
|
||||
# ── PendingCostGroupPick ──────────────────────────────────────────────────────
|
||||
|
||||
func on_cost_group_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
pending_req_id = str(req.get("requestId", ""))
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
|
||||
var group_raw: Variant = JSON.parse_string(str(req.get("costGroupJson", "{}")))
|
||||
var group: Dictionary = _normalize_keys(group_raw) as Dictionary if group_raw is Dictionary else {}
|
||||
var entries: Array = group.get("entries", []) as Array
|
||||
var groups: Array = group.get("groups", []) as Array
|
||||
var logic: String = str(group.get("logicop", group.get("logicOp", "OR")))
|
||||
|
||||
hide_pending_prompt_panel()
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 160)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
vbox.custom_minimum_size = Vector2(200, 0)
|
||||
|
||||
var title: Label = Label.new()
|
||||
title.text = "Choose Cost (%s):" % logic
|
||||
title.add_theme_font_size_override("font_size", 13)
|
||||
title.add_theme_color_override("font_color", Color(1.0, 0.75, 0.2))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
var option_idx: int = 0
|
||||
for entry: Variant in entries:
|
||||
var entry_d: Dictionary = entry as Dictionary
|
||||
var label: String = str(entry_d.get("typestr", entry_d.get("typeStr", "Option %d" % (option_idx + 1))))
|
||||
var btn: Button = Button.new()
|
||||
btn.text = label
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_idx: int = option_idx
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id; pending_req_id = ""
|
||||
Game.send_cost_group_pick_response(rid, cap_idx))
|
||||
vbox.add_child(btn)
|
||||
option_idx += 1
|
||||
for grp: Variant in groups:
|
||||
var grp_d: Dictionary = grp as Dictionary
|
||||
var lop: String = str(grp_d.get("logicop", grp_d.get("logicOp", "OR")))
|
||||
var btn: Button = Button.new()
|
||||
btn.text = "Group (%s)" % lop
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_idx: int = option_idx
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id; pending_req_id = ""
|
||||
Game.send_cost_group_pick_response(rid, cap_idx))
|
||||
vbox.add_child(btn)
|
||||
option_idx += 1
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
pending_prompt_panel = panel
|
||||
|
||||
# ── PendingActionGroupPick ────────────────────────────────────────────────────
|
||||
|
||||
func on_action_group_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
pending_req_id = str(req.get("requestId", ""))
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
|
||||
var group_raw: Variant = JSON.parse_string(str(req.get("actionGroupJson", "{}")))
|
||||
var group: Dictionary = _normalize_keys(group_raw) as Dictionary if group_raw is Dictionary else {}
|
||||
var actions: Array = group.get("actions", []) as Array
|
||||
var subgrps: Array = group.get("groups", []) as Array
|
||||
var logic: String = str(group.get("logicop", group.get("logicOp", "OR")))
|
||||
|
||||
hide_pending_prompt_panel()
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 160)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
vbox.custom_minimum_size = Vector2(200, 0)
|
||||
|
||||
var title: Label = Label.new()
|
||||
title.text = "Choose Action (%s):" % logic
|
||||
title.add_theme_font_size_override("font_size", 13)
|
||||
title.add_theme_color_override("font_color", Color(0.4, 0.8, 1.0))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
var option_idx: int = 0
|
||||
for act: Variant in actions:
|
||||
var act_d: Dictionary = act as Dictionary
|
||||
var label: String = str(act_d.get("label", "Action %d" % (option_idx + 1)))
|
||||
if label.is_empty():
|
||||
var tgt: Dictionary = act_d.get("target", {}) as Dictionary
|
||||
label = "%s %s" % [tgt.get("ownership", ""), tgt.get("targetType", "")]
|
||||
label = label.strip_edges()
|
||||
if label.is_empty():
|
||||
label = "Action %d" % (option_idx + 1)
|
||||
var btn: Button = Button.new()
|
||||
btn.text = label
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_idx: int = option_idx
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id; pending_req_id = ""
|
||||
Game.send_action_group_pick_response(rid, cap_idx))
|
||||
vbox.add_child(btn)
|
||||
option_idx += 1
|
||||
for grp: Variant in subgrps:
|
||||
var grp_d: Dictionary = grp as Dictionary
|
||||
var lop: String = str(grp_d.get("logicop", grp_d.get("logicOp", "OR")))
|
||||
var btn: Button = Button.new()
|
||||
btn.text = "Group (%s)" % lop
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_idx: int = option_idx
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id; pending_req_id = ""
|
||||
Game.send_action_group_pick_response(rid, cap_idx))
|
||||
vbox.add_child(btn)
|
||||
option_idx += 1
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
pending_prompt_panel = panel
|
||||
|
||||
# ── PendingBranchPick ─────────────────────────────────────────────────────────
|
||||
|
||||
func on_branch_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
pending_req_id = str(req.get("requestId", ""))
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
|
||||
var branches_raw: Variant = JSON.parse_string(str(req.get("branchesJson", "[]")))
|
||||
var branches: Array = _normalize_keys(branches_raw) as Array if branches_raw is Array else []
|
||||
|
||||
hide_pending_prompt_panel()
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 120)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
vbox.custom_minimum_size = Vector2(190, 0)
|
||||
|
||||
var title: Label = 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: int in branches.size():
|
||||
var branch: Dictionary = branches[i] as Dictionary
|
||||
var label: String = str(branch.get("label", "Option %d" % (i + 1)))
|
||||
var btn: Button = Button.new()
|
||||
btn.text = label
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_idx: int = i
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id; pending_req_id = ""
|
||||
Game.send_branch_pick_response(rid, cap_idx))
|
||||
vbox.add_child(btn)
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
pending_prompt_panel = panel
|
||||
|
||||
# ── PendingTargetPick ─────────────────────────────────────────────────────────
|
||||
|
||||
func on_target_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
if ability_targeting == null:
|
||||
return
|
||||
|
||||
ability_targeting.is_target_pick = true
|
||||
ability_targeting.pending_req_id = str(req.get("requestId", ""))
|
||||
pending_req_id = ability_targeting.pending_req_id
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
ability_targeting.ability_unit_id = pending_source_id
|
||||
ability_targeting.ability_idx = -1
|
||||
ability_targeting.ability_card_id = ""
|
||||
ability_targeting.ability_target_conditions = []
|
||||
|
||||
var action_json: String = str(req.get("actionJson", "{}"))
|
||||
var action_raw: Variant = JSON.parse_string(action_json)
|
||||
if action_raw is Dictionary:
|
||||
ability_targeting.ability_def = [_normalize_keys(action_raw)]
|
||||
elif action_raw is Array:
|
||||
ability_targeting.ability_def = _normalize_keys(action_raw) as Array
|
||||
else:
|
||||
ability_targeting.ability_def = []
|
||||
|
||||
var range_json: String = str(req.get("rangeJson", ""))
|
||||
if not range_json.is_empty() and range_json != "null":
|
||||
var r: Variant = JSON.parse_string(range_json)
|
||||
ability_targeting.ability_range = _normalize_keys(r) as Dictionary if r is Dictionary else {}
|
||||
else:
|
||||
ability_targeting.ability_range = {}
|
||||
|
||||
ability_targeting.ability_targets = []
|
||||
ability_targeting.ability_cur_action_idx = 0
|
||||
ability_targeting.ability_target_n = 1
|
||||
ability_targeting.ability_target_up_to = false
|
||||
ability_targeting.ability_targets_this_action = 0
|
||||
ability_targeting.start_ability_targeting()
|
||||
|
||||
# ── PendingTilePick ───────────────────────────────────────────────────────────
|
||||
|
||||
func on_tile_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
|
||||
var req_id: String = str(req.get("requestId", ""))
|
||||
var source_id: String = str(req.get("sourceInstanceId", ""))
|
||||
|
||||
tile_pick_max_range = int(req.get("maxRange", 0))
|
||||
tile_pick_require_empty = bool(req.get("requireEmpty", false))
|
||||
tile_pick_require_occupied = bool(req.get("requireOccupied", false))
|
||||
|
||||
# Write shared state so selection_controller's forced-target click can read it.
|
||||
if ability_targeting != null:
|
||||
ability_targeting.is_tile_pick = true
|
||||
ability_targeting.pending_req_id = req_id
|
||||
ability_targeting.ability_unit_id = source_id
|
||||
pending_req_id = req_id
|
||||
pending_source_id = source_id
|
||||
|
||||
if selection_controller != null:
|
||||
selection_controller.set_mode(SelectionController.Mode.ABILITY_TARGET_FORCED)
|
||||
emit_signal("highlights_cleared")
|
||||
|
||||
var bw: int = Game.board_width()
|
||||
var bh: int = Game.board_height()
|
||||
var src_pos: Dictionary = {}
|
||||
if not source_id.is_empty():
|
||||
var src_unit: Variant = Game.get_unit_by_id(source_id)
|
||||
if src_unit is Dictionary:
|
||||
src_pos = (src_unit as Dictionary).get("position", {}) as Dictionary
|
||||
|
||||
var occupant_ownership: String = str(req.get("occupantOwnership", "Any"))
|
||||
for tx: int in range(bw):
|
||||
for ty: int in range(bh):
|
||||
if tile_pick_max_range > 0 and not src_pos.is_empty() and pathfinder != null:
|
||||
var dist: int = pathfinder.board_distance(
|
||||
tx, ty, int(src_pos.get("x", 0)), int(src_pos.get("y", 0)))
|
||||
if dist > tile_pick_max_range:
|
||||
continue
|
||||
var tile: Dictionary = Game.get_tile(tx, ty)
|
||||
if tile.is_empty():
|
||||
continue
|
||||
var occ_id: String = str(tile.get("occupantId", ""))
|
||||
if tile_pick_require_empty and not occ_id.is_empty():
|
||||
continue
|
||||
if tile_pick_require_occupied and occ_id.is_empty():
|
||||
continue
|
||||
if tile_pick_require_occupied and not occ_id.is_empty() and occupant_ownership != "Any":
|
||||
var occ_owner: String = str(tile.get("occupantOwner", ""))
|
||||
var my_id: String = Auth.user_id
|
||||
if occupant_ownership == "Self" and occ_owner != my_id:
|
||||
continue
|
||||
if occupant_ownership == "Enemy" and occ_owner == my_id:
|
||||
continue
|
||||
emit_signal("highlight_add_requested", tx, ty, "ability")
|
||||
|
||||
# ── PendingPlayerPick ─────────────────────────────────────────────────────────
|
||||
|
||||
func on_player_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
pending_req_id = str(req.get("requestId", ""))
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
|
||||
var valid_ids_raw: Variant = req.get("validPlayerIds")
|
||||
var valid_ids: Array = valid_ids_raw as Array if valid_ids_raw is Array else []
|
||||
|
||||
hide_pending_prompt_panel()
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 180)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
vbox.custom_minimum_size = Vector2(160, 0)
|
||||
|
||||
var title: Label = Label.new()
|
||||
title.text = "Choose Player:"
|
||||
title.add_theme_font_size_override("font_size", 13)
|
||||
title.add_theme_color_override("font_color", Color(0.7, 0.8, 1.0))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
for pid_raw: Variant in valid_ids:
|
||||
var pid: String = str(pid_raw)
|
||||
var pname: String = Game.get_display_name(pid)
|
||||
if pname.is_empty():
|
||||
pname = pid.substr(0, 8)
|
||||
var btn: Button = Button.new()
|
||||
btn.text = pname
|
||||
btn.add_theme_font_size_override("font_size", 12)
|
||||
var cap_pid: String = pid
|
||||
btn.pressed.connect(func() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id; pending_req_id = ""
|
||||
Game.send_player_pick_response(rid, cap_pid))
|
||||
vbox.add_child(btn)
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
pending_prompt_panel = panel
|
||||
|
||||
# ── PendingRevealChoicePick ───────────────────────────────────────────────────
|
||||
|
||||
func on_reveal_choice_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
pending_req_id = str(req.get("requestId", ""))
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
reveal_required_count = int(req.get("count", 1))
|
||||
reveal_ordered_indices.clear()
|
||||
|
||||
var cards_raw: Variant = JSON.parse_string(str(req.get("revealedCardsJson", "[]")))
|
||||
var cards: Array = _normalize_keys(cards_raw) as Array if cards_raw is Array else []
|
||||
reveal_total_cards = cards.size()
|
||||
|
||||
hide_pending_prompt_panel()
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 100)
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 6)
|
||||
vbox.custom_minimum_size = Vector2(210, 0)
|
||||
|
||||
var title: Label = Label.new()
|
||||
title.text = "Order top %d card(s):" % reveal_required_count
|
||||
title.add_theme_font_size_override("font_size", 13)
|
||||
title.add_theme_color_override("font_color", Color(0.6, 1.0, 0.8))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
for i: int in cards.size():
|
||||
var card_d: Dictionary = cards[i] as Dictionary
|
||||
var name_: String = str(card_d.get("name", "Card %d" % (i + 1)))
|
||||
var btn: Button = Button.new()
|
||||
btn.text = "%d. %s" % [i + 1, name_]
|
||||
btn.add_theme_font_size_override("font_size", 11)
|
||||
var cap_i: int = i
|
||||
var cap_btn: Button = btn
|
||||
btn.pressed.connect(func() -> void:
|
||||
if cap_i in reveal_ordered_indices: return
|
||||
reveal_ordered_indices.append(cap_i)
|
||||
cap_btn.modulate = Color(0.4, 1.0, 0.5)
|
||||
cap_btn.text = "#%d %s" % [reveal_ordered_indices.size(), name_]
|
||||
if reveal_ordered_indices.size() >= reveal_required_count:
|
||||
finish_reveal_pick())
|
||||
vbox.add_child(btn)
|
||||
|
||||
var confirm: Button = Button.new()
|
||||
confirm.text = "Confirm Order"
|
||||
confirm.add_theme_font_size_override("font_size", 12)
|
||||
confirm.pressed.connect(finish_reveal_pick)
|
||||
vbox.add_child(HSeparator.new())
|
||||
vbox.add_child(confirm)
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
pending_prompt_panel = panel
|
||||
|
||||
|
||||
func finish_reveal_pick() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id; pending_req_id = ""
|
||||
Game.send_reveal_choice_pick_response(rid, reveal_ordered_indices)
|
||||
reveal_ordered_indices.clear()
|
||||
@@ -0,0 +1 @@
|
||||
uid://dxl0o2g2aj4bc
|
||||
Reference in New Issue
Block a user