Files

81 lines
3.9 KiB
C#

namespace SOR.Game.Abilities.Models;
/// <summary>Ability type determines activation model and required fields.</summary>
public enum AbilityType
{
/// <summary>Manually activated by the controlling player. Costs optional range and UsesPerTurn.</summary>
Active,
/// <summary>Always active while the unit is in play and conditions are met. No activation, no cost.</summary>
Passive,
/// <summary>Always-on area effect anchored to a unit's position. Evaluated per-turn and on unit entry.</summary>
Aura,
/// <summary>Automatically fires when a matching TriggerEvent occurs.</summary>
Triggered,
}
/// <summary>
/// The top-level definition of a unit ability or card effect.
/// Stored as JSONB in CardDefinition.AbilitiesJson (array) and CardDefinition.EffectsJson.
///
/// All four ability types share the Action/Effect/Condition model.
/// Type-specific fields are non-null only for the relevant type.
/// </summary>
public sealed class AbilityDefinition
{
public AbilityType Type { get; set; }
public Condition[]? ActivationConditions { get; set; }
public Action[] Actions { get; set; } = [];
// ── Active only ──────────────────────────────────────────────────────────
public CostEntry[]? Cost { get; set; }
public AbilityRange? Range { get; set; }
/// <summary>How many times this Active ability may be used per turn (default 1).</summary>
public int UsesPerTurn { get; set; } = 1;
// ── Aura only ────────────────────────────────────────────────────────────
public AbilityRange? AuraRange { get; set; }
/// <summary>
/// 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 <see cref="LingerDuration"/> is set.
/// </summary>
public bool ClearOnLeave { get; set; }
/// <summary>
/// If set, effects switch to this duration when a unit leaves range instead of
/// being reverted immediately. Takes precedence over <see cref="ClearOnLeave"/>.
/// Null means effects expire at their own configured Duration.
/// </summary>
public DurationModel? LingerDuration { get; set; }
// ── Triggered only ───────────────────────────────────────────────────────
/// <summary>The event that fires this ability. Must be set for Triggered type.</summary>
public TriggerEvent? TriggerEvent { get; set; }
/// <summary>
/// Optional display name shown in the admin tool and client ability list.
/// Not required for game logic.
/// </summary>
public string? Name { get; set; }
/// <summary>
/// Plain-English description of what this ability does.
/// Used in the admin ability builder. Not used by game logic.
/// </summary>
public string? Description { get; set; }
/// <summary>
/// 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).
/// </summary>
public DurationModel? Duration { get; set; }
/// <summary>
/// Optional client-side animation and sound metadata.
/// Not used by server game logic. Null means the client uses its default effect.
/// </summary>
public AbilityAnimationDefinition? Animation { get; set; }
}