Files
sor/Server/src/SOR.Game/Abilities/AbilityContext.cs
T
2026-07-02 13:09:05 -04:00

136 lines
5.1 KiB
C#

namespace SOR.Game.Abilities;
using SOR.Game.Abilities.Models;
using SOR.Game.Grid;
/// <summary>
/// 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.
/// </summary>
public sealed class AbilityContext
{
public required GameState State { get; init; }
public required string ActorId { get; init; }
/// <summary>The unit (ArchSpirit or Spirit) that owns the ability being resolved.</summary>
public CardInstance? Source { get; init; }
/// <summary>
/// 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).
/// </summary>
public Dictionary<int, List<object>> ResolvedTargets { get; } = new();
/// <summary>
/// Optional payload from the triggering event — available to Triggered ability actions.
/// </summary>
public TriggerEventData? EventData { get; init; }
/// <summary>
/// Actions remaining after the current one in the parent ExecuteActions loop.
/// Set by ExecuteSingleAction so that effect-level pauses (ChannelCardFromZone, etc.)
/// can store the full continuation for later resume.
/// </summary>
public Models.Action[] ContinuationActions { get; set; } = [];
/// <summary>
/// Activation range propagated from the top-level ExecuteActions call.
/// Available to ExecuteEffect when it needs to store a continuation pause.
/// </summary>
public AbilityRange? ActivationRange { get; set; }
// ── Intra-action position tracking (set per-loop-iteration by ExecuteSingleAction) ──
/// <summary>Index of the currently-executing effect within <see cref="CurrentActionAllEffects"/>.</summary>
public int CurrentEffectIndex { get; set; }
/// <summary>Index of the currently-executing target within the resolved target list.</summary>
public int CurrentTargetIndex { get; set; }
/// <summary>Snapshot of all resolved targets for the current action.</summary>
public object[]? CurrentActionTargets { get; set; }
/// <summary>All effects in the current action (the full Effects array, not just remaining).</summary>
public Effect[]? CurrentActionAllEffects { get; set; }
/// <summary>Resolved duration for the current action (forceDuration ?? action.Duration).</summary>
public DurationModel? CurrentActionDuration { get; set; }
}
/// <summary>
/// Payload data from the event that caused a Triggered ability to fire.
/// Fields are populated according to the event type; unused fields are null.
/// </summary>
public sealed class TriggerEventData
{
/// <summary>Numeric magnitude of the event (damage amount, SP gained, etc.).</summary>
public int? Amount { get; init; }
/// <summary>Instance ID of the unit/player that caused the event.</summary>
public string? SourceId { get; init; }
/// <summary>Instance ID of the unit/player the event acted upon.</summary>
public string? TargetId { get; init; }
/// <summary>For movement events: previous tile coordinate.</summary>
public Coord? PreviousTile { get; init; }
/// <summary>For movement events: destination tile coordinate.</summary>
public Coord? DestinationTile { get; init; }
/// <summary>For damage events: "HP" | "Defense". Null = unspecified (matches "Any" only).</summary>
public string? DamageType { get; init; }
}
/// <summary>
/// Discriminates which kind of entity a runtime trigger event is carrying.
/// Used by AbilitySystem.FireTrigger to match against AbilityDefinition.TriggerEvent.
/// </summary>
public enum TriggerEventKind
{
TurnStart,
TurnEnd,
Channeled,
Ascend,
Transition,
UnitMove,
UnitAttack,
UnitAbilityActivated,
DamageDealt,
Healed,
TokenSummoned,
DamagePrevented,
BeforeDamageApplied,
BeforeUnitDeath,
UnitDeath,
UnitSentToDiscard,
SpiritSacrificed,
UnitEnterBattlefield,
UnitLeaveBattlefield,
SPGained,
SPSpent,
STGained,
STSpent,
CardDrawn,
TileAffinityChanged,
EnterAuraRange,
LeaveAuraRange,
RuinActivation,
UnitOccupyRuin,
}
/// <summary>
/// Describes a single triggered-event occurrence, used when calling
/// <see cref="AbilitySystem.FireTrigger"/>.
/// </summary>
public sealed class TriggerOccurrence
{
public required TriggerEventKind Kind { get; init; }
/// <summary>The player whose units/actions caused this event.</summary>
public required string ActorId { get; init; }
/// <summary>Optional event data (damage amount, source/target IDs, etc.).</summary>
public TriggerEventData? Data { get; init; }
/// <summary>For unit-related events: the card type string ("Spirit", "ArchSpirit", etc.).</summary>
public string? UnitType { get; init; }
/// <summary>For channeling events: the card type string ("Spirit", "Terramorpha", etc.).</summary>
public string? CardType { get; init; }
}