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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user