From 4f0f0e9c0f37f56783cb68ac2cb824e2e4eecae7 Mon Sep 17 00:00:00 2001 From: dingo Date: Tue, 17 Mar 2026 23:15:05 -0400 Subject: [PATCH] Feature: ability-level Duration override + WhileSourceOnBattlefield in duration list AbilityDefinition gains an optional Duration property. When set it is used as forceDuration for every ExecuteActions call that resolves that ability, overriding whatever per-action Duration individual effects specify. - Active abilities: def.Duration is threaded through as forceDuration - Triggered abilities: same - Passive abilities: def.Duration ?? WhileSourceOnBattlefield (both ApplyPassivesForSource and ApplyPassivesToNewTarget paths) AbilityBuilder admin panel: - Duration row added after type-specific fields (dropdown + N input for ForNTurns) - "WhileSourceOnBattlefield" added to the DurationTypeValues list - Parse and compile paths updated for the new Duration field Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../Pages/Cards/AbilityBuilder.razor | 43 ++++++++++++++++++- .../src/SOR.Game/Abilities/AbilitySystem.cs | 13 +++--- .../Abilities/Models/AbilityDefinition.cs | 9 ++++ 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor index 78fd59d..485436c 100644 --- a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor +++ b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor @@ -158,6 +158,30 @@ } + +
+
+ + +
+ @if (ab.DurationStr == "ForNTurns") + { +
+ + +
+ } +
+
@@ -498,7 +522,7 @@ private static readonly string[] MovementTypeValues = ["Walk", "Flight", "Jump", "Teleport"]; private static readonly string[] DirectionValues = ["North", "South", "East", "West", "NorthEast", "NorthWest", "SouthEast", "SouthWest"]; private static readonly string[] ComparatorValues = ["Equal", "NotEqual", "LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual"]; - private static readonly string[] DurationTypeValues = ["Instant", "UntilEndOfTurn", "UntilStartOfOwnerTurn", "UntilStartOfSourceOwnerTurn", "ForNTurns", "PermanentInMatch"]; + private static readonly string[] DurationTypeValues = ["Instant", "UntilEndOfTurn", "UntilStartOfOwnerTurn", "UntilStartOfSourceOwnerTurn", "ForNTurns", "WhileSourceOnBattlefield", "PermanentInMatch"]; private static readonly string[] StatTargetValues = ["Current", "Base", "Max"]; private static readonly string[] StatValues = ["Damage", "Defense", "Health", "MP"]; private static readonly string[] PositionValues = ["Top", "Bottom"]; @@ -732,6 +756,12 @@ ab.Actions.Add(act); } + if (node["Duration"] is JsonObject dur) + { + ab.DurationStr = dur["Type"]?.GetValue() ?? ""; + ab.DurationN = dur["N"]?.GetValue() ?? 1; + } + if (node["Animation"] is JsonObject anim) { ab.HasAnimation = true; @@ -999,6 +1029,13 @@ node["Actions"] = actionsArr; + if (!string.IsNullOrEmpty(ab.DurationStr)) + { + var durNode = new JsonObject { ["Type"] = ab.DurationStr }; + if (ab.DurationStr == "ForNTurns") durNode["N"] = ab.DurationN; + node["Duration"] = durNode; + } + if (ab.HasAnimation) { var animNode = new JsonObject @@ -1931,6 +1968,10 @@ public string TriggerOccupantOwnership { get; set; } = ""; public string TriggerUnitOwnership { get; set; } = "Any"; public string TriggerAuraOwnership { get; set; } = "Owner"; + // Ability-level duration (overrides per-action Duration when set; "" = per-action) + public string DurationStr { get; set; } = ""; + public int DurationN { get; set; } = 1; + public List Costs { get; set; } = new(); public List Conditions { get; set; } = new(); public List Actions { get; set; } = new(); diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 47b3bb4..586aaf6 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -100,7 +100,7 @@ public static class AbilitySystem source.AbilityUsesThisTurn[abilityIndex] = usedThisTurn + 1; - ExecuteActions(def.Actions, ctx, clientTargets, requireClientTargets: true, activationRange: def.Range); + ExecuteActions(def.Actions, ctx, clientTargets, requireClientTargets: true, activationRange: def.Range, forceDuration: def.Duration); return state; } @@ -152,7 +152,7 @@ public static class AbilitySystem if (def.ActivationConditions.Any(c => !EvaluateCondition(c, ctx, unit))) continue; - ExecuteActions(def.Actions, ctx, clientTargets: null); + ExecuteActions(def.Actions, ctx, clientTargets: null, forceDuration: def.Duration); } } } @@ -1933,9 +1933,10 @@ public static class AbilitySystem if (source is null) return; var ctx = new AbilityContext { State = state, ActorId = ownerId, Source = source }; - var duration = new DurationModel { Type = DurationType.WhileSourceOnBattlefield }; + var fallback = new DurationModel { Type = DurationType.WhileSourceOnBattlefield }; foreach (var def in ParseAbilities(source.AbilitiesJson).Where(d => d.Type == AbilityType.Passive)) - ExecuteActions(def.Actions, ctx, clientTargets: null, forceDuration: duration); + ExecuteActions(def.Actions, ctx, clientTargets: null, + forceDuration: def.Duration ?? fallback); } /// @@ -1946,7 +1947,7 @@ public static class AbilitySystem public static void ApplyPassivesToNewTarget(GameState state, string newUnitId) { var restrict = new HashSet { newUnitId }; - var duration = new DurationModel { Type = DurationType.WhileSourceOnBattlefield }; + var fallback = new DurationModel { Type = DurationType.WhileSourceOnBattlefield }; foreach (var (ownerId, player) in state.Players) foreach (var sourceUnit in player.Field.OfType() .Where(f => f.InstanceId != newUnitId).ToList()) @@ -1954,7 +1955,7 @@ public static class AbilitySystem var ctx = new AbilityContext { State = state, ActorId = ownerId, Source = sourceUnit }; foreach (var def in ParseAbilities(sourceUnit.AbilitiesJson).Where(d => d.Type == AbilityType.Passive)) ExecuteActions(def.Actions, ctx, clientTargets: null, - restrictTargets: restrict, forceDuration: duration); + restrictTargets: restrict, forceDuration: def.Duration ?? fallback); } } diff --git a/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs b/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs index 55aa0dd..c897be9 100644 --- a/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs +++ b/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs @@ -51,6 +51,15 @@ public sealed class AbilityDefinition /// public string? Description { get; set; } + /// + /// Optional ability-level duration that overrides per-action Duration for every effect + /// this ability produces. When null, each Action's own Duration is used instead. + /// + /// For Passive abilities this defaults to WhileSourceOnBattlefield when left null; + /// set it explicitly to choose a different lifespan (e.g. UntilEndOfTurn). + /// + public DurationModel? Duration { get; set; } + /// /// Optional client-side animation and sound metadata. /// Not used by server game logic. Null means the client uses its default effect.