Add SOR ability system reference snapshot and change draft
This commit is contained in:
@@ -0,0 +1,626 @@
|
||||
# Proposed Changes for `SOR.Game/Abilities`
|
||||
|
||||
This document is meant to sit beside the copied reference snapshot in:
|
||||
|
||||
- `reference/SOR.Game/Abilities/`
|
||||
|
||||
It is a practical draft of what should be added or changed in the **current** ability system based on:
|
||||
- the deck conversion audits in `decks-r1/`
|
||||
- the cross-deck gap synthesis
|
||||
- the freshly pulled current source from `SOR/Server/src/SOR.Game/Abilities`
|
||||
|
||||
The goal is not to redesign everything.
|
||||
The goal is to make a **targeted set of additions** that unlocks a lot more card text cleanly.
|
||||
|
||||
---
|
||||
|
||||
# Design principles
|
||||
|
||||
1. **Prefer additive changes over rewrites**
|
||||
- the current system is already strong
|
||||
- we should extend the model, not tear it up
|
||||
|
||||
2. **Keep JSON authoring coherent**
|
||||
- new conditions/effects/triggers should look like they belong beside the existing ones
|
||||
|
||||
3. **Favor generally useful primitives**
|
||||
- e.g. `RepositionUnitEffect` is better than a bespoke “move one friendly unit adjacent to marsh tile” special case
|
||||
|
||||
4. **Preserve reversibility where possible**
|
||||
- temporary effects should continue to use tracked durations and undo logic
|
||||
|
||||
5. **Support deck conversion first**
|
||||
- the audited decks are a good real-world test suite
|
||||
|
||||
---
|
||||
|
||||
# Priority 1 — highest-value additions
|
||||
|
||||
## 1. Trigger frequency caps for Triggered abilities
|
||||
|
||||
## Problem
|
||||
Current `UsesPerTurn` exists on `Active` only.
|
||||
That makes these common lines awkward or impossible:
|
||||
- once per turn
|
||||
- first time each turn
|
||||
- first friendly unit each turn
|
||||
|
||||
This came up repeatedly across deck audits.
|
||||
|
||||
## Proposed model change
|
||||
### File
|
||||
- `reference/SOR.Game/Abilities/Models/AbilityDefinition.cs`
|
||||
|
||||
### Add
|
||||
```csharp
|
||||
// ── Triggered only / shared runtime limiter ─────────────────────────────
|
||||
/// <summary>
|
||||
/// Maximum times this ability may resolve per turn.
|
||||
/// 0 or null = unlimited.
|
||||
/// Intended primarily for Triggered abilities.
|
||||
/// </summary>
|
||||
public int? TriggerLimitPerTurn { get; set; }
|
||||
```
|
||||
|
||||
Optionally, if you want a more semantic flag:
|
||||
```csharp
|
||||
public bool FirstTimeEachTurn { get; set; }
|
||||
```
|
||||
but I think `TriggerLimitPerTurn = 1` is cleaner and more general.
|
||||
|
||||
## Engine work
|
||||
### File
|
||||
- `AbilitySystem.cs`
|
||||
|
||||
Need per-turn runtime tracking keyed by something like:
|
||||
- source instance id
|
||||
- ability name or ability index
|
||||
- turn number
|
||||
|
||||
Pseudo-shape:
|
||||
```csharp
|
||||
Dictionary<(Guid SourceInstanceId, string AbilityKey, int TurnNumber), int> TriggerCounts
|
||||
```
|
||||
|
||||
Before resolving a triggered ability:
|
||||
- look up count
|
||||
- if `TriggerLimitPerTurn` reached, skip
|
||||
- otherwise resolve, then increment
|
||||
|
||||
## Why this is high value
|
||||
This unlocks a huge amount of card text with very little authoring complexity.
|
||||
|
||||
---
|
||||
|
||||
## 2. First-class `RepositionUnitEffect`
|
||||
|
||||
## Problem
|
||||
The engine has:
|
||||
- `PushUnit`
|
||||
- `PullUnit`
|
||||
- `DisplaceUnit`
|
||||
- `GrantMovementControl`
|
||||
|
||||
But many designs want:
|
||||
- “move target unit 1 tile”
|
||||
- “another friendly unit may move 1 tile”
|
||||
- “move into or adjacent to a target tile”
|
||||
|
||||
Push/pull are not the same thing.
|
||||
Granting MP is only an approximation.
|
||||
|
||||
## Proposed model change
|
||||
### File
|
||||
- `Models/Effects.cs`
|
||||
|
||||
### Add polytype + effect
|
||||
```csharp
|
||||
[PolyType(typeof(RepositionUnitEffect), "RepositionUnit")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class RepositionUnitEffect : Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Maximum number of tiles the unit may be repositioned.
|
||||
/// Most first-pass use cases are 1.
|
||||
/// </summary>
|
||||
public int Tiles { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// When true, destination must be adjacent to the source unit.
|
||||
/// </summary>
|
||||
public bool AdjacentToSource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional reference to a previously selected tile target,
|
||||
/// e.g. "Action1.Target". Useful for “into or adjacent to that tile”.
|
||||
/// </summary>
|
||||
public string? RelativeToTargetRef { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If set, destination must be adjacent to the tile/entity referenced by RelativeToTargetRef.
|
||||
/// </summary>
|
||||
public bool AdjacentToRelativeTarget { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If set, destination may be exactly the referenced tile.
|
||||
/// </summary>
|
||||
public bool AllowRelativeTargetTile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional additional tile legality filters for destination selection.
|
||||
/// </summary>
|
||||
public Filter[]? DestinationTileFilters { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
## Engine work
|
||||
### File
|
||||
- `AbilitySystem.cs`
|
||||
|
||||
Needs:
|
||||
1. resolve the unit target
|
||||
2. compute legal destination tiles
|
||||
3. if client target selection is required, validate chosen destination
|
||||
4. move unit directly without consuming normal MP unless intended otherwise
|
||||
5. fire appropriate move-related triggers if reposition should count as movement
|
||||
|
||||
## Important decision
|
||||
Decide whether reposition:
|
||||
- counts as movement for `OnUnitMove`
|
||||
- triggers “moves onto Marsh” effects
|
||||
|
||||
My recommendation:
|
||||
- **yes**, unless you deliberately add a flag like `CountsAsMovement = false`
|
||||
|
||||
That will make card text feel more intuitive.
|
||||
|
||||
---
|
||||
|
||||
## 3. Replacement/prevention timing
|
||||
|
||||
## Problem
|
||||
The system currently has good post-event triggers, but weak pre-resolution hooks.
|
||||
That blocks text like:
|
||||
- if it would die, prevent that death and set health to 1
|
||||
- prevent the next damage
|
||||
- prevent damage this action
|
||||
|
||||
## Proposed additions
|
||||
### File
|
||||
- `Models/Triggers.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
[PolyType(typeof(BeforeUnitDeathTrigger), "BeforeUnitDeath")]
|
||||
[PolyType(typeof(BeforeDamageAppliedTrigger), "BeforeDamageApplied")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class BeforeUnitDeathTrigger : TriggerEvent
|
||||
{
|
||||
public string UnitType { get; set; } = "Unit";
|
||||
public string Ownership { get; set; } = "Any";
|
||||
public Filter? Filter { get; set; }
|
||||
}
|
||||
|
||||
public sealed class BeforeDamageAppliedTrigger : TriggerEvent
|
||||
{
|
||||
public string SourceOwnership { get; set; } = "Any";
|
||||
public string TargetOwnership { get; set; } = "Any";
|
||||
public Filter? Filter { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
### File
|
||||
- `Models/Effects.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
[PolyType(typeof(PreventDeathEffect), "PreventDeath")]
|
||||
[PolyType(typeof(PreventNextDamageEffect), "PreventNextDamage")]
|
||||
[PolyType(typeof(SetHealthMinimumEffect), "SetHealthMinimum")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class PreventDeathEffect : Effect { }
|
||||
|
||||
public sealed class PreventNextDamageEffect : Effect
|
||||
{
|
||||
public ValueExpr? MaxAmount { get; set; }
|
||||
}
|
||||
|
||||
public sealed class SetHealthMinimumEffect : Effect
|
||||
{
|
||||
public int Minimum { get; set; } = 1;
|
||||
}
|
||||
```
|
||||
|
||||
## Engine work
|
||||
This is the trickiest part.
|
||||
|
||||
You need a pre-resolution pathway where:
|
||||
- impending lethal damage / death is recognized
|
||||
- triggered prevention abilities can fire
|
||||
- damage/death resolution can be altered or canceled
|
||||
|
||||
A practical first pass:
|
||||
1. before finalizing death, emit `BeforeUnitDeath`
|
||||
2. allow effects to set a unit-level transient marker like `PreventDeathThisResolution`
|
||||
3. if set, suppress death and optionally apply `SetHealthMinimum`
|
||||
|
||||
For damage prevention:
|
||||
1. before applying damage, emit `BeforeDamageApplied`
|
||||
2. collect prevention effects / caps
|
||||
3. reduce or cancel the damage payload
|
||||
4. emit `OnDamagePrevented` if relevant
|
||||
|
||||
## Why this matters
|
||||
This is what unlocks the most iconic “mercy / covenant / rescue / shield” cards.
|
||||
|
||||
---
|
||||
|
||||
## 4. Destination-aware movement context
|
||||
|
||||
## Problem
|
||||
A lot of cards want to know:
|
||||
- where a unit moved from
|
||||
- where it moved to
|
||||
- whether it moved onto a terrain type
|
||||
- whether it moved from or into an affinity
|
||||
|
||||
Right now movement triggers are not rich enough.
|
||||
|
||||
## Proposed change
|
||||
### File
|
||||
- `AbilityContext.cs`
|
||||
|
||||
Extend movement trigger event data with something like:
|
||||
```csharp
|
||||
public sealed class TriggerEventData
|
||||
{
|
||||
// existing fields...
|
||||
public Coord? PreviousTile { get; set; }
|
||||
public Coord? DestinationTile { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
Or richer:
|
||||
```csharp
|
||||
public Affinity? PreviousTileAffinity { get; set; }
|
||||
public Affinity? DestinationTileAffinity { get; set; }
|
||||
```
|
||||
|
||||
### File
|
||||
- `Models/Conditions.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
[PolyType(typeof(DestinationTileAffinityIsCondition), "DestinationTileAffinityIs")]
|
||||
[PolyType(typeof(PreviousTileAffinityIsCondition), "PreviousTileAffinityIs")]
|
||||
[PolyType(typeof(MovedFromOrIntoAffinityCondition), "MovedFromOrIntoAffinity")]
|
||||
```
|
||||
|
||||
Example shapes:
|
||||
```csharp
|
||||
public sealed class DestinationTileAffinityIsCondition : Condition
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
}
|
||||
|
||||
public sealed class PreviousTileAffinityIsCondition : Condition
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
}
|
||||
|
||||
public sealed class MovedFromOrIntoAffinityCondition : Condition
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
## Why this matters
|
||||
It directly improves:
|
||||
- move triggers
|
||||
- reposition effects
|
||||
- terrain identity gameplay
|
||||
|
||||
And it avoids a pile of awkward card-specific hacks.
|
||||
|
||||
---
|
||||
|
||||
# Priority 2 — strong cleanup additions
|
||||
|
||||
## 5. `NotCondition`
|
||||
|
||||
## Problem
|
||||
You have `AND`, `OR`, `XOR` but not `NOT`.
|
||||
That makes inverse card text clunky.
|
||||
|
||||
## Proposed change
|
||||
### File
|
||||
- `Models/Conditions.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
[PolyType(typeof(NotCondition), "NOT")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class NotCondition : Condition
|
||||
{
|
||||
public Condition Condition { get; set; } = null!;
|
||||
}
|
||||
```
|
||||
|
||||
## Engine work
|
||||
Add evaluation support in condition resolver.
|
||||
|
||||
## Why it matters
|
||||
Tiny change, big templating payoff.
|
||||
|
||||
---
|
||||
|
||||
## 6. More relational conditions and filters
|
||||
|
||||
## Problem
|
||||
You can target tiles adjacent to units now, which is good.
|
||||
But we still need things like:
|
||||
- target unit adjacent to Fort tile
|
||||
- enemies adjacent to a friendly Fort unit
|
||||
- unit on or adjacent to Marsh
|
||||
|
||||
## Proposed additions
|
||||
### File
|
||||
- `Models/Conditions.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
[PolyType(typeof(IsAdjacentToTileWithAffinityCondition), "IsAdjacentToTileWithAffinity")]
|
||||
[PolyType(typeof(IsOnOrAdjacentToTileWithAffinityCondition), "IsOnOrAdjacentToTileWithAffinity")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class IsAdjacentToTileWithAffinityCondition : Condition
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
}
|
||||
|
||||
public sealed class IsOnOrAdjacentToTileWithAffinityCondition : Condition
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
### File
|
||||
- `Models/Filters.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
[PolyType(typeof(IsAdjacentToUnitMatchingFilter), "IsAdjacentToUnitMatching")]
|
||||
[PolyType(typeof(IsAdjacentToTileMatchingFilter), "IsAdjacentToTileMatching")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class IsAdjacentToUnitMatchingFilter : Filter
|
||||
{
|
||||
public string Ownership { get; set; } = "Any";
|
||||
public Filter[]? UnitFilters { get; set; }
|
||||
}
|
||||
|
||||
public sealed class IsAdjacentToTileMatchingFilter : Filter
|
||||
{
|
||||
public Filter[]? TileFilters { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
## Why it matters
|
||||
This unlocks a lot of positional deck identity without weird special-cases.
|
||||
|
||||
---
|
||||
|
||||
## 7. `UntilEndOfSequence`
|
||||
|
||||
## Problem
|
||||
Interrupt cards and prevention windows often want:
|
||||
- until this action resolves
|
||||
- until end of current sequence
|
||||
|
||||
End-of-turn is too broad.
|
||||
|
||||
## Proposed change
|
||||
### File
|
||||
- `Models/DurationModel.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
UntilEndOfSequence
|
||||
```
|
||||
|
||||
## Engine work
|
||||
Need a clear definition of “sequence.”
|
||||
I would define it as:
|
||||
- one top-level action resolution block
|
||||
- including all chained actions/effects inside it
|
||||
- but ending before the next interrupt window / new top-level action
|
||||
|
||||
## Why it matters
|
||||
This makes Instinct/protection design dramatically cleaner.
|
||||
|
||||
---
|
||||
|
||||
# Priority 3 — useful but can wait a bit
|
||||
|
||||
## 8. Movement-state-sensitive conditions
|
||||
|
||||
## Problem
|
||||
Cards often want:
|
||||
- can’t be blocked while moving
|
||||
- gains X only during movement
|
||||
|
||||
## Proposed additions
|
||||
### File
|
||||
- `Models/Conditions.cs`
|
||||
|
||||
Add:
|
||||
```csharp
|
||||
[PolyType(typeof(IsCurrentlyMovingCondition), "IsCurrentlyMoving")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class IsCurrentlyMovingCondition : Condition { }
|
||||
```
|
||||
|
||||
You may also want a movement-phase duration concept later, but I’d avoid overcomplicating this first.
|
||||
|
||||
---
|
||||
|
||||
## 9. Source-qualified damage triggers
|
||||
|
||||
## Problem
|
||||
Some card text wants:
|
||||
- enemies damaged by **this**
|
||||
- whenever **this unit** deals damage
|
||||
|
||||
`OnDamageDealt` is broad, but exact source matching is important.
|
||||
|
||||
## Proposed addition
|
||||
### File
|
||||
- `Models/Triggers.cs`
|
||||
|
||||
Extend `OnDamageDealtTrigger` with:
|
||||
```csharp
|
||||
public Filter? SourceFilter { get; set; }
|
||||
```
|
||||
|
||||
or a direct exact-self option.
|
||||
|
||||
---
|
||||
|
||||
## 10. Tile-control / tile-count conditions
|
||||
|
||||
## Problem
|
||||
Decks often want:
|
||||
- if you control a Marsh tile
|
||||
- if you control 3+ Grove tiles
|
||||
|
||||
## Proposed addition
|
||||
### File
|
||||
- `Models/Conditions.cs`
|
||||
|
||||
Add something like:
|
||||
```csharp
|
||||
[PolyType(typeof(ControlledTileCountWithAffinityCondition), "ControlledTileCountWithAffinity")]
|
||||
```
|
||||
|
||||
```csharp
|
||||
public sealed class ControlledTileCountWithAffinityCondition : Condition
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
public Comparator Comparator { get; set; } = Comparator.GreaterThanOrEqual;
|
||||
public int N { get; set; }
|
||||
public string Ownership { get; set; } = "Owner";
|
||||
}
|
||||
```
|
||||
|
||||
Need to define “control” clearly. Likely:
|
||||
- occupied by your unit
|
||||
- or in your starting side / claimed side if such system exists
|
||||
|
||||
If “control” is not fully formalized yet, defer until game-side semantics are settled.
|
||||
|
||||
---
|
||||
|
||||
## 11. Reveal-result references
|
||||
|
||||
## Problem
|
||||
Future designs may want:
|
||||
- reveal top card; if it is X, do Y
|
||||
|
||||
## Proposed addition
|
||||
Expose reveal results in action context for chained actions.
|
||||
|
||||
This is useful, but not as urgent as the others.
|
||||
|
||||
---
|
||||
|
||||
# Current features that should be kept and leaned into
|
||||
|
||||
These are already solid and should remain the backbone:
|
||||
- terrain-conditioned passives
|
||||
- aura entry/leave triggers
|
||||
- push/pull displacement
|
||||
- tile affinity mutation
|
||||
- draw/discard/zone actions
|
||||
- ruin randomization pattern
|
||||
- reversible temporary stat/flag effects
|
||||
- `ApplyOnEvent` deferred effects
|
||||
- `ClearOnLeave` / `LingerDuration` on auras
|
||||
- `ChooseOne` support if it is indeed now functional in execution
|
||||
|
||||
---
|
||||
|
||||
# Suggested concrete implementation order
|
||||
|
||||
If I were actually patching the code, I would do this order:
|
||||
|
||||
## Phase 1
|
||||
1. `TriggerLimitPerTurn`
|
||||
2. `NotCondition`
|
||||
3. `RepositionUnitEffect`
|
||||
4. destination-aware movement context + conditions
|
||||
|
||||
## Phase 2
|
||||
5. `BeforeUnitDeath` / `BeforeDamageApplied`
|
||||
6. `PreventDeathEffect` / `PreventNextDamageEffect`
|
||||
7. `UntilEndOfSequence`
|
||||
|
||||
## Phase 3
|
||||
8. relational adjacency filters/conditions
|
||||
9. movement-state-sensitive conditions
|
||||
10. source-qualified damage triggers
|
||||
11. tile-control conditions
|
||||
|
||||
That order gives the biggest card-authoring payoff early.
|
||||
|
||||
---
|
||||
|
||||
# Example of what this unlocks immediately
|
||||
|
||||
With just:
|
||||
- `TriggerLimitPerTurn`
|
||||
- `RepositionUnitEffect`
|
||||
- destination-aware movement conditions
|
||||
- prevention timing
|
||||
|
||||
…a huge amount of the audited deck text becomes native instead of templated compromises.
|
||||
|
||||
Examples:
|
||||
- “once per turn, when a Spirit enters aura range…”
|
||||
- “move another friendly unit 1 tile”
|
||||
- “if it moved onto Marsh, draw 1 then discard 1”
|
||||
- “if that unit would die, prevent that death and set it to 1”
|
||||
- “prevent the next damage this sequence”
|
||||
|
||||
That’s a big payoff for a relatively focused tranche of engine work.
|
||||
|
||||
---
|
||||
|
||||
# Final read
|
||||
|
||||
The current ability system is already good.
|
||||
This proposal is not about fixing a broken design.
|
||||
It’s about making a strong design noticeably more expressive with a handful of additions that repeatedly showed up across real deck conversions.
|
||||
|
||||
If you end up copy-pasting parts of this into the live system planning, my strongest recommendation is:
|
||||
|
||||
> implement the things that remove the most templating compromises first, not the flashiest features.
|
||||
|
||||
That means:
|
||||
- trigger caps
|
||||
- reposition
|
||||
- prevention timing
|
||||
- movement destination awareness
|
||||
|
||||
Those four pull the most weight.
|
||||
@@ -0,0 +1,92 @@
|
||||
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; }
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,100 @@
|
||||
namespace SOR.Game.Abilities;
|
||||
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using SOR.Game.Abilities.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Generic base converter that fixes polymorphic deserialization when the
|
||||
/// <c>$type</c> discriminator is not the first property in a JSON object.
|
||||
///
|
||||
/// System.Text.Json requires <c>$type</c> to appear first for abstract base
|
||||
/// classes. Card-definition JSON authored in the admin tool does not guarantee
|
||||
/// that ordering. This converter buffers the entire JSON object, finds
|
||||
/// <c>$type</c> at any position, looks up the concrete type from the
|
||||
/// <see cref="JsonDerivedTypeAttribute"/> map on <typeparamref name="T"/>,
|
||||
/// then deserializes via the default converter.
|
||||
///
|
||||
/// <c>CanConvert</c> returns <c>true</c> <em>only</em> for the exact base type
|
||||
/// <typeparamref name="T"/> — not for concrete derived types — so there is no
|
||||
/// infinite recursion when the default converter processes derived-type properties.
|
||||
/// </summary>
|
||||
internal abstract class PolymorphicAbilityConverter<T> : JsonConverter<T> where T : class
|
||||
{
|
||||
// Static fields are per closed type T — each T gets its own map.
|
||||
private static readonly Dictionary<string, Type> s_typeMap;
|
||||
private static readonly Dictionary<Type, string> s_reverseMap;
|
||||
|
||||
static PolymorphicAbilityConverter()
|
||||
{
|
||||
s_typeMap = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
|
||||
s_reverseMap = new Dictionary<Type, string>();
|
||||
|
||||
foreach (var attr in typeof(T).GetCustomAttributes<PolyTypeAttribute>())
|
||||
{
|
||||
s_typeMap[attr.Discriminator] = attr.DerivedType;
|
||||
// First [PolyType] for a given concrete type wins for writing (canonical discriminator).
|
||||
// Additional attributes register read-only aliases for backwards compatibility.
|
||||
s_reverseMap.TryAdd(attr.DerivedType, attr.Discriminator);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Only intercept the abstract base <typeparamref name="T"/> itself.
|
||||
/// Concrete derived types fall through to the default serializer.
|
||||
/// </summary>
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(T);
|
||||
|
||||
public override T? Read(
|
||||
ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
JsonSerializerOptions options)
|
||||
{
|
||||
using var doc = JsonDocument.ParseValue(ref reader);
|
||||
var root = doc.RootElement;
|
||||
|
||||
if (!root.TryGetProperty("$type", out var discriminatorProp))
|
||||
throw new JsonException($"{typeof(T).Name} object is missing the '$type' discriminator.");
|
||||
|
||||
var discriminator = discriminatorProp.GetString()
|
||||
?? throw new JsonException($"{typeof(T).Name} '$type' discriminator is null.");
|
||||
|
||||
if (!s_typeMap.TryGetValue(discriminator, out var concreteType))
|
||||
throw new JsonException($"Unknown {typeof(T).Name} '$type': '{discriminator}'.");
|
||||
|
||||
// CanConvert returns false for concrete derived types, so no infinite recursion.
|
||||
return (T?)root.Deserialize(concreteType, options);
|
||||
}
|
||||
|
||||
public override void Write(
|
||||
Utf8JsonWriter writer,
|
||||
T value,
|
||||
JsonSerializerOptions options)
|
||||
{
|
||||
var concreteType = value.GetType();
|
||||
if (!s_reverseMap.TryGetValue(concreteType, out var discriminator))
|
||||
throw new JsonException($"No '$type' discriminator registered for {concreteType.Name}.");
|
||||
|
||||
// Serialize the concrete object (CanConvert=false for it → no recursion).
|
||||
using var mem = new System.IO.MemoryStream();
|
||||
using (var inner = new Utf8JsonWriter(mem))
|
||||
JsonSerializer.Serialize(inner, value, concreteType, options);
|
||||
|
||||
using var doc = JsonDocument.Parse(mem.ToArray());
|
||||
|
||||
// Write with $type first so round-trip JSON is always well-formed.
|
||||
writer.WriteStartObject();
|
||||
writer.WriteString("$type", discriminator);
|
||||
foreach (var prop in doc.RootElement.EnumerateObject())
|
||||
prop.WriteTo(writer);
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
|
||||
// ── Concrete converters ───────────────────────────────────────────────────────
|
||||
|
||||
internal sealed class EffectPolymorphicConverter : PolymorphicAbilityConverter<Effect> { }
|
||||
internal sealed class ConditionPolymorphicConverter : PolymorphicAbilityConverter<Condition> { }
|
||||
internal sealed class TriggerPolymorphicConverter : PolymorphicAbilityConverter<TriggerEvent>{ }
|
||||
internal sealed class FilterPolymorphicConverter : PolymorphicAbilityConverter<Filter> { }
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
/// <summary>The visual presentation style for an ability animation.</summary>
|
||||
public enum AbilityAnimationType
|
||||
{
|
||||
/// <summary>A projectile that arcs from caster to target.</summary>
|
||||
Projectile,
|
||||
/// <summary>A projectile that travels in a straight line from caster to target.</summary>
|
||||
LinearProjectile,
|
||||
/// <summary>A projectile that follows a parabolic arc from caster to target.</summary>
|
||||
ArcProjectile,
|
||||
/// <summary>A radial aura effect centered on the caster or target.</summary>
|
||||
Aura,
|
||||
}
|
||||
|
||||
/// <summary>Where the animation effect VFX is rendered.</summary>
|
||||
public enum AbilityAnimationEffect
|
||||
{
|
||||
/// <summary>Effect plays on the ability's source unit.</summary>
|
||||
Self,
|
||||
/// <summary>Effect plays on each selected target.</summary>
|
||||
Target,
|
||||
/// <summary>Effect plays on a subset of affected units.</summary>
|
||||
Some,
|
||||
/// <summary>Effect covers the entire board (e.g. board-wide clear).</summary>
|
||||
All,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client-side animation and sound metadata for an ability.
|
||||
/// Stored inside AbilityDefinition.Animation (JSONB).
|
||||
/// Not used by server game logic — purely for the client renderer and audio system.
|
||||
/// </summary>
|
||||
public sealed class AbilityAnimationDefinition
|
||||
{
|
||||
public AbilityAnimationType Type { get; set; } = AbilityAnimationType.Projectile;
|
||||
public AbilityAnimationEffect Effect { get; set; } = AbilityAnimationEffect.Target;
|
||||
|
||||
/// <summary>CDN URL to the animation asset (particle effect, sprite sheet, etc.).</summary>
|
||||
public string? AssetUrl { get; set; }
|
||||
|
||||
/// <summary>Scale width multiplier for the effect (1.0 = default size).</summary>
|
||||
public float Width { get; set; } = 1f;
|
||||
|
||||
/// <summary>Scale height multiplier for the effect (1.0 = default size).</summary>
|
||||
public float Height { get; set; } = 1f;
|
||||
|
||||
/// <summary>Duration of the animation in seconds.</summary>
|
||||
public float Duration { get; set; } = 1f;
|
||||
|
||||
/// <summary>CDN URL to the sound played when the ability is cast/activated.</summary>
|
||||
public string? CastSoundUrl { get; set; }
|
||||
|
||||
/// <summary>CDN URL to the sound played on impact/effect resolution.</summary>
|
||||
public string? ImpactSoundUrl { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
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; }
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
// ── Value expression ──────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// An integer value that may be a fixed constant or a dynamic runtime reference.
|
||||
/// Dynamic references (§4.5) use dot-path notation, e.g.:
|
||||
/// "EventData.Amount", "Self.Damage", "Action1.Target.Defense"
|
||||
/// </summary>
|
||||
public sealed class ValueExpr
|
||||
{
|
||||
public int? Fixed { get; set; }
|
||||
public string? Ref { get; set; }
|
||||
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public bool IsDynamic => Ref is not null;
|
||||
|
||||
public static implicit operator ValueExpr(int n) => new() { Fixed = n };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An affinity value that may be fixed or a dynamic reference.
|
||||
/// E.g.: "Self.Affinity", "Action1.Target.Affinity".
|
||||
/// </summary>
|
||||
public sealed class AffinityExpr
|
||||
{
|
||||
public SOR.Database.Enums.Affinity? Fixed { get; set; }
|
||||
public string? Ref { get; set; }
|
||||
}
|
||||
|
||||
// ── Target selector ───────────────────────────────────────────────────────────
|
||||
|
||||
public enum TargetScope { Hand, Deck, Discard, Battlefield, Player, AnyZone }
|
||||
public enum TargetType { Unit, ArchSpirit, Spirit, SpiritToken, Ruin, Tile, Card, Player }
|
||||
public enum TargetOwnership { Self, ExactSelf, Owner, Ally, Enemy, Any, Random, Target }
|
||||
|
||||
public sealed class TargetCount
|
||||
{
|
||||
/// <summary>Exact number of targets; or the maximum when UpTo=true.</summary>
|
||||
public int N { get; set; } = 1;
|
||||
/// <summary>Player may select fewer than N valid targets.</summary>
|
||||
public bool UpTo { get; set; }
|
||||
/// <summary>Target all valid entities (N is ignored).</summary>
|
||||
public bool All { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines how targets are resolved for a single Action.
|
||||
/// Scope + Type + Ownership narrow the pool; Filters refine further.
|
||||
/// </summary>
|
||||
public sealed class TargetSelector
|
||||
{
|
||||
public TargetScope Scope { get; set; }
|
||||
public TargetType Type { get; set; }
|
||||
public TargetOwnership Ownership { get; set; }
|
||||
public TargetCount Count { get; set; } = new();
|
||||
public Filter[]? Filters { get; set; }
|
||||
}
|
||||
|
||||
// ── Action ────────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// The atomic unit of targeting and effect delivery within an ability.
|
||||
/// All effects within one action share the same target and duration.
|
||||
/// Actions within an ability resolve sequentially; a prior action's resolved
|
||||
/// target is accessible in subsequent actions via chained targeting filters.
|
||||
/// </summary>
|
||||
public sealed class Action
|
||||
{
|
||||
public TargetSelector Target { get; set; } = new();
|
||||
public Condition[]? Conditions { get; set; }
|
||||
public Effect[] Effects { get; set; } = [];
|
||||
public DurationModel? Duration { get; set; }
|
||||
}
|
||||
|
||||
// ── ChooseOne ─────────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Presents the controlling player with a set of mutually exclusive action branches.
|
||||
/// Exactly one branch is selected and its actions resolve; other branches are skipped.
|
||||
/// ChooseOne may appear anywhere an Action[] is accepted.
|
||||
/// </summary>
|
||||
public sealed class ChooseOne
|
||||
{
|
||||
public Branch[] Branches { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed class Branch
|
||||
{
|
||||
public string Label { get; set; } = string.Empty;
|
||||
public Action[] Actions { get; set; } = [];
|
||||
}
|
||||
|
||||
// ── Cost entry ────────────────────────────────────────────────────────────────
|
||||
|
||||
public enum CostType
|
||||
{
|
||||
SpiritPoints,
|
||||
SacrificeTokens,
|
||||
DiscardFromHand,
|
||||
MillTopOfDeck,
|
||||
MillBottomOfDeck,
|
||||
SendSpiritFromBattlefieldToDiscard,
|
||||
DealDamageToOwnArchSpirit,
|
||||
DealDamageToOwnSpirit,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A single cost element for an Active ability.
|
||||
/// Multiple CostEntry items must all be paid simultaneously before the ability resolves.
|
||||
/// </summary>
|
||||
public sealed class CostEntry
|
||||
{
|
||||
public CostType Type { get; set; }
|
||||
public int Amount { get; set; } = 1;
|
||||
/// <summary>Optional filter for targeted costs (e.g. "Discard a Spirit card from hand").</summary>
|
||||
public Filter[]? Filters { get; set; }
|
||||
}
|
||||
|
||||
// ── Ability range ─────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed class AbilityRange
|
||||
{
|
||||
public int Min { get; set; } = 1;
|
||||
public int Max { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// When true, the engine validates that a clear line of sight exists between the
|
||||
/// caster and the target tile/unit before allowing the ability to be used.
|
||||
/// </summary>
|
||||
public bool RequiresLos { get; set; } = false;
|
||||
/// <summary>
|
||||
/// When true, only targets that lie on a straight cardinal or diagonal line from
|
||||
/// the caster are valid (e.g. Push, Pull, beam-style abilities).
|
||||
/// </summary>
|
||||
public bool LinearOnly { get; set; } = false;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
// ── Condition base ────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// A boolean predicate evaluated against a subject entity.
|
||||
/// The default subject is Self (the source unit or ability owner).
|
||||
/// Override with Subject = "Target" to evaluate against the current action's resolved target.
|
||||
/// </summary>
|
||||
// Composite
|
||||
[PolyType(typeof(AndCondition), "AND")]
|
||||
[PolyType(typeof(OrCondition), "OR")]
|
||||
[PolyType(typeof(XorCondition), "XOR")]
|
||||
// Unit (§6.1)
|
||||
[PolyType(typeof(HealthBelowCondition), "HealthBelow")]
|
||||
[PolyType(typeof(HealthAboveCondition), "HealthAbove")]
|
||||
[PolyType(typeof(DefenseIsCondition), "DefenseIs")]
|
||||
[PolyType(typeof(HasGenusCondition), "HasGenus")]
|
||||
[PolyType(typeof(HasAbilityCondition), "HasAbility")]
|
||||
[PolyType(typeof(IsOnTileWithAffinityCondition), "IsOnTileWithAffinity")]
|
||||
[PolyType(typeof(IsAdjacentToCondition), "IsAdjacentTo")]
|
||||
[PolyType(typeof(WithinRangeOfCondition), "WithinRangeOf")]
|
||||
[PolyType(typeof(MovementTypeIsCondition), "MovementTypeIs")]
|
||||
// Player (§6.2)
|
||||
[PolyType(typeof(SPAtLeastCondition), "SPAtLeast")]
|
||||
[PolyType(typeof(SPAtMostCondition), "SPAtMost")]
|
||||
[PolyType(typeof(STAtLeastCondition), "STAtLeast")]
|
||||
[PolyType(typeof(STAtMostCondition), "STAtMost")]
|
||||
[PolyType(typeof(HandSizeAtLeastCondition), "HandSizeAtLeast")]
|
||||
[PolyType(typeof(HandSizeAtMostCondition), "HandSizeAtMost")]
|
||||
[PolyType(typeof(DeckSizeAtLeastCondition), "DeckSizeAtLeast")]
|
||||
[PolyType(typeof(DiscardSizeAtLeastCondition), "DiscardSizeAtLeast")]
|
||||
// Tile (§6.3)
|
||||
[PolyType(typeof(TileAffinityMatchesCondition), "TileAffinityMatches")]
|
||||
[PolyType(typeof(TileIsOccupiedCondition), "TileIsOccupied")]
|
||||
[PolyType(typeof(TileIsUnoccupiedCondition), "TileIsUnoccupied")]
|
||||
// Turn/timing (§6.4)
|
||||
[PolyType(typeof(IsOwnTurnCondition), "IsOwnTurn")]
|
||||
[PolyType(typeof(IsOpponentTurnCondition), "IsOpponentTurn")]
|
||||
[PolyType(typeof(IsAllyTurnCondition), "IsAllyTurn")]
|
||||
[PolyType(typeof(IsActivePlayerTurnCondition), "IsActivePlayerTurn")]
|
||||
// Battlefield (§6.5)
|
||||
[PolyType(typeof(UnitCountOnBattlefieldCondition), "UnitCountOnBattlefield")]
|
||||
[PolyType(typeof(CardInZoneCondition), "CardInZone")]
|
||||
public abstract class Condition
|
||||
{
|
||||
/// <summary>
|
||||
/// Which entity to evaluate this condition against.
|
||||
/// "Self" (default) = the source unit / ability owner.
|
||||
/// "Target" = the current action's resolved target.
|
||||
/// </summary>
|
||||
public string Subject { get; set; } = "Self";
|
||||
}
|
||||
|
||||
// ── Composite conditions ──────────────────────────────────────────────────────
|
||||
|
||||
public sealed class AndCondition : Condition { public Condition[] Conditions { get; set; } = []; }
|
||||
public sealed class OrCondition : Condition { public Condition[] Conditions { get; set; } = []; }
|
||||
public sealed class XorCondition : Condition { public Condition[] Conditions { get; set; } = []; }
|
||||
|
||||
// ── Unit conditions (§6.1) ────────────────────────────────────────────────────
|
||||
|
||||
public sealed class HealthBelowCondition : Condition { public int N { get; set; } }
|
||||
public sealed class HealthAboveCondition : Condition { public int N { get; set; } }
|
||||
public sealed class DefenseIsCondition : Condition { public int N { get; set; } }
|
||||
public sealed class HasGenusCondition : Condition { public string Tag { get; set; } = string.Empty; }
|
||||
/// <summary>Unit must have an ability with the given reference name.</summary>
|
||||
public sealed class HasAbilityCondition : Condition { public string AbilityRef { get; set; } = string.Empty; }
|
||||
public sealed class IsOnTileWithAffinityCondition : Condition { public Affinity Affinity { get; set; } }
|
||||
|
||||
public sealed class IsAdjacentToCondition : Condition
|
||||
{
|
||||
public string UnitType { get; set; } = "Unit";
|
||||
public string Ownership { get; set; } = "Any";
|
||||
}
|
||||
|
||||
public sealed class WithinRangeOfCondition : Condition
|
||||
{
|
||||
/// <summary>Reference to another action's target, e.g. "Action1.Target".</summary>
|
||||
public string Target { get; set; } = string.Empty;
|
||||
public int Min { get; set; } = 1;
|
||||
public int Max { get; set; } = 1;
|
||||
}
|
||||
|
||||
public sealed class MovementTypeIsCondition : Condition { public MovementType MovementType { get; set; } }
|
||||
|
||||
// ── Player conditions (§6.2) ──────────────────────────────────────────────────
|
||||
|
||||
public sealed class SPAtLeastCondition : Condition { public int N { get; set; } }
|
||||
public sealed class SPAtMostCondition : Condition { public int N { get; set; } }
|
||||
public sealed class STAtLeastCondition : Condition { public int N { get; set; } }
|
||||
public sealed class STAtMostCondition : Condition { public int N { get; set; } }
|
||||
public sealed class HandSizeAtLeastCondition : Condition { public int N { get; set; } }
|
||||
public sealed class HandSizeAtMostCondition : Condition { public int N { get; set; } }
|
||||
public sealed class DeckSizeAtLeastCondition : Condition { public int N { get; set; } }
|
||||
public sealed class DiscardSizeAtLeastCondition : Condition { public int N { get; set; } }
|
||||
|
||||
// ── Tile conditions (§6.3) ────────────────────────────────────────────────────
|
||||
|
||||
public sealed class TileAffinityMatchesCondition : Condition { public Affinity Affinity { get; set; } }
|
||||
public sealed class TileIsOccupiedCondition : Condition { public string? UnitType { get; set; } }
|
||||
public sealed class TileIsUnoccupiedCondition : Condition { }
|
||||
|
||||
// ── Turn/timing conditions (§6.4) ────────────────────────────────────────────
|
||||
|
||||
public sealed class IsOwnTurnCondition : Condition { }
|
||||
public sealed class IsOpponentTurnCondition : Condition { }
|
||||
public sealed class IsAllyTurnCondition : Condition { }
|
||||
public sealed class IsActivePlayerTurnCondition : Condition { public string Ownership { get; set; } = "Owner"; }
|
||||
|
||||
// ── Battlefield conditions (§6.5) ─────────────────────────────────────────────
|
||||
|
||||
public enum Comparator { Equal, NotEqual, LessThan, LessThanOrEqual, GreaterThan, GreaterThanOrEqual }
|
||||
|
||||
public sealed class UnitCountOnBattlefieldCondition : Condition
|
||||
{
|
||||
public string Ownership { get; set; } = "Enemy";
|
||||
public string UnitType { get; set; } = "Unit";
|
||||
public Comparator Comparator { get; set; } = Comparator.GreaterThanOrEqual;
|
||||
public int N { get; set; }
|
||||
}
|
||||
|
||||
public sealed class CardInZoneCondition : Condition
|
||||
{
|
||||
/// <summary>Reference to a specific card instance ID or definition ID.</summary>
|
||||
public string CardRef { get; set; } = string.Empty;
|
||||
public string Zone { get; set; } = "Hand";
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
/// <summary>How long an applied effect persists.</summary>
|
||||
public enum DurationType
|
||||
{
|
||||
/// <summary>One-time change; no ongoing tracking required.</summary>
|
||||
Instant,
|
||||
/// <summary>Expires at the end of the current active player's turn.</summary>
|
||||
UntilEndOfTurn,
|
||||
/// <summary>Expires at the start of the ability-owner's next turn.</summary>
|
||||
UntilStartOfOwnerTurn,
|
||||
/// <summary>Expires at the start of the source unit's owner's next turn.</summary>
|
||||
UntilStartOfSourceOwnerTurn,
|
||||
/// <summary>Expires after exactly N turns have elapsed.</summary>
|
||||
ForNTurns,
|
||||
/// <summary>Active while a condition evaluates to true; expires when it becomes false.</summary>
|
||||
WhileCondition,
|
||||
/// <summary>Active while the ability's source unit is on the battlefield; revoked on leave/death.</summary>
|
||||
WhileSourceOnBattlefield,
|
||||
/// <summary>Persists for the entire match; never expires.</summary>
|
||||
PermanentInMatch,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Duration descriptor attached to every Action in the ability model.
|
||||
/// Governs how long the action's effects remain active.
|
||||
/// </summary>
|
||||
public sealed class DurationModel
|
||||
{
|
||||
public DurationType Type { get; set; } = DurationType.Instant;
|
||||
|
||||
/// <summary>Turn count for <see cref="DurationType.ForNTurns"/>.</summary>
|
||||
public int? N { get; set; }
|
||||
|
||||
/// <summary>Condition evaluated each turn for <see cref="DurationType.WhileCondition"/>.</summary>
|
||||
public Condition? Condition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional ownership scope for timing anchors.
|
||||
/// E.g., "Owner" scopes "UntilEndOfTurn" to the ability-owner's turn end specifically.
|
||||
/// </summary>
|
||||
public string? PlayerScope { get; set; }
|
||||
|
||||
public static DurationModel Instant => new() { Type = DurationType.Instant };
|
||||
public static DurationModel Permanent => new() { Type = DurationType.PermanentInMatch };
|
||||
public static DurationModel EndOfTurn => new() { Type = DurationType.UntilEndOfTurn };
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
// ── Effect base ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// The atomic unit of game-state mutation delivered to a resolved target.
|
||||
/// All effects share a DurationModel (from their containing Action).
|
||||
/// </summary>
|
||||
// §5.1 Stat modification
|
||||
[PolyType(typeof(ModifyHealthEffect), "ModifyHealth")]
|
||||
[PolyType(typeof(ModifyDefenseEffect), "ModifyDefense")]
|
||||
[PolyType(typeof(ModifyDamageEffect), "ModifyDamage")]
|
||||
[PolyType(typeof(ModifyMPEffect), "ModifyMP")]
|
||||
[PolyType(typeof(SetMovementTypeEffect), "SetMovementType")]
|
||||
[PolyType(typeof(SetAttackRangeEffect), "SetAttackRange")]
|
||||
[PolyType(typeof(ModifyMinAttackRangeEffect), "ModifyMinAttackRange")]
|
||||
[PolyType(typeof(ModifyMaxAttackRangeEffect), "ModifyMaxAttackRange")]
|
||||
[PolyType(typeof(ModifyCostEffect), "ModifyCost")]
|
||||
[PolyType(typeof(SetAffinityEffect), "SetAffinity")]
|
||||
[PolyType(typeof(GrantAdditionalAttackEffect), "GrantAdditionalAttack")]
|
||||
[PolyType(typeof(SetStatModMultiplierEffect), "SetStatModMultiplier")]
|
||||
// §5.2 Flag modification — unit
|
||||
[PolyType(typeof(SetCanMoveEffect), "SetCanMove")]
|
||||
[PolyType(typeof(SetCanAttackEffect), "SetCanAttack")]
|
||||
[PolyType(typeof(SetCanDefendEffect), "SetCanDefend")]
|
||||
[PolyType(typeof(SetCanBeAttackedEffect), "SetCanBeAttacked")]
|
||||
[PolyType(typeof(SetCanBeBlockedEffect), "SetCanBeBlocked")]
|
||||
[PolyType(typeof(SetCanBeObstructedEffect), "SetCanBeObstructed")]
|
||||
[PolyType(typeof(SetCanUseAbilityEffect), "SetCanUseAbility")]
|
||||
[PolyType(typeof(SetCanBeSacrificedEffect), "SetCanBeSacrificed")]
|
||||
// §5.2 Flag modification — player
|
||||
[PolyType(typeof(SetCanDrawCardsEffect), "SetCanDrawCards")]
|
||||
[PolyType(typeof(SetAccumulatesSPEffect), "SetAccumulatesSP")]
|
||||
[PolyType(typeof(SetCanChannelSpiritEffect), "SetCanChannelSpirit")]
|
||||
[PolyType(typeof(SetCanSacrificeSpiritEffect), "SetCanSacrificeSpirit")]
|
||||
[PolyType(typeof(SetCanAscendArchSpiritEffect), "SetCanAscendArchSpirit")]
|
||||
[PolyType(typeof(SetCanTransitionArchSpiritEffect), "SetCanTransitionArchSpirit")]
|
||||
[PolyType(typeof(SetCanChannelRepentanceEffect), "SetCanChannelRepentance")]
|
||||
[PolyType(typeof(SetCanChannelInstinctEffect), "SetCanChannelInstinct")]
|
||||
[PolyType(typeof(SetCanChannelRuinEffect), "SetCanChannelRuin")]
|
||||
[PolyType(typeof(SetCanChannelTerramorphaMonoEffect), "SetCanChannelTerramorphaMono")]
|
||||
[PolyType(typeof(SetCanChannelTerramorphaDiEffect), "SetCanChannelTerramorphaDi")]
|
||||
[PolyType(typeof(SetCanChannelTerramorphaTriEffect), "SetCanChannelTerramorphaTri")]
|
||||
// §5.3 Ability modification
|
||||
[PolyType(typeof(AddAbilityEffect), "AddAbility")]
|
||||
[PolyType(typeof(RemoveAbilityEffect), "RemoveAbility")]
|
||||
[PolyType(typeof(EnableAbilityEffect), "EnableAbility")]
|
||||
[PolyType(typeof(DisableAbilityEffect),"DisableAbility")]
|
||||
// §5.4 Genus modification
|
||||
[PolyType(typeof(AddGenusEffect), "AddGenus")]
|
||||
[PolyType(typeof(RemoveGenusEffect), "RemoveGenus")]
|
||||
// §5.5 Player resource modification
|
||||
[PolyType(typeof(ModifySPEffect), "ModifySP")]
|
||||
[PolyType(typeof(ModifySPAccumulationEffect), "ModifySPAccumulation")]
|
||||
[PolyType(typeof(ModifySTEffect), "ModifyST")]
|
||||
[PolyType(typeof(ModifyCardsDrawnPerTurnEffect), "ModifyCardsDrawnPerTurn")]
|
||||
// §5.6 Tile modification
|
||||
[PolyType(typeof(SetBaseAffinity1Effect), "SetBaseAffinity1")]
|
||||
[PolyType(typeof(SetBaseAffinity2Effect), "SetBaseAffinity2")]
|
||||
[PolyType(typeof(PushAffinityEffect), "PushAffinity")]
|
||||
[PolyType(typeof(PushFinalAffinityEffect), "PushFinalAffinity")]
|
||||
// §5.7 Zone / card operations
|
||||
[PolyType(typeof(DrawCardsEffect), "DrawCards")]
|
||||
[PolyType(typeof(DiscardCardsEffect), "DiscardCards")]
|
||||
[PolyType(typeof(ReturnToHandEffect), "ReturnToHand")]
|
||||
[PolyType(typeof(ReturnToDeckEffect), "ReturnToDeck")]
|
||||
[PolyType(typeof(ReturnToBattlefieldEffect), "ReturnToBattlefield")]
|
||||
[PolyType(typeof(SendToDiscardEffect), "SendToDiscard")]
|
||||
[PolyType(typeof(SearchDeckEffect), "SearchDeck")]
|
||||
[PolyType(typeof(ShuffleDeckEffect), "ShuffleDeck")]
|
||||
[PolyType(typeof(RevealCardsEffect), "RevealCards")]
|
||||
[PolyType(typeof(PlaceOnDeckEffect), "PlaceOnDeck")]
|
||||
[PolyType(typeof(ChannelCardEffect), "ChannelCard")]
|
||||
// §5.8 Combat / damage
|
||||
[PolyType(typeof(DealDamageEffect), "DealDamage")]
|
||||
[PolyType(typeof(HealEffect), "Heal")]
|
||||
[PolyType(typeof(DealDamageToSelfEffect), "DealDamageToSelf")]
|
||||
[PolyType(typeof(DOTEffect), "DOT")]
|
||||
[PolyType(typeof(HOTEffect), "HOT")]
|
||||
// §5.9 Displacement
|
||||
[PolyType(typeof(PushUnitEffect), "PushUnit")]
|
||||
[PolyType(typeof(PullUnitEffect), "PullUnit")]
|
||||
[PolyType(typeof(DisplaceUnitEffect), "DisplaceUnit")]
|
||||
// §5.10 Control
|
||||
[PolyType(typeof(TakeControlEffect), "TakeControl")]
|
||||
[PolyType(typeof(GrantMovementControlEffect), "GrantMovementControl")]
|
||||
[PolyType(typeof(SetFixedSacrificeReturnEffect),"SetFixedSacrificeReturn")]
|
||||
// §5.11 Token
|
||||
[PolyType(typeof(SummonTokenEffect), "SummonToken")]
|
||||
// §5.12 Deferred
|
||||
[PolyType(typeof(ApplyOnEventEffect), "ApplyOnEvent")]
|
||||
public abstract class Effect { }
|
||||
|
||||
// ── §5.1 Stat modification ────────────────────────────────────────────────────
|
||||
|
||||
public enum StatTarget { Current, Max }
|
||||
|
||||
public sealed class ModifyHealthEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; }
|
||||
public sealed class ModifyDefenseEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; }
|
||||
public sealed class ModifyDamageEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifyMPEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; }
|
||||
|
||||
public sealed class SetMovementTypeEffect : Effect { public MovementType MovementType { get; set; } }
|
||||
public sealed class SetAttackRangeEffect : Effect { public int Min { get; set; } public int Max { get; set; } }
|
||||
public sealed class ModifyMinAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifyMaxAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifyCostEffect : Effect { public int? Sp { get; set; } public int? St { get; set; } }
|
||||
public sealed class SetAffinityEffect : Effect { public AffinityExpr Affinity { get; set; } = new(); }
|
||||
public sealed class GrantAdditionalAttackEffect : Effect { public int N { get; set; } = 1; }
|
||||
public sealed class SetStatModMultiplierEffect : Effect { public string Stat { get; set; } = string.Empty; public double Multiplier { get; set; } = 1.0; }
|
||||
|
||||
// ── §5.2 Flag modification — unit ─────────────────────────────────────────────
|
||||
|
||||
public sealed class SetCanMoveEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanAttackEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanDefendEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanBeAttackedEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanBeBlockedEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanBeObstructedEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanUseAbilityEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanBeSacrificedEffect : Effect { public bool Value { get; set; } }
|
||||
|
||||
// ── §5.2 Flag modification — player ───────────────────────────────────────────
|
||||
|
||||
public sealed class SetCanDrawCardsEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetAccumulatesSPEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanChannelSpiritEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanSacrificeSpiritEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanAscendArchSpiritEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanTransitionArchSpiritEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanChannelRepentanceEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanChannelInstinctEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanChannelRuinEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanChannelTerramorphaMonoEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanChannelTerramorphaDiEffect : Effect { public bool Value { get; set; } }
|
||||
public sealed class SetCanChannelTerramorphaTriEffect : Effect { public bool Value { get; set; } }
|
||||
|
||||
// ── §5.3 Ability modification ─────────────────────────────────────────────────
|
||||
|
||||
public sealed class AddAbilityEffect : Effect { public AbilityDefinition AbilityDef { get; set; } = new(); }
|
||||
/// <summary>AbilityRef is the ability name (matches AbilityDefinition.Name).</summary>
|
||||
public sealed class RemoveAbilityEffect : Effect { public string AbilityRef { get; set; } = string.Empty; }
|
||||
public sealed class EnableAbilityEffect : Effect { public string AbilityRef { get; set; } = string.Empty; }
|
||||
public sealed class DisableAbilityEffect: Effect { public string AbilityRef { get; set; } = string.Empty; }
|
||||
|
||||
// ── §5.4 Genus modification ───────────────────────────────────────────────────
|
||||
|
||||
public sealed class AddGenusEffect : Effect { public string Tag { get; set; } = string.Empty; }
|
||||
public sealed class RemoveGenusEffect : Effect { public string Tag { get; set; } = string.Empty; }
|
||||
|
||||
// ── §5.5 Player resource modification ─────────────────────────────────────────
|
||||
|
||||
public sealed class ModifySPEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifySPAccumulationEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifySTEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifyCardsDrawnPerTurnEffect: Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
|
||||
// ── §5.6 Tile modification ────────────────────────────────────────────────────
|
||||
|
||||
public sealed class SetBaseAffinity1Effect : Effect { public AffinityExpr Affinity { get; set; } = new(); }
|
||||
public sealed class SetBaseAffinity2Effect : Effect { public AffinityExpr Affinity { get; set; } = new(); }
|
||||
public sealed class PushAffinityEffect : Effect { public AffinityExpr Affinity { get; set; } = new(); }
|
||||
public sealed class PushFinalAffinityEffect : Effect { public AffinityExpr Affinity { get; set; } = new(); }
|
||||
|
||||
// ── §5.7 Zone / card operations ───────────────────────────────────────────────
|
||||
|
||||
public sealed class DrawCardsEffect : Effect { public int N { get; set; } = 1; public string Player { get; set; } = "Owner"; }
|
||||
public sealed class DiscardCardsEffect : Effect { public int N { get; set; } = 1; public string Player { get; set; } = "Owner"; public Filter[]? Filters { get; set; } }
|
||||
public sealed class ReturnToHandEffect : Effect { } // target is the card (from action target)
|
||||
public sealed class ReturnToDeckEffect : Effect { public string Position { get; set; } = "top"; } // top | bottom | random
|
||||
public sealed class ReturnToBattlefieldEffect : Effect { public string? Controller { get; set; } public Filter[]? TileFilter { get; set; } }
|
||||
public sealed class SendToDiscardEffect: Effect { }
|
||||
public sealed class SearchDeckEffect : Effect
|
||||
{
|
||||
public Filter[]? Filters { get; set; }
|
||||
public int Count { get; set; } = 1;
|
||||
/// <summary>Action applied to each found card (SearchResult references current card).</summary>
|
||||
public Action? ThenAction { get; set; }
|
||||
}
|
||||
public sealed class ShuffleDeckEffect : Effect { public string Player { get; set; } = "Owner"; }
|
||||
public sealed class RevealCardsEffect : Effect { public int N { get; set; } = 1; public string ToOwnership { get; set; } = "Any"; }
|
||||
public sealed class PlaceOnDeckEffect : Effect { public string Position { get; set; } = "top"; }
|
||||
public sealed class ChannelCardEffect : Effect
|
||||
{
|
||||
public bool PayCost { get; set; } = true;
|
||||
public double? CostMultiplier { get; set; }
|
||||
}
|
||||
|
||||
// ── §5.8 Combat / damage ──────────────────────────────────────────────────────
|
||||
|
||||
public sealed class DealDamageEffect : Effect { public ValueExpr Amount { get; set; } = new(); public bool BypassDefense { get; set; } }
|
||||
public sealed class HealEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class DealDamageToSelfEffect : Effect { public ValueExpr Amount { get; set; } = new(); public bool BypassDefense { get; set; } }
|
||||
public sealed class DOTEffect : Effect { public ValueExpr Amount { get; set; } = new(); public DurationModel Duration { get; set; } = DurationModel.EndOfTurn; public bool BypassDefense { get; set; } }
|
||||
public sealed class HOTEffect : Effect { public ValueExpr Amount { get; set; } = new(); public DurationModel Duration { get; set; } = DurationModel.EndOfTurn; }
|
||||
|
||||
// ── §5.9 Displacement ─────────────────────────────────────────────────────────
|
||||
|
||||
public sealed class PushUnitEffect : Effect
|
||||
{
|
||||
public int Tiles { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// Direct HP damage dealt to the pushed unit if it cannot complete the full push
|
||||
/// (blocked by a boundary or another unit). 0 = no knockback damage.
|
||||
/// </summary>
|
||||
public int BlockedDamage { get; set; } = 0;
|
||||
}
|
||||
|
||||
public sealed class PullUnitEffect : Effect
|
||||
{
|
||||
public int Tiles { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// Direct HP damage dealt to the pulled unit if it cannot complete the full pull
|
||||
/// (blocked by a boundary or another unit). 0 = no knockback damage.
|
||||
/// </summary>
|
||||
public int BlockedDamage { get; set; } = 0;
|
||||
}
|
||||
public sealed class DisplaceUnitEffect : Effect { public int Tiles { get; set; } = 1; public string Direction { get; set; } = "North"; }
|
||||
|
||||
// ── §5.10 Control effects ─────────────────────────────────────────────────────
|
||||
|
||||
public sealed class TakeControlEffect : Effect { public DurationModel Duration { get; set; } = DurationModel.EndOfTurn; }
|
||||
public sealed class GrantMovementControlEffect : Effect { public int N { get; set; } = 1; }
|
||||
/// <summary>Overrides the sacrifice formula: controller receives exactly StAmount ST instead.</summary>
|
||||
public sealed class SetFixedSacrificeReturnEffect : Effect { public int StAmount { get; set; } }
|
||||
|
||||
// ── §5.11 Token summoning ─────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Summons a SpiritToken onto a player-selected tile meeting the filter.
|
||||
/// TokenDefJson is a JSONB blob matching a mini-CardDefinition for the token.
|
||||
/// </summary>
|
||||
public sealed class SummonTokenEffect : Effect
|
||||
{
|
||||
public string TokenDefJson { get; set; } = "{}";
|
||||
public Filter[]? TileFilter { get; set; }
|
||||
}
|
||||
|
||||
// ── §5.12 Deferred effects ────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Schedules effects to fire once the next time the specified trigger event occurs.
|
||||
/// Consumed after firing. Cancelled if source leaves battlefield before event fires.
|
||||
/// </summary>
|
||||
public sealed class ApplyOnEventEffect : Effect
|
||||
{
|
||||
public TriggerEvent Trigger { get; set; } = null!;
|
||||
public Effect[] Effects { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
// ── Filter base ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Narrows which entities a TargetSelector or condition matches.
|
||||
/// Unit/card filters apply to spirits and ArchSpirits; tile filters to board tiles.
|
||||
/// </summary>
|
||||
// ── Unit / card filters ──────────────────────────────────────────────────────
|
||||
[PolyType(typeof(GenusContainsFilter), "GenusContains")]
|
||||
[PolyType(typeof(AffinityMatchesFilter), "AffinityMatches")]
|
||||
[PolyType(typeof(HealthBelowFilter), "HealthBelow")]
|
||||
[PolyType(typeof(HealthAboveFilter), "HealthAbove")]
|
||||
[PolyType(typeof(DamageRangeFilter), "DamageRange")]
|
||||
[PolyType(typeof(DefenseRangeFilter), "DefenseRange")]
|
||||
[PolyType(typeof(MPRangeFilter), "MPRange")]
|
||||
[PolyType(typeof(HasFlagFilter), "HasFlag")]
|
||||
[PolyType(typeof(TierIsFilter), "TierIs")]
|
||||
[PolyType(typeof(IsAdjacentToSourceFilter), "IsAdjacentToSource")]
|
||||
[PolyType(typeof(CardTypeIsFilter), "CardTypeIs")]
|
||||
[PolyType(typeof(CardSPCostRangeFilter), "CardSPCostRange")]
|
||||
[PolyType(typeof(CardSTCostRangeFilter), "CardSTCostRange")]
|
||||
[PolyType(typeof(WithinRangeFilter), "WithinRange")]
|
||||
[PolyType(typeof(IsSelfFilter), "IsSelf")]
|
||||
[PolyType(typeof(IsExactSelfFilter), "IsExactSelf")]
|
||||
// ── Tile filters ─────────────────────────────────────────────────────────────
|
||||
[PolyType(typeof(TileAffinityMatchesFilter), "TileAffinityMatches")]
|
||||
[PolyType(typeof(TileAffinityMatchesFilter), "TileAffinityMatchesFilter")] // legacy alias (typo in admin v1)
|
||||
[PolyType(typeof(TileIsOccupiedFilter), "TileIsOccupied")]
|
||||
[PolyType(typeof(TileIsUnoccupiedFilter), "TileIsUnoccupied")]
|
||||
[PolyType(typeof(TileWithinRangeFilter), "TileWithinRange")]
|
||||
[PolyType(typeof(TileIsAdjacentToUnitFilter), "TileIsAdjacentToUnit")]
|
||||
[PolyType(typeof(TileIsOnPlayerSideFilter), "TileIsOnPlayerSide")]
|
||||
[PolyType(typeof(TileIsInArchSpiritChannelRangeFilter), "TileIsInArchSpiritChannelRange")]
|
||||
public abstract class Filter { }
|
||||
|
||||
// ── Unit / card filter implementations ───────────────────────────────────────
|
||||
|
||||
/// <summary>Unit's genus array must contain the given tag.</summary>
|
||||
public sealed class GenusContainsFilter : Filter
|
||||
{
|
||||
public string Tag { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>Unit's affinity must match.</summary>
|
||||
public sealed class AffinityMatchesFilter : Filter
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
}
|
||||
|
||||
public sealed class HealthBelowFilter : Filter { public int N { get; set; } }
|
||||
public sealed class HealthAboveFilter : Filter { public int N { get; set; } }
|
||||
|
||||
public sealed class DamageRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
|
||||
public sealed class DefenseRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
|
||||
public sealed class MPRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
|
||||
|
||||
/// <summary>
|
||||
/// Unit must have the specified boolean flag set to true.
|
||||
/// Flag names: CanAttack, CanMove, CanDefend, CanBeAttacked, CanBeBlocked, CanBeSacrificed, etc.
|
||||
/// </summary>
|
||||
public sealed class HasFlagFilter : Filter
|
||||
{
|
||||
public string Flag { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>ArchSpirit must be at the specified tier number.</summary>
|
||||
public sealed class TierIsFilter : Filter
|
||||
{
|
||||
public int Tier { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Target unit must be orthogonally adjacent to the ability's source unit.</summary>
|
||||
public sealed class IsAdjacentToSourceFilter : Filter { }
|
||||
|
||||
public sealed class CardTypeIsFilter : Filter
|
||||
{
|
||||
public CardType CardType { get; set; }
|
||||
}
|
||||
|
||||
public sealed class CardSPCostRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
|
||||
public sealed class CardSTCostRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
|
||||
|
||||
/// <summary>Unit must be within Min..Max Manhattan distance of the ability's source unit.</summary>
|
||||
public sealed class WithinRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
|
||||
|
||||
/// <summary>
|
||||
/// Matches any unit that shares the same card definition as the ability source.
|
||||
/// Use for abilities that affect "all copies of this card type".
|
||||
/// </summary>
|
||||
public sealed class IsSelfFilter : Filter { }
|
||||
|
||||
/// <summary>
|
||||
/// Matches only the exact unit instance that owns this ability (by InstanceId).
|
||||
/// Use this instead of IsSelf when only the specific unit on the battlefield should be affected.
|
||||
/// </summary>
|
||||
public sealed class IsExactSelfFilter : Filter { }
|
||||
|
||||
// ── Tile filter implementations ───────────────────────────────────────────────
|
||||
|
||||
public sealed class TileAffinityMatchesFilter : Filter
|
||||
{
|
||||
public Affinity Affinity { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Tile must be occupied; optionally restrict to a specific unit type.</summary>
|
||||
public sealed class TileIsOccupiedFilter : Filter
|
||||
{
|
||||
public string? UnitType { get; set; } // "Spirit" | "ArchSpirit" | "SpiritToken" | null (any)
|
||||
}
|
||||
|
||||
public sealed class TileIsUnoccupiedFilter : Filter { }
|
||||
|
||||
public sealed class TileWithinRangeFilter : Filter { public int Min { get; set; } public int Max { get; set; } }
|
||||
|
||||
public sealed class TileIsAdjacentToUnitFilter : Filter
|
||||
{
|
||||
public string Ownership { get; set; } = "Any"; // TargetOwnership as string
|
||||
public Filter? UnitFilter { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Tile falls within the starting placement side of the specified player ownership group.</summary>
|
||||
public sealed class TileIsOnPlayerSideFilter : Filter
|
||||
{
|
||||
public string Ownership { get; set; } = "Owner";
|
||||
}
|
||||
|
||||
/// <summary>Tile is within the active ArchSpirit's channeling range for the specified player.</summary>
|
||||
public sealed class TileIsInArchSpiritChannelRangeFilter : Filter
|
||||
{
|
||||
public string Ownership { get; set; } = "Owner";
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Maps a type-discriminator string to a concrete derived type for the custom
|
||||
/// <c>PolymorphicAbilityConverter<T></c>. This is intentionally NOT a
|
||||
/// <see cref="System.Text.Json.Serialization.JsonDerivedTypeAttribute"/> — using
|
||||
/// that attribute (even without [JsonPolymorphic]) causes System.Text.Json to
|
||||
/// activate its built-in PolymorphicTypeResolver, which conflicts with our
|
||||
/// custom converter.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
|
||||
internal sealed class PolyTypeAttribute(Type derivedType, string discriminator) : Attribute
|
||||
{
|
||||
public Type DerivedType { get; } = derivedType;
|
||||
public string Discriminator { get; } = discriminator;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
|
||||
// ── TriggerEvent base ─────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the game event that causes a Triggered ability to fire.
|
||||
/// Every event supports an optional ownership scope applied to the acting entity
|
||||
/// and most accept an optional filter for further narrowing.
|
||||
/// </summary>
|
||||
// §8.1 Turn phase
|
||||
[PolyType(typeof(OnTurnStartTrigger), "OnTurnStart")]
|
||||
[PolyType(typeof(OnTurnEndTrigger), "OnTurnEnd")]
|
||||
// §8.2 Channeling
|
||||
[PolyType(typeof(OnChanneledTrigger), "OnChanneled")]
|
||||
// §8.3 ArchSpirit tier actions
|
||||
[PolyType(typeof(OnAscendTrigger), "OnAscend")]
|
||||
[PolyType(typeof(OnTransitionTrigger), "OnTransition")]
|
||||
// §8.4 Unit actions
|
||||
[PolyType(typeof(OnUnitMoveTrigger), "OnUnitMove")]
|
||||
[PolyType(typeof(OnUnitAttackTrigger), "OnUnitAttack")]
|
||||
[PolyType(typeof(OnUnitAbilityActivatedTrigger), "OnUnitAbilityActivated")]
|
||||
[PolyType(typeof(OnUnitMPSpentTrigger), "OnUnitMPSpent")]
|
||||
// §8.5 Damage and healing
|
||||
[PolyType(typeof(OnDamageDealtTrigger), "OnDamageDealt")]
|
||||
[PolyType(typeof(OnDamagePreventedTrigger), "OnDamagePrevented")]
|
||||
[PolyType(typeof(OnHealedTrigger), "OnHealed")]
|
||||
// §8.6 Unit lifecycle
|
||||
[PolyType(typeof(OnUnitEnterBattlefieldTrigger), "OnUnitEnterBattlefield")]
|
||||
[PolyType(typeof(OnUnitLeaveBattlefieldTrigger), "OnUnitLeaveBattlefield")]
|
||||
[PolyType(typeof(OnUnitDeathTrigger), "OnUnitDeath")]
|
||||
[PolyType(typeof(OnUnitSentToDiscardTrigger), "OnUnitSentToDiscard")]
|
||||
[PolyType(typeof(OnSpiritSacrificedTrigger), "OnSpiritSacrificed")]
|
||||
[PolyType(typeof(OnTokenSummonedTrigger), "OnTokenSummoned")]
|
||||
// §8.7 Unit state changes
|
||||
[PolyType(typeof(OnStatModifiedTrigger), "OnStatModified")]
|
||||
[PolyType(typeof(OnAbilityAddedTrigger), "OnAbilityAdded")]
|
||||
[PolyType(typeof(OnAbilityRemovedTrigger), "OnAbilityRemoved")]
|
||||
[PolyType(typeof(OnGenusChangedTrigger), "OnGenusChanged")]
|
||||
// §8.8 Ruin
|
||||
[PolyType(typeof(OnRuinActivationTrigger), "OnRuinActivation")]
|
||||
[PolyType(typeof(OnUnitOccupyRuinTrigger), "OnUnitOccupyRuin")]
|
||||
// §8.9 Tile
|
||||
[PolyType(typeof(OnTileAffinityChangedTrigger), "OnTileAffinityChanged")]
|
||||
// §8.10 Player resources
|
||||
[PolyType(typeof(OnSPGainedTrigger), "OnSPGained")]
|
||||
[PolyType(typeof(OnSPSpentTrigger), "OnSPSpent")]
|
||||
[PolyType(typeof(OnSTGainedTrigger), "OnSTGained")]
|
||||
[PolyType(typeof(OnSTSpentTrigger), "OnSTSpent")]
|
||||
// §8.11 Card zone events
|
||||
[PolyType(typeof(OnCardDrawnTrigger), "OnCardDrawn")]
|
||||
[PolyType(typeof(OnCardDiscardedTrigger), "OnCardDiscarded")]
|
||||
[PolyType(typeof(OnCardReturnedToHandTrigger), "OnCardReturnedToHand")]
|
||||
[PolyType(typeof(OnCardReturnedToDeckTrigger), "OnCardReturnedToDeck")]
|
||||
[PolyType(typeof(OnDeckShuffledTrigger), "OnDeckShuffled")]
|
||||
[PolyType(typeof(OnCardsRevealedTrigger), "OnCardsRevealed")]
|
||||
// §8.12 Effect and targeting lifecycle
|
||||
[PolyType(typeof(OnTargetedByAbilityTrigger), "OnTargetedByAbility")]
|
||||
[PolyType(typeof(OnEffectAppliedTrigger), "OnEffectApplied")]
|
||||
[PolyType(typeof(OnEnterAuraRangeTrigger), "OnEnterAuraRange")]
|
||||
[PolyType(typeof(OnLeaveAuraRangeTrigger), "OnLeaveAuraRange")]
|
||||
public abstract class TriggerEvent { }
|
||||
|
||||
// ── §8.1 Turn phase ───────────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnTurnStartTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; }
|
||||
public sealed class OnTurnEndTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; }
|
||||
|
||||
// ── §8.2 Channeling ───────────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnChanneledTrigger : TriggerEvent
|
||||
{
|
||||
public string CardType { get; set; } = "Spirit";
|
||||
public string Ownership { get; set; } = "Owner";
|
||||
public Filter? Filter { get; set; }
|
||||
}
|
||||
|
||||
// ── §8.3 ArchSpirit tier actions ──────────────────────────────────────────────
|
||||
|
||||
public sealed class OnAscendTrigger : TriggerEvent { public string Ownership { get; set; } = "Owner"; }
|
||||
public sealed class OnTransitionTrigger : TriggerEvent { public string Ownership { get; set; } = "Owner"; }
|
||||
|
||||
// ── §8.4 Unit actions ─────────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnUnitMoveTrigger : TriggerEvent { public string Ownership { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnUnitAttackTrigger : TriggerEvent { public string Ownership { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnUnitAbilityActivatedTrigger : TriggerEvent { public string Ownership { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnUnitMPSpentTrigger : TriggerEvent { public string Ownership { get; set; } = "Owner"; public Filter? Filter { get; set; } public int? Amount { get; set; } }
|
||||
|
||||
// ── §8.5 Damage and healing ───────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnDamageDealtTrigger : TriggerEvent
|
||||
{
|
||||
public string SourceOwnership { get; set; } = "Any";
|
||||
public string TargetOwnership { get; set; } = "Any";
|
||||
public string DamageType { get; set; } = "Any"; // "HP" | "Defense" | "Any"
|
||||
public int? Amount { get; set; }
|
||||
}
|
||||
public sealed class OnDamagePreventedTrigger : TriggerEvent { public string TargetOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnHealedTrigger : TriggerEvent { public string TargetOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } public int? Amount { get; set; } }
|
||||
|
||||
// ── §8.6 Unit lifecycle ───────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnUnitEnterBattlefieldTrigger : TriggerEvent { public string UnitType { get; set; } = "Unit"; public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnUnitLeaveBattlefieldTrigger : TriggerEvent { public string UnitType { get; set; } = "Unit"; public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnUnitDeathTrigger : TriggerEvent { public string UnitType { get; set; } = "Unit"; public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnUnitSentToDiscardTrigger : TriggerEvent { public string UnitType { get; set; } = "Unit"; public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } public string? CausedBy { get; set; } }
|
||||
public sealed class OnSpiritSacrificedTrigger : TriggerEvent { public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnTokenSummonedTrigger : TriggerEvent { public string Ownership { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
|
||||
// ── §8.7 Unit state changes ───────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnStatModifiedTrigger : TriggerEvent { public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } public string? Stat { get; set; } }
|
||||
public sealed class OnAbilityAddedTrigger : TriggerEvent { public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnAbilityRemovedTrigger: TriggerEvent { public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnGenusChangedTrigger : TriggerEvent { public string Ownership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
|
||||
// ── §8.8 Ruin ────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnRuinActivationTrigger : TriggerEvent { public string RuinOwnership { get; set; } = "Any"; public string? OccupantOwnership { get; set; } }
|
||||
public sealed class OnUnitOccupyRuinTrigger : TriggerEvent { public string UnitOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
|
||||
// ── §8.9 Tile ────────────────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnTileAffinityChangedTrigger : TriggerEvent { public Filter? Filter { get; set; } }
|
||||
|
||||
// ── §8.10 Player resources ────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnSPGainedTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public int? Amount { get; set; } }
|
||||
public sealed class OnSPSpentTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public int? Amount { get; set; } }
|
||||
public sealed class OnSTGainedTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public int? Amount { get; set; } }
|
||||
public sealed class OnSTSpentTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public int? Amount { get; set; } }
|
||||
|
||||
// ── §8.11 Card zone events ────────────────────────────────────────────────────
|
||||
|
||||
public sealed class OnCardDrawnTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnCardDiscardedTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public Filter? Filter { get; set; } public string? Cause { get; set; } }
|
||||
public sealed class OnCardReturnedToHandTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnCardReturnedToDeckTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnDeckShuffledTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; }
|
||||
public sealed class OnCardsRevealedTrigger : TriggerEvent { public string Player { get; set; } = "Owner"; public Filter? Filter { get; set; } }
|
||||
|
||||
// ── §8.12 Effect and targeting lifecycle ──────────────────────────────────────
|
||||
|
||||
public sealed class OnTargetedByAbilityTrigger : TriggerEvent { public string TargetOwnership { get; set; } = "Owner"; public string SourceOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnEffectAppliedTrigger : TriggerEvent { public string TargetOwnership { get; set; } = "Owner"; public string SourceOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnEnterAuraRangeTrigger : TriggerEvent { public string AuraOwnership { get; set; } = "Owner"; public string UnitOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
public sealed class OnLeaveAuraRangeTrigger : TriggerEvent { public string AuraOwnership { get; set; } = "Owner"; public string UnitOwnership { get; set; } = "Any"; public Filter? Filter { get; set; } }
|
||||
Reference in New Issue
Block a user