2932 lines
170 KiB
Plaintext
2932 lines
170 KiB
Plaintext
@* 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)
|
|
{
|
|
<p class="text-muted fst-italic">No abilities defined. Click "Add Ability" to start.</p>
|
|
}
|
|
else
|
|
{
|
|
@for (int ai = 0; ai < _abilities.Count; ai++)
|
|
{
|
|
var idx = ai;
|
|
var ab = _abilities[idx];
|
|
|
|
<div class="card mb-3">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span class="fw-semibold">
|
|
<span class="badge @AbilityTypeBadge(ab.TypeStr) me-2">@ab.TypeStr</span>
|
|
@(string.IsNullOrEmpty(ab.Name) ? "(unnamed)" : ab.Name)
|
|
</span>
|
|
<button class="btn btn-sm btn-outline-danger"
|
|
@onclick="() => { _abilities.RemoveAt(idx); Compile(); }">
|
|
<i class="bi bi-trash"></i>
|
|
</button>
|
|
</div>
|
|
<div class="card-body">
|
|
|
|
<!-- Core fields -->
|
|
<div class="row g-2 mb-3">
|
|
<div class="col-md-3">
|
|
<label class="form-label small">Type</label>
|
|
<select class="form-select form-select-sm" @bind="ab.TypeStr" @bind:after="Compile">
|
|
@foreach (var t in AbilityTypes)
|
|
{ <option value="@t">@t</option> }
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label small">Name <span class="text-muted">(optional)</span></label>
|
|
<input class="form-control form-control-sm" @bind="ab.Name" @bind:after="Compile"
|
|
placeholder="Display name" />
|
|
</div>
|
|
<div class="col-md-5">
|
|
<label class="form-label small">
|
|
Description <small class="text-muted">(plain English — what it does)</small>
|
|
</label>
|
|
<input class="form-control form-control-sm" @bind="ab.Description" @bind:after="Compile"
|
|
placeholder="e.g. Deal 3 damage to target enemy unit." />
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Type-specific fields -->
|
|
@if (ab.TypeStr == "Active")
|
|
{
|
|
<div class="row g-2 mb-2">
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Range Min</label>
|
|
<input type="number" class="form-control form-control-sm"
|
|
@bind="ab.RangeMin" @bind:after="Compile" />
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Range Max</label>
|
|
<input type="number" class="form-control form-control-sm"
|
|
@bind="ab.RangeMax" @bind:after="Compile" />
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Uses / Turn</label>
|
|
<input type="number" min="1" class="form-control form-control-sm"
|
|
@bind="ab.UsesPerTurn" @bind:after="Compile" />
|
|
</div>
|
|
<div class="col-auto d-flex align-items-end pb-1">
|
|
<div class="form-check me-3">
|
|
<input type="checkbox" class="form-check-input"
|
|
id="los_@idx"
|
|
@bind="ab.RangeRequiresLos" @bind:after="Compile" />
|
|
<label class="form-check-label small" for="los_@idx">Requires LoS</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input type="checkbox" class="form-check-input"
|
|
id="linear_@idx"
|
|
@bind="ab.RangeLinearOnly" @bind:after="Compile" />
|
|
<label class="form-check-label small" for="linear_@idx">Linear Only</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Cost editor -->
|
|
<div class="mb-3">
|
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
|
<label class="form-label small fw-medium mb-0">Cost</label>
|
|
<button class="btn btn-sm btn-outline-secondary py-0 px-2"
|
|
@onclick="() => { ab.Costs.Add(new CostDraft()); Compile(); }">
|
|
<i class="bi bi-plus-lg me-1"></i>Add Cost
|
|
</button>
|
|
</div>
|
|
@if (ab.Costs.Count == 0)
|
|
{
|
|
<p class="text-muted small fst-italic mb-0">Free (no cost).</p>
|
|
}
|
|
else
|
|
{
|
|
@for (int ci = 0; ci < ab.Costs.Count; ci++)
|
|
{
|
|
var cidx = ci;
|
|
var cost = ab.Costs[cidx];
|
|
<div class="d-flex gap-1 align-items-center mb-1">
|
|
<select class="form-select form-select-sm" style="width:260px"
|
|
@bind="cost.TypeStr" @bind:after="Compile">
|
|
@foreach (var ct in CostTypes)
|
|
{ <option value="@ct">@ct</option> }
|
|
</select>
|
|
<input type="number" min="1" class="form-control form-control-sm" style="width:80px"
|
|
@bind="cost.Amount" @bind:after="Compile" placeholder="Amount" title="Amount" />
|
|
<button class="btn btn-sm btn-outline-danger py-0 px-1"
|
|
@onclick="() => { ab.Costs.RemoveAt(cidx); Compile(); }">
|
|
<i class="bi bi-x"></i>
|
|
</button>
|
|
</div>
|
|
}
|
|
}
|
|
</div>
|
|
}
|
|
else if (ab.TypeStr == "Aura")
|
|
{
|
|
<div class="row g-2 mb-3">
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Aura Range Min</label>
|
|
<input type="number" class="form-control form-control-sm"
|
|
@bind="ab.AuraRangeMin" @bind:after="Compile" />
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Aura Range Max</label>
|
|
<input type="number" class="form-control form-control-sm"
|
|
@bind="ab.AuraRangeMax" @bind:after="Compile" />
|
|
</div>
|
|
</div>
|
|
<div class="row g-2 mb-3 align-items-end">
|
|
<div class="col-auto">
|
|
<label class="form-label small mb-1">On Leave Range</label>
|
|
<div class="d-flex align-items-center gap-2">
|
|
<div class="form-check mb-0">
|
|
<input class="form-check-input" type="radio"
|
|
name="auraLeave_@ab.GetHashCode()" id="auraLeaveNone_@ab.GetHashCode()"
|
|
checked="@(string.IsNullOrEmpty(ab.AuraLingerDurationStr) && !ab.AuraClearOnLeave)"
|
|
@onchange="() => SetAuraLeaveMode(ab, 0)" />
|
|
<label class="form-check-label small" for="auraLeaveNone_@ab.GetHashCode()">Persist (effect duration)</label>
|
|
</div>
|
|
<div class="form-check mb-0">
|
|
<input class="form-check-input" type="radio"
|
|
name="auraLeave_@ab.GetHashCode()" id="auraLeaveClear_@ab.GetHashCode()"
|
|
checked="@(ab.AuraClearOnLeave && string.IsNullOrEmpty(ab.AuraLingerDurationStr))"
|
|
@onchange="() => SetAuraLeaveMode(ab, 1)" />
|
|
<label class="form-check-label small" for="auraLeaveClear_@ab.GetHashCode()">Clear immediately</label>
|
|
</div>
|
|
<div class="form-check mb-0">
|
|
<input class="form-check-input" type="radio"
|
|
name="auraLeave_@ab.GetHashCode()" id="auraLeaveLinger_@ab.GetHashCode()"
|
|
checked="@(!string.IsNullOrEmpty(ab.AuraLingerDurationStr))"
|
|
@onchange="() => SetAuraLeaveMode(ab, 2)" />
|
|
<label class="form-check-label small" for="auraLeaveLinger_@ab.GetHashCode()">Linger</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@if (!string.IsNullOrEmpty(ab.AuraLingerDurationStr))
|
|
{
|
|
<div class="col-auto">
|
|
<label class="form-label small mb-0">Linger Duration</label>
|
|
<select class="form-select form-select-sm" style="width:230px"
|
|
@bind="ab.AuraLingerDurationStr" @bind:after="Compile">
|
|
@foreach (var d in DurationTypeValues)
|
|
{ <option value="@d">@d</option> }
|
|
</select>
|
|
</div>
|
|
@if (ab.AuraLingerDurationStr == "ForNTurns")
|
|
{
|
|
<div class="col-auto">
|
|
<label class="form-label small mb-0">N</label>
|
|
<input type="number" min="1" class="form-control form-control-sm" style="width:80px"
|
|
@bind="ab.AuraLingerDurationN" @bind:after="Compile" />
|
|
</div>
|
|
}
|
|
}
|
|
</div>
|
|
}
|
|
else if (ab.TypeStr == "Triggered")
|
|
{
|
|
<div class="mb-3">
|
|
<label class="form-label small">Trigger Event</label>
|
|
<div class="row g-2">
|
|
<div class="col-md-3">
|
|
<select class="form-select form-select-sm"
|
|
value="@ab.TriggerType"
|
|
@onchange="e => SelectTrigger(ab, (string)e.Value!)">
|
|
<option value="">— select trigger —</option>
|
|
@foreach (var t in TriggerTypesList)
|
|
{ <option value="@t">@t</option> }
|
|
</select>
|
|
</div>
|
|
<div class="col-md-9">
|
|
<div class="d-flex gap-1 flex-wrap align-items-center">
|
|
@RenderTriggerFields(ab)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row g-2 mt-1">
|
|
<div class="col-md-3">
|
|
<label class="form-label small mb-0">Trigger Limit / Turn</label>
|
|
<input type="number" min="1" class="form-control form-control-sm"
|
|
@bind="ab.TriggerLimitPerTurn" @bind:after="Compile"
|
|
placeholder="blank = unlimited" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
<!-- Duration override -->
|
|
<div class="row g-2 mb-3 align-items-end">
|
|
<div class="col-auto">
|
|
<label class="form-label small mb-0">
|
|
Duration
|
|
<small class="text-muted ms-1">overrides per-action duration for all effects</small>
|
|
</label>
|
|
<select class="form-select form-select-sm" style="width:230px"
|
|
@bind="ab.DurationStr" @bind:after="Compile">
|
|
<option value="">— per-action (no override) —</option>
|
|
@foreach (var d in DurationTypeValues)
|
|
{ <option value="@d">@d</option> }
|
|
</select>
|
|
</div>
|
|
@if (ab.DurationStr == "ForNTurns")
|
|
{
|
|
<div class="col-auto">
|
|
<label class="form-label small mb-0">N</label>
|
|
<input type="number" min="1" class="form-control form-control-sm" style="width:80px"
|
|
@bind="ab.DurationN" @bind:after="Compile" />
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<!-- Activation Conditions -->
|
|
<div class="mb-3">
|
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
|
<label class="form-label small fw-medium mb-0">Activation Conditions</label>
|
|
<button class="btn btn-sm btn-outline-secondary py-0 px-2"
|
|
@onclick="() => { ab.Conditions.Add(new ConditionDraft()); Compile(); }">
|
|
<i class="bi bi-plus-lg me-1"></i>Add
|
|
</button>
|
|
</div>
|
|
@if (ab.Conditions.Count == 0)
|
|
{
|
|
<p class="text-muted small fst-italic mb-0">None (always activatable).</p>
|
|
}
|
|
else
|
|
{
|
|
@for (int condI = 0; condI < ab.Conditions.Count; condI++)
|
|
{
|
|
var condIdx = condI;
|
|
var cond = ab.Conditions[condIdx];
|
|
<div class="d-flex gap-1 align-items-center mb-1 flex-wrap">
|
|
<select class="form-select form-select-sm" style="width:200px"
|
|
@bind="cond.TypeStr" @bind:after="Compile">
|
|
@foreach (var grp in ConditionGroups)
|
|
{
|
|
<optgroup label="@grp.Label">
|
|
@foreach (var ct in grp.Types)
|
|
{ <option value="@ct">@ct</option> }
|
|
</optgroup>
|
|
}
|
|
</select>
|
|
<select class="form-select form-select-sm" style="width:85px"
|
|
@bind="cond.Subject" @bind:after="Compile" title="Subject">
|
|
<option value="Self">Self</option>
|
|
<option value="Target">Target</option>
|
|
</select>
|
|
@RenderConditionFields(cond)
|
|
<button class="btn btn-sm btn-outline-danger py-0 px-1"
|
|
@onclick="() => { ab.Conditions.RemoveAt(condIdx); Compile(); }">
|
|
<i class="bi bi-x"></i>
|
|
</button>
|
|
</div>
|
|
}
|
|
}
|
|
</div>
|
|
|
|
<!-- Actions -->
|
|
<h6 class="text-muted small mb-2">
|
|
Actions
|
|
<small class="ms-1 fw-normal">(each action = one targeting context + one or more effects)</small>
|
|
</h6>
|
|
|
|
@for (int aci = 0; aci < ab.Actions.Count; aci++)
|
|
{
|
|
var actionIdx = aci;
|
|
var action = ab.Actions[actionIdx];
|
|
|
|
<div class="card border-secondary mb-2">
|
|
<div class="card-header d-flex justify-content-between align-items-center py-1 border-bottom border-secondary">
|
|
<span class="small fw-medium">Action @(actionIdx + 1)</span>
|
|
<button class="btn btn-sm btn-outline-danger py-0"
|
|
@onclick="() => { ab.Actions.RemoveAt(actionIdx); Compile(); }">
|
|
<i class="bi bi-x"></i>
|
|
</button>
|
|
</div>
|
|
<div class="card-body py-2">
|
|
<!-- Target selector -->
|
|
<div class="row g-2 mb-2 align-items-end">
|
|
<div class="col-md-3">
|
|
<label class="form-label small mb-0">Scope</label>
|
|
<select class="form-select form-select-sm" @bind="action.Scope" @bind:after="Compile">
|
|
@foreach (var s in TargetScopes) { <option value="@s">@s</option> }
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small mb-0">Target Type</label>
|
|
<select class="form-select form-select-sm" @bind="action.TargetType" @bind:after="Compile">
|
|
@foreach (var t in TargetTypes) { <option value="@t">@t</option> }
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small mb-0">Ownership</label>
|
|
<select class="form-select form-select-sm" @bind="action.Ownership" @bind:after="Compile">
|
|
@foreach (var o in TargetOwnerships) { <option value="@o">@o</option> }
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small mb-0">Count N</label>
|
|
<input type="number" min="1" class="form-control form-control-sm"
|
|
@bind="action.Count" @bind:after="Compile" />
|
|
</div>
|
|
<div class="col-md-1">
|
|
<div class="form-check">
|
|
<input type="checkbox" class="form-check-input"
|
|
id="all_@(idx)_@(actionIdx)"
|
|
@bind="action.All" @bind:after="Compile" />
|
|
<label class="form-check-label small" for="all_@(idx)_@(actionIdx)">All</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- Target filter (optional, single filter, no-param types) -->
|
|
<div class="row g-2 mb-2 align-items-end">
|
|
<div class="col-md-4">
|
|
<label class="form-label small mb-0">Target Filter <span class="text-muted">(optional)</span></label>
|
|
<select class="form-select form-select-sm" @bind="action.FilterType" @bind:after="Compile">
|
|
<option value="">(none)</option>
|
|
<option value="IsSelf">IsSelf — same card definition</option>
|
|
<option value="IsExactSelf">IsExactSelf — same instance only</option>
|
|
<option value="IsAdjacentToSource">IsAdjacentToSource</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Effects -->
|
|
<label class="form-label small fw-medium mb-1">Effects</label>
|
|
|
|
@for (int ei = 0; ei < action.Effects.Count; ei++)
|
|
{
|
|
var effectIdx = ei;
|
|
var effect = action.Effects[effectIdx];
|
|
|
|
<div class="border rounded p-2 mb-2">
|
|
<div class="d-flex gap-2 align-items-start">
|
|
<!-- Effect type -->
|
|
<div style="min-width:160px">
|
|
<label class="form-label small mb-0">Effect Type</label>
|
|
<select class="form-select form-select-sm"
|
|
value="@effect.TypeKey"
|
|
@onchange="e => SelectEffectType(effect, (string)e.Value!)">
|
|
@foreach (var grp in EffectGroups)
|
|
{
|
|
<optgroup label="@grp.Label">
|
|
@foreach (var et in grp.Types)
|
|
{ <option value="@et">@et</option> }
|
|
</optgroup>
|
|
}
|
|
</select>
|
|
</div>
|
|
<!-- Per-type fields -->
|
|
<div class="flex-grow-1">
|
|
@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>
|
|
<label class="form-label small mb-0 invisible">x</label>
|
|
<button class="btn btn-sm btn-outline-danger d-block"
|
|
@onclick="() => { action.Effects.RemoveAt(effectIdx); Compile(); }">
|
|
<i class="bi bi-x"></i>
|
|
</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>
|
|
}
|
|
|
|
<button class="btn btn-sm btn-outline-success"
|
|
@onclick="() => { action.Effects.Add(new EffectDraft()); Compile(); }">
|
|
<i class="bi bi-plus-lg me-1"></i>Add Effect
|
|
</button>
|
|
|
|
<!-- Action conditions -->
|
|
<div class="mt-3">
|
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
|
<label class="form-label small fw-medium mb-0">Action Conditions</label>
|
|
<button class="btn btn-sm btn-outline-secondary py-0 px-2"
|
|
@onclick="() => { action.Conditions.Add(new ConditionDraft()); Compile(); }">
|
|
<i class="bi bi-plus-lg me-1"></i>Add
|
|
</button>
|
|
</div>
|
|
@if (action.Conditions.Count == 0)
|
|
{
|
|
<p class="text-muted small fst-italic mb-0">None.</p>
|
|
}
|
|
else
|
|
{
|
|
@for (int acI = 0; acI < action.Conditions.Count; acI++)
|
|
{
|
|
var acIdx = acI;
|
|
var ac = action.Conditions[acIdx];
|
|
<div class="d-flex gap-1 align-items-center mb-1 flex-wrap">
|
|
<select class="form-select form-select-sm" style="width:200px"
|
|
@bind="ac.TypeStr" @bind:after="Compile">
|
|
@foreach (var grp in ConditionGroups)
|
|
{
|
|
<optgroup label="@grp.Label">
|
|
@foreach (var ct in grp.Types)
|
|
{ <option value="@ct">@ct</option> }
|
|
</optgroup>
|
|
}
|
|
</select>
|
|
<select class="form-select form-select-sm" style="width:85px"
|
|
@bind="ac.Subject" @bind:after="Compile" title="Subject">
|
|
<option value="Self">Self</option>
|
|
<option value="Target">Target</option>
|
|
</select>
|
|
@RenderConditionFields(ac)
|
|
<button class="btn btn-sm btn-outline-danger py-0 px-1"
|
|
@onclick="() => { action.Conditions.RemoveAt(acIdx); Compile(); }">
|
|
<i class="bi bi-x"></i>
|
|
</button>
|
|
</div>
|
|
}
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
<button class="btn btn-sm btn-outline-secondary mt-1"
|
|
@onclick="() => { ab.Actions.Add(new ActionDraft()); Compile(); }">
|
|
<i class="bi bi-plus-lg me-1"></i>Add Action
|
|
</button>
|
|
|
|
<!-- Animation & Sound -->
|
|
<hr class="my-3" />
|
|
<div class="d-flex align-items-center gap-2 mb-2">
|
|
<h6 class="text-muted small mb-0">Animation & Sound</h6>
|
|
<div class="form-check form-switch mb-0">
|
|
<input class="form-check-input" type="checkbox" role="switch"
|
|
id="hasAnim_@idx"
|
|
@bind="ab.HasAnimation" @bind:after="Compile" />
|
|
<label class="form-check-label small" for="hasAnim_@idx">Enable</label>
|
|
</div>
|
|
</div>
|
|
|
|
@if (ab.HasAnimation)
|
|
{
|
|
<div class="row g-2 mb-2">
|
|
<div class="col-md-3">
|
|
<label class="form-label small">Type</label>
|
|
<select class="form-select form-select-sm" @bind="ab.AnimationType" @bind:after="Compile">
|
|
@foreach (var t in AnimationTypes)
|
|
{ <option value="@t">@t</option> }
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small">Effect</label>
|
|
<select class="form-select form-select-sm" @bind="ab.AnimationEffect" @bind:after="Compile">
|
|
@foreach (var e in AnimationEffects)
|
|
{ <option value="@e">@e</option> }
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Width</label>
|
|
<input type="number" step="0.1" class="form-control form-control-sm"
|
|
@bind="ab.AnimationWidth" @bind:after="Compile" />
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Height</label>
|
|
<input type="number" step="0.1" class="form-control form-control-sm"
|
|
@bind="ab.AnimationHeight" @bind:after="Compile" />
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small">Duration (s)</label>
|
|
<input type="number" step="0.1" class="form-control form-control-sm"
|
|
@bind="ab.AnimationDuration" @bind:after="Compile" />
|
|
</div>
|
|
</div>
|
|
<div class="row g-2 mb-2">
|
|
<div class="col-12">
|
|
<label class="form-label small">Asset URL</label>
|
|
<input class="form-control form-control-sm" @bind="ab.AnimationAssetUrl" @bind:after="Compile"
|
|
placeholder="https://cdn.sor.gg/fx/…" />
|
|
</div>
|
|
</div>
|
|
<div class="row g-2">
|
|
<div class="col-md-6">
|
|
<label class="form-label small">Cast Sound URL</label>
|
|
<input class="form-control form-control-sm" @bind="ab.CastSoundUrl" @bind:after="Compile"
|
|
placeholder="https://cdn.sor.gg/sfx/…" />
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label class="form-label small">Impact Sound URL</label>
|
|
<input class="form-control form-control-sm" @bind="ab.ImpactSoundUrl" @bind:after="Compile"
|
|
placeholder="https://cdn.sor.gg/sfx/…" />
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
<div class="d-flex gap-2 align-items-center mb-4">
|
|
<button class="btn btn-outline-primary btn-sm" @onclick="AddAbility">
|
|
<i class="bi bi-plus-lg me-1"></i>Add Ability
|
|
</button>
|
|
<button class="btn btn-outline-secondary btn-sm" @onclick="() => _showHelp = !_showHelp">
|
|
<i class="bi bi-question-circle me-1"></i>Help
|
|
</button>
|
|
</div>
|
|
|
|
<!-- JSON output / raw edit -->
|
|
<div class="border rounded p-3">
|
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
|
<span class="small fw-semibold text-muted">
|
|
<i class="bi bi-code-slash me-1"></i>Compiled JSON
|
|
</span>
|
|
<button class="btn btn-sm btn-outline-secondary" @onclick="() => _showRaw = !_showRaw">
|
|
@(_showRaw ? "Close Raw Editor" : "Edit Raw JSON")
|
|
</button>
|
|
</div>
|
|
|
|
@if (_showRaw)
|
|
{
|
|
<textarea class="form-control font-monospace mb-2" rows="15" @bind="_compiledJson"></textarea>
|
|
<div class="d-flex gap-2 align-items-center">
|
|
<button class="btn btn-sm btn-primary" @onclick="ApplyRawJson">Apply</button>
|
|
<span class="text-muted small">Parses raw JSON and rebuilds builder state.</span>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<pre class="small font-monospace mb-0 p-2 bg-light bg-opacity-10 rounded"
|
|
style="max-height:200px;overflow-y:auto">@_compiledJson</pre>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
@if (_showHelp)
|
|
{
|
|
<div class="offcanvas offcanvas-end show" style="width:700px;overflow-y:auto" tabindex="-1">
|
|
<div class="offcanvas-header border-bottom">
|
|
<h5 class="offcanvas-title fw-semibold"><i class="bi bi-book me-2"></i>Ability Builder Reference</h5>
|
|
<button type="button" class="btn-close" @onclick="() => _showHelp = false"></button>
|
|
</div>
|
|
<div class="offcanvas-body small">
|
|
|
|
<h6 class="fw-semibold text-primary">Ability Types</h6>
|
|
<table class="table table-sm table-bordered mb-3">
|
|
<thead class="table-dark"><tr><th>Type</th><th>When it fires</th><th>Key fields</th></tr></thead>
|
|
<tbody>
|
|
<tr><td><strong>Active</strong></td><td>Player explicitly activates on their turn</td><td>Range, Cost, UsesPerTurn</td></tr>
|
|
<tr><td><strong>Passive</strong></td><td>Always in effect while unit is on battlefield</td><td>Actions (target=Self)</td></tr>
|
|
<tr><td><strong>Aura</strong></td><td>Applies Actions to units entering range; fires OnEnterAuraRange / OnLeaveAuraRange triggers. On Leave: <em>Persist</em> = keep effect duration, <em>Clear</em> = revert immediately, <em>Linger</em> = switch to linger duration</td><td>AuraRange, Actions, ClearOnLeave / LingerDuration</td></tr>
|
|
<tr><td><strong>Triggered</strong></td><td>Fires automatically when a specific game event occurs</td><td>TriggerEvent, TriggerLimitPerTurn, Actions</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">Targeting — Scope</h6>
|
|
<p class="mb-1">Scope defines the <em>zone</em> searched for targets.</p>
|
|
<table class="table table-sm table-bordered mb-3">
|
|
<thead class="table-dark"><tr><th>Scope</th><th>Zone searched</th></tr></thead>
|
|
<tbody>
|
|
<tr><td>Battlefield</td><td>Units currently on the board</td></tr>
|
|
<tr><td>Hand</td><td>Cards in a player's hand</td></tr>
|
|
<tr><td>Deck</td><td>Cards in a player's deck</td></tr>
|
|
<tr><td>Discard</td><td>Cards in a player's discard pile</td></tr>
|
|
<tr><td>Player</td><td>A player entity (for player-targeting effects like ModifySP)</td></tr>
|
|
<tr><td>AnyZone</td><td>All zones simultaneously</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">Targeting — Ownership</h6>
|
|
<p class="mb-1">Ownership narrows the candidate pool and determines whether the player is prompted to pick.</p>
|
|
<table class="table table-sm table-bordered mb-3">
|
|
<thead class="table-dark"><tr><th>Ownership</th><th>Meaning</th><th>Player prompted?</th></tr></thead>
|
|
<tbody>
|
|
<tr><td>Self</td><td>Any unit owned by the same controller as the ability source</td><td>No (auto)</td></tr>
|
|
<tr><td>ExactSelf</td><td>The exact unit instance that owns this ability</td><td>No (auto)</td></tr>
|
|
<tr><td>Owner</td><td>Entities belonging to the ability owner</td><td>Yes (if Count>1 or All)</td></tr>
|
|
<tr><td>Ally</td><td>Friendly units other than self</td><td>Yes</td></tr>
|
|
<tr><td>Enemy</td><td>Opponent's units</td><td>Yes</td></tr>
|
|
<tr><td>Any</td><td>Any entity in the zone regardless of controller</td><td>Yes</td></tr>
|
|
<tr><td>Random</td><td>Engine picks a random valid target; player is not prompted</td><td>No (auto)</td></tr>
|
|
<tr><td>Target</td><td>Re-uses the resolved target from the previous action</td><td>No (chained)</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">Targeting — Target Filters</h6>
|
|
<table class="table table-sm table-bordered mb-3">
|
|
<thead class="table-dark"><tr><th>Filter</th><th>Meaning</th></tr></thead>
|
|
<tbody>
|
|
<tr><td>IsSelf</td><td>Target shares the same <em>card definition</em> as the source (matches all copies of this card type on the board)</td></tr>
|
|
<tr><td>IsExactSelf</td><td>Target is the exact <em>unit instance</em> that owns this ability (use when only this specific unit should be affected)</td></tr>
|
|
<tr><td>IsAdjacentToSource</td><td>Target must be orthogonally adjacent to the ability's source unit</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">ValueExpr References</h6>
|
|
<p class="mb-1">In any <strong>Amt</strong> field you can choose a dynamic reference instead of a fixed number. The engine resolves the reference at the moment the effect fires.</p>
|
|
<table class="table table-sm table-bordered mb-3">
|
|
<thead class="table-dark"><tr><th>Reference</th><th>Resolves to</th><th>When available</th></tr></thead>
|
|
<tbody>
|
|
<tr><td><code>EventData.Amount</code></td><td>Numeric payload from the trigger event (e.g. damage dealt)</td><td>Triggered abilities only</td></tr>
|
|
<tr><td><code>Target.Damage</code></td><td>Current damage stat of this action's first resolved target</td><td>Always</td></tr>
|
|
<tr><td><code>Target.Defense</code></td><td>Current defense stat of the target</td><td>Always</td></tr>
|
|
<tr><td><code>Target.Health</code></td><td>Current HP of the target</td><td>Always</td></tr>
|
|
<tr><td><code>Target.MP</code></td><td>Current MP of the target</td><td>Always</td></tr>
|
|
<tr><td><code>Target.SpCost</code></td><td>SP channel cost of the target card</td><td>Always</td></tr>
|
|
<tr><td><code>Target.StCost</code></td><td>ST channel cost of the target card</td><td>Always</td></tr>
|
|
<tr><td><code>Self.Damage</code></td><td>Damage stat of the ability's source unit</td><td>Always</td></tr>
|
|
<tr><td><code>Self.Defense</code></td><td>Defense stat of the source unit</td><td>Always</td></tr>
|
|
<tr><td><code>Self.Health</code></td><td>Current HP of the source unit</td><td>Always</td></tr>
|
|
<tr><td><code>Self.MP</code></td><td>Current MP of the source unit</td><td>Always</td></tr>
|
|
<tr><td><code>Self.SpCost</code></td><td>SP cost of the source card</td><td>Always</td></tr>
|
|
<tr><td><code>Self.StCost</code></td><td>ST cost of the source card</td><td>Always</td></tr>
|
|
<tr><td><code>Action0.Target.*</code></td><td>Stat of the first target resolved in Action 1</td><td>Actions 2+ only</td></tr>
|
|
<tr><td><code>Action1.Target.*</code></td><td>Stat of the first target resolved in Action 2</td><td>Actions 3+ only</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">Multi-Action Cross-Reference Example</h6>
|
|
<p class="mb-1">"Return a target Spirit to its owner's hand and refund its SP cost."</p>
|
|
<ul class="mb-3">
|
|
<li><strong>Action 1</strong> — Scope: Hand or Battlefield, Type: Spirit, Ownership: Any, Count: 1 → Effect: <em>ReturnToHand</em></li>
|
|
<li><strong>Action 2</strong> — Scope: Player, Type: Player, Ownership: Target, Count: 1 → Effect: <em>ModifySP</em>, Amt: <code>Action0.Target.SpCost</code></li>
|
|
</ul>
|
|
<p class="text-muted fst-italic mb-3">Action 2 uses <code>Ownership: Target</code> to re-target the owner of the card selected in Action 1. The Amt dropdown will show <code>Action0.Target.*</code> options once Action 2 exists.</p>
|
|
|
|
<h6 class="fw-semibold text-primary">Duration Types</h6>
|
|
<table class="table table-sm table-bordered mb-3">
|
|
<thead class="table-dark"><tr><th>Duration</th><th>When the effect expires</th></tr></thead>
|
|
<tbody>
|
|
<tr><td>Instant</td><td>Applied once, never removed (stat changes etc.)</td></tr>
|
|
<tr><td>UntilEndOfTurn</td><td>Expires at end of the active player's turn</td></tr>
|
|
<tr><td>UntilStartOfOwnerTurn</td><td>Expires at start of the <em>ability owner's</em> next turn</td></tr>
|
|
<tr><td>UntilStartOfSourceOwnerTurn</td><td>Expires at start of the <em>source unit owner's</em> next turn</td></tr>
|
|
<tr><td>ForNTurns</td><td>Expires after N complete turns have elapsed</td></tr>
|
|
<tr><td>WhileSourceOnBattlefield</td><td>Expires when the source unit leaves the battlefield</td></tr>
|
|
<tr><td>PermanentInMatch</td><td>Never expires for the rest of this game</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">Conditions</h6>
|
|
<p class="mb-1">Conditions can be added to <strong>Ability-level</strong> (ActivationConditions) or <strong>Action-level</strong>. All must pass for the ability/action to fire. The <strong>Subject</strong> dropdown selects whose state is checked: <code>Self</code> = ability source, <code>Target</code> = the resolved target.</p>
|
|
<table class="table table-sm table-bordered mb-3">
|
|
<thead class="table-dark"><tr><th>Condition</th><th>Passes when…</th></tr></thead>
|
|
<tbody>
|
|
<tr><td>IsOwnTurn / IsOpponentTurn</td><td>It is (or isn't) the owner's turn</td></tr>
|
|
<tr><td>HealthBelow / HealthAbove N</td><td>Subject's current HP < N or > N</td></tr>
|
|
<tr><td>DefenseIs / SPAtLeast / STAtLeast</td><td>Stat comparisons</td></tr>
|
|
<tr><td>HasGenus / HasAbility</td><td>Subject has a genus tag / named ability</td></tr>
|
|
<tr><td>IsOnTileWithAffinity</td><td>Subject's tile matches the specified affinity</td></tr>
|
|
<tr><td>DestinationTileAffinityIs / PreviousTileAffinityIs</td><td>On move-triggered abilities, checks the moved-to / moved-from tile affinity</td></tr>
|
|
<tr><td>MovedFromOrIntoAffinity</td><td>On move-triggered abilities, passes if either origin or destination tile matches affinity</td></tr>
|
|
<tr><td>IsAdjacentTo</td><td>Subject is adjacent to a unit matching Ownership</td></tr>
|
|
<tr><td>WithinRangeOf</td><td>Subject is within N tiles of a unit matching Ownership</td></tr>
|
|
<tr><td>UnitCountOnBattlefield</td><td>Total matching units on board satisfies comparator</td></tr>
|
|
<tr><td>CardInZone</td><td>A matching card exists in the specified zone</td></tr>
|
|
<tr><td>AND / OR / XOR</td><td>Composite — combines nested conditions</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">Trigger Events</h6>
|
|
<p class="mb-1">Available for <strong>Triggered</strong> abilities. The engine fires the ability whenever the event occurs and all ActivationConditions pass.</p>
|
|
<ul class="mb-3 column-count-2">
|
|
@foreach (var t in TriggerTypesList)
|
|
{ <li><code>@t</code></li> }
|
|
</ul>
|
|
<p class="mb-1"><strong>Trigger Ownership</strong> controls whose actions fire the trigger:</p>
|
|
<table class="table table-sm mb-3">
|
|
<thead><tr><th>Value</th><th>Meaning</th></tr></thead>
|
|
<tbody>
|
|
<tr><td><code>Any</code></td><td>Any unit's action fires the trigger</td></tr>
|
|
<tr><td><code>Owner</code></td><td>Any unit owned by the same player fires the trigger</td></tr>
|
|
<tr><td><code>Ally</code></td><td>Alias for Owner (same-player units)</td></tr>
|
|
<tr><td><code>Enemy</code></td><td>Only opponent units fire the trigger</td></tr>
|
|
<tr><td><code>ExactSelf</code></td><td><strong>Only this specific unit instance</strong> fires the trigger — use this to react to your own movement/actions, not teammates'</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6 class="fw-semibold text-primary">Trigger-Specific Fields</h6>
|
|
<p class="mb-1">Some trigger types expose extra filtering fields beyond <code>Ownership</code> and <code>UnitType</code>.</p>
|
|
|
|
<p class="mb-1"><strong>OnUnitSentToDiscard — <code>CausedBy</code></strong></p>
|
|
<p class="mb-1">Fires whenever a unit is sent to the discard pile from the battlefield. This includes:</p>
|
|
<ul class="mb-2">
|
|
<li>Combat — the attacker kills the target (or counterattack kills the attacker)</li>
|
|
<li>Ability — a <em>KillUnit</em> or <em>SendToDiscard</em> ability effect resolves</li>
|
|
</ul>
|
|
<p class="mb-1">The optional <code>CausedBy</code> field narrows the trigger to units killed by a specific owner class:</p>
|
|
<table class="table table-sm table-bordered mb-2">
|
|
<thead class="table-dark"><tr><th>CausedBy value</th><th>Fires when the killer is…</th></tr></thead>
|
|
<tbody>
|
|
<tr><td>(empty)</td><td>Any killer — trigger fires regardless of who caused the discard</td></tr>
|
|
<tr><td><code>ExactSelf</code></td><td><strong>This specific unit instance</strong> — the unit that owns this ability was the one that dealt the killing blow (Bloodlust pattern)</td></tr>
|
|
<tr><td><code>Owner</code></td><td>Any unit controlled by the same player as this unit</td></tr>
|
|
<tr><td><code>Enemy</code></td><td>Any opponent-controlled unit caused the discard</td></tr>
|
|
<tr><td><code>Any</code></td><td>Same as empty — any killer</td></tr>
|
|
</tbody>
|
|
</table>
|
|
<p class="mb-1 text-muted fst-italic">Note: <code>Ownership</code> still filters the <em>unit being discarded</em>; <code>CausedBy</code> filters the <em>killer</em>. Use <code>Ownership: Any, CausedBy: ExactSelf</code> to react whenever this unit kills anything.</p>
|
|
|
|
<p class="mb-1 mt-2"><strong>Bloodlust example</strong> — "When this spirit sends another spirit to the discard, gain +1 attack":</p>
|
|
<pre class="bg-light border rounded p-2 small mb-1">{"$type":"OnUnitSentToDiscard","UnitType":"Spirit","Ownership":"Any","CausedBy":"ExactSelf"}</pre>
|
|
<p class="mb-1">Action: Scope <code>Battlefield</code>, Ownership <code>ExactSelf</code>, Effect <code>ModifyStat</code> — Stat <code>Damage</code>, Amt +1, Duration <code>PermanentInMatch</code> (or <code>UntilEndOfTurn</code> for temporary buff).</p>
|
|
|
|
<p class="mb-1 mt-2"><strong>OnUnitDeath vs OnUnitSentToDiscard</strong></p>
|
|
<p class="mb-3 text-muted">Use <code>OnUnitDeath</code> to react to any unit being killed (e.g. opponent's unit dies anywhere). Use <code>OnUnitSentToDiscard</code> when you specifically want the <em>killer identity</em> via <code>CausedBy</code>, or when you need to distinguish combat-killed units from sacrificed/returned units (sacrificed units fire <code>OnSpiritSacrificed</code>, not <code>OnUnitSentToDiscard</code>).</p>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="offcanvas-backdrop fade show" @onclick="() => _showHelp = false" style="z-index:1040"></div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string AbilitiesJson { get; set; } = "[]";
|
|
[Parameter] public EventCallback<string> AbilitiesJsonChanged { get; set; }
|
|
|
|
private readonly List<AbilityDraft> _abilities = new();
|
|
private string _compiledJson = "[]";
|
|
private string _lastJson = "";
|
|
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"];
|
|
private static readonly string[] TargetScopes = ["Hand", "Deck", "Discard", "Battlefield", "Player", "AnyZone"];
|
|
private static readonly string[] TargetTypes = ["Unit", "ArchSpirit", "Spirit", "SpiritToken", "Ruin", "Tile", "Card", "Player"];
|
|
private static readonly string[] TargetOwnerships= ["Self", "ExactSelf", "Owner", "Ally", "Enemy", "Any", "Random", "Target"];
|
|
|
|
private static readonly string[] AffinityValues = [
|
|
"Void", "Aether", "Lake", "Hill", "Forest", "Field",
|
|
"Ocean", "Island", "Marsh", "Swamp", "Mountain", "Steppe",
|
|
"Fort", "Plains", "Grove", "Jungle",
|
|
"UnstableAether", "PerfectAether", "PureVoid",
|
|
];
|
|
private static readonly string[] MovementTypeValues = ["Walk", "Flight", "Jump", "Teleport"];
|
|
private static readonly string[] DirectionValues = ["North", "South", "East", "West", "NorthEast", "NorthWest", "SouthEast", "SouthWest"];
|
|
private static readonly string[] ComparatorValues = ["Equal", "NotEqual", "LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual"];
|
|
private static readonly string[] DurationTypeValues = ["Instant", "UntilEndOfTurn", "UntilStartOfOwnerTurn", "UntilStartOfSourceOwnerTurn", "ForNTurns", "UntilEndOfSequence", "WhileSourceOnBattlefield", "PermanentInMatch"];
|
|
private static readonly string[] StatTargetValues = ["Current", "Base", "Max"];
|
|
private static readonly string[] StatValues = ["Damage", "Defense", "Health", "MP"];
|
|
private static readonly string[] PositionValues = ["Top", "Bottom"];
|
|
private static readonly string[] PlayerValues = ["Owner", "Opponent", "Both", "Any"];
|
|
private static readonly string[] OwnershipValues = ["Any", "Owner", "Ally", "Enemy", "ExactSelf"];
|
|
private static readonly string[] UnitTypeValues = ["Unit", "Spirit", "ArchSpirit", "SpiritToken"];
|
|
private static readonly string[] TriggerCardTypeValues = ["Spirit", "ArchSpirit", "Ruin", "Repentance", "Instinct", "Terramorpha"];
|
|
private static readonly string[] TriggerDamageTypeValues= ["Any", "HP", "Defense"];
|
|
private static readonly string[] ControllerValues = ["Owner", "Opponent"];
|
|
private static readonly string[] ZoneValues = ["Hand", "Deck", "Discard", "Battlefield"];
|
|
|
|
private static readonly string[] AnimationTypes = ["Projectile", "LinearProjectile", "ArcProjectile", "Aura"];
|
|
private static readonly string[] AnimationEffects = ["Self", "Target", "Some", "All"];
|
|
|
|
private static readonly string[] CostTypes = [
|
|
"SpiritPoints", "SacrificeTokens", "DiscardFromHand", "MillTopOfDeck",
|
|
"MillBottomOfDeck", "SendSpiritFromBattlefieldToDiscard",
|
|
"DealDamageToOwnArchSpirit", "DealDamageToOwnSpirit",
|
|
];
|
|
|
|
private static readonly string[] TriggerTypesList = [
|
|
"OnTurnStart", "OnTurnEnd",
|
|
"OnChanneled", "OnAscend", "OnTransition",
|
|
"OnUnitMove", "OnUnitAttack", "OnUnitAbilityActivated", "OnUnitMPSpent",
|
|
"OnDamageDealt", "OnDamagePrevented", "OnHealed", "BeforeDamageApplied", "BeforeUnitDeath",
|
|
"OnUnitEnterBattlefield", "OnUnitLeaveBattlefield", "OnUnitDeath",
|
|
"OnUnitSentToDiscard", "OnSpiritSacrificed", "OnTokenSummoned",
|
|
"OnStatModified", "OnAbilityAdded", "OnAbilityRemoved", "OnGenusChanged",
|
|
"OnRuinActivation", "OnUnitOccupyRuin", "OnTileAffinityChanged",
|
|
"OnSPGained", "OnSPSpent", "OnSTGained", "OnSTSpent",
|
|
"OnCardDrawn", "OnCardDiscarded", "OnCardReturnedToHand", "OnCardReturnedToDeck",
|
|
"OnDeckShuffled", "OnCardsRevealed",
|
|
"OnTargetedByAbility", "OnEffectApplied", "OnEnterAuraRange", "OnLeaveAuraRange",
|
|
];
|
|
|
|
// ── Effect groups ────────────────────────────────────────────────────────────
|
|
|
|
private sealed record EffectGroup(string Label, string[] Types);
|
|
|
|
private static readonly EffectGroup[] EffectGroups =
|
|
[
|
|
new("Damage & Healing", ["DealDamage", "Heal", "DealDamageToSelf", "DOT", "HOT", "PreventDeath", "PreventNextDamage", "SetHealthMinimum"]),
|
|
new("Stat Modification", ["ModifyHealth", "ModifyDefense", "ModifyDamage", "ModifyMP",
|
|
"GrantAdditionalAttack", "SetAttackRange",
|
|
"ModifyMinAttackRange", "ModifyMaxAttackRange",
|
|
"SetMovementType", "ModifyCost", "SetStatModMultiplier"]),
|
|
new("Player Resources", ["ModifySP", "ModifyST", "ModifyCardsDrawnPerTurn", "ModifySPAccumulation"]),
|
|
new("Unit Flags", ["SetCanMove", "SetCanAttack", "SetCanDefend", "SetCanBeAttacked",
|
|
"SetCanBeBlocked", "SetCanBeObstructed", "SetCanUseAbility", "SetCanBeSacrificed"]),
|
|
new("Player Flags", ["SetCanDrawCards", "SetAccumulatesSP", "SetCanChannelSpirit",
|
|
"SetCanSacrificeSpirit", "SetCanAscendArchSpirit", "SetCanTransitionArchSpirit",
|
|
"SetCanChannelRepentance", "SetCanChannelInstinct", "SetCanChannelRuin",
|
|
"SetCanChannelTerramorphaMono", "SetCanChannelTerramorphaDi", "SetCanChannelTerramorphaTri"]),
|
|
new("Zone Operations", ["DrawCards", "DiscardCards", "ReturnToHand", "ReturnToDeck", "SendToDiscard",
|
|
"ShuffleDeck", "ReturnToBattlefield", "SearchDeck", "RevealCards",
|
|
"PlaceOnDeck", "ChannelCard"]),
|
|
new("Genus & Affinity", ["AddGenus", "RemoveGenus", "SetAffinity",
|
|
"SetBaseAffinity1", "SetBaseAffinity2", "PushAffinity", "PushFinalAffinity"]),
|
|
new("Ability Mgmt", ["AddAbility", "RemoveAbility", "EnableAbility", "DisableAbility"]),
|
|
new("Displacement", ["PushUnit", "PullUnit", "DisplaceUnit", "RepositionUnit"]),
|
|
new("Control", ["TakeControl", "GrantMovementControl", "SetFixedSacrificeReturn"]),
|
|
new("Token & Deferred", ["SummonToken", "ApplyOnEvent"]),
|
|
];
|
|
|
|
// ── Condition groups ─────────────────────────────────────────────────────────
|
|
|
|
private static readonly EffectGroup[] ConditionGroups =
|
|
[
|
|
new("Turn / Timing", ["IsOwnTurn", "IsOpponentTurn", "IsAllyTurn", "IsActivePlayerTurn"]),
|
|
new("Unit", ["HealthBelow", "HealthAbove", "DefenseIs", "HasGenus", "HasAbility",
|
|
"IsOnTileWithAffinity", "IsAdjacentTo", "WithinRangeOf", "MovementTypeIs",
|
|
"DestinationTileAffinityIs", "PreviousTileAffinityIs", "MovedFromOrIntoAffinity"]),
|
|
new("Player", ["SPAtLeast", "SPAtMost", "STAtLeast", "STAtMost",
|
|
"HandSizeAtLeast", "HandSizeAtMost", "DeckSizeAtLeast", "DiscardSizeAtLeast"]),
|
|
new("Tile", ["TileAffinityMatches", "TileIsOccupied", "TileIsUnoccupied"]),
|
|
new("Battlefield", ["UnitCountOnBattlefield", "CardInZone"]),
|
|
new("Composite", ["AND", "OR", "XOR", "NOT"]),
|
|
];
|
|
|
|
// ── Effect type categories for rendering ─────────────────────────────────────
|
|
|
|
private static readonly HashSet<string> _amountBypassTypes = ["DealDamage", "DealDamageToSelf"];
|
|
private static readonly HashSet<string> _amountOnlyTypes = ["Heal", "ModifyDamage", "ModifySP", "ModifyST", "ModifyCardsDrawnPerTurn", "ModifySPAccumulation",
|
|
"ModifyMinAttackRange", "ModifyMaxAttackRange", "PreventNextDamage"];
|
|
private static readonly HashSet<string> _amountStatTypes = ["ModifyHealth", "ModifyDefense", "ModifyMP"];
|
|
private static readonly HashSet<string> _valueTypes = [
|
|
"SetCanMove", "SetCanAttack", "SetCanDefend", "SetCanBeAttacked",
|
|
"SetCanBeBlocked", "SetCanBeObstructed", "SetCanUseAbility", "SetCanBeSacrificed",
|
|
"SetCanDrawCards", "SetAccumulatesSP", "SetCanChannelSpirit", "SetCanSacrificeSpirit",
|
|
"SetCanAscendArchSpirit", "SetCanTransitionArchSpirit",
|
|
"SetCanChannelRepentance", "SetCanChannelInstinct", "SetCanChannelRuin",
|
|
"SetCanChannelTerramorphaMono", "SetCanChannelTerramorphaDi", "SetCanChannelTerramorphaTri",
|
|
];
|
|
private static readonly HashSet<string> _affinityTypes = ["SetAffinity", "SetBaseAffinity1", "SetBaseAffinity2", "PushAffinity", "PushFinalAffinity"];
|
|
private static readonly HashSet<string> _rawJsonTypes = ["AddAbility", "ApplyOnEvent"];
|
|
private static readonly HashSet<string> _noFieldTypes = ["ReturnToHand", "SendToDiscard"];
|
|
|
|
// ── Trigger templates ────────────────────────────────────────────────────────
|
|
|
|
private static readonly Dictionary<string, string> TriggerTemplates = new()
|
|
{
|
|
["OnTurnStart"] = """{"$type":"OnTurnStart","Player":"Owner"}""",
|
|
["OnTurnEnd"] = """{"$type":"OnTurnEnd","Player":"Owner"}""",
|
|
["OnChanneled"] = """{"$type":"OnChanneled","CardType":"Spirit","Ownership":"Owner"}""",
|
|
["OnAscend"] = """{"$type":"OnAscend","Ownership":"Owner"}""",
|
|
["OnTransition"] = """{"$type":"OnTransition","Ownership":"Owner"}""",
|
|
["OnUnitMove"] = """{"$type":"OnUnitMove","Ownership":"Owner"}""",
|
|
["OnUnitAttack"] = """{"$type":"OnUnitAttack","Ownership":"Owner"}""",
|
|
["OnUnitAbilityActivated"] = """{"$type":"OnUnitAbilityActivated","Ownership":"Owner"}""",
|
|
["OnUnitMPSpent"] = """{"$type":"OnUnitMPSpent","Ownership":"Owner"}""",
|
|
["OnDamageDealt"] = """{"$type":"OnDamageDealt","SourceOwnership":"Any","TargetOwnership":"Any"}""",
|
|
["OnDamagePrevented"] = """{"$type":"OnDamagePrevented","TargetOwnership":"Any"}""",
|
|
["OnHealed"] = """{"$type":"OnHealed","TargetOwnership":"Any"}""",
|
|
["BeforeDamageApplied"] = """{"$type":"BeforeDamageApplied","SourceOwnership":"Any","TargetOwnership":"Any"}""",
|
|
["BeforeUnitDeath"] = """{"$type":"BeforeUnitDeath","UnitType":"Unit","Ownership":"Any"}""",
|
|
["OnUnitEnterBattlefield"] = """{"$type":"OnUnitEnterBattlefield","UnitType":"Unit","Ownership":"Any"}""",
|
|
["OnUnitLeaveBattlefield"] = """{"$type":"OnUnitLeaveBattlefield","UnitType":"Unit","Ownership":"Any"}""",
|
|
["OnUnitDeath"] = """{"$type":"OnUnitDeath","UnitType":"Unit","Ownership":"Any"}""",
|
|
["OnUnitSentToDiscard"] = """{"$type":"OnUnitSentToDiscard","UnitType":"Unit","Ownership":"Any"}""",
|
|
["OnSpiritSacrificed"] = """{"$type":"OnSpiritSacrificed","Ownership":"Any"}""",
|
|
["OnTokenSummoned"] = """{"$type":"OnTokenSummoned","Ownership":"Owner"}""",
|
|
["OnStatModified"] = """{"$type":"OnStatModified","Ownership":"Any"}""",
|
|
["OnAbilityAdded"] = """{"$type":"OnAbilityAdded","Ownership":"Any"}""",
|
|
["OnAbilityRemoved"] = """{"$type":"OnAbilityRemoved","Ownership":"Any"}""",
|
|
["OnGenusChanged"] = """{"$type":"OnGenusChanged","Ownership":"Any"}""",
|
|
["OnRuinActivation"] = """{"$type":"OnRuinActivation","RuinOwnership":"Any"}""",
|
|
["OnUnitOccupyRuin"] = """{"$type":"OnUnitOccupyRuin","UnitOwnership":"Any"}""",
|
|
["OnTileAffinityChanged"] = """{"$type":"OnTileAffinityChanged"}""",
|
|
["OnSPGained"] = """{"$type":"OnSPGained","Player":"Owner"}""",
|
|
["OnSPSpent"] = """{"$type":"OnSPSpent","Player":"Owner"}""",
|
|
["OnSTGained"] = """{"$type":"OnSTGained","Player":"Owner"}""",
|
|
["OnSTSpent"] = """{"$type":"OnSTSpent","Player":"Owner"}""",
|
|
["OnCardDrawn"] = """{"$type":"OnCardDrawn","Player":"Owner"}""",
|
|
["OnCardDiscarded"] = """{"$type":"OnCardDiscarded","Player":"Owner"}""",
|
|
["OnCardReturnedToHand"] = """{"$type":"OnCardReturnedToHand","Player":"Owner"}""",
|
|
["OnCardReturnedToDeck"] = """{"$type":"OnCardReturnedToDeck","Player":"Owner"}""",
|
|
["OnDeckShuffled"] = """{"$type":"OnDeckShuffled","Player":"Owner"}""",
|
|
["OnCardsRevealed"] = """{"$type":"OnCardsRevealed","Player":"Owner"}""",
|
|
["OnTargetedByAbility"] = """{"$type":"OnTargetedByAbility","TargetOwnership":"Owner","SourceOwnership":"Any"}""",
|
|
["OnEffectApplied"] = """{"$type":"OnEffectApplied","TargetOwnership":"Owner","SourceOwnership":"Any"}""",
|
|
["OnEnterAuraRange"] = """{"$type":"OnEnterAuraRange","AuraOwnership":"Owner","UnitOwnership":"Any"}""",
|
|
["OnLeaveAuraRange"] = """{"$type":"OnLeaveAuraRange","AuraOwnership":"Owner","UnitOwnership":"Any"}""",
|
|
};
|
|
|
|
// ── Lifecycle ────────────────────────────────────────────────────────────────
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(AbilitiesJson) && AbilitiesJson != _lastJson)
|
|
{
|
|
_lastJson = AbilitiesJson;
|
|
ParseJson(AbilitiesJson);
|
|
}
|
|
}
|
|
|
|
// ── Parse ────────────────────────────────────────────────────────────────────
|
|
|
|
private void ParseJson(string json)
|
|
{
|
|
try
|
|
{
|
|
_abilities.Clear();
|
|
var arr = JsonNode.Parse(json) as JsonArray ?? new JsonArray();
|
|
|
|
foreach (var node in arr.OfType<JsonObject>())
|
|
{
|
|
var ab = new AbilityDraft
|
|
{
|
|
TypeStr = node["Type"]?.GetValue<string>() ?? "Active",
|
|
Name = node["Name"]?.GetValue<string>() ?? "",
|
|
Description = node["Description"]?.GetValue<string>() ?? "",
|
|
UsesPerTurn = node["UsesPerTurn"]?.GetValue<int>() ?? 1,
|
|
TriggerLimitPerTurn = node["TriggerLimitPerTurn"]?.GetValue<int?>(),
|
|
RangeMin = node["Range"]?["Min"]?.GetValue<int>(),
|
|
RangeMax = node["Range"]?["Max"]?.GetValue<int>(),
|
|
RangeRequiresLos = node["Range"]?["RequiresLos"]?.GetValue<bool>() ?? false,
|
|
RangeLinearOnly = node["Range"]?["LinearOnly"]?.GetValue<bool>() ?? false,
|
|
AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue<int>(),
|
|
AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue<int>(),
|
|
AuraClearOnLeave = node["ClearOnLeave"]?.GetValue<bool>() ?? false,
|
|
AuraLingerDurationStr = node["LingerDuration"]?["Type"]?.GetValue<string>() ?? "",
|
|
AuraLingerDurationN = node["LingerDuration"]?["N"]?.GetValue<int>() ?? 1,
|
|
};
|
|
|
|
if (node["TriggerEvent"] is JsonNode trig)
|
|
{
|
|
ab.TriggerType = trig["$type"]?.GetValue<string>() ?? "";
|
|
ab.TriggerPlayer = trig["Player"]?.GetValue<string>() ?? "Owner";
|
|
ab.TriggerOwnership = trig["Ownership"]?.GetValue<string>() ?? "Owner";
|
|
ab.TriggerSourceOwnership = trig["SourceOwnership"]?.GetValue<string>() ?? "Any";
|
|
ab.TriggerTargetOwnership = trig["TargetOwnership"]?.GetValue<string>() ?? "Any";
|
|
ab.TriggerUnitType = trig["UnitType"]?.GetValue<string>() ?? "Unit";
|
|
ab.TriggerCardType = trig["CardType"]?.GetValue<string>() ?? "Spirit";
|
|
ab.TriggerDamageType = trig["DamageType"]?.GetValue<string>() ?? "Any";
|
|
ab.TriggerAmount = trig["Amount"] is JsonNode amtNode ? amtNode.GetValue<int>() : null;
|
|
ab.TriggerStat = trig["Stat"]?.GetValue<string>() ?? "";
|
|
ab.TriggerCause = trig["Cause"]?.GetValue<string>() ?? "";
|
|
ab.TriggerCausedBy = trig["CausedBy"]?.GetValue<string>() ?? "";
|
|
ab.TriggerRuinOwnership = trig["RuinOwnership"]?.GetValue<string>() ?? "Any";
|
|
ab.TriggerOccupantOwnership = trig["OccupantOwnership"]?.GetValue<string>() ?? "";
|
|
ab.TriggerUnitOwnership = trig["UnitOwnership"]?.GetValue<string>() ?? "Any";
|
|
ab.TriggerAuraOwnership = trig["AuraOwnership"]?.GetValue<string>() ?? "Owner";
|
|
}
|
|
|
|
if (node["Cost"] is JsonArray costs)
|
|
foreach (var c in costs.OfType<JsonObject>())
|
|
ab.Costs.Add(new CostDraft
|
|
{
|
|
TypeStr = c["Type"]?.GetValue<string>() ?? "SpiritPoints",
|
|
Amount = c["Amount"]?.GetValue<int>() ?? 1,
|
|
});
|
|
|
|
if (node["ActivationConditions"] is JsonArray aconds)
|
|
foreach (var c in aconds.OfType<JsonObject>())
|
|
ab.Conditions.Add(ParseCondition(c));
|
|
|
|
if (node["Actions"] is JsonArray actions)
|
|
foreach (var actionNode in actions.OfType<JsonObject>())
|
|
{
|
|
var target = actionNode["Target"] as JsonObject;
|
|
var firstFilter= (target?["Filters"] as JsonArray)?.OfType<JsonObject>().FirstOrDefault();
|
|
var act = new ActionDraft
|
|
{
|
|
Scope = target?["Scope"]?.GetValue<string>() ?? "Battlefield",
|
|
TargetType = target?["Type"]?.GetValue<string>() ?? "Unit",
|
|
Ownership = target?["Ownership"]?.GetValue<string>() ?? "Enemy",
|
|
Count = target?["Count"]?["N"]?.GetValue<int>() ?? 1,
|
|
All = target?["Count"]?["All"]?.GetValue<bool>() ?? false,
|
|
FilterType = firstFilter?["$type"]?.GetValue<string>() ?? "",
|
|
};
|
|
|
|
if (actionNode["Conditions"] is JsonArray actionConds)
|
|
foreach (var c in actionConds.OfType<JsonObject>())
|
|
act.Conditions.Add(ParseCondition(c));
|
|
|
|
if (actionNode["Effects"] is JsonArray effects)
|
|
foreach (var eff in effects.OfType<JsonObject>())
|
|
act.Effects.Add(ParseEffect(eff));
|
|
|
|
ab.Actions.Add(act);
|
|
}
|
|
|
|
if (node["Duration"] is JsonObject dur)
|
|
{
|
|
ab.DurationStr = dur["Type"]?.GetValue<string>() ?? "";
|
|
ab.DurationN = dur["N"]?.GetValue<int>() ?? 1;
|
|
}
|
|
|
|
if (node["Animation"] is JsonObject anim)
|
|
{
|
|
ab.HasAnimation = true;
|
|
ab.AnimationType = anim["Type"]?.GetValue<string>() ?? "Projectile";
|
|
ab.AnimationEffect = anim["Effect"]?.GetValue<string>() ?? "Target";
|
|
ab.AnimationAssetUrl = anim["AssetUrl"]?.GetValue<string>() ?? "";
|
|
ab.AnimationWidth = anim["Width"]?.GetValue<float>() ?? 1f;
|
|
ab.AnimationHeight = anim["Height"]?.GetValue<float>() ?? 1f;
|
|
ab.AnimationDuration = anim["Duration"]?.GetValue<float>() ?? 1f;
|
|
ab.CastSoundUrl = anim["CastSoundUrl"]?.GetValue<string>() ?? "";
|
|
ab.ImpactSoundUrl = anim["ImpactSoundUrl"]?.GetValue<string>() ?? "";
|
|
}
|
|
|
|
_abilities.Add(ab);
|
|
}
|
|
|
|
_compiledJson = json;
|
|
}
|
|
catch { /* invalid JSON — keep existing state */ }
|
|
}
|
|
|
|
private static ConditionDraft ParseCondition(JsonObject c) => new()
|
|
{
|
|
TypeStr = c["$type"]?.GetValue<string>() ?? "IsOwnTurn",
|
|
Subject = c["Subject"]?.GetValue<string>() ?? "Self",
|
|
N = c["N"]?.GetValue<int>() ?? 1,
|
|
Min = c["Min"]?.GetValue<int>() ?? 1,
|
|
Max = c["Max"]?.GetValue<int>() ?? 1,
|
|
Tag = c["Tag"]?.GetValue<string>() ?? "",
|
|
AbilityRef = c["AbilityRef"]?.GetValue<string>() ?? "",
|
|
Affinity = c["Affinity"]?.GetValue<string>() ?? "Aether",
|
|
UnitType = c["UnitType"]?.GetValue<string>() ?? "Unit",
|
|
Ownership = c["Ownership"]?.GetValue<string>() ?? "Any",
|
|
Target = c["Target"]?.GetValue<string>() ?? "Self",
|
|
MovementType = c["MovementType"]?.GetValue<string>() ?? "Walk",
|
|
Comparator = c["Comparator"]?.GetValue<string>() ?? "GreaterThanOrEqual",
|
|
Zone = c["Zone"]?.GetValue<string>() ?? "Hand",
|
|
CardRef = c["CardRef"]?.GetValue<string>() ?? "",
|
|
InnerConditionJson = c["Condition"]?.ToJsonString() ?? "{\"$type\":\"IsOwnTurn\"}",
|
|
};
|
|
|
|
private static EffectDraft ParseEffect(JsonObject eff)
|
|
{
|
|
var typeKey = eff["$type"]?.GetValue<string>() ?? "DealDamage";
|
|
var d = new EffectDraft { TypeKey = typeKey };
|
|
|
|
// ValueExpr helpers — eff[key] may be a raw JsonValue (legacy) or a JsonObject
|
|
// with a "Fixed" int field or a "Ref" string field. Calling GetValue<int>() on a
|
|
// JsonObject throws InvalidOperationException, so we branch on the node kind.
|
|
int ReadFixed(string key, int def = 1) =>
|
|
eff[key] is JsonObject o
|
|
? o["Fixed"]?.GetValue<int>() ?? def
|
|
: eff[key]?.GetValue<int>() ?? def;
|
|
string ReadRef(string key) =>
|
|
eff[key]?["Ref"]?.GetValue<string>() ?? "";
|
|
void ReadValueExpr(string key) { d.Amount = ReadFixed(key); d.AmountRef = ReadRef(key); }
|
|
|
|
string ReadStr(string key, string def = "") =>
|
|
eff[key]?.GetValue<string>() ?? def;
|
|
|
|
bool ReadBool(string key, bool def = false) =>
|
|
eff[key]?.GetValue<bool>() ?? def;
|
|
|
|
int ReadInt(string key, int def = 1) =>
|
|
eff[key]?.GetValue<int>() ?? def;
|
|
|
|
string ReadDurType() =>
|
|
eff["Duration"]?["Type"]?.GetValue<string>() ?? "UntilEndOfTurn";
|
|
|
|
int ReadDurN() =>
|
|
eff["Duration"]?["N"]?.GetValue<int>() ?? 1;
|
|
|
|
if (_amountBypassTypes.Contains(typeKey))
|
|
{
|
|
ReadValueExpr("Amount"); d.BypassDefense = ReadBool("BypassDefense");
|
|
}
|
|
else if (typeKey == "DOT")
|
|
{
|
|
ReadValueExpr("Amount"); d.BypassDefense = ReadBool("BypassDefense");
|
|
d.DurationType = ReadDurType(); d.DurationN = ReadDurN();
|
|
}
|
|
else if (typeKey == "HOT")
|
|
{
|
|
ReadValueExpr("Amount"); d.DurationType = ReadDurType(); d.DurationN = ReadDurN();
|
|
}
|
|
else if (_amountStatTypes.Contains(typeKey))
|
|
{
|
|
ReadValueExpr("Amount"); d.StatTarget = ReadStr("StatTarget", "Current");
|
|
}
|
|
else if (_amountOnlyTypes.Contains(typeKey))
|
|
{
|
|
ReadValueExpr("Amount");
|
|
}
|
|
else if (typeKey is "DrawCards" or "DiscardCards")
|
|
{
|
|
d.N = ReadInt("N"); d.Player = ReadStr("Player", "Owner");
|
|
}
|
|
else if (typeKey is "GrantAdditionalAttack" or "SearchDeck" or "RevealCards" or "GrantMovementControl" or "SetHealthMinimum")
|
|
{
|
|
d.N = ReadInt(typeKey == "SetHealthMinimum" ? "Minimum" : "N");
|
|
}
|
|
else if (_valueTypes.Contains(typeKey))
|
|
{
|
|
d.Value = ReadBool("Value", true);
|
|
}
|
|
else if (typeKey is "PushUnit" or "PullUnit")
|
|
{
|
|
d.Tiles = ReadInt("Tiles"); d.BlockedDamage = ReadInt("BlockedDamage", 0);
|
|
}
|
|
else if (typeKey == "DisplaceUnit")
|
|
{
|
|
d.Tiles = ReadInt("Tiles"); d.Direction = ReadStr("Direction", "North");
|
|
}
|
|
else if (typeKey == "RepositionUnit")
|
|
{
|
|
d.Tiles = ReadInt("Tiles");
|
|
d.AdjacentToSource = ReadBool("AdjacentToSource");
|
|
d.RelativeToTargetRef = ReadStr("RelativeToTargetRef", "");
|
|
d.AdjacentToRelativeTarget = ReadBool("AdjacentToRelativeTarget");
|
|
d.AllowRelativeTargetTile = ReadBool("AllowRelativeTargetTile");
|
|
}
|
|
else if (typeKey == "SetAttackRange")
|
|
{
|
|
d.Min = ReadInt("Min"); d.Max = ReadInt("Max", 2);
|
|
}
|
|
else if (_affinityTypes.Contains(typeKey))
|
|
{
|
|
d.Affinity = eff["Affinity"]?["Fixed"]?.GetValue<string>()
|
|
?? eff["Affinity"]?.GetValue<string>() ?? "Aether";
|
|
}
|
|
else if (typeKey is "AddGenus" or "RemoveGenus")
|
|
{
|
|
d.Tag = ReadStr("Tag");
|
|
}
|
|
else if (typeKey == "SetMovementType")
|
|
{
|
|
d.MovementType = ReadStr("MovementType", "Walk");
|
|
}
|
|
else if (typeKey == "ShuffleDeck")
|
|
{
|
|
d.Player = ReadStr("Player", "Owner");
|
|
}
|
|
else if (typeKey is "ReturnToDeck" or "PlaceOnDeck")
|
|
{
|
|
d.Position = ReadStr("Position", "Top");
|
|
}
|
|
else if (typeKey == "ReturnToBattlefield")
|
|
{
|
|
d.Controller = ReadStr("Controller", "Owner");
|
|
}
|
|
else if (typeKey == "ChannelCard")
|
|
{
|
|
d.PayCost = ReadBool("PayCost", true);
|
|
}
|
|
else if (typeKey == "TakeControl")
|
|
{
|
|
d.DurationType = ReadDurType(); d.DurationN = ReadDurN();
|
|
}
|
|
else if (typeKey == "SetFixedSacrificeReturn")
|
|
{
|
|
d.StAmount = ReadInt("StAmount");
|
|
}
|
|
else if (typeKey == "ModifyCost")
|
|
{
|
|
d.Sp = eff["Sp"]?.GetValue<int?>(); d.St = eff["St"]?.GetValue<int?>();
|
|
}
|
|
else if (typeKey == "SetStatModMultiplier")
|
|
{
|
|
d.Stat = ReadStr("Stat", "Damage"); d.Multiplier = eff["Multiplier"]?.GetValue<float>() ?? 1.5f;
|
|
}
|
|
else if (typeKey is "RemoveAbility" or "EnableAbility" or "DisableAbility")
|
|
{
|
|
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();
|
|
foreach (var prop in eff)
|
|
if (prop.Key != "$type")
|
|
fields[prop.Key] = prop.Value?.DeepClone();
|
|
d.RawJson = fields.ToJsonString();
|
|
}
|
|
|
|
return d;
|
|
}
|
|
|
|
// ── Compile ──────────────────────────────────────────────────────────────────
|
|
|
|
private void Compile()
|
|
{
|
|
try
|
|
{
|
|
var arr = new JsonArray();
|
|
|
|
foreach (var ab in _abilities)
|
|
{
|
|
var node = new JsonObject
|
|
{
|
|
["Type"] = ab.TypeStr,
|
|
["Name"] = ab.Name,
|
|
["Description"] = ab.Description,
|
|
};
|
|
|
|
if (ab.TypeStr == "Active")
|
|
{
|
|
if (ab.RangeMin.HasValue || ab.RangeMax.HasValue)
|
|
{
|
|
var rangeNode = new JsonObject
|
|
{
|
|
["Min"] = ab.RangeMin ?? 1,
|
|
["Max"] = ab.RangeMax ?? 1,
|
|
};
|
|
if (ab.RangeRequiresLos) rangeNode["RequiresLos"] = true;
|
|
if (ab.RangeLinearOnly) rangeNode["LinearOnly"] = true;
|
|
node["Range"] = rangeNode;
|
|
}
|
|
node["UsesPerTurn"] = ab.UsesPerTurn;
|
|
|
|
if (ab.Costs.Count > 0)
|
|
{
|
|
var costsArr = new JsonArray();
|
|
foreach (var cost in ab.Costs)
|
|
costsArr.Add(new JsonObject { ["Type"] = cost.TypeStr, ["Amount"] = cost.Amount });
|
|
node["Cost"] = costsArr;
|
|
}
|
|
}
|
|
else if (ab.TypeStr == "Aura")
|
|
{
|
|
if (ab.AuraRangeMin.HasValue || ab.AuraRangeMax.HasValue)
|
|
node["AuraRange"] = new JsonObject
|
|
{
|
|
["Min"] = ab.AuraRangeMin ?? 1,
|
|
["Max"] = ab.AuraRangeMax ?? 1,
|
|
};
|
|
if (!string.IsNullOrEmpty(ab.AuraLingerDurationStr))
|
|
{
|
|
var ld = new JsonObject { ["Type"] = ab.AuraLingerDurationStr };
|
|
if (ab.AuraLingerDurationStr == "ForNTurns") ld["N"] = ab.AuraLingerDurationN;
|
|
node["LingerDuration"] = ld;
|
|
}
|
|
else if (ab.AuraClearOnLeave)
|
|
node["ClearOnLeave"] = true;
|
|
}
|
|
else if (ab.TypeStr == "Triggered" && !string.IsNullOrEmpty(ab.TriggerType))
|
|
{
|
|
node["TriggerEvent"] = CompileTrigger(ab);
|
|
if (ab.TriggerLimitPerTurn is > 0)
|
|
node["TriggerLimitPerTurn"] = ab.TriggerLimitPerTurn.Value;
|
|
}
|
|
|
|
if (ab.Conditions.Count > 0)
|
|
{
|
|
var ca = new JsonArray();
|
|
foreach (var c in ab.Conditions) ca.Add(CompileCondition(c));
|
|
node["ActivationConditions"] = ca;
|
|
}
|
|
|
|
var actionsArr = new JsonArray();
|
|
foreach (var action in ab.Actions)
|
|
{
|
|
var targetNode = new JsonObject
|
|
{
|
|
["Scope"] = action.Scope,
|
|
["Type"] = action.TargetType,
|
|
["Ownership"] = action.Ownership,
|
|
["Count"] = new JsonObject
|
|
{
|
|
["N"] = action.All ? 1 : action.Count,
|
|
["UpTo"] = false,
|
|
["All"] = action.All,
|
|
},
|
|
};
|
|
if (!string.IsNullOrEmpty(action.FilterType))
|
|
targetNode["Filters"] = new JsonArray(
|
|
new JsonObject { ["$type"] = action.FilterType });
|
|
var actionNode = new JsonObject { ["Target"] = targetNode };
|
|
|
|
if (action.Conditions.Count > 0)
|
|
{
|
|
var ca = new JsonArray();
|
|
foreach (var c in action.Conditions) ca.Add(CompileCondition(c));
|
|
actionNode["Conditions"] = ca;
|
|
}
|
|
|
|
var effectsArr = new JsonArray();
|
|
foreach (var eff in action.Effects)
|
|
effectsArr.Add(CompileEffect(eff));
|
|
actionNode["Effects"] = effectsArr;
|
|
actionsArr.Add(actionNode);
|
|
}
|
|
|
|
node["Actions"] = actionsArr;
|
|
|
|
if (!string.IsNullOrEmpty(ab.DurationStr))
|
|
{
|
|
var durNode = new JsonObject { ["Type"] = ab.DurationStr };
|
|
if (ab.DurationStr == "ForNTurns") durNode["N"] = ab.DurationN;
|
|
node["Duration"] = durNode;
|
|
}
|
|
|
|
if (ab.HasAnimation)
|
|
{
|
|
var animNode = new JsonObject
|
|
{
|
|
["Type"] = ab.AnimationType,
|
|
["Effect"] = ab.AnimationEffect,
|
|
["Width"] = ab.AnimationWidth,
|
|
["Height"] = ab.AnimationHeight,
|
|
["Duration"] = ab.AnimationDuration,
|
|
};
|
|
if (!string.IsNullOrWhiteSpace(ab.AnimationAssetUrl))
|
|
animNode["AssetUrl"] = ab.AnimationAssetUrl;
|
|
if (!string.IsNullOrWhiteSpace(ab.CastSoundUrl))
|
|
animNode["CastSoundUrl"] = ab.CastSoundUrl;
|
|
if (!string.IsNullOrWhiteSpace(ab.ImpactSoundUrl))
|
|
animNode["ImpactSoundUrl"] = ab.ImpactSoundUrl;
|
|
node["Animation"] = animNode;
|
|
}
|
|
|
|
arr.Add(node);
|
|
}
|
|
|
|
_compiledJson = arr.ToJsonString(new JsonSerializerOptions { WriteIndented = true });
|
|
_ = AbilitiesJsonChanged.InvokeAsync(_compiledJson);
|
|
}
|
|
catch { /* keep last valid */ }
|
|
}
|
|
|
|
private static JsonObject CompileCondition(ConditionDraft c)
|
|
{
|
|
var node = new JsonObject { ["$type"] = c.TypeStr };
|
|
if (c.Subject != "Self") node["Subject"] = c.Subject;
|
|
|
|
switch (c.TypeStr)
|
|
{
|
|
case "HealthBelow": case "HealthAbove": case "DefenseIs":
|
|
case "SPAtLeast": case "SPAtMost": case "STAtLeast": case "STAtMost":
|
|
case "HandSizeAtLeast": case "HandSizeAtMost":
|
|
case "DeckSizeAtLeast": case "DiscardSizeAtLeast":
|
|
node["N"] = c.N; break;
|
|
case "HasGenus":
|
|
node["Tag"] = c.Tag; break;
|
|
case "HasAbility":
|
|
node["AbilityRef"] = c.AbilityRef; break;
|
|
case "IsOnTileWithAffinity":
|
|
case "TileAffinityMatches":
|
|
case "DestinationTileAffinityIs":
|
|
case "PreviousTileAffinityIs":
|
|
case "MovedFromOrIntoAffinity":
|
|
node["Affinity"] = c.Affinity; break;
|
|
case "IsAdjacentTo":
|
|
node["UnitType"] = c.UnitType; node["Ownership"] = c.Ownership; break;
|
|
case "WithinRangeOf":
|
|
node["Target"] = c.Target; node["Min"] = c.Min; node["Max"] = c.Max; break;
|
|
case "MovementTypeIs":
|
|
node["MovementType"] = c.MovementType; break;
|
|
case "TileIsOccupied":
|
|
if (!string.IsNullOrEmpty(c.UnitType)) node["UnitType"] = c.UnitType; break;
|
|
case "IsActivePlayerTurn":
|
|
node["Ownership"] = c.Ownership; break;
|
|
case "UnitCountOnBattlefield":
|
|
node["Ownership"] = c.Ownership; node["UnitType"] = c.UnitType;
|
|
node["Comparator"] = c.Comparator; node["N"] = c.N; break;
|
|
case "CardInZone":
|
|
node["CardRef"] = c.CardRef; node["Zone"] = c.Zone; break;
|
|
case "NOT":
|
|
try
|
|
{
|
|
var inner = JsonNode.Parse(string.IsNullOrWhiteSpace(c.InnerConditionJson)
|
|
? "{\"$type\":\"IsOwnTurn\"}"
|
|
: c.InnerConditionJson) as JsonObject;
|
|
node["Condition"] = inner ?? new JsonObject { ["$type"] = "IsOwnTurn" };
|
|
}
|
|
catch
|
|
{
|
|
node["Condition"] = new JsonObject { ["$type"] = "IsOwnTurn" };
|
|
}
|
|
break;
|
|
}
|
|
return node;
|
|
}
|
|
|
|
private static JsonObject CompileTrigger(AbilityDraft ab)
|
|
{
|
|
var t = ab.TriggerType;
|
|
var n = new JsonObject { ["$type"] = t };
|
|
|
|
// Player-only
|
|
if (t is "OnTurnStart" or "OnTurnEnd" or "OnCardDrawn"
|
|
or "OnCardReturnedToHand" or "OnCardReturnedToDeck"
|
|
or "OnDeckShuffled" or "OnCardsRevealed")
|
|
{
|
|
n["Player"] = ab.TriggerPlayer;
|
|
}
|
|
// Player + optional Amount
|
|
else if (t is "OnSPGained" or "OnSPSpent" or "OnSTGained" or "OnSTSpent")
|
|
{
|
|
n["Player"] = ab.TriggerPlayer;
|
|
if (ab.TriggerAmount.HasValue) n["Amount"] = ab.TriggerAmount.Value;
|
|
}
|
|
// Player + optional Cause
|
|
else if (t == "OnCardDiscarded")
|
|
{
|
|
n["Player"] = ab.TriggerPlayer;
|
|
if (!string.IsNullOrEmpty(ab.TriggerCause)) n["Cause"] = ab.TriggerCause;
|
|
}
|
|
// Ownership-only
|
|
else if (t is "OnAscend" or "OnTransition" or "OnUnitMove" or "OnUnitAttack"
|
|
or "OnUnitAbilityActivated" or "OnSpiritSacrificed" or "OnTokenSummoned"
|
|
or "OnAbilityAdded" or "OnAbilityRemoved" or "OnGenusChanged")
|
|
{
|
|
n["Ownership"] = ab.TriggerOwnership;
|
|
}
|
|
// Ownership + optional Amount
|
|
else if (t == "OnUnitMPSpent")
|
|
{
|
|
n["Ownership"] = ab.TriggerOwnership;
|
|
if (ab.TriggerAmount.HasValue) n["Amount"] = ab.TriggerAmount.Value;
|
|
}
|
|
// Ownership + optional Stat
|
|
else if (t == "OnStatModified")
|
|
{
|
|
n["Ownership"] = ab.TriggerOwnership;
|
|
if (!string.IsNullOrEmpty(ab.TriggerStat)) n["Stat"] = ab.TriggerStat;
|
|
}
|
|
// Ownership + CardType
|
|
else if (t == "OnChanneled")
|
|
{
|
|
n["Ownership"] = ab.TriggerOwnership;
|
|
n["CardType"] = ab.TriggerCardType;
|
|
}
|
|
// Ownership + UnitType
|
|
else if (t is "OnUnitEnterBattlefield" or "OnUnitLeaveBattlefield" or "OnUnitDeath" or "BeforeUnitDeath")
|
|
{
|
|
n["Ownership"] = ab.TriggerOwnership;
|
|
n["UnitType"] = ab.TriggerUnitType;
|
|
}
|
|
// Ownership + UnitType + optional CausedBy
|
|
else if (t == "OnUnitSentToDiscard")
|
|
{
|
|
n["Ownership"] = ab.TriggerOwnership;
|
|
n["UnitType"] = ab.TriggerUnitType;
|
|
if (!string.IsNullOrEmpty(ab.TriggerCausedBy)) n["CausedBy"] = ab.TriggerCausedBy;
|
|
}
|
|
// SourceOwnership + TargetOwnership + optional DamageType + optional Amount
|
|
else if (t == "OnDamageDealt")
|
|
{
|
|
n["SourceOwnership"] = ab.TriggerSourceOwnership;
|
|
n["TargetOwnership"] = ab.TriggerTargetOwnership;
|
|
if (ab.TriggerDamageType != "Any") n["DamageType"] = ab.TriggerDamageType;
|
|
if (ab.TriggerAmount.HasValue) n["Amount"] = ab.TriggerAmount.Value;
|
|
}
|
|
else if (t == "BeforeDamageApplied")
|
|
{
|
|
n["SourceOwnership"] = ab.TriggerSourceOwnership;
|
|
n["TargetOwnership"] = ab.TriggerTargetOwnership;
|
|
}
|
|
// TargetOwnership only
|
|
else if (t == "OnDamagePrevented")
|
|
{
|
|
n["TargetOwnership"] = ab.TriggerTargetOwnership;
|
|
}
|
|
// TargetOwnership + optional Amount
|
|
else if (t == "OnHealed")
|
|
{
|
|
n["TargetOwnership"] = ab.TriggerTargetOwnership;
|
|
if (ab.TriggerAmount.HasValue) n["Amount"] = ab.TriggerAmount.Value;
|
|
}
|
|
// TargetOwnership + SourceOwnership
|
|
else if (t is "OnTargetedByAbility" or "OnEffectApplied")
|
|
{
|
|
n["TargetOwnership"] = ab.TriggerTargetOwnership;
|
|
n["SourceOwnership"] = ab.TriggerSourceOwnership;
|
|
}
|
|
// RuinOwnership + optional OccupantOwnership
|
|
else if (t == "OnRuinActivation")
|
|
{
|
|
n["RuinOwnership"] = ab.TriggerRuinOwnership;
|
|
if (!string.IsNullOrEmpty(ab.TriggerOccupantOwnership))
|
|
n["OccupantOwnership"] = ab.TriggerOccupantOwnership;
|
|
}
|
|
// UnitOwnership only
|
|
else if (t == "OnUnitOccupyRuin")
|
|
{
|
|
n["UnitOwnership"] = ab.TriggerUnitOwnership;
|
|
}
|
|
// AuraOwnership + UnitOwnership
|
|
else if (t is "OnEnterAuraRange" or "OnLeaveAuraRange")
|
|
{
|
|
n["AuraOwnership"] = ab.TriggerAuraOwnership;
|
|
n["UnitOwnership"] = ab.TriggerUnitOwnership;
|
|
}
|
|
// OnTileAffinityChanged: no additional fields
|
|
|
|
return n;
|
|
}
|
|
|
|
private static JsonObject CompileEffect(EffectDraft d)
|
|
{
|
|
var node = new JsonObject { ["$type"] = d.TypeKey };
|
|
|
|
JsonObject ValueExpr() => string.IsNullOrEmpty(d.AmountRef)
|
|
? new JsonObject { ["Fixed"] = d.Amount }
|
|
: new JsonObject { ["Ref"] = d.AmountRef };
|
|
JsonObject Duration() => d.DurationType == "ForNTurns"
|
|
? new JsonObject { ["Type"] = d.DurationType, ["N"] = d.DurationN }
|
|
: new JsonObject { ["Type"] = d.DurationType };
|
|
|
|
if (_amountBypassTypes.Contains(d.TypeKey))
|
|
{
|
|
node["Amount"] = ValueExpr(); node["BypassDefense"] = d.BypassDefense;
|
|
}
|
|
else if (d.TypeKey == "DOT")
|
|
{
|
|
node["Amount"] = ValueExpr(); node["BypassDefense"] = d.BypassDefense;
|
|
node["Duration"] = Duration();
|
|
}
|
|
else if (d.TypeKey == "HOT")
|
|
{
|
|
node["Amount"] = ValueExpr(); node["Duration"] = Duration();
|
|
}
|
|
else if (_amountStatTypes.Contains(d.TypeKey))
|
|
{
|
|
node["Amount"] = ValueExpr(); node["StatTarget"] = d.StatTarget;
|
|
}
|
|
else if (_amountOnlyTypes.Contains(d.TypeKey))
|
|
{
|
|
node["Amount"] = ValueExpr();
|
|
}
|
|
else if (d.TypeKey is "DrawCards" or "DiscardCards")
|
|
{
|
|
node["N"] = d.N; node["Player"] = d.Player;
|
|
}
|
|
else if (d.TypeKey is "GrantAdditionalAttack" or "SearchDeck" or "RevealCards" or "GrantMovementControl")
|
|
{
|
|
node["N"] = d.N;
|
|
}
|
|
else if (d.TypeKey == "SetHealthMinimum")
|
|
{
|
|
node["Minimum"] = d.N;
|
|
}
|
|
else if (_valueTypes.Contains(d.TypeKey))
|
|
{
|
|
node["Value"] = d.Value;
|
|
}
|
|
else if (d.TypeKey is "PushUnit" or "PullUnit")
|
|
{
|
|
node["Tiles"] = d.Tiles;
|
|
if (d.BlockedDamage > 0) node["BlockedDamage"] = d.BlockedDamage;
|
|
}
|
|
else if (d.TypeKey == "DisplaceUnit")
|
|
{
|
|
node["Tiles"] = d.Tiles; node["Direction"] = d.Direction;
|
|
}
|
|
else if (d.TypeKey == "RepositionUnit")
|
|
{
|
|
node["Tiles"] = d.Tiles;
|
|
if (d.AdjacentToSource) node["AdjacentToSource"] = true;
|
|
if (!string.IsNullOrWhiteSpace(d.RelativeToTargetRef)) node["RelativeToTargetRef"] = d.RelativeToTargetRef;
|
|
if (d.AdjacentToRelativeTarget) node["AdjacentToRelativeTarget"] = true;
|
|
if (d.AllowRelativeTargetTile) node["AllowRelativeTargetTile"] = true;
|
|
}
|
|
else if (d.TypeKey == "SetAttackRange")
|
|
{
|
|
node["Min"] = d.Min; node["Max"] = d.Max;
|
|
}
|
|
else if (_affinityTypes.Contains(d.TypeKey))
|
|
{
|
|
node["Affinity"] = new JsonObject { ["Fixed"] = d.Affinity };
|
|
}
|
|
else if (d.TypeKey is "AddGenus" or "RemoveGenus")
|
|
{
|
|
node["Tag"] = d.Tag;
|
|
}
|
|
else if (d.TypeKey == "SetMovementType")
|
|
{
|
|
node["MovementType"] = d.MovementType;
|
|
}
|
|
else if (d.TypeKey == "ShuffleDeck")
|
|
{
|
|
node["Player"] = d.Player;
|
|
}
|
|
else if (d.TypeKey is "ReturnToDeck" or "PlaceOnDeck")
|
|
{
|
|
node["Position"] = d.Position;
|
|
}
|
|
else if (d.TypeKey == "ReturnToBattlefield")
|
|
{
|
|
node["Controller"] = d.Controller;
|
|
}
|
|
else if (d.TypeKey == "ChannelCard")
|
|
{
|
|
node["PayCost"] = d.PayCost;
|
|
}
|
|
else if (d.TypeKey == "TakeControl")
|
|
{
|
|
node["Duration"] = Duration();
|
|
}
|
|
else if (d.TypeKey == "SetFixedSacrificeReturn")
|
|
{
|
|
node["StAmount"] = d.StAmount;
|
|
}
|
|
else if (d.TypeKey == "ModifyCost")
|
|
{
|
|
if (d.Sp.HasValue) node["Sp"] = d.Sp.Value;
|
|
if (d.St.HasValue) node["St"] = d.St.Value;
|
|
}
|
|
else if (d.TypeKey == "SetStatModMultiplier")
|
|
{
|
|
node["Stat"] = d.Stat; node["Multiplier"] = d.Multiplier;
|
|
}
|
|
else if (d.TypeKey is "RemoveAbility" or "EnableAbility" or "DisableAbility")
|
|
{
|
|
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"] = "TileAffinityMatches", ["Affinity"] = d.TokenAffinity });
|
|
}
|
|
}
|
|
else if (_rawJsonTypes.Contains(d.TypeKey))
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(d.RawJson))
|
|
{
|
|
try
|
|
{
|
|
var fields = JsonNode.Parse(d.RawJson)?.AsObject();
|
|
if (fields != null)
|
|
foreach (var prop in fields)
|
|
node[prop.Key] = prop.Value?.DeepClone();
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
// _noFieldTypes: nothing extra to add
|
|
|
|
return node;
|
|
}
|
|
|
|
// ── Per-type field renderers (RenderFragment) ─────────────────────────────────
|
|
|
|
private RenderFragment RenderConditionFields(ConditionDraft c) => __builder =>
|
|
{
|
|
var t = c.TypeStr;
|
|
|
|
if (t is "HealthBelow" or "HealthAbove" or "DefenseIs" or
|
|
"SPAtLeast" or "SPAtMost" or "STAtLeast" or "STAtMost" or
|
|
"HandSizeAtLeast" or "HandSizeAtMost" or
|
|
"DeckSizeAtLeast" or "DiscardSizeAtLeast")
|
|
{
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "type", "number");
|
|
__builder.AddAttribute(2, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(3, "style", "width:80px");
|
|
__builder.AddAttribute(4, "placeholder", "N");
|
|
__builder.AddAttribute(5, "title", "N");
|
|
__builder.AddAttribute(6, "value", c.N);
|
|
__builder.AddAttribute(7, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { c.N = int.TryParse(e.Value?.ToString(), out var v) ? v : c.N; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (t == "HasGenus")
|
|
{
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(2, "style", "width:120px");
|
|
__builder.AddAttribute(3, "placeholder", "Tag");
|
|
__builder.AddAttribute(4, "value", c.Tag);
|
|
__builder.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { c.Tag = e.Value?.ToString() ?? ""; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (t == "HasAbility")
|
|
{
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(2, "style", "width:150px");
|
|
__builder.AddAttribute(3, "placeholder", "AbilityRef");
|
|
__builder.AddAttribute(4, "value", c.AbilityRef);
|
|
__builder.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { c.AbilityRef = e.Value?.ToString() ?? ""; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (t is "IsOnTileWithAffinity" or "TileAffinityMatches" or "DestinationTileAffinityIs" or "PreviousTileAffinityIs" or "MovedFromOrIntoAffinity")
|
|
{
|
|
BuildSelect(__builder, AffinityValues, c.Affinity, v => { c.Affinity = v; Compile(); }, 120);
|
|
}
|
|
else if (t == "IsAdjacentTo")
|
|
{
|
|
BuildSelect(__builder, UnitTypeValues, c.UnitType, v => { c.UnitType = v; Compile(); }, 100);
|
|
BuildSelect(__builder, OwnershipValues, c.Ownership, v => { c.Ownership = v; Compile(); }, 90);
|
|
}
|
|
else if (t == "WithinRangeOf")
|
|
{
|
|
BuildIntInput(__builder, c.Min, v => { c.Min = v; Compile(); }, 60, "Min");
|
|
BuildIntInput(__builder, c.Max, v => { c.Max = v; Compile(); }, 60, "Max");
|
|
}
|
|
else if (t == "MovementTypeIs")
|
|
{
|
|
BuildSelect(__builder, MovementTypeValues, c.MovementType, v => { c.MovementType = v; Compile(); }, 100);
|
|
}
|
|
else if (t == "TileIsOccupied")
|
|
{
|
|
BuildSelect(__builder, UnitTypeValues, c.UnitType, v => { c.UnitType = v; Compile(); }, 110);
|
|
}
|
|
else if (t == "IsActivePlayerTurn")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, c.Ownership, v => { c.Ownership = v; Compile(); }, 90);
|
|
}
|
|
else if (t == "UnitCountOnBattlefield")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, c.Ownership, v => { c.Ownership = v; Compile(); }, 90);
|
|
BuildSelect(__builder, UnitTypeValues, c.UnitType, v => { c.UnitType = v; Compile(); }, 100);
|
|
BuildSelect(__builder, ComparatorValues, c.Comparator, v => { c.Comparator = v; Compile(); }, 150);
|
|
BuildIntInput(__builder, c.N, v => { c.N = v; Compile(); }, 60, "N");
|
|
}
|
|
else if (t == "CardInZone")
|
|
{
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(2, "style", "width:130px");
|
|
__builder.AddAttribute(3, "placeholder", "CardRef");
|
|
__builder.AddAttribute(4, "value", c.CardRef);
|
|
__builder.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { c.CardRef = e.Value?.ToString() ?? ""; Compile(); }));
|
|
__builder.CloseElement();
|
|
BuildSelect(__builder, ZoneValues, c.Zone, v => { c.Zone = v; Compile(); }, 110);
|
|
}
|
|
else if (t == "NOT")
|
|
{
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm font-monospace");
|
|
__builder.AddAttribute(2, "style", "width:360px");
|
|
__builder.AddAttribute(3, "placeholder", "Inner condition JSON e.g. {\"$type\":\"IsOwnTurn\"}");
|
|
__builder.AddAttribute(4, "value", c.InnerConditionJson);
|
|
__builder.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { c.InnerConditionJson = e.Value?.ToString() ?? ""; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
// AND/OR/XOR + no-field types: no extra inputs
|
|
};
|
|
|
|
private RenderFragment RenderEffectFields(EffectDraft d, int actionIdx = 0, bool isTriggered = false) => __builder =>
|
|
{
|
|
var t = d.TypeKey;
|
|
|
|
if (_amountBypassTypes.Contains(t))
|
|
{
|
|
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
|
|
BuildCheckbox(__builder, "BypassDefense", d.BypassDefense, v => { d.BypassDefense = v; Compile(); });
|
|
}
|
|
else if (t == "DOT")
|
|
{
|
|
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
|
|
BuildCheckbox(__builder, "BypassDefense", d.BypassDefense, v => { d.BypassDefense = v; Compile(); });
|
|
BuildDuration(__builder, d);
|
|
}
|
|
else if (t == "HOT")
|
|
{
|
|
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
|
|
BuildDuration(__builder, d);
|
|
}
|
|
else if (_amountStatTypes.Contains(t))
|
|
{
|
|
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
|
|
BuildSelect(__builder, StatTargetValues, d.StatTarget, v => { d.StatTarget = v; Compile(); }, 100);
|
|
}
|
|
else if (_amountOnlyTypes.Contains(t))
|
|
{
|
|
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
|
|
}
|
|
else if (t is "DrawCards" or "DiscardCards")
|
|
{
|
|
BuildIntInput(__builder, d.N, v => { d.N = v; Compile(); }, 70, "N");
|
|
BuildSelect(__builder, PlayerValues, d.Player, v => { d.Player = v; Compile(); }, 100);
|
|
}
|
|
else if (t is "GrantAdditionalAttack" or "SearchDeck" or "RevealCards" or "GrantMovementControl")
|
|
{
|
|
BuildIntInput(__builder, d.N, v => { d.N = v; Compile(); }, 70, "N");
|
|
}
|
|
else if (t == "SetHealthMinimum")
|
|
{
|
|
BuildIntInput(__builder, d.N, v => { d.N = v; Compile(); }, 90, "Minimum");
|
|
}
|
|
else if (_valueTypes.Contains(t))
|
|
{
|
|
BuildCheckbox(__builder, "Value", d.Value, v => { d.Value = v; Compile(); });
|
|
}
|
|
else if (t is "PushUnit" or "PullUnit")
|
|
{
|
|
BuildIntInput(__builder, d.Tiles, v => { d.Tiles = v; Compile(); }, 70, "Tiles");
|
|
BuildIntInput(__builder, d.BlockedDamage, v => { d.BlockedDamage = v; Compile(); }, 90, "BlockedDmg");
|
|
}
|
|
else if (t == "DisplaceUnit")
|
|
{
|
|
BuildIntInput(__builder, d.Tiles, v => { d.Tiles = v; Compile(); }, 70, "Tiles");
|
|
BuildSelect(__builder, DirectionValues, d.Direction, v => { d.Direction = v; Compile(); }, 110);
|
|
}
|
|
else if (t == "RepositionUnit")
|
|
{
|
|
BuildIntInput(__builder, d.Tiles, v => { d.Tiles = v; Compile(); }, 70, "Tiles");
|
|
BuildCheckbox(__builder, "Adj Source", d.AdjacentToSource, v => { d.AdjacentToSource = v; Compile(); });
|
|
BuildCheckbox(__builder, "Adj Ref", d.AdjacentToRelativeTarget, v => { d.AdjacentToRelativeTarget = v; Compile(); });
|
|
BuildCheckbox(__builder, "Allow Ref Tile", d.AllowRelativeTargetTile, v => { d.AllowRelativeTargetTile = v; Compile(); });
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(2, "style", "width:160px");
|
|
__builder.AddAttribute(3, "placeholder", "RelativeToTargetRef");
|
|
__builder.AddAttribute(4, "value", d.RelativeToTargetRef);
|
|
__builder.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.RelativeToTargetRef = e.Value?.ToString() ?? ""; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (t == "SetAttackRange")
|
|
{
|
|
BuildIntInput(__builder, d.Min, v => { d.Min = v; Compile(); }, 70, "Min");
|
|
BuildIntInput(__builder, d.Max, v => { d.Max = v; Compile(); }, 70, "Max");
|
|
}
|
|
else if (_affinityTypes.Contains(t))
|
|
{
|
|
BuildSelect(__builder, AffinityValues, d.Affinity, v => { d.Affinity = v; Compile(); }, 150);
|
|
}
|
|
else if (t is "AddGenus" or "RemoveGenus")
|
|
{
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(2, "style", "width:130px");
|
|
__builder.AddAttribute(3, "placeholder", "Tag");
|
|
__builder.AddAttribute(4, "value", d.Tag);
|
|
__builder.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.Tag = e.Value?.ToString() ?? ""; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (t == "SetMovementType")
|
|
{
|
|
BuildSelect(__builder, MovementTypeValues, d.MovementType, v => { d.MovementType = v; Compile(); }, 110);
|
|
}
|
|
else if (t == "ShuffleDeck")
|
|
{
|
|
BuildSelect(__builder, PlayerValues, d.Player, v => { d.Player = v; Compile(); }, 110);
|
|
}
|
|
else if (t is "ReturnToDeck" or "PlaceOnDeck")
|
|
{
|
|
BuildSelect(__builder, PositionValues, d.Position, v => { d.Position = v; Compile(); }, 90);
|
|
}
|
|
else if (t == "ReturnToBattlefield")
|
|
{
|
|
BuildSelect(__builder, ControllerValues, d.Controller, v => { d.Controller = v; Compile(); }, 110);
|
|
}
|
|
else if (t == "ChannelCard")
|
|
{
|
|
BuildCheckbox(__builder, "Pay Cost", d.PayCost, v => { d.PayCost = v; Compile(); });
|
|
}
|
|
else if (t == "TakeControl")
|
|
{
|
|
BuildDuration(__builder, d);
|
|
}
|
|
else if (t == "SetFixedSacrificeReturn")
|
|
{
|
|
BuildIntInput(__builder, d.StAmount, v => { d.StAmount = v; Compile(); }, 80, "ST Amount");
|
|
}
|
|
else if (t == "ModifyCost")
|
|
{
|
|
// SP nullable
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "type", "number");
|
|
__builder.AddAttribute(2, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(3, "style", "width:80px");
|
|
__builder.AddAttribute(4, "placeholder", "SP");
|
|
__builder.AddAttribute(5, "title", "SP delta (leave blank = no change)");
|
|
__builder.AddAttribute(6, "value", d.Sp?.ToString() ?? "");
|
|
__builder.AddAttribute(7, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.Sp = int.TryParse(e.Value?.ToString(), out var v) ? v : null; Compile(); }));
|
|
__builder.CloseElement();
|
|
// ST nullable
|
|
__builder.OpenElement(8, "input");
|
|
__builder.AddAttribute(9, "type", "number");
|
|
__builder.AddAttribute(10, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(11, "style", "width:80px");
|
|
__builder.AddAttribute(12, "placeholder", "ST");
|
|
__builder.AddAttribute(13, "title", "ST delta (leave blank = no change)");
|
|
__builder.AddAttribute(14, "value", d.St?.ToString() ?? "");
|
|
__builder.AddAttribute(15, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.St = int.TryParse(e.Value?.ToString(), out var v) ? v : null; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (t == "SetStatModMultiplier")
|
|
{
|
|
BuildSelect(__builder, StatValues, d.Stat, v => { d.Stat = v; Compile(); }, 100);
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "type", "number");
|
|
__builder.AddAttribute(2, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(3, "style", "width:90px");
|
|
__builder.AddAttribute(4, "step", "0.1");
|
|
__builder.AddAttribute(5, "title", "Multiplier");
|
|
__builder.AddAttribute(6, "value", d.Multiplier.ToString("F1", System.Globalization.CultureInfo.InvariantCulture));
|
|
__builder.AddAttribute(7, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.Multiplier = float.TryParse(e.Value?.ToString(), System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out var v) ? v : d.Multiplier; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (t is "RemoveAbility" or "EnableAbility" or "DisableAbility")
|
|
{
|
|
__builder.OpenElement(0, "input");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm");
|
|
__builder.AddAttribute(2, "style", "width:160px");
|
|
__builder.AddAttribute(3, "placeholder", "AbilityRef");
|
|
__builder.AddAttribute(4, "value", d.AbilityRef);
|
|
__builder.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.AbilityRef = e.Value?.ToString() ?? ""; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (_rawJsonTypes.Contains(t))
|
|
{
|
|
__builder.OpenElement(0, "textarea");
|
|
__builder.AddAttribute(1, "class", "form-control form-control-sm font-monospace");
|
|
__builder.AddAttribute(2, "rows", "3");
|
|
__builder.AddAttribute(3, "style", "min-width:260px");
|
|
__builder.AddAttribute(4, "placeholder", "Fields JSON (omit $type)");
|
|
__builder.AddContent(5, d.RawJson);
|
|
__builder.AddAttribute(6, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.RawJson = e.Value?.ToString() ?? "{}"; Compile(); }));
|
|
__builder.CloseElement();
|
|
}
|
|
else if (_noFieldTypes.Contains(t))
|
|
{
|
|
__builder.OpenElement(0, "span");
|
|
__builder.AddAttribute(1, "class", "text-muted small fst-italic");
|
|
__builder.AddContent(2, "No fields.");
|
|
__builder.CloseElement();
|
|
}
|
|
};
|
|
|
|
private RenderFragment RenderTriggerFields(AbilityDraft ab) => __builder =>
|
|
{
|
|
var t = ab.TriggerType;
|
|
if (string.IsNullOrEmpty(t))
|
|
{
|
|
__builder.OpenElement(0, "span");
|
|
__builder.AddAttribute(1, "class", "text-muted small fst-italic");
|
|
__builder.AddContent(2, "Select a trigger event.");
|
|
__builder.CloseElement();
|
|
return;
|
|
}
|
|
|
|
// Player-only
|
|
if (t is "OnTurnStart" or "OnTurnEnd" or "OnCardDrawn"
|
|
or "OnCardReturnedToHand" or "OnCardReturnedToDeck"
|
|
or "OnDeckShuffled" or "OnCardsRevealed")
|
|
{
|
|
BuildSelect(__builder, PlayerValues, ab.TriggerPlayer,
|
|
v => { ab.TriggerPlayer = v; Compile(); }, 100);
|
|
}
|
|
// Player + optional Amount
|
|
else if (t is "OnSPGained" or "OnSPSpent" or "OnSTGained" or "OnSTSpent")
|
|
{
|
|
BuildSelect(__builder, PlayerValues, ab.TriggerPlayer,
|
|
v => { ab.TriggerPlayer = v; Compile(); }, 100);
|
|
BuildOptionalAmountInput(__builder, ab.TriggerAmount,
|
|
v => { ab.TriggerAmount = v; Compile(); });
|
|
}
|
|
// Player + optional Cause
|
|
else if (t == "OnCardDiscarded")
|
|
{
|
|
BuildSelect(__builder, PlayerValues, ab.TriggerPlayer,
|
|
v => { ab.TriggerPlayer = v; Compile(); }, 100);
|
|
BuildStringInput(__builder, ab.TriggerCause,
|
|
v => { ab.TriggerCause = v; Compile(); }, 130, "Cause (optional)");
|
|
}
|
|
// Ownership-only
|
|
else if (t is "OnAscend" or "OnTransition" or "OnUnitMove" or "OnUnitAttack"
|
|
or "OnUnitAbilityActivated" or "OnSpiritSacrificed" or "OnTokenSummoned"
|
|
or "OnAbilityAdded" or "OnAbilityRemoved" or "OnGenusChanged")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerOwnership,
|
|
v => { ab.TriggerOwnership = v; Compile(); }, 100);
|
|
}
|
|
// Ownership + optional Amount
|
|
else if (t == "OnUnitMPSpent")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerOwnership,
|
|
v => { ab.TriggerOwnership = v; Compile(); }, 100);
|
|
BuildOptionalAmountInput(__builder, ab.TriggerAmount,
|
|
v => { ab.TriggerAmount = v; Compile(); });
|
|
}
|
|
// Ownership + optional Stat
|
|
else if (t == "OnStatModified")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerOwnership,
|
|
v => { ab.TriggerOwnership = v; Compile(); }, 100);
|
|
BuildOptionalStringSelect(__builder, StatValues, ab.TriggerStat,
|
|
v => { ab.TriggerStat = v; Compile(); }, 110, "Any stat");
|
|
}
|
|
// Ownership + CardType
|
|
else if (t == "OnChanneled")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerOwnership,
|
|
v => { ab.TriggerOwnership = v; Compile(); }, 100);
|
|
BuildSelect(__builder, TriggerCardTypeValues, ab.TriggerCardType,
|
|
v => { ab.TriggerCardType = v; Compile(); }, 120);
|
|
}
|
|
// Ownership + UnitType
|
|
else if (t is "OnUnitEnterBattlefield" or "OnUnitLeaveBattlefield" or "OnUnitDeath" or "BeforeUnitDeath")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerOwnership,
|
|
v => { ab.TriggerOwnership = v; Compile(); }, 100);
|
|
BuildSelect(__builder, UnitTypeValues, ab.TriggerUnitType,
|
|
v => { ab.TriggerUnitType = v; Compile(); }, 110);
|
|
}
|
|
// Ownership + UnitType + optional CausedBy
|
|
else if (t == "OnUnitSentToDiscard")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerOwnership,
|
|
v => { ab.TriggerOwnership = v; Compile(); }, 100);
|
|
BuildSelect(__builder, UnitTypeValues, ab.TriggerUnitType,
|
|
v => { ab.TriggerUnitType = v; Compile(); }, 110);
|
|
BuildStringInput(__builder, ab.TriggerCausedBy,
|
|
v => { ab.TriggerCausedBy = v; Compile(); }, 140, "CausedBy (optional)");
|
|
}
|
|
// SourceOwnership → TargetOwnership + DamageType + optional Amount
|
|
else if (t == "OnDamageDealt")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerSourceOwnership,
|
|
v => { ab.TriggerSourceOwnership = v; Compile(); }, 100);
|
|
__builder.OpenElement(50, "span");
|
|
__builder.AddAttribute(51, "class", "text-muted small");
|
|
__builder.AddContent(52, "→");
|
|
__builder.CloseElement();
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerTargetOwnership,
|
|
v => { ab.TriggerTargetOwnership = v; Compile(); }, 100);
|
|
BuildSelect(__builder, TriggerDamageTypeValues, ab.TriggerDamageType,
|
|
v => { ab.TriggerDamageType = v; Compile(); }, 100);
|
|
BuildOptionalAmountInput(__builder, ab.TriggerAmount,
|
|
v => { ab.TriggerAmount = v; Compile(); });
|
|
}
|
|
else if (t == "BeforeDamageApplied")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerSourceOwnership,
|
|
v => { ab.TriggerSourceOwnership = v; Compile(); }, 100);
|
|
__builder.OpenElement(50, "span");
|
|
__builder.AddAttribute(51, "class", "text-muted small");
|
|
__builder.AddContent(52, "→");
|
|
__builder.CloseElement();
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerTargetOwnership,
|
|
v => { ab.TriggerTargetOwnership = v; Compile(); }, 100);
|
|
}
|
|
// TargetOwnership only
|
|
else if (t == "OnDamagePrevented")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerTargetOwnership,
|
|
v => { ab.TriggerTargetOwnership = v; Compile(); }, 100);
|
|
}
|
|
// TargetOwnership + optional Amount
|
|
else if (t == "OnHealed")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerTargetOwnership,
|
|
v => { ab.TriggerTargetOwnership = v; Compile(); }, 100);
|
|
BuildOptionalAmountInput(__builder, ab.TriggerAmount,
|
|
v => { ab.TriggerAmount = v; Compile(); });
|
|
}
|
|
// TargetOwnership + SourceOwnership
|
|
else if (t is "OnTargetedByAbility" or "OnEffectApplied")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerTargetOwnership,
|
|
v => { ab.TriggerTargetOwnership = v; Compile(); }, 100);
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerSourceOwnership,
|
|
v => { ab.TriggerSourceOwnership = v; Compile(); }, 100);
|
|
}
|
|
// RuinOwnership + optional OccupantOwnership
|
|
else if (t == "OnRuinActivation")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerRuinOwnership,
|
|
v => { ab.TriggerRuinOwnership = v; Compile(); }, 100);
|
|
BuildOptionalStringSelect(__builder, OwnershipValues, ab.TriggerOccupantOwnership,
|
|
v => { ab.TriggerOccupantOwnership = v; Compile(); }, 110, "Any occupant");
|
|
}
|
|
// UnitOwnership only
|
|
else if (t == "OnUnitOccupyRuin")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerUnitOwnership,
|
|
v => { ab.TriggerUnitOwnership = v; Compile(); }, 100);
|
|
}
|
|
// AuraOwnership + UnitOwnership
|
|
else if (t is "OnEnterAuraRange" or "OnLeaveAuraRange")
|
|
{
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerAuraOwnership,
|
|
v => { ab.TriggerAuraOwnership = v; Compile(); }, 100);
|
|
BuildSelect(__builder, OwnershipValues, ab.TriggerUnitOwnership,
|
|
v => { ab.TriggerUnitOwnership = v; Compile(); }, 100);
|
|
}
|
|
else if (t == "OnTileAffinityChanged")
|
|
{
|
|
__builder.OpenElement(0, "span");
|
|
__builder.AddAttribute(1, "class", "text-muted small fst-italic");
|
|
__builder.AddContent(2, "No additional fields.");
|
|
__builder.CloseElement();
|
|
}
|
|
};
|
|
|
|
// ── Builder helper methods (emit common UI patterns) ─────────────────────────
|
|
|
|
private void BuildSelect(RenderTreeBuilder b, string[] options, string current,
|
|
Action<string> onChange, int widthPx)
|
|
{
|
|
b.OpenElement(0, "select");
|
|
b.AddAttribute(1, "class", "form-select form-select-sm");
|
|
b.AddAttribute(2, "style", $"width:{widthPx}px");
|
|
b.AddAttribute(3, "value", current);
|
|
b.AddAttribute(4, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => onChange(e.Value?.ToString() ?? current)));
|
|
foreach (var opt in options)
|
|
{
|
|
b.OpenElement(5, "option");
|
|
b.AddAttribute(6, "value", opt);
|
|
if (opt == current) b.AddAttribute(7, "selected", true);
|
|
b.AddContent(8, opt);
|
|
b.CloseElement();
|
|
}
|
|
b.CloseElement();
|
|
}
|
|
|
|
private void BuildIntInput(RenderTreeBuilder b, int value, Action<int> onChange, int widthPx, string placeholder)
|
|
{
|
|
b.OpenElement(0, "input");
|
|
b.AddAttribute(1, "type", "number");
|
|
b.AddAttribute(2, "class", "form-control form-control-sm");
|
|
b.AddAttribute(3, "style", $"width:{widthPx}px");
|
|
b.AddAttribute(4, "placeholder", placeholder);
|
|
b.AddAttribute(5, "title", placeholder);
|
|
b.AddAttribute(6, "value", value);
|
|
b.AddAttribute(7, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { if (int.TryParse(e.Value?.ToString(), out var v)) onChange(v); }));
|
|
b.CloseElement();
|
|
}
|
|
|
|
private void BuildValueExprInput(RenderTreeBuilder b, EffectDraft d, int actionIdx, bool isTriggered)
|
|
{
|
|
var refs = BuildValueRefs(actionIdx, isTriggered);
|
|
b.OpenElement(0, "div");
|
|
b.AddAttribute(1, "class", "d-flex align-items-center gap-1 flex-wrap");
|
|
// "Amt" label
|
|
b.OpenElement(2, "label");
|
|
b.AddAttribute(3, "class", "form-label small mb-0 text-nowrap");
|
|
b.AddContent(4, "Amt");
|
|
b.CloseElement();
|
|
// Ref dropdown
|
|
b.OpenElement(5, "select");
|
|
b.AddAttribute(6, "class", "form-select form-select-sm");
|
|
b.AddAttribute(7, "style", "width:185px");
|
|
b.AddAttribute(8, "value", d.AmountRef);
|
|
b.AddAttribute(9, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => { d.AmountRef = e.Value?.ToString() ?? ""; Compile(); }));
|
|
// Fixed option
|
|
b.OpenElement(10, "option");
|
|
b.AddAttribute(11, "value", "");
|
|
if (string.IsNullOrEmpty(d.AmountRef)) b.AddAttribute(12, "selected", true);
|
|
b.AddContent(13, "— fixed value —");
|
|
b.CloseElement();
|
|
// Dynamic ref options
|
|
foreach (var r in refs)
|
|
{
|
|
b.OpenElement(10, "option");
|
|
b.AddAttribute(11, "value", r);
|
|
if (r == d.AmountRef) b.AddAttribute(12, "selected", true);
|
|
b.AddContent(13, r);
|
|
b.CloseElement();
|
|
}
|
|
b.CloseElement(); // select
|
|
// Number input — only shown when fixed mode
|
|
if (string.IsNullOrEmpty(d.AmountRef))
|
|
BuildIntInput(b, d.Amount, v => { d.Amount = v; Compile(); }, 70, "Fixed value");
|
|
b.CloseElement(); // outer div
|
|
}
|
|
|
|
private static string[] BuildValueRefs(int actionIdx, bool isTriggered)
|
|
{
|
|
var refs = new List<string>();
|
|
if (isTriggered) refs.Add("EventData.Amount");
|
|
refs.AddRange(["Target.Damage", "Target.Defense", "Target.Health", "Target.MP", "Target.SpCost", "Target.StCost"]);
|
|
refs.AddRange(["Self.Damage", "Self.Defense", "Self.Health", "Self.MP", "Self.SpCost", "Self.StCost"]);
|
|
for (int i = 0; i < actionIdx; i++)
|
|
refs.AddRange([$"Action{i}.Target.Damage", $"Action{i}.Target.Defense",
|
|
$"Action{i}.Target.Health", $"Action{i}.Target.MP",
|
|
$"Action{i}.Target.SpCost", $"Action{i}.Target.StCost"]);
|
|
return [.. refs];
|
|
}
|
|
|
|
private void BuildCheckbox(RenderTreeBuilder b, string label, bool value, Action<bool> onChange)
|
|
{
|
|
b.OpenElement(0, "div");
|
|
b.AddAttribute(1, "class", "form-check d-flex align-items-center gap-1 mb-0");
|
|
b.OpenElement(2, "input");
|
|
b.AddAttribute(3, "type", "checkbox");
|
|
b.AddAttribute(4, "class", "form-check-input");
|
|
b.AddAttribute(5, "checked", value);
|
|
b.AddAttribute(6, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => onChange(e.Value is bool bv ? bv : bool.Parse(e.Value?.ToString() ?? "false"))));
|
|
b.CloseElement();
|
|
b.OpenElement(7, "label");
|
|
b.AddAttribute(8, "class", "form-check-label small");
|
|
b.AddContent(9, label);
|
|
b.CloseElement();
|
|
b.CloseElement();
|
|
}
|
|
|
|
private void BuildDuration(RenderTreeBuilder b, EffectDraft d)
|
|
{
|
|
BuildSelect(b, DurationTypeValues, d.DurationType, v => { d.DurationType = v; Compile(); }, 190);
|
|
if (d.DurationType == "ForNTurns")
|
|
BuildIntInput(b, d.DurationN, v => { d.DurationN = v; Compile(); }, 60, "N");
|
|
}
|
|
|
|
private void BuildStringInput(RenderTreeBuilder b, string value, Action<string> onChange, int widthPx, string placeholder)
|
|
{
|
|
b.OpenElement(0, "input");
|
|
b.AddAttribute(1, "class", "form-control form-control-sm");
|
|
b.AddAttribute(2, "style", $"width:{widthPx}px");
|
|
b.AddAttribute(3, "placeholder", placeholder);
|
|
b.AddAttribute(4, "value", value);
|
|
b.AddAttribute(5, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => onChange(e.Value?.ToString() ?? "")));
|
|
b.CloseElement();
|
|
}
|
|
|
|
private void BuildOptionalAmountInput(RenderTreeBuilder b, int? value, Action<int?> onChange)
|
|
{
|
|
b.OpenElement(0, "input");
|
|
b.AddAttribute(1, "type", "number");
|
|
b.AddAttribute(2, "class", "form-control form-control-sm");
|
|
b.AddAttribute(3, "style", "width:90px");
|
|
b.AddAttribute(4, "placeholder", "Amt (opt)");
|
|
b.AddAttribute(5, "title", "Minimum amount (blank = any)");
|
|
b.AddAttribute(6, "value", value?.ToString() ?? "");
|
|
b.AddAttribute(7, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => onChange(int.TryParse(e.Value?.ToString(), out var v) ? v : null)));
|
|
b.CloseElement();
|
|
}
|
|
|
|
private void BuildOptionalStringSelect(RenderTreeBuilder b, string[] options, string current,
|
|
Action<string> onChange, int widthPx, string emptyLabel)
|
|
{
|
|
b.OpenElement(0, "select");
|
|
b.AddAttribute(1, "class", "form-select form-select-sm");
|
|
b.AddAttribute(2, "style", $"width:{widthPx}px");
|
|
b.AddAttribute(3, "value", current);
|
|
b.AddAttribute(4, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(
|
|
this, e => onChange(e.Value?.ToString() ?? "")));
|
|
b.OpenElement(5, "option");
|
|
b.AddAttribute(6, "value", "");
|
|
if (string.IsNullOrEmpty(current)) b.AddAttribute(7, "selected", true);
|
|
b.AddContent(8, $"— {emptyLabel} —");
|
|
b.CloseElement();
|
|
foreach (var opt in options)
|
|
{
|
|
b.OpenElement(5, "option");
|
|
b.AddAttribute(6, "value", opt);
|
|
if (opt == current) b.AddAttribute(7, "selected", true);
|
|
b.AddContent(8, opt);
|
|
b.CloseElement();
|
|
}
|
|
b.CloseElement();
|
|
}
|
|
|
|
// ── Event helpers ─────────────────────────────────────────────────────────────
|
|
|
|
/// <param name="mode">0=Persist, 1=ClearOnLeave, 2=Linger(ForNTurns)</param>
|
|
private void SetAuraLeaveMode(AbilityDraft ab, int mode)
|
|
{
|
|
ab.AuraClearOnLeave = mode == 1;
|
|
ab.AuraLingerDurationStr = mode == 2 ? "ForNTurns" : string.Empty;
|
|
Compile();
|
|
}
|
|
|
|
private void SelectTrigger(AbilityDraft ab, string triggerType)
|
|
{
|
|
ab.TriggerType = triggerType;
|
|
ab.TriggerPlayer = "Owner";
|
|
ab.TriggerOwnership = "Owner";
|
|
ab.TriggerSourceOwnership = "Any";
|
|
ab.TriggerTargetOwnership = "Any";
|
|
ab.TriggerUnitType = "Unit";
|
|
ab.TriggerCardType = "Spirit";
|
|
ab.TriggerDamageType = "Any";
|
|
ab.TriggerAmount = null;
|
|
ab.TriggerStat = "";
|
|
ab.TriggerCause = "";
|
|
ab.TriggerCausedBy = "";
|
|
ab.TriggerRuinOwnership = "Any";
|
|
ab.TriggerOccupantOwnership = "";
|
|
ab.TriggerUnitOwnership = "Any";
|
|
ab.TriggerAuraOwnership = "Owner";
|
|
Compile();
|
|
}
|
|
|
|
private void SelectEffectType(EffectDraft effect, string typeKey)
|
|
{
|
|
// Reset all typed fields so we start fresh for the new type
|
|
effect.TypeKey = typeKey;
|
|
effect.Amount = 1; effect.AmountRef = ""; effect.N = 1; effect.Tiles = 1; effect.BlockedDamage = 0;
|
|
effect.BypassDefense = false; effect.Value = true; effect.PayCost = true;
|
|
effect.Min = 1; effect.Max = 2; effect.StAmount = 1;
|
|
effect.Player = "Owner"; effect.Controller = "Owner"; effect.StatTarget = "Current";
|
|
effect.Direction = "North"; effect.MovementType = "Walk"; effect.Position = "Top";
|
|
effect.Affinity = "Aether"; effect.Tag = ""; effect.AbilityRef = "";
|
|
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();
|
|
}
|
|
|
|
private void AddAbility()
|
|
{
|
|
_abilities.Add(new AbilityDraft());
|
|
Compile();
|
|
}
|
|
|
|
private void ApplyRawJson()
|
|
{
|
|
ParseJson(_compiledJson);
|
|
_showRaw = false;
|
|
_ = AbilitiesJsonChanged.InvokeAsync(_compiledJson);
|
|
}
|
|
|
|
private static string AbilityTypeBadge(string t) => t switch
|
|
{
|
|
"Active" => "bg-primary",
|
|
"Passive" => "bg-success",
|
|
"Aura" => "bg-info text-dark",
|
|
"Triggered" => "bg-warning text-dark",
|
|
_ => "bg-secondary",
|
|
};
|
|
|
|
// ── Draft models ─────────────────────────────────────────────────────────────
|
|
|
|
private sealed class AbilityDraft
|
|
{
|
|
public string TypeStr { get; set; } = "Active";
|
|
public string Name { get; set; } = "";
|
|
public string Description { get; set; } = "";
|
|
public int? RangeMin { get; set; }
|
|
public int? RangeMax { get; set; }
|
|
public bool RangeRequiresLos { get; set; } = false;
|
|
public bool RangeLinearOnly { get; set; } = false;
|
|
public int UsesPerTurn { get; set; } = 1;
|
|
public int? AuraRangeMin { get; set; }
|
|
public int? AuraRangeMax { get; set; }
|
|
public bool AuraClearOnLeave { get; set; } = false;
|
|
public string AuraLingerDurationStr { get; set; } = "";
|
|
public int AuraLingerDurationN { get; set; } = 1;
|
|
public string TriggerType { get; set; } = "";
|
|
public string TriggerPlayer { get; set; } = "Owner";
|
|
public string TriggerOwnership { get; set; } = "Owner";
|
|
public string TriggerSourceOwnership { get; set; } = "Any";
|
|
public string TriggerTargetOwnership { get; set; } = "Any";
|
|
public string TriggerUnitType { get; set; } = "Unit";
|
|
public string TriggerCardType { get; set; } = "Spirit";
|
|
public string TriggerDamageType { get; set; } = "Any";
|
|
public int? TriggerAmount { get; set; }
|
|
public string TriggerStat { get; set; } = "";
|
|
public string TriggerCause { get; set; } = "";
|
|
public string TriggerCausedBy { get; set; } = "";
|
|
public string TriggerRuinOwnership { get; set; } = "Any";
|
|
public string TriggerOccupantOwnership { get; set; } = "";
|
|
public string TriggerUnitOwnership { get; set; } = "Any";
|
|
public string TriggerAuraOwnership { get; set; } = "Owner";
|
|
public int? TriggerLimitPerTurn { get; set; }
|
|
// Ability-level duration (overrides per-action Duration when set; "" = per-action)
|
|
public string DurationStr { get; set; } = "";
|
|
public int DurationN { get; set; } = 1;
|
|
|
|
public List<CostDraft> Costs { get; set; } = new();
|
|
public List<ConditionDraft> Conditions { get; set; } = new();
|
|
public List<ActionDraft> Actions { get; set; } = new();
|
|
|
|
// Animation & Sound (client-side metadata only)
|
|
public bool HasAnimation { get; set; } = false;
|
|
public string AnimationType { get; set; } = "Projectile";
|
|
public string AnimationEffect { get; set; } = "Target";
|
|
public string AnimationAssetUrl { get; set; } = "";
|
|
public float AnimationWidth { get; set; } = 1f;
|
|
public float AnimationHeight { get; set; } = 1f;
|
|
public float AnimationDuration { get; set; } = 1f;
|
|
public string CastSoundUrl { get; set; } = "";
|
|
public string ImpactSoundUrl { get; set; } = "";
|
|
}
|
|
|
|
private sealed class ActionDraft
|
|
{
|
|
public string Scope { get; set; } = "Battlefield";
|
|
public string TargetType { get; set; } = "Unit";
|
|
public string Ownership { get; set; } = "Enemy";
|
|
public int Count { get; set; } = 1;
|
|
public bool All { get; set; }
|
|
/// <summary>
|
|
/// Optional filter type applied to the target pool (single filter, no-param variant).
|
|
/// "" = no filter. Maps to Target.Filters[0] in the compiled JSON.
|
|
/// </summary>
|
|
public string FilterType { get; set; } = "";
|
|
public List<ConditionDraft> Conditions { get; set; } = new();
|
|
public List<EffectDraft> Effects { get; set; } = new();
|
|
}
|
|
|
|
private sealed class EffectDraft
|
|
{
|
|
public string TypeKey { get; set; } = "DealDamage";
|
|
public int Amount { get; set; } = 1;
|
|
public string AmountRef { get; set; } = ""; // "" = use Fixed; non-empty = ValueExpr Ref path
|
|
public int N { get; set; } = 1;
|
|
public bool BypassDefense{ get; set; } = false;
|
|
public bool Value { get; set; } = true;
|
|
public bool PayCost { get; set; } = true;
|
|
public int Tiles { get; set; } = 1;
|
|
public int BlockedDamage{ get; set; } = 0;
|
|
public string Direction { get; set; } = "North";
|
|
public bool AdjacentToSource { get; set; } = false;
|
|
public string RelativeToTargetRef { get; set; } = "";
|
|
public bool AdjacentToRelativeTarget { get; set; } = false;
|
|
public bool AllowRelativeTargetTile { get; set; } = false;
|
|
public int Min { get; set; } = 1;
|
|
public int Max { get; set; } = 2;
|
|
public string DurationType { get; set; } = "UntilEndOfTurn";
|
|
public int DurationN { get; set; } = 1;
|
|
public string Player { get; set; } = "Owner";
|
|
public string Controller { get; set; } = "Owner";
|
|
public string StatTarget { get; set; } = "Current";
|
|
public string MovementType { get; set; } = "Walk";
|
|
public string Position { get; set; } = "Top";
|
|
public string Tag { get; set; } = "";
|
|
public string Affinity { get; set; } = "Aether";
|
|
public string AbilityRef { get; set; } = "";
|
|
public string Stat { get; set; } = "Damage";
|
|
public float Multiplier { get; set; } = 1.5f;
|
|
public int StAmount { get; set; } = 1;
|
|
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
|
|
{
|
|
public string TypeStr { get; set; } = "IsOwnTurn";
|
|
public string Subject { get; set; } = "Self";
|
|
public int N { get; set; } = 1;
|
|
public int Min { get; set; } = 1;
|
|
public int Max { get; set; } = 1;
|
|
public string Tag { get; set; } = "";
|
|
public string AbilityRef { get; set; } = "";
|
|
public string Affinity { get; set; } = "Aether";
|
|
public string UnitType { get; set; } = "Unit";
|
|
public string Ownership { get; set; } = "Any";
|
|
public string Target { get; set; } = "Self";
|
|
public string MovementType { get; set; } = "Walk";
|
|
public string Comparator { get; set; } = "GreaterThanOrEqual";
|
|
public string Zone { get; set; } = "Hand";
|
|
public string CardRef { get; set; } = "";
|
|
public string InnerConditionJson { get; set; } = "{\"$type\":\"IsOwnTurn\"}";
|
|
}
|
|
|
|
private sealed class CostDraft
|
|
{
|
|
public string TypeStr { get; set; } = "SpiritPoints";
|
|
public int Amount { get; set; } = 1;
|
|
}
|
|
}
|