Fix: replace [JsonDerivedType] with [PolyType] to avoid STJ PolymorphicTypeResolver conflict

[JsonDerivedType] alone (without [JsonPolymorphic]) is sufficient in .NET 8 to
activate the built-in PolymorphicTypeResolver, which then throws
NotSupportedException because our custom converter does not support metadata
reads/writes.

Introduce PolyTypeAttribute — a plain internal attribute unknown to the
framework — and replace all [JsonDerivedType] usages on Effect, Condition,
TriggerEvent, and Filter with [PolyType]. PolymorphicAbilityConverter<T> reads
[PolyType] via reflection to build its type map; the framework ignores it entirely.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-09 20:53:02 -04:00
co-authored by Claude Happy
parent bd07c0cdde
commit 696452f4c9
6 changed files with 178 additions and 168 deletions
@@ -1,6 +1,5 @@
namespace SOR.Game.Abilities.Models;
using System.Text.Json.Serialization;
using SOR.Database.Enums;
// ── Condition base ────────────────────────────────────────────────────────────
@@ -11,40 +10,40 @@ using SOR.Database.Enums;
/// Override with Subject = "Target" to evaluate against the current action's resolved target.
/// </summary>
// Composite
[JsonDerivedType(typeof(AndCondition), "AND")]
[JsonDerivedType(typeof(OrCondition), "OR")]
[JsonDerivedType(typeof(XorCondition), "XOR")]
[PolyType(typeof(AndCondition), "AND")]
[PolyType(typeof(OrCondition), "OR")]
[PolyType(typeof(XorCondition), "XOR")]
// Unit (§6.1)
[JsonDerivedType(typeof(HealthBelowCondition), "HealthBelow")]
[JsonDerivedType(typeof(HealthAboveCondition), "HealthAbove")]
[JsonDerivedType(typeof(DefenseIsCondition), "DefenseIs")]
[JsonDerivedType(typeof(HasGenusCondition), "HasGenus")]
[JsonDerivedType(typeof(HasAbilityCondition), "HasAbility")]
[JsonDerivedType(typeof(IsOnTileWithAffinityCondition), "IsOnTileWithAffinity")]
[JsonDerivedType(typeof(IsAdjacentToCondition), "IsAdjacentTo")]
[JsonDerivedType(typeof(WithinRangeOfCondition), "WithinRangeOf")]
[JsonDerivedType(typeof(MovementTypeIsCondition), "MovementTypeIs")]
[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)
[JsonDerivedType(typeof(SPAtLeastCondition), "SPAtLeast")]
[JsonDerivedType(typeof(SPAtMostCondition), "SPAtMost")]
[JsonDerivedType(typeof(STAtLeastCondition), "STAtLeast")]
[JsonDerivedType(typeof(STAtMostCondition), "STAtMost")]
[JsonDerivedType(typeof(HandSizeAtLeastCondition), "HandSizeAtLeast")]
[JsonDerivedType(typeof(HandSizeAtMostCondition), "HandSizeAtMost")]
[JsonDerivedType(typeof(DeckSizeAtLeastCondition), "DeckSizeAtLeast")]
[JsonDerivedType(typeof(DiscardSizeAtLeastCondition), "DiscardSizeAtLeast")]
[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)
[JsonDerivedType(typeof(TileAffinityMatchesCondition), "TileAffinityMatches")]
[JsonDerivedType(typeof(TileIsOccupiedCondition), "TileIsOccupied")]
[JsonDerivedType(typeof(TileIsUnoccupiedCondition), "TileIsUnoccupied")]
[PolyType(typeof(TileAffinityMatchesCondition), "TileAffinityMatches")]
[PolyType(typeof(TileIsOccupiedCondition), "TileIsOccupied")]
[PolyType(typeof(TileIsUnoccupiedCondition), "TileIsUnoccupied")]
// Turn/timing (§6.4)
[JsonDerivedType(typeof(IsOwnTurnCondition), "IsOwnTurn")]
[JsonDerivedType(typeof(IsOpponentTurnCondition), "IsOpponentTurn")]
[JsonDerivedType(typeof(IsAllyTurnCondition), "IsAllyTurn")]
[JsonDerivedType(typeof(IsActivePlayerTurnCondition), "IsActivePlayerTurn")]
[PolyType(typeof(IsOwnTurnCondition), "IsOwnTurn")]
[PolyType(typeof(IsOpponentTurnCondition), "IsOpponentTurn")]
[PolyType(typeof(IsAllyTurnCondition), "IsAllyTurn")]
[PolyType(typeof(IsActivePlayerTurnCondition), "IsActivePlayerTurn")]
// Battlefield (§6.5)
[JsonDerivedType(typeof(UnitCountOnBattlefieldCondition), "UnitCountOnBattlefield")]
[JsonDerivedType(typeof(CardInZoneCondition), "CardInZone")]
[PolyType(typeof(UnitCountOnBattlefieldCondition), "UnitCountOnBattlefield")]
[PolyType(typeof(CardInZoneCondition), "CardInZone")]
public abstract class Condition
{
/// <summary>