Files
cardgen/proposed_changes_sor_game_abilities.md
T

627 lines
15 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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.