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:
@@ -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