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:
@@ -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.
|
||||
|
||||
@@ -402,6 +402,25 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action-level duration override -->
|
||||
<div class="row g-2 mb-2 align-items-end">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small mb-0">Action Duration <span class="text-muted">(overrides ability-level)</span></label>
|
||||
<select class="form-select form-select-sm" @bind="action.DurationStr" @bind:after="Compile">
|
||||
<option value="">(none / use ability duration)</option>
|
||||
@foreach (var d in DurationTypeValues) { <option value="@d">@d</option> }
|
||||
</select>
|
||||
</div>
|
||||
@if (action.DurationStr == "ForNTurns")
|
||||
{
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small mb-0">N Turns</label>
|
||||
<input type="number" min="1" class="form-control form-control-sm"
|
||||
@bind="action.DurationN" @bind:after="Compile" />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Effects -->
|
||||
<label class="form-label small fw-medium mb-1">Effects</label>
|
||||
|
||||
@@ -2346,7 +2365,7 @@
|
||||
RangeLinearOnly = node["Range"]?["LinearOnly"]?.GetValue<bool>() ?? false,
|
||||
AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue<int>(),
|
||||
AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue<int>(),
|
||||
AuraClearOnLeave = node["ClearOnLeave"]?.GetValue<bool>() ?? false,
|
||||
AuraClearOnLeave = node["ClearOnLeave"]?.GetValue<bool>() ?? true,
|
||||
AuraLingerDurationStr = node["LingerDuration"]?["Type"]?.GetValue<string>() ?? "",
|
||||
AuraLingerDurationN = node["LingerDuration"]?["N"]?.GetValue<int>() ?? 1,
|
||||
};
|
||||
@@ -2706,6 +2725,11 @@
|
||||
All = target?["Count"]?["All"]?.GetValue<bool>() ?? false,
|
||||
FilterType = firstFilter?["$type"]?.GetValue<string>() ?? "",
|
||||
};
|
||||
if (actionNode["Duration"] is JsonObject actionDur)
|
||||
{
|
||||
act.DurationStr = actionDur["Type"]?.GetValue<string>() ?? "";
|
||||
act.DurationN = actionDur["N"]?.GetValue<int>() ?? 1;
|
||||
}
|
||||
if (actionNode["Conditions"] is JsonArray actionConds)
|
||||
foreach (var c in actionConds.OfType<JsonObject>())
|
||||
act.Conditions.Add(ParseCondition(c));
|
||||
@@ -2882,6 +2906,12 @@
|
||||
foreach (var eff in action.Effects)
|
||||
effectsArr.Add(CompileEffect(eff));
|
||||
actionNode["Effects"] = effectsArr;
|
||||
if (!string.IsNullOrEmpty(action.DurationStr))
|
||||
{
|
||||
var durNode = new JsonObject { ["Type"] = action.DurationStr };
|
||||
if (action.DurationStr == "ForNTurns") durNode["N"] = action.DurationN;
|
||||
actionNode["Duration"] = durNode;
|
||||
}
|
||||
return actionNode;
|
||||
}
|
||||
|
||||
@@ -4474,7 +4504,7 @@
|
||||
public string CostGroupChooserRole { get; set; } = "Self";
|
||||
public int? AuraRangeMin { get; set; }
|
||||
public int? AuraRangeMax { get; set; }
|
||||
public bool AuraClearOnLeave { get; set; } = false;
|
||||
public bool AuraClearOnLeave { get; set; } = true;
|
||||
public string AuraLingerDurationStr { get; set; } = "";
|
||||
public int AuraLingerDurationN { get; set; } = 1;
|
||||
public string TriggerType { get; set; } = "";
|
||||
@@ -4537,6 +4567,12 @@
|
||||
/// "" = no filter. Maps to Target.Filters[0] in the compiled JSON.
|
||||
/// </summary>
|
||||
public string FilterType { get; set; } = "";
|
||||
/// <summary>
|
||||
/// Action-level duration override. "" = no override (each effect uses its own duration or the ability-level duration).
|
||||
/// Written to "Duration": {"Type": ...} in the compiled action JSON.
|
||||
/// </summary>
|
||||
public string DurationStr { get; set; } = "";
|
||||
public int DurationN { get; set; } = 1;
|
||||
public List<ConditionDraft> Conditions { get; set; } = new();
|
||||
public List<EffectDraft> Effects { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -4814,9 +4814,12 @@ public static class AbilitySystem
|
||||
catch { continue; }
|
||||
if (eff is null) continue;
|
||||
|
||||
var tgt = state.Players.Values
|
||||
var tgt = (CardInstance?)state.Players.Values
|
||||
.SelectMany(p => p.Field)
|
||||
.FirstOrDefault(c => c.InstanceId == ae.TargetRef);
|
||||
.FirstOrDefault(c => c.InstanceId == ae.TargetRef)
|
||||
?? state.Players.Values
|
||||
.Select(p => p.ArchSpirit)
|
||||
.FirstOrDefault(a => a?.InstanceId == ae.TargetRef);
|
||||
if (tgt is null) continue;
|
||||
|
||||
var src = state.Players.Values
|
||||
@@ -4951,7 +4954,7 @@ public static class AbilitySystem
|
||||
catch { return; }
|
||||
if (eff is null) return;
|
||||
|
||||
// Find target by instanceId (any zone) or by accountId (player).
|
||||
// Find target by instanceId (any zone, including ArchSpirit) or by accountId (player).
|
||||
object? tgt = null;
|
||||
foreach (var p in state.Players.Values)
|
||||
{
|
||||
@@ -4959,7 +4962,8 @@ public static class AbilitySystem
|
||||
p.Field.FirstOrDefault(c => c.InstanceId == ae.TargetRef)
|
||||
?? p.Hand.FirstOrDefault(c => c.InstanceId == ae.TargetRef)
|
||||
?? p.Deck.FirstOrDefault(c => c.InstanceId == ae.TargetRef)
|
||||
?? p.Discard.FirstOrDefault(c => c.InstanceId == ae.TargetRef));
|
||||
?? p.Discard.FirstOrDefault(c => c.InstanceId == ae.TargetRef)
|
||||
?? (p.ArchSpirit?.InstanceId == ae.TargetRef ? p.ArchSpirit : null));
|
||||
if (tgt is not null) break;
|
||||
if (p.AccountId == ae.TargetRef) { tgt = p; break; }
|
||||
}
|
||||
@@ -5258,6 +5262,7 @@ public static class AbilitySystem
|
||||
/// <summary>
|
||||
/// Executes the aura ability's own Actions on <paramref name="targetUnitId"/> when it enters
|
||||
/// range. Uses <paramref name="def"/>.Duration if set, otherwise WhileSourceOnBattlefield.
|
||||
/// Supports both ActionGroup (modern) and legacy flat Actions.
|
||||
/// </summary>
|
||||
private static void ApplyAuraEffects(
|
||||
GameState state,
|
||||
@@ -5266,8 +5271,6 @@ public static class AbilitySystem
|
||||
AbilityDefinition def,
|
||||
string targetUnitId)
|
||||
{
|
||||
if (def.Actions is not { Length: > 0 }) return;
|
||||
|
||||
// Honour aura-level activation conditions (e.g. IsOnTileWithAffinity of the aura source).
|
||||
var ctx = new AbilityContext { State = state, ActorId = auraOwnerId, Source = auraUnit };
|
||||
if (def.ActivationConditions is { Length: > 0 } &&
|
||||
@@ -5275,9 +5278,12 @@ public static class AbilitySystem
|
||||
return;
|
||||
|
||||
var fallback = new DurationModel { Type = DurationType.WhileSourceOnBattlefield };
|
||||
ExecuteActions(def.Actions, ctx, clientTargets: null,
|
||||
var forceDuration = def.Duration ?? fallback;
|
||||
var actions = GetEffectiveActions(def, ctx, abilityIndex: 0, def.AuraRange, forceDuration);
|
||||
if (actions is not { Length: > 0 }) return;
|
||||
ExecuteActions(actions, ctx, clientTargets: null,
|
||||
restrictTargets: new HashSet<string> { targetUnitId },
|
||||
forceDuration: def.Duration ?? fallback);
|
||||
forceDuration: forceDuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -5293,8 +5299,6 @@ public static class AbilitySystem
|
||||
string targetUnitId,
|
||||
string auraOwnerId)
|
||||
{
|
||||
if (def.Actions is not { Length: > 0 }) return;
|
||||
|
||||
var matching = state.ActiveEffects
|
||||
.Where(ae => ae.SourceInstanceId == auraUnit.InstanceId && ae.TargetRef == targetUnitId)
|
||||
.ToList();
|
||||
|
||||
@@ -52,10 +52,10 @@ public sealed class AbilityDefinition
|
||||
public AbilityRange? AuraRange { get; set; }
|
||||
/// <summary>
|
||||
/// When true, effects applied by this aura to a unit are reverted immediately when that
|
||||
/// unit leaves range. Default false: effects expire at their configured Duration.
|
||||
/// unit leaves range. Default true. Set false to let effects expire at their configured Duration.
|
||||
/// Ignored when <see cref="LingerDuration"/> is set.
|
||||
/// </summary>
|
||||
public bool ClearOnLeave { get; set; }
|
||||
public bool ClearOnLeave { get; set; } = true;
|
||||
/// <summary>
|
||||
/// If set, effects switch to this duration when a unit leaves range instead of
|
||||
/// being reverted immediately. Takes precedence over <see cref="ClearOnLeave"/>.
|
||||
|
||||
Reference in New Issue
Block a user