diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor
index c256655..45cb5cc 100644
--- a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor
+++ b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor
@@ -139,6 +139,53 @@
@bind="ab.AuraRangeMax" @bind:after="Compile" />
+
+
+ @if (!string.IsNullOrEmpty(ab.AuraLingerDurationStr))
+ {
+
+
+
+
+ @if (ab.AuraLingerDurationStr == "ForNTurns")
+ {
+
+
+
+
+ }
+ }
+
}
else if (ab.TypeStr == "Triggered")
{
@@ -759,7 +806,7 @@
| Active | Player explicitly activates on their turn | Range, Cost, UsesPerTurn |
| Passive | Always in effect while unit is on battlefield | Actions (target=Self) |
- | Aura | Continuously affects all units in range | AuraRange, Actions |
+ | Aura | Applies Actions to units entering range; fires OnEnterAuraRange / OnLeaveAuraRange triggers. On Leave: Persist = keep effect duration, Clear = revert immediately, Linger = switch to linger duration | AuraRange, Actions, ClearOnLeave / LingerDuration |
| Triggered | Fires automatically when a specific game event occurs | TriggerEvent, Actions |
@@ -1186,8 +1233,11 @@
RangeMax = node["Range"]?["Max"]?.GetValue(),
RangeRequiresLos = node["Range"]?["RequiresLos"]?.GetValue() ?? false,
RangeLinearOnly = node["Range"]?["LinearOnly"]?.GetValue() ?? false,
- AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue(),
- AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue(),
+ AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue(),
+ AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue(),
+ AuraClearOnLeave = node["ClearOnLeave"]?.GetValue() ?? false,
+ AuraLingerDurationStr = node["LingerDuration"]?["Type"]?.GetValue() ?? "",
+ AuraLingerDurationN = node["LingerDuration"]?["N"]?.GetValue() ?? 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 ─────────────────────────────────────────────────────────────
+ /// 0=Persist, 1=ClearOnLeave, 2=Linger(ForNTurns)
+ 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";
diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs
index bbdc8df..e9614c6 100644
--- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs
+++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs
@@ -2246,7 +2246,7 @@ public static class AbilitySystem
{
var auraPos = auraUnit.Position!.Value;
int min = def.AuraRange!.Min, max = def.AuraRange.Max;
- FireAuraTransition(state, auraOwnerId, auraUnit.InstanceId, movingUnitId,
+ FireAuraTransition(state, auraOwnerId, auraUnit, def, movingUnitId,
wasIn: from.ManhattanDistance(auraPos) >= min && from.ManhattanDistance(auraPos) <= max,
isIn: to.ManhattanDistance(auraPos) >= min && to.ManhattanDistance(auraPos) <= max);
}
@@ -2272,7 +2272,7 @@ public static class AbilitySystem
.Where(f => f.Position.HasValue && f.InstanceId != movingUnitId).ToList())
{
var otherPos = other.Position!.Value;
- FireAuraTransition(state, movingOwnerId, movingUnitId, other.InstanceId,
+ FireAuraTransition(state, movingOwnerId, movingUnit, def, other.InstanceId,
wasIn: from.ManhattanDistance(otherPos) >= min && from.ManhattanDistance(otherPos) <= max,
isIn: to.ManhattanDistance(otherPos) >= min && to.ManhattanDistance(otherPos) <= max);
}
@@ -2305,12 +2305,7 @@ public static class AbilitySystem
{
int dist = newPos.ManhattanDistance(auraUnit.Position!.Value);
if (dist >= def.AuraRange!.Min && dist <= def.AuraRange.Max)
- FireTrigger(state, new TriggerOccurrence
- {
- Kind = TriggerEventKind.EnterAuraRange,
- ActorId = auraOwnerId,
- Data = new TriggerEventData { SourceId = auraUnit.InstanceId, TargetId = newUnitId },
- });
+ FireAuraTransition(state, auraOwnerId, auraUnit, def, newUnitId, wasIn: false, isIn: true);
}
}
@@ -2329,12 +2324,7 @@ public static class AbilitySystem
{
int dist = newPos.ManhattanDistance(other.Position!.Value);
if (dist >= def.AuraRange!.Min && dist <= def.AuraRange.Max)
- FireTrigger(state, new TriggerOccurrence
- {
- Kind = TriggerEventKind.EnterAuraRange,
- ActorId = newUnitOwnerId,
- Data = new TriggerEventData { SourceId = newUnitId, TargetId = other.InstanceId },
- });
+ FireAuraTransition(state, newUnitOwnerId, newUnit, def, other.InstanceId, wasIn: false, isIn: true);
}
}
@@ -2364,12 +2354,7 @@ public static class AbilitySystem
{
int dist = leavingPos.ManhattanDistance(auraUnit.Position!.Value);
if (dist >= def.AuraRange!.Min && dist <= def.AuraRange.Max)
- FireTrigger(state, new TriggerOccurrence
- {
- Kind = TriggerEventKind.LeaveAuraRange,
- ActorId = auraOwnerId,
- Data = new TriggerEventData { SourceId = auraUnit.InstanceId, TargetId = leavingUnitId },
- });
+ FireAuraTransition(state, auraOwnerId, auraUnit, def, leavingUnitId, wasIn: true, isIn: false);
}
}
@@ -2388,39 +2373,109 @@ public static class AbilitySystem
{
int dist = leavingPos.ManhattanDistance(other.Position!.Value);
if (dist >= def.AuraRange!.Min && dist <= def.AuraRange.Max)
- FireTrigger(state, new TriggerOccurrence
- {
- Kind = TriggerEventKind.LeaveAuraRange,
- ActorId = leavingOwnerId,
- Data = new TriggerEventData { SourceId = leavingUnitId, TargetId = other.InstanceId },
- });
+ FireAuraTransition(state, leavingOwnerId, leavingUnit, def, other.InstanceId, wasIn: true, isIn: false);
}
}
return state;
}
+ ///
+ /// Executes the aura ability's own Actions on when it enters
+ /// range. Uses .Duration if set, otherwise WhileSourceOnBattlefield.
+ ///
+ private static void ApplyAuraEffects(
+ GameState state,
+ string auraOwnerId,
+ FieldCard auraUnit,
+ 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 } &&
+ !def.ActivationConditions.All(c => EvaluateCondition(c, ctx, auraUnit)))
+ return;
+
+ var fallback = new DurationModel { Type = DurationType.WhileSourceOnBattlefield };
+ ExecuteActions(def.Actions, ctx, clientTargets: null,
+ restrictTargets: new HashSet { targetUnitId },
+ forceDuration: def.Duration ?? fallback);
+ }
+
+ ///
+ /// Handles the leave-range side-effects of an aura.
+ /// If is set, switches tracked effects to that
+ /// duration instead of revoking them. If is set,
+ /// immediately reverts and removes the effects. Otherwise does nothing (effects expire normally).
+ ///
+ private static void HandleAuraLeave(
+ GameState state,
+ FieldCard auraUnit,
+ AbilityDefinition def,
+ 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();
+ if (matching.Count == 0) return;
+
+ if (def.LingerDuration is not null)
+ {
+ // Switch the tracked effects to the linger duration so they outlive the aura range.
+ foreach (var ae in matching)
+ {
+ ae.DurationJson = JsonSerializer.Serialize(
+ new TrackedDuration { Duration = def.LingerDuration, OwnerAccountId = auraOwnerId },
+ _jsonOpts);
+ ae.TurnsRemaining = def.LingerDuration.N ?? 0;
+ }
+ }
+ else if (def.ClearOnLeave)
+ {
+ foreach (var ae in matching)
+ {
+ TrackedDuration? td = null;
+ try { td = JsonSerializer.Deserialize(ae.DurationJson, _jsonOpts); } catch { }
+ if (td is not null && !td.IsTick) ApplyReversal(state, ae, td.OwnerAccountId);
+ state.ActiveEffects.Remove(ae);
+ }
+ }
+ }
+
private static void FireAuraTransition(
- GameState state,
- string auraOwnerId,
- string auraUnitId,
- string targetUnitId,
- bool wasIn,
- bool isIn)
+ GameState state,
+ string auraOwnerId,
+ FieldCard auraUnit,
+ AbilityDefinition def,
+ string targetUnitId,
+ bool wasIn,
+ bool isIn)
{
if (!wasIn && isIn)
+ {
FireTrigger(state, new TriggerOccurrence
{
Kind = TriggerEventKind.EnterAuraRange,
ActorId = auraOwnerId,
- Data = new TriggerEventData { SourceId = auraUnitId, TargetId = targetUnitId },
+ Data = new TriggerEventData { SourceId = auraUnit.InstanceId, TargetId = targetUnitId },
});
+ ApplyAuraEffects(state, auraOwnerId, auraUnit, def, targetUnitId);
+ }
else if (wasIn && !isIn)
+ {
FireTrigger(state, new TriggerOccurrence
{
Kind = TriggerEventKind.LeaveAuraRange,
ActorId = auraOwnerId,
- Data = new TriggerEventData { SourceId = auraUnitId, TargetId = targetUnitId },
+ Data = new TriggerEventData { SourceId = auraUnit.InstanceId, TargetId = targetUnitId },
});
+ HandleAuraLeave(state, auraUnit, def, targetUnitId, auraOwnerId);
+ }
}
}
diff --git a/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs b/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs
index c897be9..f8ec3ea 100644
--- a/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs
+++ b/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs
@@ -33,7 +33,19 @@ public sealed class AbilityDefinition
public int UsesPerTurn { get; set; } = 1;
// ── Aura only ────────────────────────────────────────────────────────────
- public AbilityRange? AuraRange { get; set; }
+ public AbilityRange? AuraRange { get; set; }
+ ///
+ /// 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.
+ /// Ignored when is set.
+ ///
+ public bool ClearOnLeave { get; set; }
+ ///
+ /// If set, effects switch to this duration when a unit leaves range instead of
+ /// being reverted immediately. Takes precedence over .
+ /// Null means effects expire at their own configured Duration.
+ ///
+ public DurationModel? LingerDuration { get; set; }
// ── Triggered only ───────────────────────────────────────────────────────
/// The event that fires this ability. Must be set for Triggered type.