Aura: self-apply Actions + ClearOnLeave / LingerDuration on leave

Previously, Aura abilities only fired OnEnterAuraRange / OnLeaveAuraRange
trigger events — their own Actions were never executed. Auras now directly
apply their Actions to any unit that enters range (using WhileSourceOnBattlefield
by default) and handle departure via three modes:

- Persist (default): effects expire at their configured Duration unchanged
- ClearOnLeave: effects are reverted immediately when the unit leaves range
- LingerDuration: effects switch to the specified duration when leaving range,
  allowing them to outlive the aura's reach (and the source if it leaves)

Server:
- AbilityDefinition: add ClearOnLeave (bool) and LingerDuration (DurationModel?)
- AbilitySystem: add ApplyAuraEffects + HandleAuraLeave helpers;
  refactor FireAuraTransition to take FieldCard + AbilityDefinition and call
  both helpers; update all six call sites in EvaluateAuraTransitions /
  EvaluateAurasOnEnter / EvaluateAurasOnLeave to use the unified path

Admin:
- AbilityBuilder: add AuraClearOnLeave / AuraLingerDurationStr / N draft fields;
  parse + compile round-trip; 3-radio On Leave UI + optional Linger duration select;
  update Aura help row to describe the new behaviour

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-24 21:11:56 -04:00
co-authored by Claude Happy
parent afb083093a
commit 9c42e5c1c8
3 changed files with 176 additions and 40 deletions
@@ -139,6 +139,53 @@
@bind="ab.AuraRangeMax" @bind:after="Compile" />
</div>
</div>
<div class="row g-2 mb-3 align-items-end">
<div class="col-auto">
<label class="form-label small mb-1">On Leave Range</label>
<div class="d-flex align-items-center gap-2">
<div class="form-check mb-0">
<input class="form-check-input" type="radio"
name="auraLeave_@ab.GetHashCode()" id="auraLeaveNone_@ab.GetHashCode()"
checked="@(string.IsNullOrEmpty(ab.AuraLingerDurationStr) && !ab.AuraClearOnLeave)"
@onchange="() => SetAuraLeaveMode(ab, 0)" />
<label class="form-check-label small" for="auraLeaveNone_@ab.GetHashCode()">Persist (effect duration)</label>
</div>
<div class="form-check mb-0">
<input class="form-check-input" type="radio"
name="auraLeave_@ab.GetHashCode()" id="auraLeaveClear_@ab.GetHashCode()"
checked="@(ab.AuraClearOnLeave && string.IsNullOrEmpty(ab.AuraLingerDurationStr))"
@onchange="() => SetAuraLeaveMode(ab, 1)" />
<label class="form-check-label small" for="auraLeaveClear_@ab.GetHashCode()">Clear immediately</label>
</div>
<div class="form-check mb-0">
<input class="form-check-input" type="radio"
name="auraLeave_@ab.GetHashCode()" id="auraLeaveLinger_@ab.GetHashCode()"
checked="@(!string.IsNullOrEmpty(ab.AuraLingerDurationStr))"
@onchange="() => SetAuraLeaveMode(ab, 2)" />
<label class="form-check-label small" for="auraLeaveLinger_@ab.GetHashCode()">Linger</label>
</div>
</div>
</div>
@if (!string.IsNullOrEmpty(ab.AuraLingerDurationStr))
{
<div class="col-auto">
<label class="form-label small mb-0">Linger Duration</label>
<select class="form-select form-select-sm" style="width:230px"
@bind="ab.AuraLingerDurationStr" @bind:after="Compile">
@foreach (var d in DurationTypeValues)
{ <option value="@d">@d</option> }
</select>
</div>
@if (ab.AuraLingerDurationStr == "ForNTurns")
{
<div class="col-auto">
<label class="form-label small mb-0">N</label>
<input type="number" min="1" class="form-control form-control-sm" style="width:80px"
@bind="ab.AuraLingerDurationN" @bind:after="Compile" />
</div>
}
}
</div>
}
else if (ab.TypeStr == "Triggered")
{
@@ -759,7 +806,7 @@
<tbody>
<tr><td><strong>Active</strong></td><td>Player explicitly activates on their turn</td><td>Range, Cost, UsesPerTurn</td></tr>
<tr><td><strong>Passive</strong></td><td>Always in effect while unit is on battlefield</td><td>Actions (target=Self)</td></tr>
<tr><td><strong>Aura</strong></td><td>Continuously affects all units in range</td><td>AuraRange, Actions</td></tr>
<tr><td><strong>Aura</strong></td><td>Applies Actions to units entering range; fires OnEnterAuraRange / OnLeaveAuraRange triggers. On Leave: <em>Persist</em> = keep effect duration, <em>Clear</em> = revert immediately, <em>Linger</em> = switch to linger duration</td><td>AuraRange, Actions, ClearOnLeave / LingerDuration</td></tr>
<tr><td><strong>Triggered</strong></td><td>Fires automatically when a specific game event occurs</td><td>TriggerEvent, Actions</td></tr>
</tbody>
</table>
@@ -1186,8 +1233,11 @@
RangeMax = node["Range"]?["Max"]?.GetValue<int>(),
RangeRequiresLos = node["Range"]?["RequiresLos"]?.GetValue<bool>() ?? false,
RangeLinearOnly = node["Range"]?["LinearOnly"]?.GetValue<bool>() ?? false,
AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue<int>(),
AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue<int>(),
AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue<int>(),
AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue<int>(),
AuraClearOnLeave = node["ClearOnLeave"]?.GetValue<bool>() ?? false,
AuraLingerDurationStr = node["LingerDuration"]?["Type"]?.GetValue<string>() ?? "",
AuraLingerDurationN = node["LingerDuration"]?["N"]?.GetValue<int>() ?? 1,
};
if (node["TriggerEvent"] is JsonNode trig)
@@ -1513,6 +1563,14 @@
["Min"] = ab.AuraRangeMin ?? 1,
["Max"] = ab.AuraRangeMax ?? 1,
};
if (!string.IsNullOrEmpty(ab.AuraLingerDurationStr))
{
var ld = new JsonObject { ["Type"] = ab.AuraLingerDurationStr };
if (ab.AuraLingerDurationStr == "ForNTurns") ld["N"] = ab.AuraLingerDurationN;
node["LingerDuration"] = ld;
}
else if (ab.AuraClearOnLeave)
node["ClearOnLeave"] = true;
}
else if (ab.TypeStr == "Triggered" && !string.IsNullOrEmpty(ab.TriggerType))
{
@@ -2502,6 +2560,14 @@
// ── Event helpers ─────────────────────────────────────────────────────────────
/// <param name="mode">0=Persist, 1=ClearOnLeave, 2=Linger(ForNTurns)</param>
private void SetAuraLeaveMode(AbilityDraft ab, int mode)
{
ab.AuraClearOnLeave = mode == 1;
ab.AuraLingerDurationStr = mode == 2 ? "ForNTurns" : string.Empty;
Compile();
}
private void SelectTrigger(AbilityDraft ab, string triggerType)
{
ab.TriggerType = triggerType;
@@ -2585,8 +2651,11 @@
public bool RangeRequiresLos { get; set; } = false;
public bool RangeLinearOnly { get; set; } = false;
public int UsesPerTurn { get; set; } = 1;
public int? AuraRangeMin { get; set; }
public int? AuraRangeMax { get; set; }
public int? AuraRangeMin { get; set; }
public int? AuraRangeMax { get; set; }
public bool AuraClearOnLeave { get; set; } = false;
public string AuraLingerDurationStr { get; set; } = "";
public int AuraLingerDurationN { get; set; } = 1;
public string TriggerType { get; set; } = "";
public string TriggerPlayer { get; set; } = "Owner";
public string TriggerOwnership { get; set; } = "Owner";