diff --git a/Server/src/SOR.Game/Abilities/AbilityContext.cs b/Server/src/SOR.Game/Abilities/AbilityContext.cs
new file mode 100644
index 0000000..397f99c
--- /dev/null
+++ b/Server/src/SOR.Game/Abilities/AbilityContext.cs
@@ -0,0 +1,87 @@
+namespace SOR.Game.Abilities;
+
+using SOR.Game.Abilities.Models;
+using SOR.Game.Grid;
+
+///
+/// Captures the runtime state and bookkeeping needed to evaluate a single ability activation
+/// or triggered ability firing — including the source unit, owner, and any chained target results.
+///
+public sealed class AbilityContext
+{
+ public required GameState State { get; init; }
+ public required string ActorId { get; init; }
+
+ /// The unit (ArchSpirit or Spirit) that owns the ability being resolved.
+ public CardInstance? Source { get; init; }
+
+ ///
+ /// Resolved targets keyed by action index (0-based).
+ /// Populated incrementally as actions resolve, enabling chained targeting.
+ /// Each value is a list of the resolved target objects (CardInstance, Coord, or string for playerId).
+ ///
+ public Dictionary> ResolvedTargets { get; } = new();
+
+ ///
+ /// Optional payload from the triggering event — available to Triggered ability actions.
+ ///
+ public TriggerEventData? EventData { get; init; }
+}
+
+///
+/// Payload data from the event that caused a Triggered ability to fire.
+/// Fields are populated according to the event type; unused fields are null.
+///
+public sealed class TriggerEventData
+{
+ /// Numeric magnitude of the event (damage amount, SP gained, etc.).
+ public int? Amount { get; init; }
+ /// Instance ID of the unit/player that caused the event.
+ public string? SourceId { get; init; }
+ /// Instance ID of the unit/player the event acted upon.
+ public string? TargetId { get; init; }
+}
+
+///
+/// Discriminates which kind of entity a runtime trigger event is carrying.
+/// Used by AbilitySystem.FireTrigger to match against AbilityDefinition.TriggerEvent.
+///
+public enum TriggerEventKind
+{
+ TurnStart,
+ TurnEnd,
+ Channeled,
+ Ascend,
+ Transition,
+ UnitMove,
+ UnitAttack,
+ UnitAbilityActivated,
+ DamageDealt,
+ UnitDeath,
+ SpiritSacrificed,
+ UnitEnterBattlefield,
+ UnitLeaveBattlefield,
+ SPGained,
+ SPSpent,
+ STGained,
+ STSpent,
+ CardDrawn,
+ TileAffinityChanged,
+}
+
+///
+/// Describes a single triggered-event occurrence, used when calling
+/// .
+///
+public sealed class TriggerOccurrence
+{
+ public required TriggerEventKind Kind { get; init; }
+ /// The player whose units/actions caused this event.
+ public required string ActorId { get; init; }
+ /// Optional event data (damage amount, source/target IDs, etc.).
+ public TriggerEventData? Data { get; init; }
+ /// For unit-related events: the card type string ("Spirit", "ArchSpirit", etc.).
+ public string? UnitType { get; init; }
+ /// For channeling events: the card type string ("Spirit", "Terramorpha", etc.).
+ public string? CardType { get; init; }
+}
diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs
index f63b3ee..bc5dcc4 100644
--- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs
+++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs
@@ -1,16 +1,1105 @@
namespace SOR.Game.Abilities;
+using System.Text.Json;
+using SOR.Database.Enums;
+using SOR.Game.Abilities.Models;
+using SOR.Game.Grid;
+
///
-/// Ability activation and resolution stub.
+/// Evaluates and resolves ability activations and triggered ability firings.
///
-/// Full ability model is defined in Shared/context-files/abilities.md.
-/// Types: Activated, Triggered, Static, Instinct.
-/// Costs: SP, ST, discard, mill, self-damage, etc.
-/// Targets: units, tiles, players, zones.
-/// Durations: UntilEndOfTurn, UntilStartOfOwnerTurn, ForNTurns, WhileCondition, PermanentInMatch.
-///
-/// TODO: Implement full ability model in a future pass.
+/// Design:
+/// • GameEngine delegates directly to the static methods here.
+/// • All mutation is on GameState (pure — no DB access).
+/// • Triggered abilities are fired inline during engine mutations via FireTrigger.
///
public static class AbilitySystem
{
+ // ── JSON options shared across all parse calls ─────────────────────────────
+
+ private static readonly JsonSerializerOptions _jsonOpts = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ };
+
+ // ── Parsing ────────────────────────────────────────────────────────────────
+
+ public static AbilityDefinition[] ParseAbilities(string? json)
+ {
+ if (string.IsNullOrWhiteSpace(json)) return [];
+ return JsonSerializer.Deserialize(json, _jsonOpts) ?? [];
+ }
+
+ public static Models.Action[] ParseEffects(string? json)
+ {
+ if (string.IsNullOrWhiteSpace(json)) return [];
+ return JsonSerializer.Deserialize(json, _jsonOpts) ?? [];
+ }
+
+ // ── Active ability activation ──────────────────────────────────────────────
+
+ ///
+ /// Entry point for a player manually activating an Active ability on one of
+ /// their units. Validates conditions, pays cost, resolves targets and effects.
+ /// Returns the mutated game state.
+ ///
+ public static GameState ActivateAbility(
+ GameState state,
+ string actorId,
+ string sourceInstanceId,
+ int abilityIndex,
+ IReadOnlyList? clientTargets)
+ {
+ // Find the source unit on the battlefield.
+ var player = state.Players[actorId];
+ var source = player.Field.OfType()
+ .FirstOrDefault(f => f.InstanceId == sourceInstanceId)
+ ?? throw new GameException("UNIT_NOT_FOUND");
+
+ if (source.IsExhausted)
+ throw new GameException("UNIT_EXHAUSTED");
+
+ // Parse abilities from the copied JSON blob on the card instance.
+ var abilities = ParseAbilities(source.AbilitiesJson);
+ if (abilityIndex < 0 || abilityIndex >= abilities.Length)
+ throw new GameException("ABILITY_INDEX_OUT_OF_RANGE");
+
+ var def = abilities[abilityIndex];
+
+ if (def.Type != AbilityType.Active)
+ throw new GameException("ABILITY_NOT_ACTIVE");
+
+ // Enforce UsesPerTurn limit.
+ source.AbilityUsesThisTurn ??= new();
+ source.AbilityUsesThisTurn.TryGetValue(abilityIndex, out int usedThisTurn);
+ if (usedThisTurn >= def.UsesPerTurn)
+ throw new GameException("ABILITY_USES_EXHAUSTED");
+
+ var ctx = new AbilityContext
+ {
+ State = state,
+ ActorId = actorId,
+ Source = source,
+ };
+
+ // Check activation conditions.
+ if (def.ActivationConditions is { Length: > 0 })
+ foreach (var cond in def.ActivationConditions)
+ if (!EvaluateCondition(cond, ctx, source))
+ throw new GameException("ABILITY_CONDITION_NOT_MET");
+
+ // Pay cost.
+ if (def.Cost is { Length: > 0 })
+ PayCost(def.Cost, ctx);
+
+ // Track use.
+ source.AbilityUsesThisTurn[abilityIndex] = usedThisTurn + 1;
+
+ // Execute actions.
+ ExecuteActions(def.Actions, ctx, clientTargets);
+
+ return state;
+ }
+
+ // ── Triggered ability firing ───────────────────────────────────────────────
+
+ ///
+ /// Called from GameEngine mutation methods to fire any Triggered abilities
+ /// that match the given occurrence. Scans every unit on the battlefield.
+ ///
+ public static GameState FireTrigger(GameState state, TriggerOccurrence occurrence)
+ {
+ foreach (var (ownerId, player) in state.Players)
+ {
+ // Snapshot the current field — effects may mutate it.
+ var units = player.Field.OfType().ToList();
+ foreach (var unit in units)
+ {
+ var abilities = ParseAbilities(unit.AbilitiesJson);
+ for (int i = 0; i < abilities.Length; i++)
+ {
+ var def = abilities[i];
+ if (def.Type != AbilityType.Triggered) continue;
+ if (def.TriggerEvent is null) continue;
+ if (!TriggerMatches(def.TriggerEvent, occurrence, state, ownerId)) continue;
+
+ var ctx = new AbilityContext
+ {
+ State = state,
+ ActorId = ownerId,
+ Source = unit,
+ EventData = occurrence.Data,
+ };
+
+ if (def.ActivationConditions is { Length: > 0 })
+ if (def.ActivationConditions.Any(c => !EvaluateCondition(c, ctx, unit)))
+ continue;
+
+ ExecuteActions(def.Actions, ctx, clientTargets: null);
+ }
+ }
+
+ // Also fire effects from non-unit cards (EffectsJson on Field cards).
+ foreach (var unit in player.Field.ToList())
+ {
+ var actions = ParseEffects(unit.EffectsJson);
+ // EffectsJson is a raw Actions array — fire unconditionally.
+ if (actions.Length == 0) continue;
+ var ctx = new AbilityContext { State = state, ActorId = ownerId, Source = unit };
+ foreach (var action in actions)
+ ExecuteSingleAction(action, ctx, clientTargets: null, actionIndex: 0);
+ }
+ }
+ return state;
+ }
+
+ // ── Passive / Aura evaluation (applied per-turn refresh) ──────────────────
+
+ ///
+ /// Resets and re-applies all Passive and Aura abilities for all units.
+ /// Called at the start of each player's turn to keep derived stats current.
+ ///
+ public static GameState RefreshPassives(GameState state)
+ {
+ // Passive effects are handled as permanent stat modifiers baked into
+ // the unit's stat block at FieldCard construction time. A full
+ // re-evaluation pass would require baseline snapshots; that complexity
+ // is deferred until the stat-mod layer is fleshed out.
+ return state;
+ }
+
+ // ── Cost payment ──────────────────────────────────────────────────────────
+
+ private static void PayCost(CostEntry[] costs, AbilityContext ctx)
+ {
+ var player = ctx.State.Players[ctx.ActorId];
+
+ foreach (var cost in costs)
+ {
+ switch (cost.Type)
+ {
+ case CostType.SpiritPoints:
+ if (player.CurrentSp < cost.Amount)
+ throw new GameException("INSUFFICIENT_SP");
+ player.CurrentSp -= cost.Amount;
+ break;
+
+ case CostType.SacrificeTokens:
+ if (player.CurrentSt < cost.Amount)
+ throw new GameException("INSUFFICIENT_ST");
+ player.CurrentSt -= cost.Amount;
+ break;
+
+ case CostType.DiscardFromHand:
+ {
+ var candidates = player.Hand
+ .Where(c => cost.Filters is null || FiltersMatch(cost.Filters, c, ctx))
+ .Take(cost.Amount)
+ .ToList();
+ if (candidates.Count < cost.Amount)
+ throw new GameException("INSUFFICIENT_CARDS_TO_DISCARD");
+ foreach (var c in candidates)
+ {
+ player.Hand.Remove(c);
+ player.Discard.Add(c);
+ }
+ break;
+ }
+
+ case CostType.MillTopOfDeck:
+ for (int i = 0; i < cost.Amount && player.Deck.Count > 0; i++)
+ {
+ var top = player.Deck[^1];
+ player.Deck.RemoveAt(player.Deck.Count - 1);
+ player.Discard.Add(top);
+ }
+ break;
+
+ case CostType.MillBottomOfDeck:
+ for (int i = 0; i < cost.Amount && player.Deck.Count > 0; i++)
+ {
+ var bottom = player.Deck[0];
+ player.Deck.RemoveAt(0);
+ player.Discard.Add(bottom);
+ }
+ break;
+
+ case CostType.DealDamageToOwnArchSpirit:
+ if (player.ArchSpirit is null)
+ throw new GameException("NO_ARCHSPIRIT");
+ ApplyDamageToUnit(player.ArchSpirit, cost.Amount, bypassDefense: false, ctx);
+ break;
+
+ case CostType.DealDamageToOwnSpirit:
+ {
+ var spirit = player.Field
+ .OfType()
+ .FirstOrDefault(f => !f.IsLeader
+ && (cost.Filters is null || FiltersMatch(cost.Filters, f, ctx)));
+ if (spirit is null)
+ throw new GameException("NO_VALID_SPIRIT_FOR_COST");
+ ApplyDamageToUnit(spirit, cost.Amount, bypassDefense: false, ctx);
+ break;
+ }
+
+ case CostType.SendSpiritFromBattlefieldToDiscard:
+ {
+ var spirit = player.Field
+ .OfType()
+ .FirstOrDefault(f => !f.IsLeader
+ && (cost.Filters is null || FiltersMatch(cost.Filters, f, ctx)));
+ if (spirit is null)
+ throw new GameException("NO_VALID_SPIRIT_FOR_COST");
+ player.Field.Remove(spirit);
+ if (spirit.Position.HasValue && ctx.State.Board is not null)
+ ctx.State.Board.ClearUnit(spirit.Position.Value);
+ player.Discard.Add(spirit);
+ break;
+ }
+ }
+ }
+ }
+
+ // ── Action execution ──────────────────────────────────────────────────────
+
+ private static void ExecuteActions(
+ Models.Action[] actions,
+ AbilityContext ctx,
+ IReadOnlyList? clientTargets)
+ {
+ for (int i = 0; i < actions.Length; i++)
+ ExecuteSingleAction(actions[i], ctx, clientTargets, actionIndex: i);
+ }
+
+ private static void ExecuteSingleAction(
+ Models.Action action,
+ AbilityContext ctx,
+ IReadOnlyList? clientTargets,
+ int actionIndex)
+ {
+ // Check per-action conditions.
+ if (action.Conditions is { Length: > 0 })
+ foreach (var cond in action.Conditions)
+ if (!EvaluateCondition(cond, ctx, ctx.Source!))
+ return; // skip this action if condition not met
+
+ // Resolve targets.
+ var resolved = ResolveTargets(action.Target, ctx, clientTargets, actionIndex);
+ ctx.ResolvedTargets[actionIndex] = resolved;
+
+ // Execute effects on each resolved target.
+ foreach (var target in resolved)
+ {
+ foreach (var effect in action.Effects)
+ ExecuteEffect(effect, target, action.Duration, ctx);
+ }
+ }
+
+ // ── Target resolution ─────────────────────────────────────────────────────
+
+ private static List