Files

93 lines
3.2 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>
/// 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>
/// 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,
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; }
}