Ability system: zone-scope card picks, target-pick prompts, builder filter editor, tests
Server engine (SOR.Game): - Zone-scope card targets (Hand/Deck/Discard/AnyZone) pause with a server- enumerated candidates list (PendingTargetPick.CandidatesJson) instead of failing when the client submits player accountIds for hidden zones - Missing mandatory target picks now prompt (PendingTargetPick) rather than throwing INSUFFICIENT_TARGETS; all post-pick resume flows run with requireClientTargets so actions never silently auto-hit the first candidate - ChannelCardFromZone: Filters + InOwn/InTargetChannelRange enforced via shared IsWithinChannelConstraints (incl. player-picked tile validation) - TakeControl duration reversal via internal __ReturnControl effect; board occupant-owner kept in sync both ways - TrackedDuration gains SourceOwnerAccountId (UntilStartOfSourceOwnerTurn now anchors correctly) and IsAura (aura reapply no longer strips unrelated buffs) - RevealCards honours N for player targets; IsAllyTurn means teammate's turn; content-keyed ParseAbilities cache; AbilityValidator for save-time linting; duplicate PolyType attributes removed (converter reads base registry only) Admin builder (AbilityBuilder/CardEditor): - Full multi-filter editor (28 filter types with parameter fields) replacing the single param-less dropdown; raw-JSON ChooseOne editor per action - Cost PickMode, TriggerLimitPerGame, SourceZoneGate inputs - Save-time ability validation with error list (blocks invalid saves) Client (Godot): - Card-list picker for zone-scope target picks; OR/XOR-root abilities skip speculative upfront targeting; ally units included in team-aware highlight pools (Game.get_ally_units); state re-sync on rejected pick responses Tests: new SOR.Game.Tests project (21 passing) covering the regression suite from SOR.Abilities-Review-and-solutions.md §8 plus validator rules. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -360,20 +360,21 @@ func highlight_ability_targets(action: Dictionary) -> void:
|
||||
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
|
||||
|
||||
# Unit-type target. Pools mirror the server's team-aware BuildCandidates:
|
||||
# Owner = own units only, Ally = teammates only, Enemy = non-allies, Any = everyone.
|
||||
var targets: Array = []
|
||||
if include_enemy:
|
||||
if ownership in ["Enemy", "Any"]:
|
||||
targets.append_array(Game.get_all_enemy_units())
|
||||
if include_friendly:
|
||||
if ownership in ["Owner", "Any"]:
|
||||
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)
|
||||
if ownership in ["Ally", "Any"]:
|
||||
targets.append_array(Game.get_ally_units())
|
||||
if targets.is_empty() and not ownership in ["Owner", "Ally", "Enemy", "Any"]:
|
||||
# Unknown ownership string — fall back to enemies (legacy behaviour).
|
||||
targets.append_array(Game.get_all_enemy_units())
|
||||
|
||||
for u: Dictionary in targets:
|
||||
if type_ in ["Spirit", "ArchSpirit", "SpiritToken", "Ruin"]:
|
||||
@@ -511,6 +512,50 @@ func unit_passes_filters(unit: Dictionary, filters: Array) -> bool:
|
||||
int(src_pos.get("x", 0)), int(src_pos.get("y", 0)))
|
||||
if dist != 1:
|
||||
return false
|
||||
"genuscontains":
|
||||
var genus_v: Variant = unit.get("genus")
|
||||
var genus: Array = genus_v as Array if genus_v is Array else []
|
||||
if not genus.has(str(f.get("tag", ""))):
|
||||
return false
|
||||
"cardtypeis":
|
||||
if str(unit.get("cardType", "")) != str(f.get("cardtype", f.get("cardType", ""))):
|
||||
return false
|
||||
"affinitymatches":
|
||||
if str(unit.get("affinity", "")) != str(f.get("affinity", "")):
|
||||
return false
|
||||
"tieris":
|
||||
if int(unit.get("tier", 0)) != int(f.get("tier", 0)):
|
||||
return false
|
||||
"healthbelow":
|
||||
if int(unit.get("currentHealth", 0)) >= int(f.get("n", 0)):
|
||||
return false
|
||||
"healthabove":
|
||||
if int(unit.get("currentHealth", 0)) <= int(f.get("n", 0)):
|
||||
return false
|
||||
"damagerange":
|
||||
var dmg: int = int(unit.get("damage", 0))
|
||||
if dmg < int(f.get("min", 0)) or dmg > int(f.get("max", 999)):
|
||||
return false
|
||||
"defenserange":
|
||||
var def_: int = int(unit.get("currentDefense", 0))
|
||||
if def_ < int(f.get("min", 0)) or def_ > int(f.get("max", 999)):
|
||||
return false
|
||||
"ownership":
|
||||
var uid: String = str(unit.get("instanceId", ""))
|
||||
match str(f.get("ownership", "Any")).to_lower():
|
||||
"self", "owner", "ally":
|
||||
if unit_registry != null and not unit_registry.friendly_unit_ids.has(uid):
|
||||
return false
|
||||
"enemy", "opponent":
|
||||
if unit_registry != null and not unit_registry.enemy_unit_ids.has(uid):
|
||||
return false
|
||||
"isself":
|
||||
# Same card definition as the ability source.
|
||||
if str(unit.get("cardDefinitionId", "")) != str(src.get("cardDefinitionId", "")):
|
||||
return false
|
||||
"isexactself":
|
||||
if str(unit.get("instanceId", "")) != ability_unit_id:
|
||||
return false
|
||||
for cond: Dictionary in ability_target_conditions:
|
||||
match str(cond.get("$type", "")).to_lower():
|
||||
"isontilewithaffinity":
|
||||
@@ -578,6 +623,33 @@ func tile_passes_filters(tx: int, ty: int, filters: Array) -> bool:
|
||||
var tile: Dictionary = Game.get_tile(tx, ty)
|
||||
if tile.get("occupantId", null) != null:
|
||||
return false
|
||||
"tileisoccupied":
|
||||
var tile: Dictionary = Game.get_tile(tx, ty)
|
||||
var occ_v: Variant = tile.get("occupantId")
|
||||
if occ_v == null or str(occ_v).is_empty():
|
||||
return false
|
||||
var want_type: String = str(f.get("unittype", f.get("unitType", "")))
|
||||
if not want_type.is_empty() and want_type != "Unit":
|
||||
var occ_unit: Dictionary = Game.get_unit_by_id(str(occ_v))
|
||||
if str(occ_unit.get("cardType", "")) != want_type:
|
||||
return false
|
||||
"tileoccupancy":
|
||||
var tile: Dictionary = Game.get_tile(tx, ty)
|
||||
var occ_v: Variant = tile.get("occupantId")
|
||||
if occ_v == null or str(occ_v).is_empty():
|
||||
return false
|
||||
var occ_id: String = str(occ_v)
|
||||
var occ_unit: Dictionary = Game.get_unit_by_id(occ_id)
|
||||
var want_type: String = str(f.get("unittype", f.get("unitType", "Unit")))
|
||||
if want_type != "Unit" and str(occ_unit.get("cardType", "")) != want_type:
|
||||
return false
|
||||
match str(f.get("ownership", "Any")).to_lower():
|
||||
"self", "owner", "ally":
|
||||
if unit_registry != null and not unit_registry.friendly_unit_ids.has(occ_id):
|
||||
return false
|
||||
"enemy", "opponent":
|
||||
if unit_registry != null and not unit_registry.enemy_unit_ids.has(occ_id):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
@@ -859,7 +931,14 @@ func get_ability_actions(ab: Dictionary) -> Array:
|
||||
return legacy
|
||||
var ag: Variant = ab.get("actiongroup")
|
||||
if ag is Dictionary:
|
||||
return flatten_and_group(ag as Dictionary)
|
||||
var group: Dictionary = ag as Dictionary
|
||||
# OR/XOR root group: the server either pauses for an action_group_pick BEFORE
|
||||
# costs (Self/Opponent chooser) or picks one child at index 0 (Random) — either
|
||||
# way upfront targets collected against the flattened list would misalign and be
|
||||
# discarded. The server re-prompts for whatever targets the chosen branch needs.
|
||||
if str(group.get("logicop", "and")).to_lower() != "and":
|
||||
return []
|
||||
return flatten_and_group(group)
|
||||
return []
|
||||
|
||||
|
||||
|
||||
@@ -319,11 +319,25 @@ func on_branch_pick_request(req: Dictionary) -> void:
|
||||
|
||||
# ── PendingTargetPick ─────────────────────────────────────────────────────────
|
||||
|
||||
# Zone-scope card pick accumulation
|
||||
var target_pick_selected: Array = [] # [{actionIndex, instanceId}]
|
||||
var target_pick_required: int = 1
|
||||
var target_pick_up_to: bool = false
|
||||
|
||||
func on_target_pick_request(req: Dictionary) -> void:
|
||||
_cancel_current_mode()
|
||||
if ability_targeting == null:
|
||||
return
|
||||
|
||||
# Zone-scope pick: the server sends an explicit candidates list (hidden zones) —
|
||||
# show a card list panel instead of board targeting.
|
||||
var candidates_json: String = str(req.get("candidatesJson", ""))
|
||||
if not candidates_json.is_empty() and candidates_json != "null" and candidates_json != "<null>":
|
||||
var cand_raw: Variant = JSON.parse_string(candidates_json)
|
||||
if cand_raw is Array and not (cand_raw as Array).is_empty():
|
||||
_show_zone_target_panel(req, cand_raw as Array)
|
||||
return
|
||||
|
||||
ability_targeting.is_target_pick = true
|
||||
ability_targeting.pending_req_id = str(req.get("requestId", ""))
|
||||
pending_req_id = ability_targeting.pending_req_id
|
||||
@@ -356,6 +370,79 @@ func on_target_pick_request(req: Dictionary) -> void:
|
||||
ability_targeting.ability_targets_this_action = 0
|
||||
ability_targeting.start_ability_targeting()
|
||||
|
||||
## Card-list picker for zone-scope target picks (hand/deck/discard candidates
|
||||
## enumerated by the server). Resumed action is replayed at index 0 server-side,
|
||||
## so picks are submitted with actionIndex 0.
|
||||
func _show_zone_target_panel(req: Dictionary, candidates: Array) -> void:
|
||||
pending_req_id = str(req.get("requestId", ""))
|
||||
pending_source_id = str(req.get("sourceInstanceId", ""))
|
||||
target_pick_selected.clear()
|
||||
target_pick_required = 1
|
||||
target_pick_up_to = false
|
||||
|
||||
# Count requirements come from the action's target selector.
|
||||
var action_raw: Variant = JSON.parse_string(str(req.get("actionJson", "{}")))
|
||||
if action_raw is Dictionary:
|
||||
var action_n: Dictionary = _normalize_keys(action_raw) as Dictionary
|
||||
var count_d: Dictionary = (action_n.get("target", {}) as Dictionary).get("count", {}) as Dictionary
|
||||
target_pick_required = maxi(1, int(count_d.get("n", 1)))
|
||||
target_pick_up_to = bool(count_d.get("upto", false))
|
||||
|
||||
hide_pending_prompt_panel()
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.position = Vector2(8, 140)
|
||||
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 = "Choose %s%d card(s):" % ["up to " if target_pick_up_to else "", target_pick_required]
|
||||
title.add_theme_font_size_override("font_size", 13)
|
||||
title.add_theme_color_override("font_color", Color(0.5, 0.9, 1.0))
|
||||
vbox.add_child(title)
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
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 ctype: String = str(card_d.get("cardType", ""))
|
||||
var btn: Button = Button.new()
|
||||
btn.text = "%s%s" % [name_, "" if ctype.is_empty() else " (%s)" % ctype]
|
||||
btn.add_theme_font_size_override("font_size", 11)
|
||||
var cap_iid: String = iid
|
||||
var cap_btn: Button = btn
|
||||
btn.pressed.connect(func() -> void:
|
||||
for sel_v: Variant in target_pick_selected:
|
||||
if str((sel_v as Dictionary).get("instanceId", "")) == cap_iid:
|
||||
return
|
||||
target_pick_selected.append({ "actionIndex": 0, "instanceId": cap_iid })
|
||||
cap_btn.modulate = Color(0.4, 1.0, 0.5)
|
||||
if target_pick_selected.size() >= target_pick_required:
|
||||
_finish_zone_target_pick())
|
||||
vbox.add_child(btn)
|
||||
|
||||
if target_pick_up_to:
|
||||
var done: Button = Button.new()
|
||||
done.text = "Done Selecting"
|
||||
done.add_theme_font_size_override("font_size", 12)
|
||||
done.pressed.connect(_finish_zone_target_pick)
|
||||
vbox.add_child(HSeparator.new())
|
||||
vbox.add_child(done)
|
||||
|
||||
panel.add_child(vbox)
|
||||
if hud != null:
|
||||
hud.add_child(panel)
|
||||
pending_prompt_panel = panel
|
||||
|
||||
|
||||
func _finish_zone_target_pick() -> void:
|
||||
hide_pending_prompt_panel()
|
||||
var rid: String = pending_req_id
|
||||
pending_req_id = ""
|
||||
Game.send_target_pick_response(rid, target_pick_selected.duplicate())
|
||||
target_pick_selected.clear()
|
||||
|
||||
# ── PendingTilePick ───────────────────────────────────────────────────────────
|
||||
|
||||
func on_tile_pick_request(req: Dictionary) -> void:
|
||||
|
||||
Reference in New Issue
Block a user