From 324537ded0226d3d5e2d8808eae0344a508bdcce Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 22 Mar 2026 16:15:36 -0400 Subject: [PATCH] SummonToken: structured admin editor + affinity enforcement + art URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AbilityBuilder.razor: replace raw JSON textarea with full structured editor for SummonToken effects. Supports two modes: • Existing Card — searchable autocomplete from Spirit card catalog • Custom Token — inline editor for all Spirit stats (name, affinity, health/defense/damage, movement type/MP, attack range, LOS, all permission flags, genus tags, abilities JSON, 2D art URL, 3D model URL) Compiles TileFilter[TileAffinityMatchesFilter] when affinity is non-Void, enabling client-side tile highlighting to match server enforcement. - AbilitySystem.cs (SummonTokenEffect): validate that the target tile's affinity is compatible with the token's affinity before placing. - GameState.cs (CardInstance): add Art2dUrl + ModelUrl so summoned tokens can carry visual asset references through the game state. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../Pages/Cards/AbilityBuilder.razor | 472 +++++++++++++++++- .../src/SOR.Game/Abilities/AbilitySystem.cs | 10 + Server/src/SOR.Game/GameState.cs | 7 + 3 files changed, 484 insertions(+), 5 deletions(-) diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor index 4b03178..e15c8b7 100644 --- a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor +++ b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor @@ -1,5 +1,10 @@ @* AbilityBuilder.razor — structured UI for AbilityDefinition[] / Action[] JSON *@ @using Microsoft.AspNetCore.Components.Rendering +@using Microsoft.EntityFrameworkCore +@using SOR.Database.Contexts +@using SOR.Database.Entities.Catalog +@using SOR.Database.Enums +@inject CatalogDbContext CatalogDb
@if (_abilities.Count == 0) @@ -321,10 +326,13 @@
- -
- @RenderEffectFields(effect, actionIdx, ab.TypeStr == "Triggered") -
+ @if (effect.TypeKey != "SummonToken") + { + +
+ @RenderEffectFields(effect, actionIdx, ab.TypeStr == "Triggered") +
+ }
@@ -335,6 +343,240 @@
+ + @* ── SummonToken inline editor ── *@ + @if (effect.TypeKey == "SummonToken") + { + var eff2 = effect; +
+ +
+ Token source: +
+ + +
+
+ + @if (eff2.TokenMode == "ExistingCard") + { + +
+
+ + + @if (eff2.TokenShowDropdown) + { + var filtered = _spiritCards.Where(c => + string.IsNullOrEmpty(eff2.TokenExistingSearch) || + c.Name.Contains(eff2.TokenExistingSearch, StringComparison.OrdinalIgnoreCase)).ToList(); + @if (filtered.Count > 0) + { +
+ @foreach (var sc in filtered) + { + var sc2 = sc; + + } +
+ } + } +
+ @if (eff2.TokenExistingId.HasValue) + { +
+ + @eff2.TokenName + + +
+ } +
+

Stats below are loaded from the selected card. You may tweak them after loading.

+ } + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+ + +
+
+ + +
+
+ + +
+
+ +

+ Set Action Target type to Tile. Non-Void tokens only place on affinity-matching tiles. +

+
+ } } @@ -647,6 +889,104 @@ private bool _showRaw; private bool _showHelp; + // ── Spirit card list for "Existing Card" token mode ─────────────────────── + + private sealed record SpiritCardEntry(Guid Id, string Name, string Affinity, + int? MaxHealth, int? MaxDefense, int? Damage, int? MovementPoints, string MovementType, + int? MinAttackRange, int? MaxAttackRange, bool RequiresLos, + bool CanMove, bool CanAttack, bool CanDefend, + bool CanBeAttacked, bool CanBeBlocked, bool CanBeObstructed, + bool CanUseAbility, bool CanBeSacrificed, + string? AbilitiesJson); + + private List _spiritCards = []; + + protected override async Task OnInitializedAsync() + { + _spiritCards = await CatalogDb.Set() + .AsNoTracking() + .Where(c => c.CardType == CardType.Spirit) + .OrderBy(c => c.Name) + .Select(c => new SpiritCardEntry( + c.Id, c.Name, c.Affinity.ToString(), + c.MaxHealth, c.MaxDefense, c.Damage, c.MovementPoints, + c.MovementType != null ? c.MovementType.ToString()! : "Walk", + c.MinAttackRange, c.MaxAttackRange, c.RequiresLos ?? false, + c.CanMove ?? false, c.CanAttack ?? false, c.CanDefend ?? true, + c.CanBeAttacked ?? true, c.CanBeBlocked ?? true, c.CanBeObstructed ?? true, + c.CanUseAbility ?? true, c.CanBeSacrificed ?? false, + c.AbilitiesJson)) + .ToListAsync(); + } + + private void ApplySpiritCardToToken(EffectDraft d, SpiritCardEntry card) + { + d.TokenExistingId = card.Id; + d.TokenExistingSearch = card.Name; + d.TokenShowDropdown = false; + d.TokenName = card.Name; + d.TokenAffinity = card.Affinity; + d.TokenHealth = card.MaxHealth ?? 1; + d.TokenDefense = card.MaxDefense ?? 0; + d.TokenDamage = card.Damage ?? 1; + d.TokenMaxMp = card.MovementPoints; + d.TokenMovement = card.MovementType; + d.TokenMinRange = card.MinAttackRange ?? 1; + d.TokenMaxRange = card.MaxAttackRange ?? 1; + d.TokenRequiresLos = card.RequiresLos; + d.TokenCanMove = card.CanMove; + d.TokenCanAttack = card.CanAttack; + d.TokenCanDefend = card.CanDefend; + d.TokenCanBeAttacked = card.CanBeAttacked; + d.TokenCanBeBlocked = card.CanBeBlocked; + d.TokenCanBeObstructed = card.CanBeObstructed; + d.TokenCanUseAbility = card.CanUseAbility; + d.TokenCanBeSacrificed = card.CanBeSacrificed; + d.TokenAbilitiesJson = card.AbilitiesJson ?? "[]"; + Compile(); + } + + private async Task HideTokenDropdownAsync(EffectDraft d) + { + await Task.Delay(150); + d.TokenShowDropdown = false; + StateHasChanged(); + } + + private void SetTokenMode(EffectDraft d, string mode) { d.TokenMode = mode; Compile(); } + private void ClearTokenExisting(EffectDraft d) { d.TokenExistingId = null; d.TokenExistingSearch = ""; Compile(); } + private void ShowTokenDropdown(EffectDraft d) { d.TokenShowDropdown = true; } + private void SetTokenSearch(EffectDraft d, string v) { d.TokenExistingSearch = v; d.TokenShowDropdown = true; } + private void SetTokenName(EffectDraft d, string v) { d.TokenName = v; Compile(); } + private void SetTokenAffinity(EffectDraft d, string v) { d.TokenAffinity = v; Compile(); } + private void SetTokenMovement(EffectDraft d, string v) { d.TokenMovement = v; Compile(); } + private void SetTokenGenus(EffectDraft d, string v) { d.TokenGenus = v; Compile(); } + private void SetTokenArt2dUrl(EffectDraft d, string v) { d.TokenArt2dUrl = v; Compile(); } + private void SetTokenModelUrl(EffectDraft d, string v) { d.TokenModelUrl = v; Compile(); } + private void SetTokenHealth(EffectDraft d, string? v) { d.TokenHealth = int.TryParse(v, out var n) ? n : d.TokenHealth; Compile(); } + private void SetTokenDefense(EffectDraft d, string? v) { d.TokenDefense = int.TryParse(v, out var n) ? n : d.TokenDefense; Compile(); } + private void SetTokenDamage(EffectDraft d, string? v) { d.TokenDamage = int.TryParse(v, out var n) ? n : d.TokenDamage; Compile(); } + private void SetTokenMaxMp(EffectDraft d, string? v) { d.TokenMaxMp = int.TryParse(v, out var n) ? n : null; Compile(); } + private void SetTokenMinRange(EffectDraft d, string? v) { d.TokenMinRange = int.TryParse(v, out var n) ? n : d.TokenMinRange; Compile(); } + private void SetTokenMaxRange(EffectDraft d, string? v) { d.TokenMaxRange = int.TryParse(v, out var n) ? n : d.TokenMaxRange; Compile(); } + private void SetTokenBool(EffectDraft d, string field, ChangeEventArgs e) + { + var v = e.Value is bool bv ? bv : bool.TryParse(e.Value?.ToString(), out var p) && p; + switch (field) + { + case "RequiresLos": d.TokenRequiresLos = v; break; + case "CanMove": d.TokenCanMove = v; break; + case "CanAttack": d.TokenCanAttack = v; break; + case "CanDefend": d.TokenCanDefend = v; break; + case "CanBeAttacked": d.TokenCanBeAttacked = v; break; + case "CanBeBlocked": d.TokenCanBeBlocked = v; break; + case "CanBeObstructed": d.TokenCanBeObstructed = v; break; + case "CanUseAbility": d.TokenCanUseAbility = v; break; + case "CanBeSacrificed": d.TokenCanBeSacrificed = v; break; + } + Compile(); + } + // ── Static enum options ────────────────────────────────────────────────────── private static readonly string[] AbilityTypes = ["Active", "Passive", "Aura", "Triggered"]; @@ -755,7 +1095,7 @@ "SetCanChannelTerramorphaMono", "SetCanChannelTerramorphaDi", "SetCanChannelTerramorphaTri", ]; private static readonly HashSet _affinityTypes = ["SetAffinity", "SetBaseAffinity1", "SetBaseAffinity2", "PushAffinity", "PushFinalAffinity"]; - private static readonly HashSet _rawJsonTypes = ["AddAbility", "ApplyOnEvent", "SummonToken"]; + private static readonly HashSet _rawJsonTypes = ["AddAbility", "ApplyOnEvent"]; private static readonly HashSet _noFieldTypes = ["ReturnToHand", "SendToDiscard"]; // ── Trigger templates ──────────────────────────────────────────────────────── @@ -1068,6 +1408,40 @@ { d.AbilityRef = ReadStr("AbilityRef"); } + else if (typeKey == "SummonToken") + { + // Parse TokenDefJson blob back into individual draft fields. + var tokenDefStr = eff["TokenDefJson"]?.GetValue() ?? "{}"; + try + { + var tok = JsonNode.Parse(tokenDefStr) as JsonObject ?? new JsonObject(); + d.TokenName = tok["Name"]?.GetValue() ?? "Token"; + d.TokenAffinity = tok["Affinity"]?.GetValue() ?? "Aether"; + d.TokenHealth = tok["MaxHealth"]?.GetValue() ?? 1; + d.TokenDefense = tok["MaxDefense"]?.GetValue() ?? 0; + d.TokenDamage = tok["Damage"]?.GetValue() ?? 1; + d.TokenMaxMp = tok["MaxMp"]?.GetValue(); + d.TokenMovement = tok["MovementType"]?.GetValue() ?? "Walk"; + d.TokenMinRange = tok["MinAttackRange"]?.GetValue() ?? 1; + d.TokenMaxRange = tok["MaxAttackRange"]?.GetValue() ?? 1; + d.TokenRequiresLos = tok["RequiresLos"]?.GetValue() ?? false; + d.TokenCanMove = tok["CanMove"]?.GetValue() ?? false; + d.TokenCanAttack = tok["CanAttack"]?.GetValue() ?? false; + d.TokenCanDefend = tok["CanDefend"]?.GetValue() ?? true; + d.TokenCanBeAttacked = tok["CanBeAttacked"]?.GetValue() ?? true; + d.TokenCanBeBlocked = tok["CanBeBlocked"]?.GetValue() ?? true; + d.TokenCanBeObstructed = tok["CanBeObstructed"]?.GetValue() ?? true; + d.TokenCanUseAbility = tok["CanUseAbility"]?.GetValue() ?? true; + d.TokenCanBeSacrificed = tok["CanBeSacrificed"]?.GetValue() ?? false; + if (tok["Genus"] is JsonArray genusArr) + d.TokenGenus = string.Join(", ", genusArr.Select(g => g?.GetValue() ?? "")); + d.TokenAbilitiesJson = tok["AbilitiesJson"]?.GetValue() ?? "[]"; + d.TokenArt2dUrl = tok["Art2dUrl"]?.GetValue() ?? ""; + d.TokenModelUrl = tok["ModelUrl"]?.GetValue() ?? ""; + } + catch { /* keep defaults */ } + d.TokenMode = "Custom"; + } else if (_rawJsonTypes.Contains(typeKey)) { var fields = new JsonObject(); @@ -1466,6 +1840,54 @@ { node["AbilityRef"] = d.AbilityRef; } + else if (d.TypeKey == "SummonToken") + { + var tok = new JsonObject + { + ["Name"] = d.TokenName, + ["Affinity"] = d.TokenAffinity, + ["MaxHealth"] = d.TokenHealth, + ["CurrentHealth"] = d.TokenHealth, + ["MaxDefense"] = d.TokenDefense, + ["CurrentDefense"] = d.TokenDefense, + ["Damage"] = d.TokenDamage, + ["MovementType"] = d.TokenMovement, + ["MinAttackRange"] = d.TokenMinRange, + ["MaxAttackRange"] = d.TokenMaxRange, + ["RequiresLos"] = d.TokenRequiresLos, + ["CanMove"] = d.TokenCanMove, + ["CanAttack"] = d.TokenCanAttack, + ["CanDefend"] = d.TokenCanDefend, + ["CanBeAttacked"] = d.TokenCanBeAttacked, + ["CanBeBlocked"] = d.TokenCanBeBlocked, + ["CanBeObstructed"] = d.TokenCanBeObstructed, + ["CanUseAbility"] = d.TokenCanUseAbility, + ["CanBeSacrificed"] = d.TokenCanBeSacrificed, + }; + if (d.TokenMaxMp.HasValue) tok["MaxMp"] = d.TokenMaxMp.Value; + if (!string.IsNullOrWhiteSpace(d.TokenGenus)) + { + var genArr = new JsonArray(); + foreach (var g in d.TokenGenus.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)) + genArr.Add(g); + tok["Genus"] = genArr; + } + if (!string.IsNullOrWhiteSpace(d.TokenAbilitiesJson) && d.TokenAbilitiesJson != "[]") + tok["AbilitiesJson"] = d.TokenAbilitiesJson; + if (!string.IsNullOrWhiteSpace(d.TokenArt2dUrl)) + tok["Art2dUrl"] = d.TokenArt2dUrl; + if (!string.IsNullOrWhiteSpace(d.TokenModelUrl)) + tok["ModelUrl"] = d.TokenModelUrl; + node["TokenDefJson"] = tok.ToJsonString(); + + // Include TileFilter for affinity-restricted tokens so the client + // can visually highlight valid placement tiles. + if (d.TokenAffinity != "Void" && !string.IsNullOrEmpty(d.TokenAffinity)) + { + node["TileFilter"] = new JsonArray( + new JsonObject { ["$type"] = "TileAffinityMatchesFilter", ["Affinity"] = d.TokenAffinity }); + } + } else if (_rawJsonTypes.Contains(d.TypeKey)) { if (!string.IsNullOrWhiteSpace(d.RawJson)) @@ -2103,6 +2525,18 @@ effect.Stat = "Damage"; effect.Multiplier = 1.5f; effect.Sp = null; effect.St = null; effect.DurationType = "UntilEndOfTurn"; effect.DurationN = 1; effect.RawJson = "{}"; + // SummonToken reset + effect.TokenMode = "Custom"; effect.TokenExistingId = null; effect.TokenExistingSearch = ""; + effect.TokenShowDropdown = false; + effect.TokenName = "Token"; effect.TokenAffinity = "Aether"; + effect.TokenHealth = 1; effect.TokenDefense = 0; effect.TokenDamage = 1; + effect.TokenMaxMp = null; effect.TokenMovement = "Walk"; + effect.TokenMinRange = 1; effect.TokenMaxRange = 1; effect.TokenRequiresLos = false; + effect.TokenCanMove = false; effect.TokenCanAttack = false; effect.TokenCanDefend = true; + effect.TokenCanBeAttacked = true; effect.TokenCanBeBlocked = true; + effect.TokenCanBeObstructed = true; effect.TokenCanUseAbility = true; effect.TokenCanBeSacrificed = false; + effect.TokenGenus = ""; effect.TokenAbilitiesJson = "[]"; + effect.TokenArt2dUrl = ""; effect.TokenModelUrl = ""; Compile(); } @@ -2224,6 +2658,34 @@ public int? Sp { get; set; } public int? St { get; set; } public string RawJson { get; set; } = "{}"; + + // ── SummonToken fields ───────────────────────────────────────────────── + public string TokenMode { get; set; } = "Custom"; // "Custom" | "ExistingCard" + public Guid? TokenExistingId { get; set; } + public string TokenExistingSearch { get; set; } = ""; + public bool TokenShowDropdown { get; set; } = false; + public string TokenName { get; set; } = "Token"; + public string TokenAffinity { get; set; } = "Aether"; + public int TokenHealth { get; set; } = 1; + public int TokenDefense { get; set; } = 0; + public int TokenDamage { get; set; } = 1; + public int? TokenMaxMp { get; set; } + public string TokenMovement { get; set; } = "Walk"; + public int TokenMinRange { get; set; } = 1; + public int TokenMaxRange { get; set; } = 1; + public bool TokenRequiresLos { get; set; } = false; + public bool TokenCanMove { get; set; } = false; + public bool TokenCanAttack { get; set; } = false; + public bool TokenCanDefend { get; set; } = true; + public bool TokenCanBeAttacked { get; set; } = true; + public bool TokenCanBeBlocked { get; set; } = true; + public bool TokenCanBeObstructed { get; set; } = true; + public bool TokenCanUseAbility { get; set; } = true; + public bool TokenCanBeSacrificed { get; set; } = false; + public string TokenGenus { get; set; } = ""; + public string TokenAbilitiesJson { get; set; } = "[]"; + public string TokenArt2dUrl { get; set; } = ""; + public string TokenModelUrl { get; set; } = ""; } private sealed class ConditionDraft diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 7bbeff5..2b279ec 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -1235,6 +1235,13 @@ public static class AbilitySystem var proto = JsonSerializer.Deserialize(ste.TokenDefJson, _jsonOpts); if (proto is null) break; + // Enforce tile affinity: a token with a non-Void affinity may only be + // placed on a tile whose resolved affinity is compatible with the token. + if (!string.IsNullOrEmpty(proto.Affinity) && proto.Affinity != "Void" + && Enum.TryParse(proto.Affinity, out var tokenAffinity) + && !AffinitySystem.IsAffinityValid(tile, tokenAffinity)) + break; + proto.InstanceId = Guid.NewGuid().ToString("N")[..8]; proto.CardType = "SpiritToken"; @@ -1307,6 +1314,9 @@ public static class AbilitySystem MaxAttackRange = proto.MaxAttackRange, RequiresLos = proto.RequiresLos, AbilitiesJson = proto.AbilitiesJson, + Genus = proto.Genus is null ? null : [.. proto.Genus], + Art2dUrl = proto.Art2dUrl, + ModelUrl = proto.ModelUrl, IsExhausted = false, Position = position, }; diff --git a/Server/src/SOR.Game/GameState.cs b/Server/src/SOR.Game/GameState.cs index 5e2fe67..e1a8649 100644 --- a/Server/src/SOR.Game/GameState.cs +++ b/Server/src/SOR.Game/GameState.cs @@ -214,6 +214,13 @@ public class CardInstance /// public Dictionary? AbilityUsesThisTurn { get; set; } + // ── Visual assets (used primarily for SpiritToken rendering) ───────────── + + /// URL of the 2-D card art image (used by client for token display). + public string? Art2dUrl { get; set; } + /// URL of the 3-D model GLTF/GLB (used by client for token rendering). + public string? ModelUrl { get; set; } + /// /// Genus tags on this unit (e.g. "Beast", "Plant"). May be modified by abilities. /// Null until at least one genus tag is added.