feat(phase2): ability revamp DB migration -- add SpiritToken, drop EffectsJson

- Add CardType.SpiritToken enum value (stored as text, no Postgres enum change)
- Drop catalog.card_definitions.effects column (migration 20260419170135)
  with safety-pass to copy any remaining effects -> abilities before drop
- Remove CardDefinition.EffectsJson property and CatalogDbContext mapping
- Remove CardInstance.EffectsJson snapshot from GameState/GameEngine
- Remove EffectsJson from all DTOs: UnitDelta, CardUpdateDto, ContentCardDto
- Remove EffectsJson from GameStateDiffer, ContentDtoMapper, CardEditor, CardReport
- Simplify AbilitySystem.FireCardEffects to use AbilitiesJson only (no fallback)
- Enforce SpiritToken exclusion in CollectionAddCardHandler (deck builds)
- Enforce SpiritToken exclusion in BazaarBuyBoosterPackHandler (pack draws)

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-04-19 13:02:24 -04:00
co-authored by Claude Happy
parent 3b8de2deac
commit 768dfcee86
18 changed files with 673 additions and 85 deletions
@@ -945,12 +945,7 @@ else
_availableGenus.Add(tag);
_availableGenus.Sort(StringComparer.OrdinalIgnoreCase);
_abilitiesJson = _card.CardType is CardType.Repentance
or CardType.Instinct or CardType.Terramorpha
? (!string.IsNullOrWhiteSpace(_card.AbilitiesJson)
? _card.AbilitiesJson!
: _card.EffectsJson ?? string.Empty)
: _card.AbilitiesJson ?? string.Empty;
_abilitiesJson = _card.AbilitiesJson ?? string.Empty;
}
}
}
@@ -968,18 +963,7 @@ else
{
_card.Genus = _selectedGenus.Count > 0 ? _selectedGenus.ToArray() : null;
if (_card.CardType is CardType.Repentance or CardType.Instinct or CardType.Terramorpha)
{
var canonical = string.IsNullOrWhiteSpace(_abilitiesJson) ? null : _abilitiesJson;
// Canonical store for ability-schema cards.
_card.AbilitiesJson = canonical;
// Transition mirror-write for backward compatibility.
_card.EffectsJson = canonical;
}
else
{
_card.AbilitiesJson = string.IsNullOrWhiteSpace(_abilitiesJson) ? null : _abilitiesJson;
}
_card.AbilitiesJson = string.IsNullOrWhiteSpace(_abilitiesJson) ? null : _abilitiesJson;
_card.UpdatedAt = DateTimeOffset.UtcNow;
@@ -366,7 +366,7 @@
var art = c.Assets.Where(a => a.AssetType == CardAssetType.Art2D).ToList();
var hasSfx = c.MoveSoundUrl != null || c.DamagedSoundUrl != null
|| c.BlockedSoundUrl != null || c.AttackSoundUrl != null || c.DeathSoundUrl != null;
var abilityJson = c.AbilitiesJson ?? c.EffectsJson;
var abilityJson = c.AbilitiesJson;
var hasAbilities = JsonArrayHasElements(abilityJson);
cardToDecks.TryGetValue(c.Id, out var decks);
return new CardRow(
@@ -114,7 +114,8 @@ internal sealed class BazaarBuyBoosterPackHandler : BazaarHandlerBase, IMessageH
else if (pack.CardSetId.HasValue)
setId = pack.CardSetId;
var q = _catalogDb.CardDefinitions.Where(cd => cd.Rarity == rarity && cd.IsPublished);
var q = _catalogDb.CardDefinitions.Where(cd => cd.Rarity == rarity && cd.IsPublished
&& cd.CardType != CardType.SpiritToken);
if (setId.HasValue) q = q.Where(cd => cd.SetId == setId.Value);
var pool = await q.Select(cd => new { cd.Id, cd.Name, cd.Rarity }).ToListAsync(ct);
@@ -157,7 +158,8 @@ internal sealed class BazaarBuyBoosterPackHandler : BazaarHandlerBase, IMessageH
if (!Guid.TryParse(sp.GetString(), out var setId)) break;
var pool = await _catalogDb.CardDefinitions
.Where(cd => cd.SetId == setId && cd.IsPublished)
.Where(cd => cd.SetId == setId && cd.IsPublished
&& cd.CardType != CardType.SpiritToken)
.Select(cd => new { cd.Id, cd.Name, cd.Rarity })
.ToListAsync(ct);
if (pool.Count == 0) break;
@@ -176,7 +178,7 @@ internal sealed class BazaarBuyBoosterPackHandler : BazaarHandlerBase, IMessageH
case "Random":
{
var pool = await _catalogDb.CardDefinitions
.Where(cd => cd.IsPublished)
.Where(cd => cd.IsPublished && cd.CardType != CardType.SpiritToken)
.Select(cd => new { cd.Id, cd.Name, cd.Rarity })
.ToListAsync(ct);
if (pool.Count == 0) break;
@@ -68,6 +68,10 @@ internal sealed class CollectionAddCardHandler : CollectionHandlerBase, IMessage
if (cardMeta == null)
return ServerMessage.Error(message.Seq, "CARD_NOT_FOUND", "Card definition not found.");
if (cardMeta.CardType == CardType.SpiritToken)
return ServerMessage.Error(message.Seq, "SPIRIT_TOKEN_NOT_ALLOWED",
"Spirit tokens are summoned by effects and cannot be added to decks.");
// if (cardMeta.CardType == CardType.ArchSpirit && (cardMeta.Tier ?? 1) == 1)
// return ServerMessage.Error(message.Seq, "ARCH_SPIRIT_NOT_ALLOWED",
// "Tier 1 ArchSpirits are your deck commander — set them at the deck level. " +
@@ -89,7 +89,6 @@ public sealed record CardDefinitionDto(
Guid? PreviousTierId,
string? TerramorphaMode,
string? AbilitiesJson,
string? EffectsJson,
// Publishing
Guid? SetId,
int? CollectorNumber,
@@ -38,7 +38,6 @@ internal static class ContentDtoMapper
PreviousTierId: c.PreviousTierId,
TerramorphaMode: c.TerramorphaMode?.ToString(),
AbilitiesJson: c.AbilitiesJson,
EffectsJson: c.EffectsJson,
SetId: c.SetId,
CollectorNumber: c.CollectorNumber,
IsPublished: c.IsPublished,
@@ -64,9 +64,6 @@ public sealed class CatalogDbContext : DbContext
e.Property(c => c.AbilitiesJson)
.HasColumnType("jsonb")
.HasColumnName("abilities");
e.Property(c => c.EffectsJson)
.HasColumnType("jsonb")
.HasColumnName("effects");
e.Property(c => c.OtherCostsJson)
.HasColumnType("jsonb")
.HasColumnName("other_costs");
@@ -9,9 +9,8 @@ using SOR.Database.Enums;
/// (name, type, affinity, costs, combat stats).
///
/// The ability/effect system is highly recursive and type-specific, so it is
/// stored as JSONB. The game engine and admin tool own serialization.
/// AbilitiesJson: used by ArchSpirit, Spirit, Ruin.
/// EffectsJson: used by Repentance, Instinct, Terramorpha.
/// stored as JSONB in AbilitiesJson (array of AbilityDefinition) for all card types.
/// The game engine and admin tool own serialization.
///
/// Genus tags are stored as a Postgres text[] array — fast for containment
/// queries (@>) without the overhead of a junction table.
@@ -97,12 +96,9 @@ public sealed class CardDefinition
public string? DeathSoundUrl { get; set; }
// ── Ability / Effect data (JSONB) ────────────────────────────────────────
/// <summary>JSONB array of AbilityDefinition objects (ArchSpirit, Spirit, Ruin).</summary>
/// <summary>JSONB array of AbilityDefinition objects (all card types).</summary>
public string? AbilitiesJson { get; set; }
/// <summary>JSONB array of Action objects (Repentance, Instinct, Terramorpha).</summary>
public string? EffectsJson { get; set; }
// ── Publishing metadata ──────────────────────────────────────────────────
public CardRarity Rarity { get; set; } = CardRarity.Common;
public Guid? SetId { get; set; }
@@ -8,6 +8,12 @@ public enum CardType
Terramorpha,
Ruin,
Instinct,
/// <summary>
/// Spirit tokens are summoned by effects; they cannot be added to decks
/// or granted to player collections. Stored as full CardDefinition rows
/// so the engine can reference their stats and abilities.
/// </summary>
SpiritToken,
}
/// <summary>
@@ -0,0 +1,604 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SOR.Database.Contexts;
#nullable disable
namespace SOR.Database.Migrations.Catalog
{
[DbContext(typeof(CatalogDbContext))]
[Migration("20260419170135_AbilityRevamp_Phase2")]
partial class AbilityRevamp_Phase2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("catalog")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAnimationBinding", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ActionName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("AnimationCdnUrl")
.IsRequired()
.HasColumnType("text");
b.Property<string>("AnimationTrackName")
.HasColumnType("text");
b.Property<Guid>("CardDefinitionId")
.HasColumnType("uuid");
b.Property<string>("CastSoundCdnUrl")
.HasColumnType("text");
b.Property<string>("ImpactSoundCdnUrl")
.HasColumnType("text");
b.Property<bool>("IsAiGenerated")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("CardDefinitionId", "ActionName")
.IsUnique();
b.ToTable("card_animation_bindings", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAsset", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AssetType")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("CardDefinitionId")
.HasColumnType("uuid");
b.Property<string>("CdnUrl")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ContentETag")
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsAiGenerated")
.HasColumnType("boolean");
b.Property<string>("MimeType")
.HasColumnType("text");
b.Property<string>("ModelFacingDirection")
.HasColumnType("text");
b.Property<string>("ModelTintMaskUrl")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("CardDefinitionId", "AssetType");
b.ToTable("card_assets", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AbilitiesJson")
.HasColumnType("jsonb")
.HasColumnName("abilities");
b.Property<string>("Affinity")
.IsRequired()
.HasColumnType("text");
b.Property<string>("AttackSoundUrl")
.HasColumnType("text");
b.Property<string>("AttackType")
.HasColumnType("text");
b.Property<string>("BlockedSoundUrl")
.HasColumnType("text");
b.Property<bool?>("CanAttack")
.HasColumnType("boolean");
b.Property<bool?>("CanBeAttacked")
.HasColumnType("boolean");
b.Property<bool?>("CanBeBlocked")
.HasColumnType("boolean");
b.Property<bool?>("CanBeObstructed")
.HasColumnType("boolean");
b.Property<bool?>("CanBeSacrificed")
.HasColumnType("boolean");
b.Property<bool?>("CanDefend")
.HasColumnType("boolean");
b.Property<bool?>("CanMove")
.HasColumnType("boolean");
b.Property<bool?>("CanUseAbility")
.HasColumnType("boolean");
b.Property<string>("CardType")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("CollectorNumber")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int?>("Damage")
.HasColumnType("integer");
b.Property<string>("DamagedSoundUrl")
.HasColumnType("text");
b.Property<string>("DeathSoundUrl")
.HasColumnType("text");
b.Property<long>("DefinitionVersion")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasDefaultValue(0L);
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string[]>("Genus")
.HasColumnType("text[]");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<bool>("IsRetired")
.HasColumnType("boolean");
b.Property<int?>("MaxAttackRange")
.HasColumnType("integer");
b.Property<int?>("MaxChannelRange")
.HasColumnType("integer");
b.Property<int?>("MaxDefense")
.HasColumnType("integer");
b.Property<int?>("MaxHealth")
.HasColumnType("integer");
b.Property<int?>("MinAttackRange")
.HasColumnType("integer");
b.Property<int?>("MinChannelRange")
.HasColumnType("integer");
b.Property<float?>("ModelScale")
.HasColumnType("real");
b.Property<string>("ModelTintColor")
.HasColumnType("text");
b.Property<string>("MoveSoundUrl")
.HasColumnType("text");
b.Property<int?>("MovementPoints")
.HasColumnType("integer");
b.Property<string>("MovementType")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("OtherCostsJson")
.HasColumnType("jsonb")
.HasColumnName("other_costs");
b.Property<Guid?>("PreviousTierId")
.HasColumnType("uuid");
b.Property<string>("Rarity")
.IsRequired()
.HasColumnType("text");
b.Property<bool?>("RequiresLos")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("RetiredAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("SetId")
.HasColumnType("uuid");
b.Property<int>("SpCost")
.HasColumnType("integer");
b.Property<int>("StCost")
.HasColumnType("integer");
b.Property<string>("TerramorphaMode")
.HasColumnType("text");
b.Property<int?>("Tier")
.HasColumnType("integer");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Affinity");
b.HasIndex("CardType");
b.HasIndex("DefinitionVersion");
b.HasIndex("Name");
b.HasIndex("PreviousTierId");
b.HasIndex("Rarity");
b.HasIndex("SetId");
b.HasIndex("IsPublished", "SetId");
b.ToTable("card_definitions", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardSet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsActive")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<DateOnly?>("ReleaseDate")
.HasColumnType("date");
b.HasKey("Id");
b.HasIndex("Code")
.IsUnique();
b.ToTable("card_sets", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CdnUploadRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ContentType")
.HasColumnType("text");
b.Property<bool>("IsAiGenerated")
.HasColumnType("boolean");
b.Property<string>("ObjectKey")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Prefix")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PublicUrl")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("UploadedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("IsAiGenerated");
b.HasIndex("ObjectKey")
.IsUnique();
b.HasIndex("Prefix");
b.ToTable("cdn_upload_records", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.GameAudioConfig", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Context")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsActive")
.HasColumnType("boolean");
b.Property<string>("TrackCdnUrl")
.IsRequired()
.HasColumnType("text");
b.Property<string>("TrackName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("Context");
b.HasIndex("IsActive");
b.ToTable("game_audio_configs", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.HighlightConfig", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("CdnPath")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FallbackHex")
.IsRequired()
.HasColumnType("text");
b.Property<float>("Fps")
.HasColumnType("real");
b.Property<int>("FrameCount")
.HasColumnType("integer");
b.Property<string>("HighlightType")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsAnimated")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("HighlightType")
.IsUnique();
b.ToTable("highlight_configs", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.SkyboxDefinition", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("CdnPath")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("CubeNxUrl")
.HasColumnType("text")
.HasColumnName("cube_nx_url");
b.Property<string>("CubeNyUrl")
.HasColumnType("text")
.HasColumnName("cube_ny_url");
b.Property<string>("CubeNzUrl")
.HasColumnType("text")
.HasColumnName("cube_nz_url");
b.Property<string>("CubePxUrl")
.HasColumnType("text")
.HasColumnName("cube_px_url");
b.Property<string>("CubePyUrl")
.HasColumnType("text")
.HasColumnName("cube_py_url");
b.Property<string>("CubePzUrl")
.HasColumnType("text")
.HasColumnName("cube_pz_url");
b.Property<float>("Fps")
.HasColumnType("real");
b.Property<int>("FrameCount")
.HasColumnType("integer");
b.Property<bool>("IsActive")
.HasColumnType("boolean");
b.Property<bool>("IsAnimated")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SkyboxType")
.HasColumnType("text")
.HasColumnName("skybox_type");
b.HasKey("Id");
b.HasIndex("IsActive");
b.ToTable("skybox_definitions", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.TileBottomModel", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("CdnKey")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("IsActive")
.HasColumnType("boolean");
b.Property<string>("PublicUrl")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Shape")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Shape", "IsActive");
b.ToTable("tile_bottom_models", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.TileModelBinding", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Affinity")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ModelCdnKey")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ModelPublicUrl")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Shape")
.IsRequired()
.HasColumnType("text");
b.Property<string>("TexturePublicUrl")
.HasColumnType("text");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("Affinity", "Shape")
.IsUnique();
b.ToTable("tile_model_bindings", "catalog");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAnimationBinding", b =>
{
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "CardDefinition")
.WithMany("AnimationBindings")
.HasForeignKey("CardDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CardDefinition");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardAsset", b =>
{
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "CardDefinition")
.WithMany("Assets")
.HasForeignKey("CardDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CardDefinition");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
{
b.HasOne("SOR.Database.Entities.Catalog.CardDefinition", "PreviousTier")
.WithMany()
.HasForeignKey("PreviousTierId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("SOR.Database.Entities.Catalog.CardSet", "Set")
.WithMany("Cards")
.HasForeignKey("SetId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("PreviousTier");
b.Navigation("Set");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardDefinition", b =>
{
b.Navigation("AnimationBindings");
b.Navigation("Assets");
});
modelBuilder.Entity("SOR.Database.Entities.Catalog.CardSet", b =>
{
b.Navigation("Cards");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,43 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SOR.Database.Migrations.Catalog
{
/// <inheritdoc />
public partial class AbilityRevamp_Phase2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// Safety pass: any card that still has effects data but no abilities data
// gets the effects copied over (guards against the BackfillAbilitiesFromEffectsForAbilityCards
// migration having been skipped or partially applied).
migrationBuilder.Sql(@"
UPDATE catalog.card_definitions
SET abilities = effects
WHERE effects IS NOT NULL
AND btrim(effects::text) NOT IN ('', 'null', '""""')
AND (
abilities IS NULL
OR btrim(abilities::text) IN ('', 'null', '""""')
);
");
migrationBuilder.DropColumn(
name: "effects",
schema: "catalog",
table: "card_definitions");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "effects",
schema: "catalog",
table: "card_definitions",
type: "jsonb",
nullable: true);
}
}
}
@@ -177,10 +177,6 @@ namespace SOR.Database.Migrations.Catalog
.IsRequired()
.HasColumnType("text");
b.Property<string>("EffectsJson")
.HasColumnType("jsonb")
.HasColumnName("effects");
b.Property<string[]>("Genus")
.HasColumnType("text[]");
+1 -28
View File
@@ -126,46 +126,19 @@ public static class AbilitySystem
// ── Triggered ability firing ───────────────────────────────────────────────
/// <summary>
/// Resolve the EffectsJson action list on a non-unit card (Repentance, Instinct, Ruin)
/// Resolve the AbilitiesJson active ability list on a non-unit card (Repentance, Instinct)
/// immediately when it is channeled. The card itself is the source in the context.
/// </summary>
public static GameState FireCardEffects(GameState state, string actorId, CardInstance card,
IReadOnlyList<AbilityTarget>? clientTargets = null)
{
// 1. EffectsJson — backward-compatible flat action list.
// NOTE: Some content pipelines historically wrote AbilityDefinition[] into
// EffectsJson for Repentance/Instinct. When that happens, ParseEffects yields
// empty/no-op actions. We still attempt to execute active abilities from
// EffectsJson below as a compatibility path.
var actions = ParseEffects(card.EffectsJson)
.Where(a => a.Effects is { Length: > 0 })
.ToArray();
if (actions.Length > 0)
{
var ctx = new AbilityContext { State = state, ActorId = actorId, Source = card };
ExecuteActions(actions, ctx, clientTargets, requireClientTargets: true);
}
// 2. AbilitiesJson — Active abilities (e.g. Repentance / Instinct cards with targeting).
// 3. Compatibility fallback: if AbilitiesJson has no active entries, also try
// parsing active abilities from EffectsJson.
var activeDefs = ParseAbilities(card.AbilitiesJson)
.Where(d => d.Type == AbilityType.Active)
.ToList();
if (activeDefs.Count == 0)
{
var fallback = ParseAbilities(card.EffectsJson)
.Where(d => d.Type == AbilityType.Active)
.ToList();
if (fallback.Count > 0)
activeDefs = fallback;
}
foreach (var def in activeDefs)
{
var ctx = new AbilityContext { State = state, ActorId = actorId, Source = card };
// Keep condition and duration behavior aligned with ActivateAbility.
if (!ValidateSourceActivationConditions(def, ctx, card))
continue;
@@ -15,7 +15,7 @@ public enum AbilityType
/// <summary>
/// The top-level definition of a unit ability or card effect.
/// Stored as JSONB in CardDefinition.AbilitiesJson (array) and CardDefinition.EffectsJson.
/// Stored as JSONB in CardDefinition.AbilitiesJson (array) for all card types.
///
/// All four ability types share the Action/Effect/Condition model.
/// Type-specific fields are non-null only for the relevant type.
+2 -7
View File
@@ -437,12 +437,11 @@ public static class GameEngine
}
else
{
// Repentance, Instinct — pay cost, fire EffectsJson actions, then discard.
// Repentance, Instinct — pay cost, fire AbilitiesJson active abilities, then discard.
player.Hand.Remove(card);
player.CurrentSp -= card.SpCost;
player.CurrentSt -= card.StCost;
// Fire inline effects if the card has an EffectsJson action list.
AbilitySystem.FireCardEffects(state, actorId, card, cardTargets);
player.Discard.Add(card);
@@ -1293,7 +1292,6 @@ public static class GameEngine
Tier = archSpiritDef.Tier,
PreviousTierId = archSpiritDef.PreviousTierId,
AbilitiesJson = archSpiritDef.AbilitiesJson,
EffectsJson = archSpiritDef.EffectsJson,
};
ps.CurrentSp = 0;
@@ -1332,7 +1330,6 @@ public static class GameEngine
PreviousTierId = def.PreviousTierId,
TerramorphaMode = def.TerramorphaMode,
AbilitiesJson = def.AbilitiesJson,
EffectsJson = def.EffectsJson,
Genus = def.Genus?.ToList(),
};
@@ -1519,7 +1516,6 @@ public static class GameEngine
PreviousTierId = source.PreviousTierId,
TerramorphaMode = source.TerramorphaMode,
AbilitiesJson = source.AbilitiesJson,
EffectsJson = source.EffectsJson,
Genus = source.Genus?.ToList(),
Position = position,
};
@@ -1586,8 +1582,7 @@ public static class GameEngine
AttackRequiresLos : c.RequiresLos,
ExtraAttacksRemaining : c.ExtraAttacksRemaining,
CanBeAttacked : c.CanBeAttacked,
AbilitiesJson : c.AbilitiesJson,
EffectsJson : c.EffectsJson);
AbilitiesJson : c.AbilitiesJson);
}
private static BoardDto ToBoardDto(Board board)
+1 -3
View File
@@ -555,7 +555,6 @@ public sealed record UnitDelta(
int? MaxMp,
int? ExtraAttacksRemaining,
CoordDto? Position,
string? EffectsJson,
string? AbilitiesJson,
string? AbilityUsesJson);
@@ -687,8 +686,7 @@ public sealed record CardInstanceDto(
bool AttackRequiresLos,
int ExtraAttacksRemaining,
bool CanBeAttacked,
string? AbilitiesJson,
string? EffectsJson);
string? AbilitiesJson);
public sealed record BoardDto(
int Width,
-6
View File
@@ -273,12 +273,6 @@ public class CardInstance
/// </summary>
public string? AbilitiesJson { get; set; }
/// <summary>
/// Snapshot of CardDefinition.EffectsJson (for Repentance/Instinct/Ruin cards).
/// Format: JSON array of Action (resolved once when the card is channeled).
/// </summary>
public string? EffectsJson { get; set; }
/// <summary>
/// Tracks Active ability uses this turn. Key = ability index, value = use count.
/// Reset to empty at the start of the owning player's turn (in EndTurn).
-2
View File
@@ -250,7 +250,6 @@ internal static class GameStateDiffer
prevC.MaxMp != nextC.MaxMp ||
prevC.ExtraAttacksRemaining != nextC.ExtraAttacksRemaining ||
prevFc?.Position != nextFc?.Position ||
prevC.EffectsJson != nextC.EffectsJson ||
prevC.AbilitiesJson != nextC.AbilitiesJson ||
abilityUsesChanged;
@@ -280,7 +279,6 @@ internal static class GameStateDiffer
MaxMp : prevC.MaxMp != nextC.MaxMp ? nextC.MaxMp : null,
ExtraAttacksRemaining : prevC.ExtraAttacksRemaining != nextC.ExtraAttacksRemaining ? nextC.ExtraAttacksRemaining : null,
Position : positionDelta,
EffectsJson : prevC.EffectsJson != nextC.EffectsJson ? nextC.EffectsJson : null,
AbilitiesJson : prevC.AbilitiesJson != nextC.AbilitiesJson ? nextC.AbilitiesJson : null,
AbilityUsesJson : abilityUsesJson);
}