SummonToken: structured admin editor + affinity enforcement + art URLs
- 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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -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
|
||||
|
||||
<div class="ability-builder">
|
||||
@if (_abilities.Count == 0)
|
||||
@@ -321,10 +326,13 @@
|
||||
</div>
|
||||
<!-- Per-type fields -->
|
||||
<div class="flex-grow-1">
|
||||
<label class="form-label small mb-0">Fields</label>
|
||||
<div class="d-flex gap-1 align-items-center flex-wrap mt-1">
|
||||
@RenderEffectFields(effect, actionIdx, ab.TypeStr == "Triggered")
|
||||
</div>
|
||||
@if (effect.TypeKey != "SummonToken")
|
||||
{
|
||||
<label class="form-label small mb-0">Fields</label>
|
||||
<div class="d-flex gap-1 align-items-center flex-wrap mt-1">
|
||||
@RenderEffectFields(effect, actionIdx, ab.TypeStr == "Triggered")
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<!-- Remove -->
|
||||
<div>
|
||||
@@ -335,6 +343,240 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* ── SummonToken inline editor ── *@
|
||||
@if (effect.TypeKey == "SummonToken")
|
||||
{
|
||||
var eff2 = effect;
|
||||
<div class="border-top mt-2 pt-2">
|
||||
<!-- Mode toggle -->
|
||||
<div class="d-flex gap-2 align-items-center mb-2">
|
||||
<span class="small fw-medium text-muted">Token source:</span>
|
||||
<div class="btn-group btn-group-sm">
|
||||
<button type="button"
|
||||
class="btn @(eff2.TokenMode == "ExistingCard" ? "btn-primary" : "btn-outline-primary")"
|
||||
@onclick='() => SetTokenMode(eff2, "ExistingCard")'>
|
||||
Existing Card
|
||||
</button>
|
||||
<button type="button"
|
||||
class="btn @(eff2.TokenMode == "Custom" ? "btn-primary" : "btn-outline-primary")"
|
||||
@onclick='() => SetTokenMode(eff2, "Custom")'>
|
||||
Custom Token
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (eff2.TokenMode == "ExistingCard")
|
||||
{
|
||||
<!-- Spirit card search autocomplete -->
|
||||
<div class="row g-2 mb-2 align-items-end">
|
||||
<div class="col-md-6 position-relative">
|
||||
<label class="form-label small mb-0">Spirit Card</label>
|
||||
<input value="@eff2.TokenExistingSearch"
|
||||
class="form-control form-control-sm"
|
||||
placeholder="Search Spirit cards…"
|
||||
autocomplete="off"
|
||||
@oninput="e => SetTokenSearch(eff2, e.Value?.ToString() ?? string.Empty)"
|
||||
@onfocus="() => ShowTokenDropdown(eff2)"
|
||||
@onblur="() => HideTokenDropdownAsync(eff2)" />
|
||||
@if (eff2.TokenShowDropdown)
|
||||
{
|
||||
var filtered = _spiritCards.Where(c =>
|
||||
string.IsNullOrEmpty(eff2.TokenExistingSearch) ||
|
||||
c.Name.Contains(eff2.TokenExistingSearch, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
@if (filtered.Count > 0)
|
||||
{
|
||||
<div class="list-group shadow position-absolute"
|
||||
style="z-index:1000;max-height:200px;overflow-y:auto;width:100%;top:100%;left:0">
|
||||
@foreach (var sc in filtered)
|
||||
{
|
||||
var sc2 = sc;
|
||||
<button type="button"
|
||||
class="list-group-item list-group-item-action py-1 d-flex justify-content-between"
|
||||
@onmousedown="() => ApplySpiritCardToToken(eff2, sc2)">
|
||||
<span class="small">@sc2.Name</span>
|
||||
<small class="text-muted">@sc2.Affinity</small>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
@if (eff2.TokenExistingId.HasValue)
|
||||
{
|
||||
<div class="col-auto">
|
||||
<span class="badge bg-success">
|
||||
<i class="bi bi-check-circle me-1"></i>@eff2.TokenName
|
||||
</span>
|
||||
<button type="button" class="btn btn-sm btn-link text-danger p-0 ms-1"
|
||||
@onclick="() => ClearTokenExisting(eff2)">clear</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<p class="text-muted small fst-italic mb-2">Stats below are loaded from the selected card. You may tweak them after loading.</p>
|
||||
}
|
||||
|
||||
<!-- Name + Affinity -->
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small mb-0">Name</label>
|
||||
<input class="form-control form-control-sm" value="@eff2.TokenName"
|
||||
@onchange="e => SetTokenName(eff2, e.Value?.ToString() ?? string.Empty)" />
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small mb-0">Affinity</label>
|
||||
<select class="form-select form-select-sm" value="@eff2.TokenAffinity"
|
||||
@onchange="e => SetTokenAffinity(eff2, e.Value?.ToString() ?? string.Empty)">
|
||||
@foreach (var a in AffinityValues)
|
||||
{ <option value="@a" selected="@(a == eff2.TokenAffinity)">@a</option> }
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Combat stats -->
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-auto">
|
||||
<label class="form-label small mb-0">HP</label>
|
||||
<input type="number" min="1" class="form-control form-control-sm" style="width:75px"
|
||||
value="@eff2.TokenHealth"
|
||||
@onchange="e => SetTokenHealth(eff2, e.Value?.ToString())" />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label small mb-0">Defense</label>
|
||||
<input type="number" min="0" class="form-control form-control-sm" style="width:75px"
|
||||
value="@eff2.TokenDefense"
|
||||
@onchange="e => SetTokenDefense(eff2, e.Value?.ToString())" />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label small mb-0">Damage</label>
|
||||
<input type="number" min="0" class="form-control form-control-sm" style="width:75px"
|
||||
value="@eff2.TokenDamage"
|
||||
@onchange="e => SetTokenDamage(eff2, e.Value?.ToString())" />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label small mb-0">Max MP</label>
|
||||
<input type="number" min="0" class="form-control form-control-sm" style="width:75px"
|
||||
value="@(eff2.TokenMaxMp?.ToString() ?? string.Empty)"
|
||||
placeholder="none"
|
||||
@onchange="e => SetTokenMaxMp(eff2, e.Value?.ToString())" />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label small mb-0">Movement</label>
|
||||
<select class="form-select form-select-sm" style="width:110px" value="@eff2.TokenMovement"
|
||||
@onchange="e => SetTokenMovement(eff2, e.Value?.ToString() ?? string.Empty)">
|
||||
@foreach (var m in MovementTypeValues)
|
||||
{ <option value="@m" selected="@(m == eff2.TokenMovement)">@m</option> }
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Attack range + LoS -->
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-auto">
|
||||
<label class="form-label small mb-0">Range Min</label>
|
||||
<input type="number" min="1" class="form-control form-control-sm" style="width:75px"
|
||||
value="@eff2.TokenMinRange"
|
||||
@onchange="e => SetTokenMinRange(eff2, e.Value?.ToString())" />
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<label class="form-label small mb-0">Range Max</label>
|
||||
<input type="number" min="1" class="form-control form-control-sm" style="width:75px"
|
||||
value="@eff2.TokenMaxRange"
|
||||
@onchange="e => SetTokenMaxRange(eff2, e.Value?.ToString())" />
|
||||
</div>
|
||||
<div class="col-auto d-flex align-items-end pb-1">
|
||||
<div class="form-check mb-0">
|
||||
<input type="checkbox" class="form-check-input" id="tok_los_@effectIdx"
|
||||
checked="@eff2.TokenRequiresLos"
|
||||
@onchange='e => SetTokenBool(eff2, "RequiresLos", e)' />
|
||||
<label class="form-check-label small" for="tok_los_@effectIdx">Requires LoS</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Flags -->
|
||||
<div class="d-flex gap-3 flex-wrap mb-2">
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanMove"
|
||||
@onchange='e => SetTokenBool(eff2, "CanMove", e)' />
|
||||
<label class="form-check-label small">Can Move</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanAttack"
|
||||
@onchange='e => SetTokenBool(eff2, "CanAttack", e)' />
|
||||
<label class="form-check-label small">Can Attack</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanDefend"
|
||||
@onchange='e => SetTokenBool(eff2, "CanDefend", e)' />
|
||||
<label class="form-check-label small">Can Defend</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanBeAttacked"
|
||||
@onchange='e => SetTokenBool(eff2, "CanBeAttacked", e)' />
|
||||
<label class="form-check-label small">Can Be Attacked</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanBeBlocked"
|
||||
@onchange='e => SetTokenBool(eff2, "CanBeBlocked", e)' />
|
||||
<label class="form-check-label small">Can Be Blocked</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanBeObstructed"
|
||||
@onchange='e => SetTokenBool(eff2, "CanBeObstructed", e)' />
|
||||
<label class="form-check-label small">Can Be Obstructed</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanUseAbility"
|
||||
@onchange='e => SetTokenBool(eff2, "CanUseAbility", e)' />
|
||||
<label class="form-check-label small">Can Use Ability</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline mb-0">
|
||||
<input type="checkbox" class="form-check-input" checked="@eff2.TokenCanBeSacrificed"
|
||||
@onchange='e => SetTokenBool(eff2, "CanBeSacrificed", e)' />
|
||||
<label class="form-check-label small">Can Be Sacrificed</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Genus -->
|
||||
<div class="row g-2 mb-2">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small mb-0">Genus Tags <small class="text-muted">(comma-separated)</small></label>
|
||||
<input class="form-control form-control-sm" value="@eff2.TokenGenus"
|
||||
placeholder="e.g. Beast, Plant"
|
||||
@onchange="e => SetTokenGenus(eff2, e.Value?.ToString() ?? string.Empty)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Abilities JSON -->
|
||||
<div class="mb-2">
|
||||
<label class="form-label small mb-0">Abilities JSON <small class="text-muted">(paste compiled ability array; leave blank for none)</small></label>
|
||||
<textarea class="form-control form-control-sm font-monospace" rows="3"
|
||||
@bind="eff2.TokenAbilitiesJson" @bind:after="Compile"
|
||||
placeholder="[]"></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Assets -->
|
||||
<div class="row g-2 mb-1">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small mb-0">2D Art URL</label>
|
||||
<input class="form-control form-control-sm" value="@eff2.TokenArt2dUrl"
|
||||
placeholder="https://cdn.sor.gg/art/…"
|
||||
@onchange="e => SetTokenArt2dUrl(eff2, e.Value?.ToString() ?? string.Empty)" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small mb-0">3D Model URL</label>
|
||||
<input class="form-control form-control-sm" value="@eff2.TokenModelUrl"
|
||||
placeholder="https://cdn.sor.gg/models/…"
|
||||
@onchange="e => SetTokenModelUrl(eff2, e.Value?.ToString() ?? string.Empty)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="text-muted small fst-italic mt-1 mb-0">
|
||||
<i class="bi bi-info-circle me-1"></i>Set Action Target type to <strong>Tile</strong>. Non-Void tokens only place on affinity-matching tiles.
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -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<SpiritCardEntry> _spiritCards = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_spiritCards = await CatalogDb.Set<CardDefinition>()
|
||||
.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<string> _affinityTypes = ["SetAffinity", "SetBaseAffinity1", "SetBaseAffinity2", "PushAffinity", "PushFinalAffinity"];
|
||||
private static readonly HashSet<string> _rawJsonTypes = ["AddAbility", "ApplyOnEvent", "SummonToken"];
|
||||
private static readonly HashSet<string> _rawJsonTypes = ["AddAbility", "ApplyOnEvent"];
|
||||
private static readonly HashSet<string> _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<string>() ?? "{}";
|
||||
try
|
||||
{
|
||||
var tok = JsonNode.Parse(tokenDefStr) as JsonObject ?? new JsonObject();
|
||||
d.TokenName = tok["Name"]?.GetValue<string>() ?? "Token";
|
||||
d.TokenAffinity = tok["Affinity"]?.GetValue<string>() ?? "Aether";
|
||||
d.TokenHealth = tok["MaxHealth"]?.GetValue<int>() ?? 1;
|
||||
d.TokenDefense = tok["MaxDefense"]?.GetValue<int>() ?? 0;
|
||||
d.TokenDamage = tok["Damage"]?.GetValue<int>() ?? 1;
|
||||
d.TokenMaxMp = tok["MaxMp"]?.GetValue<int?>();
|
||||
d.TokenMovement = tok["MovementType"]?.GetValue<string>() ?? "Walk";
|
||||
d.TokenMinRange = tok["MinAttackRange"]?.GetValue<int>() ?? 1;
|
||||
d.TokenMaxRange = tok["MaxAttackRange"]?.GetValue<int>() ?? 1;
|
||||
d.TokenRequiresLos = tok["RequiresLos"]?.GetValue<bool>() ?? false;
|
||||
d.TokenCanMove = tok["CanMove"]?.GetValue<bool>() ?? false;
|
||||
d.TokenCanAttack = tok["CanAttack"]?.GetValue<bool>() ?? false;
|
||||
d.TokenCanDefend = tok["CanDefend"]?.GetValue<bool>() ?? true;
|
||||
d.TokenCanBeAttacked = tok["CanBeAttacked"]?.GetValue<bool>() ?? true;
|
||||
d.TokenCanBeBlocked = tok["CanBeBlocked"]?.GetValue<bool>() ?? true;
|
||||
d.TokenCanBeObstructed = tok["CanBeObstructed"]?.GetValue<bool>() ?? true;
|
||||
d.TokenCanUseAbility = tok["CanUseAbility"]?.GetValue<bool>() ?? true;
|
||||
d.TokenCanBeSacrificed = tok["CanBeSacrificed"]?.GetValue<bool>() ?? false;
|
||||
if (tok["Genus"] is JsonArray genusArr)
|
||||
d.TokenGenus = string.Join(", ", genusArr.Select(g => g?.GetValue<string>() ?? ""));
|
||||
d.TokenAbilitiesJson = tok["AbilitiesJson"]?.GetValue<string>() ?? "[]";
|
||||
d.TokenArt2dUrl = tok["Art2dUrl"]?.GetValue<string>() ?? "";
|
||||
d.TokenModelUrl = tok["ModelUrl"]?.GetValue<string>() ?? "";
|
||||
}
|
||||
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
|
||||
|
||||
@@ -1235,6 +1235,13 @@ public static class AbilitySystem
|
||||
var proto = JsonSerializer.Deserialize<CardInstance>(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<Affinity>(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,
|
||||
};
|
||||
|
||||
@@ -214,6 +214,13 @@ public class CardInstance
|
||||
/// </summary>
|
||||
public Dictionary<int, int>? AbilityUsesThisTurn { get; set; }
|
||||
|
||||
// ── Visual assets (used primarily for SpiritToken rendering) ─────────────
|
||||
|
||||
/// <summary>URL of the 2-D card art image (used by client for token display).</summary>
|
||||
public string? Art2dUrl { get; set; }
|
||||
/// <summary>URL of the 3-D model GLTF/GLB (used by client for token rendering).</summary>
|
||||
public string? ModelUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Genus tags on this unit (e.g. "Beast", "Plant"). May be modified by abilities.
|
||||
/// Null until at least one genus tag is added.
|
||||
|
||||
Reference in New Issue
Block a user