Fix: Repentance/Instinct card target selection + server active ability execution

Client: Repentance/Instinct cards with Active abilities in abilitiesJson now
enter ABILITY_TARGET mode instead of sending play_card immediately. Units on
matching tile affinities (IsOnTileWithAffinity) are highlighted in blue; the
player clicks a target unit and the card is sent with the selected unit target.

Server: FireCardEffects now also processes Active abilities from AbilitiesJson
(after the existing EffectsJson path). Source-side ActivationConditions are
checked; target-side conditions (Subject=Target) are trusted from the client.

New Game.gd helper: send_play_card_with_targets sends play_card with a targets
array so the server can route unit selections to the active ability handler.

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-03-18 14:05:49 -04:00
co-authored by Claude Happy
parent 66452313d5
commit 5d3ee92553
3 changed files with 95 additions and 6 deletions
+7
View File
@@ -176,6 +176,13 @@ func send_play_card_multi(card_instance_id: String, targets: Array) -> void:
})
func send_play_card_with_targets(card_instance_id: String, targets: Array) -> void:
var payload := { "cardInstanceId": card_instance_id }
if not targets.is_empty():
payload["targets"] = targets
_game_request("game.play_card", payload)
func send_move_unit(unit_instance_id: String, target_x: int, target_y: int) -> void:
_game_request("game.move_unit", {
"unitInstanceId": unit_instance_id,
@@ -140,6 +140,8 @@ var _ability_def : Array = [] # Actions array from parsed abili
var _ability_range : Dictionary = {} # Top-level range {min, max} from ability definition
var _ability_targets : Array = [] # collected AbilityTarget dicts to send
var _ability_cur_action_idx : int = 0 # which Action we are currently collecting for
var _ability_card_id : String = "" # non-empty when targeting for a card's active ability
var _ability_target_conditions: Array = [] # target-side ActivationConditions from card ability
var _player_panel : Control = null
# ── Unit ownership lookup ─────────────────────────────────────────────────────
@@ -1873,8 +1875,10 @@ func _set_mode(new_mode: Mode) -> void:
_ability_idx = -1
_ability_def = []
_ability_range = {}
_ability_targets = []
_ability_cur_action_idx = 0
_ability_targets = []
_ability_cur_action_idx = 0
_ability_card_id = ""
_ability_target_conditions = []
_clear_highlights()
_hide_ability_panel()
_hide_player_panel()
@@ -2249,6 +2253,15 @@ func _unit_passes_filters(unit: Dictionary, filters: Array) -> bool:
var dist := (absi(int(tgt_pos.get("x", 0)) - int(src_pos.get("x", 0))) +
absi(int(tgt_pos.get("y", 0)) - int(src_pos.get("y", 0))))
if dist != 1: return false
# Check ability-level target conditions (e.g. IsOnTileWithAffinity for card abilities).
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
@@ -2270,7 +2283,10 @@ func _tile_passes_filters(tx: int, ty: int, filters: Array) -> bool:
## Fire the ability request with all collected targets.
func _send_ability() -> void:
Game.send_activate_ability(_ability_unit_id, _ability_idx, _ability_targets)
if 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)
_set_mode(Mode.NONE)
@@ -2437,6 +2453,51 @@ func _on_hand_card_clicked(iid: String, _panel: PanelContainer) -> void:
Game.send_play_card(iid, 0, 0)
return
# Repentance / Instinct — may have an active ability requiring unit target selection.
if card.get("cardType", "") in ["Repentance", "Instinct"]:
# Deselect: same card clicked again.
if (_mode == Mode.ABILITY_TARGET and _ability_card_id == iid) or \
(_mode == Mode.CARD_FROM_HAND and _sel_card_id == iid):
_set_mode(Mode.NONE); return
# Reset when switching from a previous card-targeting mode.
if _mode in [Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT] or \
(_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty()):
_set_mode(Mode.NONE)
# Parse abilitiesJson for the first Active ability.
var abs_raw : String = card.get("abilitiesJson", "")
if not abs_raw.is_empty():
var parsed_variant := JSON.parse_string(abs_raw)
if parsed_variant is Array:
var parsed : Array = _normalize_keys(parsed_variant)
for ab_var: Variant in parsed:
if not (ab_var is Dictionary): continue
var ab : Dictionary = ab_var
if ab.get("type", "") != "active": continue
# Extract target-side activation conditions.
var tgt_conds : Array = []
for cv: Variant in ab.get("activationconditions", []):
if not (cv is Dictionary): continue
var cd : Dictionary = cv
if cd.get("subject", "") == "target":
tgt_conds.append(cd)
# Enter unit-target selection mode.
_ability_card_id = iid
_ability_unit_id = ""
_ability_idx = 0
_ability_def = ab.get("actions", [])
_ability_range = {}
_ability_target_conditions = tgt_conds
_ability_targets = []
_ability_cur_action_idx = 0
_sel_card_id = iid
_set_mode(Mode.ABILITY_TARGET)
_clear_highlights()
_start_ability_targeting()
return
# No active ability — channel immediately.
Game.send_play_card(iid, 0, 0)
return
# Deselect if same card clicked again.
if _mode == Mode.CARD_FROM_HAND and _sel_card_id == iid:
print("Deselect")