feat(ability): implement AbilityBuilderR3 + engine additions

Engine:
- AbilityDefinition: add SourceZoneGate (zone-restricted triggers) and TriggerLimitPerGame
- Effects: add StatModOperator (Add/Subtract/Multiply/Divide/Percent) on all stat mod effects; reversal stored as delta
- Action/CostEntry: add CostPickMode enum (Random/SelfPick/EnemySeePick/EnemyRandomPick/EnemyPick)
- PendingCostPick: new model for interactive cost pause/resume (mirrors PendingTriggeredTarget)
- GameState: PendingCostPick field
- GameMessages: CostPickRequestPush, GameCostPickRequest, GameCostPickResponse records
- AbilitySystem: FireTrigger scans Hand/Discard/Deck when SourceZoneGate set; per-game trigger limit tracking; ApplyStatOperator helper; PayCosts/ResumeCostPick for interactive cost flow
- GameCostPickHandler + ServiceRegistration wiring

Admin:
- AbilityBuilderR3.razor: full ability builder at /cards/ability-builder-r3 (39 triggers, 69 effects, 32 conditions, form/canvas/mermaid modes, compiles to engine-native $type JSON)
- AbilityBuilderR2-Draft.razor: fix switch expression no-best-type error

Docs:
- BuilderR3.md: master plan document

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-18 20:15:13 -04:00
co-authored by Claude Happy
parent 26fa4c810d
commit 8f3911e881
20 changed files with 5290 additions and 133 deletions
+38
View File
@@ -67,6 +67,7 @@ var _message_poll_timer: Timer = null
var _message_poll_in_flight: Dictionary = {}
var _bubble_visible_requested := false
var _bubble_host: Control = null
var _bubble_visibility_owners: Dictionary = {}
const MESSAGE_POLL_INTERVAL_SEC := 0.2
@@ -112,6 +113,7 @@ func _on_auth_success(_uid: String, _dn: String) -> void:
## (e.g. MainScreen._ready / _exit_tree).
func set_bubble_visible(v: bool) -> void:
_bubble_visible_requested = v
_bubble_visibility_owners.clear()
if is_instance_valid(_overlay):
if _overlay.has_method("set_overlay_visible"):
_overlay.call("set_overlay_visible", v)
@@ -119,6 +121,20 @@ func set_bubble_visible(v: bool) -> void:
_overlay.visible = v
func claim_bubble_visibility(owner: Node) -> void:
if not is_instance_valid(owner):
return
_bubble_visibility_owners[owner.get_instance_id()] = weakref(owner)
_apply_bubble_visibility()
func release_bubble_visibility(owner: Node) -> void:
if not is_instance_valid(owner):
return
_bubble_visibility_owners.erase(owner.get_instance_id())
_apply_bubble_visibility()
func set_bubble_host(host: Control) -> void:
_bubble_host = host
if is_instance_valid(_overlay) and _overlay.has_method("set_bubble_host"):
@@ -128,6 +144,7 @@ func set_bubble_host(host: Control) -> void:
func _clear_state() -> void:
_bubble_visible_requested = false
_bubble_host = null
_bubble_visibility_owners.clear()
if is_instance_valid(_overlay):
if _overlay.has_method("set_overlay_visible"):
_overlay.call("set_overlay_visible", false)
@@ -355,6 +372,27 @@ func _setup_message_polling() -> void:
add_child(_message_poll_timer)
func _apply_bubble_visibility() -> void:
var stale_ids: Array = []
var should_show := false
for owner_id: Variant in _bubble_visibility_owners.keys():
var owner_ref: WeakRef = _bubble_visibility_owners[owner_id]
var owner : Variant = owner_ref.get_ref()
if owner == null:
stale_ids.append(owner_id)
continue
should_show = true
for owner_id: Variant in stale_ids:
_bubble_visibility_owners.erase(owner_id)
_bubble_visible_requested = should_show
if is_instance_valid(_overlay):
if _overlay.has_method("set_overlay_visible"):
_overlay.call("set_overlay_visible", should_show)
else:
_overlay.visible = should_show
func _start_message_polling() -> void:
if is_instance_valid(_message_poll_timer):
_message_poll_timer.start()
@@ -164,6 +164,9 @@ func _reload_collection() -> void:
_coll_page = 1
_coll_total = 0
_has_more = false
# A new query should supersede any in-flight collection request.
# Stale responses are already filtered by request generation.
_is_loading = false
for child in _coll_list.get_children():
child.queue_free()
_load_more_btn.visible = false
@@ -128,7 +128,7 @@ func _build_fields(r: Dictionary) -> void:
var sq_shape_row := fields_box.get_child(fields_box.get_child_count() - 1)
# Hex-only rows
add_int.call("Hex Sides", "hexSides", 3, 10, 5, "Hexagon only: tiles per side (3–10)")
add_int.call("Hex Sides", "hexSides", 3, 10, 6, "Hexagon only: tiles per side (3–10)")
var hex_sides_row := fields_box.get_child(fields_box.get_child_count() - 1)
# Board template picker — filtered by current grid type.
@@ -41,14 +41,14 @@ var _deck_btn_group : ButtonGroup = null
func _ready() -> void:
ContentCache.apply_scene_background(self)
Chat.set_bubble_visible(true)
Chat.claim_bubble_visibility(self)
_setup_ui()
_load_decks() # load decks first; lobbies load after decks arrive
_refresh_lobbies()
func _exit_tree() -> void:
Chat.set_bubble_visible(false)
Chat.release_bubble_visibility(self)
# ── UI setup ──────────────────────────────────────────────────────────────────
@@ -56,12 +56,14 @@ var _team_panel : VBoxContainer = null # dynamically added team-controls
func _ready() -> void:
ContentCache.apply_scene_background(self)
Chat.claim_bubble_visibility(self)
_setup_ui()
_connect_signals()
_refresh_display()
func _exit_tree() -> void:
Chat.release_bubble_visibility(self)
CustomLobby.guest_joined.disconnect(_on_guest_joined)
CustomLobby.ready_status_changed.disconnect(_on_ready_status_changed)
CustomLobby.lobby_rules_updated.disconnect(_on_rules_updated)
+46 -11
View File
@@ -352,7 +352,7 @@ func _ready() -> void:
HighlightConfig.texture_loaded.connect(_on_highlight_texture_loaded)
# Chat overlay — add to viewport root so it renders above everything.
Chat.set_bubble_visible(true)
Chat.claim_bubble_visibility(self)
Chat.set_bubble_host(_chat_bubble_host)
if Game.is_spectating:
@@ -410,7 +410,7 @@ func _exit_tree() -> void:
func(_c: String, _m: String) -> void: pass)
_clear_stars()
Chat.set_bubble_host(null)
Chat.set_bubble_visible(false)
Chat.release_bubble_visibility(self)
func _setup_spectator_ui() -> void:
@@ -1215,6 +1215,14 @@ func _mouse_to_tile_coord(mouse_pos: Vector2) -> Vector2i:
if body == null: return Vector2i(-1, -1)
if body.has_meta("tile_coord"):
return body.get_meta("tile_coord") as Vector2i
if body.has_meta("unit_id"):
var unit_id := str(body.get_meta("unit_id"))
if not unit_id.is_empty():
var unit := Game.get_unit_by_id(unit_id)
if not unit.is_empty():
var pos := unit.get("position", {}) as Dictionary
if not pos.is_empty():
return Vector2i(int(pos.get("x", -1)), int(pos.get("y", -1)))
return Vector2i(-1, -1)
@@ -1245,6 +1253,24 @@ func _is_friendly_unit(instance_id: String) -> bool:
return _friendly_unit_ids.has(instance_id)
func _is_ruin_unit(unit: Dictionary) -> bool:
return str(unit.get("cardType", "")).to_lower() == "ruin"
func _is_ruin_instance(instance_id: String) -> bool:
if instance_id.is_empty():
return false
var unit := Game.get_unit_by_id(instance_id)
return not unit.is_empty() and _is_ruin_unit(unit)
func _tile_has_blocking_occupant(tile: Dictionary) -> bool:
var occupant_id := str(tile.get("occupantId", ""))
if occupant_id.is_empty() or occupant_id == "null":
return false
return not _is_ruin_instance(occupant_id)
func _safe_arch(player: Dictionary) -> Dictionary:
var arch = player.get("archSpirit")
return arch as Dictionary if arch is Dictionary else {}
@@ -1269,6 +1295,8 @@ func _rebuild_ownership(state: Dictionary) -> void:
var is_ally : bool = (not is_mine) and (my_team_idx >= 0) and (team_idx == my_team_idx)
var target : Dictionary = _friendly_unit_ids if (is_mine or is_ally) else _enemy_unit_ids
for u: Dictionary in p.get("field", []):
if _is_ruin_unit(u):
continue
var iid : String = u.get("instanceId", "")
if not iid.is_empty():
target[iid] = true
@@ -2281,7 +2309,7 @@ func _update_prev_state(state: Dictionary) -> void:
if unit.is_empty(): continue
var iid := str(unit.get("instanceId", ""))
if iid.is_empty(): continue
_prev_unit_hp[iid] = int(unit.get("currentHealth", 0))
_prev_unit_hp[iid] = int(unit.get("currentHealth") or 0)
var pd = unit.get("position")
if pd is Dictionary and not (pd as Dictionary).is_empty():
_prev_unit_pos[iid] = Vector2i((pd as Dictionary).get("x", 0),
@@ -2662,7 +2690,7 @@ func _valid_play_tiles(card: Dictionary) -> Array:
var dist : int = _board_distance(tx, ty, ax, ay)
if dist < min_r or dist > max_r: continue
var tile : Dictionary = Game.get_tile(tx, ty)
if tile.get("occupantId"): continue
if _tile_has_blocking_occupant(tile): continue
if card_affinity != "" and not _tile_matches_channel_affinity(tile, card_affinity): continue
results.append(Vector2i(tx, ty))
@@ -2760,6 +2788,8 @@ func _valid_move_tiles(unit: Dictionary) -> Array:
# Build blocked set from all occupants, excluding this unit.
var blocked : Dictionary = {}
for unit_dict : Dictionary in Game.get_field():
if _is_ruin_unit(unit_dict):
continue
var up : Dictionary = unit_dict.get("position", {})
if up.is_empty(): continue
var cx : int = up.get("x", 0)
@@ -2779,7 +2809,7 @@ func _valid_move_tiles(unit: Dictionary) -> Array:
if not _tile_bodies.has("%d,%d" % [tx, ty]): continue
var dist : int = _board_distance(tx, ty, ux, uy)
if dist == 0 or dist > mp: continue
if Game.get_tile(tx, ty).get("occupantId"): continue
if _tile_has_blocking_occupant(Game.get_tile(tx, ty)): continue
# Teleport additionally requires LOS to the destination.
if mov == "teleport" and not _client_has_los(ux, uy, tx, ty): continue
results.append(Vector2i(tx, ty))
@@ -2792,12 +2822,14 @@ func _valid_attack_target_coords(unit: Dictionary) -> Array:
if pos.is_empty(): return results
var ux : int = pos.get("x", 0)
var uy : int = pos.get("y", 0)
var min_r : int = unit.get("minAttackRange", 1)
var max_r : int = unit.get("maxAttackRange", 1)
var min_r : int = int(unit.get("minAttackRange") or 1)
var max_r : int = int(unit.get("maxAttackRange") or 1)
var needs_los : bool = bool(unit.get("attackRequiresLos", false))
if unit.get("isExhausted", false) and unit.get("extraAttacksRemaining", 0) == 0:
return results
for t: Dictionary in Game.get_all_enemy_units():
if _is_ruin_unit(t):
continue
if not t.get("canBeAttacked", true): continue
var _tpos = t.get("position")
if not (_tpos is Dictionary): continue
@@ -2818,8 +2850,8 @@ func _valid_attack_target_ids(unit: Dictionary) -> Array:
if pos.is_empty(): return results
var ux : int = pos.get("x", 0)
var uy : int = pos.get("y", 0)
var min_r : int = unit.get("minAttackRange", 1)
var max_r : int = unit.get("maxAttackRange", 1)
var min_r : int = int(unit.get("minAttackRange") or 1)
var max_r : int = int(unit.get("maxAttackRange") or 1)
var needs_los : bool = bool(unit.get("attackRequiresLos", false))
if unit.get("isExhausted", false) and unit.get("extraAttacksRemaining", 0) == 0:
return results
@@ -2897,6 +2929,8 @@ func _valid_sacrifice_spirits() -> Array:
var ax : int = arch_pos.get("x", 0)
var ay : int = arch_pos.get("y", 0)
for unit: Dictionary in Game.get_field():
if _is_ruin_unit(unit):
continue
var up : Dictionary = unit.get("position", {})
if up.is_empty(): continue
var ux : int = up.get("x", 0)
@@ -3402,7 +3436,7 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
var _t := Game.get_tile(coord.x, coord.y)
var _raw_occ = _t.get("occupantId")
var _occ : Variant = _raw_occ if _raw_occ is String else ""
if not _occ.is_empty() and _occ != "null":
if not _occ.is_empty() and _occ != "null" and not _is_ruin_instance(str(_occ)):
unit_id = _occ
# Show tile detail drawer and optionally pan camera.
if coord.x >= 0:
@@ -3479,7 +3513,7 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
var _t2 := Game.get_tile(coord.x, coord.y)
var _raw_occ2 = _t2.get("occupantId")
var _occ2 : Variant = _raw_occ2 if _raw_occ2 is String else ""
if not _occ2.is_empty() and _occ2 != "null":
if not _occ2.is_empty() and _occ2 != "null" and not _is_ruin_instance(str(_occ2)):
unit_id = _occ2
if not unit_id.is_empty():
if _is_enemy_unit(unit_id):
@@ -3546,6 +3580,7 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
func _select_unit(unit_id: String) -> void:
var unit := Game.get_unit_by_id(unit_id)
if unit.is_empty(): return
if _is_ruin_unit(unit): return
_hide_ability_panel()
_sel_unit_id = unit_id
@@ -22,7 +22,7 @@ extends Control
func _ready() -> void:
ContentCache.apply_scene_background(self)
welcome_label.text = "Welcome, %s!" % Auth.display_name
Chat.set_bubble_visible(true)
Chat.claim_bubble_visibility(self)
Network.connected.connect(_update_status)
Network.disconnected.connect(_update_status)
@@ -56,7 +56,7 @@ func _ready() -> void:
func _exit_tree() -> void:
Chat.set_bubble_visible(false)
Chat.release_bubble_visibility(self)
if Network.connected.is_connected(_update_status):
Network.connected.disconnect(_update_status)
if Network.disconnected.is_connected(_update_status):