fix(game): revert UntilEndOfTurn effects on ArchSpirit targets; add action-level duration to ability builder

- ApplyReversal and TickActiveEffects were searching p.Field/Hand/Deck/Discard
  but not p.ArchSpirit, so effects applied to an ArchSpirit (e.g. SetCanBeAttacked=false
  from "Branch Between Fangs") were never reverted — the tracking entry was removed
  but CanBeAttacked stayed false permanently
- Fixes by adding p.ArchSpirit to the target lookup in both functions, matching
  the existing pattern in FindTargetByRef
- AbilityBuilder: add action-level Duration field to ActionDraft, compile/parse it
  in CompileActionNode/ParseActionNode, and expose a UI dropdown on each action
- ClearOnLeave now defaults to true in AbilityDefinition and AbilityBuilder
- Instinct/Repentance card click now correctly enters ABILITY_TARGET mode

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-04-29 07:20:51 -04:00
co-authored by Claude Happy
parent 7cbea2b907
commit b985445ae9
4 changed files with 154 additions and 23 deletions
+100 -9
View File
@@ -20,6 +20,7 @@ enum Mode {
PLACEMENT,
SACRIFICE_SELECT,
ABILITY_TARGET,
ABILITY_TARGET_FORCED,
}
# ── Node refs ─────────────────────────────────────────────────────────────────
@@ -84,6 +85,8 @@ var count : int = 0
var _cam_tween : Tween = null
var _last_click_frame : int = -1
var _last_click_iid : String = ""
var _last_board_click_frame : int = -1
var _last_board_click_coord : Vector2i = Vector2i(-999, -999)
var _is_spectating : bool = false
var _hand_focus_index : int = 0
var _hand_scroll_time : float = 0.0 # monotonic time of last hand scroll
@@ -3468,6 +3471,54 @@ func _focus_camera_on_tile(x: int, y: int) -> void:
func _handle_board_click(mouse_pos: Vector2) -> void:
var coord := _mouse_to_tile_coord(mouse_pos)
var unit_id := _mouse_to_unit_id(mouse_pos)
var cf := 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
if _mode == Mode.ABILITY_TARGET_FORCED:
# Occupied tile with no direct unit-mesh hit -> redirect to the occupant.
if unit_id.is_empty() and coord.x >= 0:
var _target_tile := Game.get_tile(coord.x, coord.y)
var _target_raw_occ = _target_tile.get("occupantId")
var _target_occ : Variant = _target_raw_occ if _target_raw_occ is String else ""
if not _target_occ.is_empty() and _target_occ != "null" and not _is_ruin_instance(str(_target_occ)):
unit_id = _target_occ
# Server-driven tile pick -> send directly and exit.
if _is_tile_pick and coord.x >= 0:
_is_tile_pick = false
var rid := _pending_req_id
_pending_req_id = ""
_set_mode(Mode.NONE)
_clear_highlights()
Game.send_tile_pick_response(rid, coord.x, coord.y)
return
# 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_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:
_ability_cur_action_idx += 1
_advance_ability_targeting()
return
match _mode:
@@ -3591,6 +3642,9 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
_set_mode(Mode.NONE); return
_confirm_sacrifice(unit_id, unit.get("name", "this spirit"))
Mode.ABILITY_TARGET_FORCED:
return
Mode.ABILITY_TARGET:
# Server-driven tile pick — send directly and exit.
if _is_tile_pick and coord.x >= 0:
@@ -3629,6 +3683,10 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
func _select_unit(unit_id: String) -> void:
# Server-driven prompt targeting must never collapse into normal unit selection.
if _mode == Mode.ABILITY_TARGET_FORCED:
return
var unit := Game.get_unit_by_id(unit_id)
if unit.is_empty(): return
if _is_ruin_unit(unit): return
@@ -3898,6 +3956,30 @@ func _normalize_keys(value: Variant) -> Variant:
return value
## Returns the flat action list to use for client-side target collection.
## Prefers the modern ActionGroup format (flattens AND groups recursively) over
## the legacy flat "actions" array. OR/XOR groups return only their leaf actions —
## the server handles the interactive pick via action_group_pick_request.
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 position so it stays within the viewport.
## Called after the panel has been added to the tree so size is valid.
func _clamp_panel_pos(desired: Vector2, panel: Control) -> Vector2:
@@ -3976,7 +4058,7 @@ func _show_ability_panel(unit_id: String, unit: Dictionary) -> void:
btn.pressed.connect(func() -> void:
_ability_unit_id = unit_id
_ability_idx = idx
_ability_def = ab_def.get("actions", [])
_ability_def = _get_ability_actions(ab_def)
_ability_range = ab_def.get("range", {})
_ability_targets = []
_ability_cur_action_idx = 0
@@ -4018,6 +4100,9 @@ func _hide_ability_panel() -> void:
_ability_panel.queue_free()
_ability_panel = null
func _current_target_mode() -> Mode:
return Mode.ABILITY_TARGET_FORCED if (_is_triggered_target or _is_target_pick or _is_tile_pick) else Mode.ABILITY_TARGET
## Determine what input is needed for the current action and either enter
## ABILITY_TARGET mode (board highlights) or show the player panel.
@@ -4032,8 +4117,9 @@ func _start_ability_targeting() -> void:
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)
var choose_one : Variant = action.get("chooseone")
if choose_one is Dictionary and not (choose_one as Dictionary).get("branches", []).is_empty():
_set_mode(_current_target_mode())
_clear_highlights()
_show_branch_panel(action)
return
@@ -4060,13 +4146,13 @@ func _start_ability_targeting() -> void:
# Player / zone selection — show the left-side player panel.
var zone_scopes := ["Player", "Hand", "Deck", "Discard", "AnyZone"]
if scope in zone_scopes:
_set_mode(Mode.ABILITY_TARGET)
_set_mode(_current_target_mode())
_clear_highlights()
_show_player_panel(scope, ownership)
return
# Board selection — enter ABILITY_TARGET mode with blue tile highlights.
_set_mode(Mode.ABILITY_TARGET)
_set_mode(_current_target_mode())
_clear_highlights()
_highlight_ability_targets(action)
@@ -4091,7 +4177,8 @@ func _highlight_ability_targets(action: Dictionary) -> void:
var target_sel : Dictionary = action.get("target", {})
var type_ : String = target_sel.get("type", "Unit")
var ownership : String = target_sel.get("ownership", "Any")
var filters : Array = target_sel.get("filters", [])
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)
@@ -4382,7 +4469,7 @@ func _on_triggered_target_request(req: Dictionary) -> void:
_ability_def = []
var range_json : String = str(req.get("rangeJson", ""))
if not range_json.is_empty() and range_json != "null":
if not range_json.is_empty() and range_json != "null" and range_json != "<null>":
var r = JSON.parse_string(range_json)
_ability_range = _normalize_keys(r) as Dictionary if r is Dictionary else {}
else:
@@ -4688,7 +4775,7 @@ func _on_tile_pick_request(req: Dictionary) -> void:
_ability_unit_id = _pending_source_id
# Highlight valid tiles.
_set_mode(Mode.ABILITY_TARGET)
_set_mode(Mode.ABILITY_TARGET_FORCED)
_clear_highlights()
var bw := Game.board_width(); var bh := Game.board_height()
var src_pos : Dictionary = {}
@@ -5032,7 +5119,7 @@ func _on_hand_card_clicked(iid: String, _panel: PanelContainer) -> void:
_ability_card_id = iid
_ability_unit_id = ""
_ability_idx = 0
_ability_def = ab.get("actions", [])
_ability_def = _get_ability_actions(ab)
_ability_range = {}
_ability_target_conditions = tgt_conds
_ability_targets = []
@@ -6066,6 +6153,10 @@ func _on_state_updated(state: Dictionary) -> void:
_highlight_tiles(_valid_play_tiles(sel_card), "movement")
_refresh_hand_selection() # mark the (new) widget as selected
Mode.ABILITY_TARGET_FORCED:
_clear_highlights()
_start_ability_targeting()
_:
# Unit selected, sacrifice, ability — clear these on any state change
# because unit positions / health / eligibility may have changed.