Phase 1: Custom game system — DB schema extensions

- Extend CustomLobby with 12 new rule override columns (Password,
  HandSizeCap, DiscardOnMaxHand, MaxDeckSize, MinDeckSize, MaxArchTier1,
  TurnTimerSeconds, TimeLimitMinutes, TurnLimit, MpBuff, BoardWidth/Height)
- Extend GameRuleSet with matching non-nullable rule fields (same set)
- Extend GameRules record with 9 new rule fields (all default to 0/false)
- Add LobbyPreset entity (owner-scoped named rule presets)
- Register LobbyPreset in GameDbContext with index on OwnerAccountId
- Migration: AddCustomGameExtensions (applied to pg-forge-01)
- Add custom-game-system-plan.md with full 8-phase architecture plan
  and deferred features tracking list
- Also includes: AbilityBuilder ValueExpr dropdowns + help panel,
  Affinity enum/system fixes (from prior sessions)

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

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-18 22:42:59 -04:00
co-authored by Claude Happy
parent 530b56c33c
commit 71947f785e
12 changed files with 1508 additions and 30 deletions
@@ -323,7 +323,7 @@
<div class="flex-grow-1">
<label class="form-label small mb-0">Fields</label>
<div class="d-flex gap-1 align-items-center flex-wrap mt-1">
@RenderEffectFields(effect)
@RenderEffectFields(effect, actionIdx, ab.TypeStr == "Triggered")
</div>
</div>
<!-- Remove -->
@@ -466,9 +466,14 @@
}
}
<button class="btn btn-outline-primary btn-sm mb-4" @onclick="AddAbility">
<i class="bi bi-plus-lg me-1"></i>Add Ability
</button>
<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">
@@ -497,6 +502,141 @@
</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>Continuously affects all units in range</td><td>AuraRange, Actions</td></tr>
<tr><td><strong>Triggered</strong></td><td>Fires automatically when a specific game event occurs</td><td>TriggerEvent, 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&gt;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 &lt; N or &gt; 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>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>
</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; }
@@ -505,6 +645,7 @@
private string _compiledJson = "[]";
private string _lastJson = "";
private bool _showRaw;
private bool _showHelp;
// ── Static enum options ──────────────────────────────────────────────────────
@@ -807,9 +948,12 @@
var typeKey = eff["$type"]?.GetValue<string>() ?? "DealDamage";
var d = new EffectDraft { TypeKey = typeKey };
// ValueExpr helper: reads {"Fixed": N}
// ValueExpr helpers
int ReadFixed(string key, int def = 1) =>
eff[key]?["Fixed"]?.GetValue<int>() ?? 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;
@@ -828,24 +972,24 @@
if (_amountBypassTypes.Contains(typeKey))
{
d.Amount = ReadFixed("Amount"); d.BypassDefense = ReadBool("BypassDefense");
ReadValueExpr("Amount"); d.BypassDefense = ReadBool("BypassDefense");
}
else if (typeKey == "DOT")
{
d.Amount = ReadFixed("Amount"); d.BypassDefense = ReadBool("BypassDefense");
ReadValueExpr("Amount"); d.BypassDefense = ReadBool("BypassDefense");
d.DurationType = ReadDurType(); d.DurationN = ReadDurN();
}
else if (typeKey == "HOT")
{
d.Amount = ReadFixed("Amount"); d.DurationType = ReadDurType(); d.DurationN = ReadDurN();
ReadValueExpr("Amount"); d.DurationType = ReadDurType(); d.DurationN = ReadDurN();
}
else if (_amountStatTypes.Contains(typeKey))
{
d.Amount = ReadFixed("Amount"); d.StatTarget = ReadStr("StatTarget", "Current");
ReadValueExpr("Amount"); d.StatTarget = ReadStr("StatTarget", "Current");
}
else if (_amountOnlyTypes.Contains(typeKey))
{
d.Amount = ReadFixed("Amount");
ReadValueExpr("Amount");
}
else if (typeKey is "DrawCards" or "DiscardCards")
{
@@ -1216,31 +1360,33 @@
{
var node = new JsonObject { ["$type"] = d.TypeKey };
JsonObject Fixed(int v) => new() { ["Fixed"] = v };
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"] = Fixed(d.Amount); node["BypassDefense"] = d.BypassDefense;
node["Amount"] = ValueExpr(); node["BypassDefense"] = d.BypassDefense;
}
else if (d.TypeKey == "DOT")
{
node["Amount"] = Fixed(d.Amount); node["BypassDefense"] = d.BypassDefense;
node["Amount"] = ValueExpr(); node["BypassDefense"] = d.BypassDefense;
node["Duration"] = Duration();
}
else if (d.TypeKey == "HOT")
{
node["Amount"] = Fixed(d.Amount); node["Duration"] = Duration();
node["Amount"] = ValueExpr(); node["Duration"] = Duration();
}
else if (_amountStatTypes.Contains(d.TypeKey))
{
node["Amount"] = Fixed(d.Amount); node["StatTarget"] = d.StatTarget;
node["Amount"] = ValueExpr(); node["StatTarget"] = d.StatTarget;
}
else if (_amountOnlyTypes.Contains(d.TypeKey))
{
node["Amount"] = Fixed(d.Amount);
node["Amount"] = ValueExpr();
}
else if (d.TypeKey is "DrawCards" or "DiscardCards")
{
@@ -1427,34 +1573,34 @@
// AND/OR/XOR + no-field types: no extra inputs
};
private RenderFragment RenderEffectFields(EffectDraft d) => __builder =>
private RenderFragment RenderEffectFields(EffectDraft d, int actionIdx = 0, bool isTriggered = false) => __builder =>
{
var t = d.TypeKey;
if (_amountBypassTypes.Contains(t))
{
BuildFixedAmountInput(__builder, d.Amount, v => { d.Amount = v; Compile(); });
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
BuildCheckbox(__builder, "BypassDefense", d.BypassDefense, v => { d.BypassDefense = v; Compile(); });
}
else if (t == "DOT")
{
BuildFixedAmountInput(__builder, d.Amount, v => { d.Amount = v; Compile(); });
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
BuildCheckbox(__builder, "BypassDefense", d.BypassDefense, v => { d.BypassDefense = v; Compile(); });
BuildDuration(__builder, d);
}
else if (t == "HOT")
{
BuildFixedAmountInput(__builder, d.Amount, v => { d.Amount = v; Compile(); });
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
BuildDuration(__builder, d);
}
else if (_amountStatTypes.Contains(t))
{
BuildFixedAmountInput(__builder, d.Amount, v => { d.Amount = v; Compile(); });
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
BuildSelect(__builder, StatTargetValues, d.StatTarget, v => { d.StatTarget = v; Compile(); }, 100);
}
else if (_amountOnlyTypes.Contains(t))
{
BuildFixedAmountInput(__builder, d.Amount, v => { d.Amount = v; Compile(); });
BuildValueExprInput(__builder, d, actionIdx, isTriggered);
}
else if (t is "DrawCards" or "DiscardCards")
{
@@ -1789,16 +1935,56 @@
b.CloseElement();
}
private void BuildFixedAmountInput(RenderTreeBuilder b, int value, Action<int> onChange)
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");
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();
BuildIntInput(b, value, onChange, 70, "Fixed value");
// 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)
@@ -1904,7 +2090,7 @@
{
// Reset all typed fields so we start fresh for the new type
effect.TypeKey = typeKey;
effect.Amount = 1; effect.N = 1; effect.Tiles = 1; effect.BlockedDamage = 0;
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";
@@ -2008,6 +2194,7 @@
{
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;