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:
@@ -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>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>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;
|
||||
|
||||
@@ -28,6 +28,7 @@ public sealed class GameDbContext : DbContext
|
||||
public DbSet<GameActionLog> ActionLogs => Set<GameActionLog>();
|
||||
public DbSet<GameRuleSet> GameRuleSets => Set<GameRuleSet>();
|
||||
public DbSet<CustomLobby> CustomLobbies => Set<CustomLobby>();
|
||||
public DbSet<LobbyPreset> LobbyPresets => Set<LobbyPreset>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
@@ -86,5 +87,12 @@ public sealed class GameDbContext : DbContext
|
||||
e.HasIndex(l => new { l.Status, l.CreatedAt });
|
||||
e.HasIndex(l => l.HostAccountId);
|
||||
});
|
||||
|
||||
builder.Entity<LobbyPreset>(e =>
|
||||
{
|
||||
e.ToTable("lobby_presets");
|
||||
e.HasKey(p => p.Id);
|
||||
e.HasIndex(p => p.OwnerAccountId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,44 @@ public sealed class CustomLobby
|
||||
public bool? SpHasCapOverride { get; set; }
|
||||
public int? SpCapOverride { get; set; }
|
||||
|
||||
// ── Extended rule overrides ───────────────────────────────────────────────
|
||||
|
||||
/// <summary>Optional password to join this lobby. Null = no password required.</summary>
|
||||
public string? Password { get; set; }
|
||||
|
||||
/// <summary>Max cards in hand. 0 = no cap.</summary>
|
||||
public int? HandSizeCapOverride { get; set; }
|
||||
|
||||
/// <summary>If true, excess cards are auto-discarded when hand is at cap. If false, draw is blocked.</summary>
|
||||
public bool? DiscardOnMaxHandOverride { get; set; }
|
||||
|
||||
/// <summary>Maximum deck size. 0 = no limit.</summary>
|
||||
public int? MaxDeckSizeOverride { get; set; }
|
||||
|
||||
/// <summary>Minimum deck size. 0 = no limit.</summary>
|
||||
public int? MinDeckSizeOverride { get; set; }
|
||||
|
||||
/// <summary>Max copies of a Tier-1 Arch card allowed per deck. 0 = no limit.</summary>
|
||||
public int? MaxArchTier1Override { get; set; }
|
||||
|
||||
/// <summary>Seconds per turn before auto-end. 0 = no timer.</summary>
|
||||
public int? TurnTimerSecondsOverride { get; set; }
|
||||
|
||||
/// <summary>Total game time limit in minutes. 0 = no limit.</summary>
|
||||
public int? TimeLimitMinutesOverride { get; set; }
|
||||
|
||||
/// <summary>Maximum number of turns before game ends. 0 = no limit.</summary>
|
||||
public int? TurnLimitOverride { get; set; }
|
||||
|
||||
/// <summary>Flat MP bonus added to each unit at the start of its owner's turn. 0 = no buff.</summary>
|
||||
public int? MpBuffOverride { get; set; }
|
||||
|
||||
/// <summary>Board width override in columns.</summary>
|
||||
public int? BoardWidthOverride { get; set; }
|
||||
|
||||
/// <summary>Board height override in rows.</summary>
|
||||
public int? BoardHeightOverride { get; set; }
|
||||
|
||||
// ── Timestamps ───────────────────────────────────────────────────────────
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
@@ -49,6 +49,33 @@ public sealed class GameRuleSet
|
||||
/// <summary>Battlefield height (rows). Default: 8.</summary>
|
||||
public int BoardHeight { get; set; } = 8;
|
||||
|
||||
/// <summary>Max cards in hand. 0 = no cap.</summary>
|
||||
public int HandSizeCap { get; set; } = 0;
|
||||
|
||||
/// <summary>If true, excess cards are auto-discarded when hand is at cap. If false, draw is blocked.</summary>
|
||||
public bool DiscardOnMaxHand { get; set; } = false;
|
||||
|
||||
/// <summary>Maximum deck size. 0 = no limit.</summary>
|
||||
public int MaxDeckSize { get; set; } = 0;
|
||||
|
||||
/// <summary>Minimum deck size. 0 = no limit.</summary>
|
||||
public int MinDeckSize { get; set; } = 0;
|
||||
|
||||
/// <summary>Max copies of a Tier-1 Arch card allowed per deck. 0 = no limit.</summary>
|
||||
public int MaxArchTier1 { get; set; } = 0;
|
||||
|
||||
/// <summary>Seconds per turn before auto-end. 0 = no timer.</summary>
|
||||
public int TurnTimerSeconds { get; set; } = 0;
|
||||
|
||||
/// <summary>Total game time limit in minutes. 0 = no limit.</summary>
|
||||
public int TimeLimitMinutes { get; set; } = 0;
|
||||
|
||||
/// <summary>Maximum number of turns before game ends. 0 = no limit.</summary>
|
||||
public int TurnLimit { get; set; } = 0;
|
||||
|
||||
/// <summary>Flat MP bonus added to each unit at the start of its owner's turn. 0 = no buff.</summary>
|
||||
public int MpBuff { get; set; } = 0;
|
||||
|
||||
// ── Origin Points Rewards ─────────────────────────────────────────────────
|
||||
|
||||
/// <summary>OP awarded to the winner of a ranked game.</summary>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace SOR.Database.Entities.Game;
|
||||
|
||||
/// <summary>
|
||||
/// A named lobby rule preset saved by a player for quick re-use.
|
||||
///
|
||||
/// Rules are stored as serialized JSON (CustomRulesOverride shape).
|
||||
/// Personal only — presets are scoped to the owner's account.
|
||||
/// Cross-schema: OwnerAccountId is a bare Guid — no EF foreign key.
|
||||
/// </summary>
|
||||
public sealed class LobbyPreset
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid OwnerAccountId { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Serialized CustomRulesOverride JSON (nullable fields = inherit default).</summary>
|
||||
public string RulesJson { get; set; } = "{}";
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
}
|
||||
@@ -26,10 +26,10 @@ public enum Affinity
|
||||
Marsh, // Lake + Field
|
||||
Swamp, // Lake + Forest
|
||||
Mountain, // Hill + Hill
|
||||
Steppe, // Field + Forest
|
||||
Steppe, // Field + Hill
|
||||
Fort, // Hill + forest
|
||||
Plains, // Field + Field
|
||||
Grove, // Field + Hill
|
||||
Grove, // Field + Forest
|
||||
Jungle, // Forest + Forest
|
||||
|
||||
// ── Aether combinations ───────────────────────────────────────────────
|
||||
|
||||
Generated
+402
@@ -0,0 +1,402 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using SOR.Database.Contexts;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Game
|
||||
{
|
||||
[DbContext(typeof(GameDbContext))]
|
||||
[Migration("20260319024116_AddCustomGameExtensions")]
|
||||
partial class AddCustomGameExtensions
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("game")
|
||||
.HasAnnotation("ProductVersion", "8.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.CustomLobby", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int?>("BoardHeightOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("BoardWidthOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool?>("DiscardOnMaxHandOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("DrawPerTurnOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool?>("FirstPlayerSkipsDrawOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid?>("GameSessionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("GuestAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid?>("GuestDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int?>("HandSizeCapOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("HostAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("HostDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int?>("MaxArchTier1Override")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MaxDeckSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MinDeckSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MpBuffOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("OpeningHandSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("SpAccumulationPerTurnOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("SpCapOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool?>("SpHasCapOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("TimeLimitMinutesOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("TurnLimitOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("TurnTimerSecondsOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostAccountId");
|
||||
|
||||
b.HasIndex("Status", "CreatedAt");
|
||||
|
||||
b.ToTable("custom_lobbies", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ActionType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("ActorAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("GameSessionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("OccurredAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("PayloadJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("payload");
|
||||
|
||||
b.Property<string>("ResultJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("result");
|
||||
|
||||
b.Property<int>("SequenceNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ActorAccountId");
|
||||
|
||||
b.HasIndex("GameSessionId", "SequenceNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("action_logs", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameRuleSet", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("BoardHeight")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("BoardWidth")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("DiscardOnMaxHand")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("DrawPerTurn")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("FirstPlayerSkipsDraw")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("HandSizeCap")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("IsCustomDefault")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsRankedDefault")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("LoserOpReward")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxArchTier1")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxDeckSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MinDeckSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MpBuff")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("OpeningHandSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RankDiffOpMultiplierPct")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SpAccumulationPerTurn")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SpCap")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("SpHasCap")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("TimeLimitMinutes")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TurnLimit")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TurnTimerSeconds")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("WinnerOpReward")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("IsCustomDefault");
|
||||
|
||||
b.HasIndex("IsRankedDefault");
|
||||
|
||||
b.ToTable("game_rule_sets", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("EndedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastActionAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("PlayerOneAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("PlayerOneDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("PlayerOneReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<Guid>("PlayerTwoAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("PlayerTwoDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<bool>("PlayerTwoReady")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("RuleSnapshotJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("rule_snapshot");
|
||||
|
||||
b.Property<DateTimeOffset?>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("StateJson")
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("state");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("WinCondition")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid?>("WinnerAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PlayerOneAccountId");
|
||||
|
||||
b.HasIndex("PlayerTwoAccountId");
|
||||
|
||||
b.HasIndex("Status", "CreatedAt");
|
||||
|
||||
b.ToTable("game_sessions", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.LobbyPreset", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("OwnerAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("RulesJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OwnerAccountId");
|
||||
|
||||
b.ToTable("lobby_presets", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.MatchmakingEntry", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("AccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("DeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("JoinedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("MatchedGameSessionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("RankScore")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset?>("ResolvedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AccountId", "Status");
|
||||
|
||||
b.HasIndex("Status", "RankScore");
|
||||
|
||||
b.ToTable("matchmaking_entries", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
|
||||
{
|
||||
b.HasOne("SOR.Database.Entities.Game.GameSession", "Session")
|
||||
.WithMany("ActionLog")
|
||||
.HasForeignKey("GameSessionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Session");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
|
||||
{
|
||||
b.Navigation("ActionLog");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SOR.Database.Migrations.Game
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddCustomGameExtensions : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "DiscardOnMaxHand",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "HandSizeCap",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxArchTier1",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxDeckSize",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MinDeckSize",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MpBuff",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TimeLimitMinutes",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TurnLimit",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TurnTimerSeconds",
|
||||
schema: "game",
|
||||
table: "game_rule_sets",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "BoardHeightOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "BoardWidthOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "DiscardOnMaxHandOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "boolean",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "HandSizeCapOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxArchTier1Override",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxDeckSizeOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MinDeckSizeOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MpBuffOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Password",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "text",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TimeLimitMinutesOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TurnLimitOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "TurnTimerSecondsOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies",
|
||||
type: "integer",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "lobby_presets",
|
||||
schema: "game",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
OwnerAccountId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
RulesJson = table.Column<string>(type: "text", nullable: false),
|
||||
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_lobby_presets", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_lobby_presets_OwnerAccountId",
|
||||
schema: "game",
|
||||
table: "lobby_presets",
|
||||
column: "OwnerAccountId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "lobby_presets",
|
||||
schema: "game");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DiscardOnMaxHand",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HandSizeCap",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxArchTier1",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxDeckSize",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MinDeckSize",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MpBuff",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TimeLimitMinutes",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TurnLimit",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TurnTimerSeconds",
|
||||
schema: "game",
|
||||
table: "game_rule_sets");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BoardHeightOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "BoardWidthOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DiscardOnMaxHandOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HandSizeCapOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxArchTier1Override",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxDeckSizeOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MinDeckSizeOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MpBuffOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Password",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TimeLimitMinutesOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TurnLimitOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "TurnTimerSecondsOverride",
|
||||
schema: "game",
|
||||
table: "custom_lobbies");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,18 @@ namespace SOR.Database.Migrations.Game
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int?>("BoardHeightOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("BoardWidthOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool?>("DiscardOnMaxHandOverride")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int?>("DrawPerTurnOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@@ -47,12 +56,27 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<Guid?>("GuestDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int?>("HandSizeCapOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Guid>("HostAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Guid>("HostDeckId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int?>("MaxArchTier1Override")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MaxDeckSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MinDeckSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("MpBuffOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
@@ -60,6 +84,9 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<int?>("OpeningHandSizeOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("SpAccumulationPerTurnOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@@ -73,6 +100,15 @@ namespace SOR.Database.Migrations.Game
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("TimeLimitMinutesOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("TurnLimitOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("TurnTimerSecondsOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostAccountId");
|
||||
@@ -137,12 +173,18 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("DiscardOnMaxHand")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("DrawPerTurn")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("FirstPlayerSkipsDraw")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("HandSizeCap")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("IsCustomDefault")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
@@ -152,6 +194,18 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<int>("LoserOpReward")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxArchTier1")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MaxDeckSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MinDeckSize")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("MpBuff")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
@@ -171,6 +225,15 @@ namespace SOR.Database.Migrations.Game
|
||||
b.Property<bool>("SpHasCap")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("TimeLimitMinutes")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TurnLimit")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("TurnTimerSeconds")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
@@ -251,6 +314,33 @@ namespace SOR.Database.Migrations.Game
|
||||
b.ToTable("game_sessions", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.LobbyPreset", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("OwnerAccountId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("RulesJson")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OwnerAccountId");
|
||||
|
||||
b.ToTable("lobby_presets", "game");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SOR.Database.Entities.Game.MatchmakingEntry", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
|
||||
@@ -23,5 +23,32 @@ public sealed record GameRules
|
||||
public int BoardWidth { get; init; } = 9;
|
||||
public int BoardHeight { get; init; } = 9;
|
||||
|
||||
/// <summary>Max cards in hand. 0 = no cap.</summary>
|
||||
public int HandSizeCap { get; init; } = 0;
|
||||
|
||||
/// <summary>If true, excess cards are discarded when hand is at cap. If false, draw is blocked.</summary>
|
||||
public bool DiscardOnMaxHand { get; init; } = false;
|
||||
|
||||
/// <summary>Maximum deck size. 0 = no limit.</summary>
|
||||
public int MaxDeckSize { get; init; } = 0;
|
||||
|
||||
/// <summary>Minimum deck size. 0 = no limit.</summary>
|
||||
public int MinDeckSize { get; init; } = 0;
|
||||
|
||||
/// <summary>Max copies of a Tier-1 Arch card allowed per deck. 0 = no limit.</summary>
|
||||
public int MaxArchTier1 { get; init; } = 0;
|
||||
|
||||
/// <summary>Seconds per turn before auto-end. 0 = no timer.</summary>
|
||||
public int TurnTimerSeconds { get; init; } = 0;
|
||||
|
||||
/// <summary>Total game time limit in minutes. 0 = no limit.</summary>
|
||||
public int TimeLimitMinutes { get; init; } = 0;
|
||||
|
||||
/// <summary>Maximum number of turns before game ends. 0 = no limit.</summary>
|
||||
public int TurnLimit { get; init; } = 0;
|
||||
|
||||
/// <summary>Flat MP bonus added to each unit at the start of its owner's turn. 0 = no buff.</summary>
|
||||
public int MpBuff { get; init; } = 0;
|
||||
|
||||
public static readonly GameRules Default = new();
|
||||
}
|
||||
|
||||
@@ -55,12 +55,12 @@ public static class AffinitySystem
|
||||
|
||||
// ── Hill pairings ─────────────────────────────────────────────────
|
||||
(Affinity.Hill, Affinity.Hill) => Affinity.Mountain,
|
||||
(Affinity.Hill, Affinity.Field) or (Affinity.Field, Affinity.Hill) => Affinity.Grove,
|
||||
(Affinity.Hill, Affinity.Field) or (Affinity.Field, Affinity.Hill) => Affinity.Steppe,
|
||||
(Affinity.Hill, Affinity.Forest) or (Affinity.Forest, Affinity.Hill) => Affinity.Fort,
|
||||
|
||||
// ── Field pairings ────────────────────────────────────────────────
|
||||
(Affinity.Field, Affinity.Field) => Affinity.Plains,
|
||||
(Affinity.Field, Affinity.Forest) or (Affinity.Forest, Affinity.Field) => Affinity.Steppe,
|
||||
(Affinity.Field, Affinity.Forest) or (Affinity.Forest, Affinity.Field) => Affinity.Grove,
|
||||
|
||||
// ── Forest pairings ───────────────────────────────────────────────
|
||||
(Affinity.Forest, Affinity.Forest) => Affinity.Jungle,
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
# Plan: Extended Custom Game System
|
||||
|
||||
## Context
|
||||
The game already has a minimal 2-player custom lobby (create/join/list), but it is missing most of the requested features: the full rule set, spectating, board templates, preset save/reload with voting, and all client-side UI. This plan extends the existing foundation into a complete custom game system.
|
||||
|
||||
**Scope decisions:**
|
||||
- **2-player only** for now (engine is strictly 2-player; MaxPlayers is a UI-only stub)
|
||||
- **Hex tile** is a stub (field stored, option shown as disabled in client)
|
||||
- **Save/reload** = named lobby-config presets (NOT mid-match state resume)
|
||||
- **Turn timer** = auto-end turn when expired (not auto-concede)
|
||||
- **Lobby privacy** = public + optional password
|
||||
|
||||
---
|
||||
|
||||
## Deferred / Out of Scope
|
||||
|
||||
The following features are intentionally excluded from this implementation pass. Track these for future work:
|
||||
|
||||
| Feature | Notes |
|
||||
|---|---|
|
||||
| **Board templates** | `BoardTemplateIdOverride` column added to schema as a nullable `Guid`, but no `BoardTemplate` entity, no admin page to create/edit templates, and no engine logic to apply a template. Wire-up deferred until template format is designed. |
|
||||
| **Admin: BoardTemplate editor** | Full CRUD page for named board templates (tile layout, size, special tiles). Requires defining what a template actually stores (JSON layout? preset size only?). |
|
||||
| **Admin: Custom lobby oversight** | Admin page listing all active/recent custom lobbies, with ability to cancel a lobby or kick a player. |
|
||||
| **Hex tile shape** | `TileShape` field can be stored as an enum stub (Square / Hex), but the engine, client renderer, and pathfinding are square-only. Hex is UI-disabled. |
|
||||
| **3+ player support** | `MinPlayers` / `MaxPlayers` are UI-only stubs. Engine is strictly 2-player. Multi-player requires engine rewrite. |
|
||||
| **Lobby chat** | In-lobby text chat between host and guest before the game starts. |
|
||||
| **Friend invite / direct invite** | Invite a specific player by name/ID to your lobby, bypassing the browser. |
|
||||
| **Spectate from browser** | Browsing and joining in-progress games as a spectator. Current plan only covers `game.spectate` by known `SessionId`. Requires a `game.custom.list_active` endpoint and browser UI flow. |
|
||||
| **Public preset sharing** | Presets are personal (owner-scoped) only. Public presets browsable by all players are deferred. |
|
||||
| **Replay system** | Recording and replaying completed games. Related to spectating infrastructure. |
|
||||
| **OP/ELO rewards for custom games** | Custom games give 0 OP and no ELO change. A configurable rewards toggle is deferred. |
|
||||
| **Vote "concede" option** | The preset-load vote only supports yes/no. A third "concede the lobby" option (host or guest exits if vote drags on) is deferred. |
|
||||
| **Lobby update while waiting** | Host changing rules after the guest has joined (without a preset vote) — rules are currently only editable while lobby is `Open`. Real-time rule editing in `Full` state requires a push + guest acknowledgement flow. |
|
||||
|
||||
---
|
||||
|
||||
## Phase 1 — DB Schema Extensions
|
||||
|
||||
### New fields on `CustomLobby`
|
||||
**File:** `Server/src/SOR.Database/Entities/Game/CustomLobby.cs`
|
||||
|
||||
Add nullable override columns (parallel to existing pattern):
|
||||
```csharp
|
||||
public string? Password { get; set; } // null = no password
|
||||
public int? HandSizeCapOverride { get; set; } // 0 = no cap
|
||||
public bool? DiscardOnMaxHandOverride { get; set; }
|
||||
public int? MaxDeckSizeOverride { get; set; } // 0 = no limit
|
||||
public int? MinDeckSizeOverride { get; set; }
|
||||
public int? MaxArchTier1Override { get; set; } // 0 = no limit
|
||||
public int? TurnTimerSecondsOverride { get; set; } // 0 = no timer
|
||||
public int? TimeLimitMinutesOverride { get; set; } // 0 = no limit
|
||||
public int? TurnLimitOverride { get; set; } // 0 = no limit
|
||||
public int? MpBuffOverride { get; set; } // flat bonus to unit MP per turn
|
||||
public int? BoardWidthOverride { get; set; }
|
||||
public int? BoardHeightOverride { get; set; }
|
||||
```
|
||||
|
||||
### New fields on `GameRuleSet`
|
||||
**File:** `Server/src/SOR.Database/Entities/Game/GameRuleSet.cs`
|
||||
|
||||
Same set of non-nullable fields with sensible defaults (0 = disabled for caps/limits).
|
||||
|
||||
### Extend `GameRules` record
|
||||
**File:** `Server/src/SOR.Game/GameRules.cs`
|
||||
|
||||
```csharp
|
||||
public int HandSizeCap { get; init; } = 0; // 0 = no cap
|
||||
public bool DiscardOnMaxHand { get; init; } = false;
|
||||
public int MaxDeckSize { get; init; } = 0;
|
||||
public int MinDeckSize { get; init; } = 0;
|
||||
public int MaxArchTier1 { get; init; } = 0; // 0 = no limit
|
||||
public int TurnTimerSeconds { get; init; } = 0; // 0 = no timer
|
||||
public int TimeLimitMinutes { get; init; } = 0;
|
||||
public int TurnLimit { get; init; } = 0;
|
||||
public int MpBuff { get; init; } = 0; // added to each unit's MP at turn start
|
||||
```
|
||||
|
||||
### New entity: `LobbyPreset`
|
||||
**File (new):** `Server/src/SOR.Database/Entities/Game/LobbyPreset.cs`
|
||||
|
||||
```csharp
|
||||
public sealed class LobbyPreset
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid OwnerAccountId { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string RulesJson { get; set; } = "{}"; // serialized CustomRulesOverride
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
}
|
||||
```
|
||||
- Add `DbSet<LobbyPreset> LobbyPresets` to `GameDbContext`.
|
||||
- EF config: `ToTable("lobby_presets", "game")`, index on `OwnerAccountId`.
|
||||
|
||||
### Migration
|
||||
**Dir:** `Server/src/SOR.Database/Migrations/Game/`
|
||||
|
||||
One migration (`AddCustomGameExtensions`) adding:
|
||||
- All new columns to `game.custom_lobbies`
|
||||
- All new columns to `game.game_rule_sets`
|
||||
- New table `game.lobby_presets`
|
||||
- Update `GameDbContextModelSnapshot.cs`
|
||||
|
||||
---
|
||||
|
||||
## Phase 2 — GameRules Application in GameEngine
|
||||
|
||||
**File:** `Server/src/SOR.Game/GameEngine.cs` (and related engine files)
|
||||
|
||||
Fixes and new rule enforcement:
|
||||
1. **`DrawPerTurn`** — currently ignored in the Draw phase; find the draw logic and apply `state.Rules.DrawPerTurn` instead of hardcoded 1.
|
||||
2. **`HandSizeCap` / `DiscardOnMaxHand`** — after drawing: if `HandSizeCap > 0 && hand.Count > HandSizeCap`, discard excess from top (or block draw if `!DiscardOnMaxHand`).
|
||||
3. **`MpBuff`** — at start of each player's turn, add `Rules.MpBuff` to all friendly unit MP values (clamped to max MP).
|
||||
4. **`TurnLimit`** — at the start of a turn, if `Rules.TurnLimit > 0 && state.TurnNumber > Rules.TurnLimit`, trigger game over with win condition `"turn_limit"` (winner = player with most ArchSpirit HP; tie = draw, loser = P2).
|
||||
5. **`TimeLimitMinutes`** — stored in rules; enforced in `GameTurnTimerService` (Phase 3) by checking `session.CreatedAt`.
|
||||
6. **Deck validation** (`MaxDeckSize`, `MinDeckSize`, `MaxArchTier1`) — add a `GameEngine.ValidateDeck(deck, rules)` method returning validation errors. Called in `GameJoinCustomLobbyHandler` before creating the session (only when custom rules have non-zero limits).
|
||||
|
||||
---
|
||||
|
||||
## Phase 3 — Turn Timer Service
|
||||
|
||||
**File (new):** `Server/src/SOR.Game/GameTurnTimerService.cs`
|
||||
|
||||
A `BackgroundService` singleton managing per-session turn timers:
|
||||
|
||||
```csharp
|
||||
internal sealed class GameTurnTimerService : BackgroundService
|
||||
{
|
||||
// sessionId → CancellationTokenSource for the current turn timer
|
||||
private readonly ConcurrentDictionary<Guid, CancellationTokenSource> _timers = new();
|
||||
|
||||
public void ResetTimer(Guid sessionId, int turnTimerSeconds, int timeLimitMinutes,
|
||||
DateTimeOffset sessionCreatedAt, Func<Guid, Task> onExpired) { ... }
|
||||
public void CancelTimer(Guid sessionId) { ... }
|
||||
}
|
||||
```
|
||||
|
||||
**Integration:**
|
||||
- `SaveStateAsync` in `GameHandlerBase` calls `GameTurnTimerService.ResetTimer(...)` after committing, passing the `state.Rules.TurnTimerSeconds` and an `onExpired` callback.
|
||||
- On expiry: the service calls `EndTurnAsync(sessionId)` — a helper that loads the session and injects a synthetic `game.end_turn` action (reusing `GameEndTurnHandler` logic via a shared static method extracted from the handler).
|
||||
- Register as singleton + hosted service in `ServiceRegistration.cs`.
|
||||
|
||||
---
|
||||
|
||||
## Phase 4 — Spectator Support
|
||||
|
||||
### `SpectatorRegistryService` (singleton)
|
||||
**File (new):** `Server/src/SOR.Game/SpectatorRegistryService.cs`
|
||||
|
||||
```csharp
|
||||
internal sealed class SpectatorRegistryService
|
||||
{
|
||||
private readonly ConcurrentDictionary<Guid, ImmutableHashSet<Guid>> _map = new();
|
||||
|
||||
public void Register(Guid sessionId, Guid accountId) { ... }
|
||||
public void Unregister(Guid sessionId, Guid accountId) { ... }
|
||||
public void RemoveSession(Guid sessionId) { ... }
|
||||
public IReadOnlySet<Guid> GetSpectators(Guid sessionId) { ... }
|
||||
}
|
||||
```
|
||||
|
||||
### New handler: `GameSpectateHandler`
|
||||
**File (new):** `Server/src/SOR.Game/Handlers/GameSpectateHandler.cs`
|
||||
|
||||
- Message: `game.spectate`
|
||||
- Request: `SpectateRequest(Guid SessionId)`
|
||||
- Loads session (must be Active), registers caller in `SpectatorRegistryService`.
|
||||
- Returns current state filtered for spectator (both hands as count-only).
|
||||
- Ack: `game.spectate.ack` with `GameStateDtoSpectator`.
|
||||
|
||||
### `GameStateDto` spectator variant
|
||||
**File:** `Server/src/SOR.Game/GameMessages.cs` or engine DTO file
|
||||
|
||||
Add `GameEngine.ToDtoSpectator(state)` — same as `ToDto` but both `MyHand` and `OpponentHand` contain only the card count (no `CardId`, no `InstanceId`). Alternatively, pass a new `viewerAccountId = null` sentinel to `ToDto` that triggers the spectator path.
|
||||
|
||||
### Push to spectators
|
||||
**File:** `Server/src/SOR.Game/Handlers/GameHandlerBase.cs`
|
||||
|
||||
Extend `PushStateToPlayersAsync` to also push to spectators:
|
||||
```csharp
|
||||
foreach (var specId in spectatorRegistry.GetSpectators(session.Id))
|
||||
await clientPush.PushAsync(specId.ToString(),
|
||||
ServerMessage.Push("game.state_update",
|
||||
new GameStateUpdatePush(GameEngine.ToDtoSpectator(state))), ct);
|
||||
```
|
||||
Also call `spectatorRegistry.RemoveSession` in `FinalizeGameAsync` after pushing `game.over` to spectators.
|
||||
|
||||
---
|
||||
|
||||
## Phase 5 — Preset Save / Propose / Vote
|
||||
|
||||
### `VoteSessionService` (singleton)
|
||||
**File (new):** `Server/src/SOR.Game/VoteSessionService.cs`
|
||||
|
||||
```csharp
|
||||
internal sealed record ActiveVote(Guid LobbyId, Guid PresetId, CustomRulesOverride Rules,
|
||||
Dictionary<Guid, bool?> Votes);
|
||||
|
||||
internal sealed class VoteSessionService
|
||||
{
|
||||
private readonly ConcurrentDictionary<Guid, ActiveVote> _votes = new(); // lobbyId → vote
|
||||
|
||||
public void Start(Guid lobbyId, Guid presetId, CustomRulesOverride rules, IEnumerable<Guid> voters);
|
||||
public VoteOutcome Cast(Guid lobbyId, Guid accountId, bool vote); // Pending/Approved/Rejected
|
||||
public ActiveVote? Get(Guid lobbyId);
|
||||
public void Cancel(Guid lobbyId);
|
||||
}
|
||||
```
|
||||
|
||||
### New handlers (in `Server/src/SOR.Game/Handlers/`)
|
||||
|
||||
| Handler | Message | Description |
|
||||
|---|---|---|
|
||||
| `GameSavePresetHandler` | `game.custom.preset.save` | Save lobby's current rules as a named `LobbyPreset` (only participants). |
|
||||
| `GameListPresetsHandler` | `game.custom.preset.list` | Return caller's saved presets. |
|
||||
| `GameDeletePresetHandler` | `game.custom.preset.delete` | Delete a preset owned by the caller. |
|
||||
| `GameProposePresetHandler` | `game.custom.preset.propose` | Host proposes loading a preset; starts `VoteSession`; pushes `game.custom.preset.vote_requested` to other player. |
|
||||
| `GameVotePresetHandler` | `game.custom.preset.vote` | Cast yes/no. If approved: update lobby rule overrides + push `game.custom.lobby_updated` to both. If rejected: push `game.custom.preset.vote_rejected`. |
|
||||
|
||||
### New message types (in `GameMessages.cs`)
|
||||
```csharp
|
||||
record SavePresetRequest(Guid LobbyId, string PresetName);
|
||||
record ListPresetsRequest;
|
||||
record DeletePresetRequest(Guid PresetId);
|
||||
record ProposePresetRequest(Guid LobbyId, Guid PresetId);
|
||||
record VotePresetRequest(Guid LobbyId, bool Accept);
|
||||
record LobbyPresetDto(Guid PresetId, string Name, CustomRulesOverride Rules, DateTimeOffset CreatedAt);
|
||||
record PresetVoteRequestedPush(Guid LobbyId, Guid PresetId, string PresetName, CustomRulesOverride Rules);
|
||||
record LobbyUpdatedPush(Guid LobbyId, CustomRulesDto NewRules);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 6 — Lobby Enhancements
|
||||
|
||||
### Password protection
|
||||
- `CreateCustomLobbyRequest`: add `string? Password = null`.
|
||||
- `CustomLobby`: store `Password` (hashed? plain text is fine for game lobbies).
|
||||
- `JoinCustomLobbyRequest`: add `string? Password = null`.
|
||||
- `GameJoinCustomLobbyHandler`: if `lobby.Password != null && lobby.Password != req.Password` → throw `GameException("WRONG_PASSWORD")`.
|
||||
|
||||
### Host notification on guest join
|
||||
**File:** `Server/src/SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs`
|
||||
- After guest joins (lobby now Full), push `game.custom.guest_joined` to host with `GuestAccountId`.
|
||||
|
||||
### Lobby browser filters
|
||||
**File:** `Server/src/SOR.Game/Handlers/GameListCustomLobbiesHandler.cs`
|
||||
- `ListCustomLobbiesRequest`: add `string? NameSearch = null`, `bool ShowPasswordProtected = true`.
|
||||
- Apply `.Where(l => NameSearch == null || l.Name.Contains(NameSearch))` etc.
|
||||
|
||||
### Get single lobby
|
||||
**File (new):** `Server/src/SOR.Game/Handlers/GameGetLobbyHandler.cs`
|
||||
- `game.custom.get` — returns full `CustomLobbyDetailDto` (all rules, host/guest presence) for a specific lobby ID.
|
||||
|
||||
---
|
||||
|
||||
## Phase 7 — Update Existing Handlers for New Rules
|
||||
|
||||
### `GameCreateCustomLobbyHandler`
|
||||
**File:** `Server/src/SOR.Game/Handlers/GameCreateCustomLobbyHandler.cs`
|
||||
|
||||
- Extend `effective` `GameRules` construction + `CustomLobby` override storage to cover all new rule fields.
|
||||
- Pass `Password` from request to entity.
|
||||
|
||||
### `GameJoinCustomLobbyHandler`
|
||||
**File:** `Server/src/SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs`
|
||||
|
||||
- Extend `GameRules` construction to include all new fields.
|
||||
- Call `GameEngine.ValidateDeck(hostDeck, rules)` and `GameEngine.ValidateDeck(guestDeck, rules)` before creating the session (requires loading decks — use `CatalogDbContext`).
|
||||
|
||||
### `GameListCustomLobbiesHandler`
|
||||
- Extend `CustomRulesDto` mapping to include new rule fields.
|
||||
- Apply new filters.
|
||||
|
||||
### `CustomRulesDto` and `CustomRulesOverride` records
|
||||
**File:** `Server/src/SOR.Game/GameMessages.cs`
|
||||
- Add all new fields with defaults to both records.
|
||||
|
||||
---
|
||||
|
||||
## Phase 8 — Client Scenes
|
||||
|
||||
### New: `CustomLobbyBrowser.tscn` + `custom_lobby_browser.gd`
|
||||
**Dir:** `Client/origin-client/scenes/lobby/`
|
||||
|
||||
- Full-screen scene with filter bar + lobby list.
|
||||
- Filter: name search input, refresh button.
|
||||
- Each row: lobby name, host username, player count (1/2), key rules summary, Join button.
|
||||
- "Create Lobby" button → opens `CustomRulesEditor` panel → sends `game.custom.create` → navigates to `CustomLobbyRoom`.
|
||||
- On Join: sends `game.custom.join` (with optional password prompt) → navigates to `CustomLobbyRoom`.
|
||||
|
||||
### New: `CustomLobbyRoom.tscn` + `custom_lobby_room.gd`
|
||||
**Dir:** `Client/origin-client/scenes/lobby/`
|
||||
|
||||
- Shows both player slots (host / guest or "Waiting...").
|
||||
- Rules panel (read-only for guest, editable for host).
|
||||
- Preset buttons: Save, Load (host only) — opens preset list dialog.
|
||||
- Start is automatic when guest joins (game.custom.started push).
|
||||
- Leave button → `game.custom.leave`.
|
||||
- On receiving `game.custom.started` push: navigate to `GameScreen` with session ID.
|
||||
|
||||
### New: `CustomRulesEditor.tscn` + `custom_rules_editor.gd`
|
||||
- Panel component embedded in both browser (create flow) and lobby room (host editing).
|
||||
- One control per rule (sliders/spinboxes for ints, checkboxes for bools).
|
||||
- "Save as Preset" button (in room only).
|
||||
|
||||
### `game_screen.gd` — spectator mode
|
||||
**File:** `Client/origin-client/scenes/game/game_screen.gd`
|
||||
|
||||
- On `game.spectate.ack`: set `_is_spectator = true`.
|
||||
- When `_is_spectator`: hide hand panel and action buttons; show "SPECTATING" label.
|
||||
- Hand display for both players shows count label only.
|
||||
|
||||
---
|
||||
|
||||
## Implementation Order
|
||||
|
||||
1. **Phase 1** — DB schema + migration (new columns + LobbyPreset table)
|
||||
2. **Phase 2** — GameRules record extension + GameEngine fixes (DrawPerTurn, HandSizeCap, MpBuff, TurnLimit, ValidateDeck)
|
||||
3. **Phase 7** — Extend existing create/join/list handlers + DTOs for all new rule fields
|
||||
4. **Phase 3** — GameTurnTimerService
|
||||
5. **Phase 4** — SpectatorRegistryService + GameSpectateHandler + PushStateToPlayersAsync changes
|
||||
6. **Phase 5** — VoteSessionService + all preset handlers
|
||||
7. **Phase 6** — Password, host-join push, lobby filters, GameGetLobbyHandler
|
||||
8. **Phase 8** — Client scenes (CustomLobbyBrowser, CustomLobbyRoom, CustomRulesEditor, spectator mode)
|
||||
|
||||
---
|
||||
|
||||
## Key Files Summary
|
||||
|
||||
| File | Change |
|
||||
|---|---|
|
||||
| `SOR.Database/Entities/Game/CustomLobby.cs` | +12 new override columns |
|
||||
| `SOR.Database/Entities/Game/GameRuleSet.cs` | +9 new rule fields |
|
||||
| `SOR.Database/Entities/Game/LobbyPreset.cs` | **NEW** entity |
|
||||
| `SOR.Database/Migrations/Game/` | **NEW** migration `AddCustomGameExtensions` |
|
||||
| `SOR.Game/GameRules.cs` | +9 new rule fields |
|
||||
| `SOR.Game/GameEngine.cs` | Fix DrawPerTurn; add HandSizeCap, MpBuff, TurnLimit, ValidateDeck |
|
||||
| `SOR.Game/GameMessages.cs` | Extend DTOs + add preset/spectate/vote message types |
|
||||
| `SOR.Game/GameTurnTimerService.cs` | **NEW** BackgroundService |
|
||||
| `SOR.Game/SpectatorRegistryService.cs` | **NEW** singleton |
|
||||
| `SOR.Game/VoteSessionService.cs` | **NEW** singleton |
|
||||
| `SOR.Game/Handlers/GameHandlerBase.cs` | Extend PushStateToPlayersAsync for spectators |
|
||||
| `SOR.Game/Handlers/GameCreateCustomLobbyHandler.cs` | Extend for all new rules + password |
|
||||
| `SOR.Game/Handlers/GameJoinCustomLobbyHandler.cs` | Extend rules + deck validation + password check |
|
||||
| `SOR.Game/Handlers/GameListCustomLobbiesHandler.cs` | Extend DTO + filters |
|
||||
| `SOR.Game/Handlers/GameSpectateHandler.cs` | **NEW** |
|
||||
| `SOR.Game/Handlers/GameSavePresetHandler.cs` | **NEW** |
|
||||
| `SOR.Game/Handlers/GameListPresetsHandler.cs` | **NEW** |
|
||||
| `SOR.Game/Handlers/GameDeletePresetHandler.cs` | **NEW** |
|
||||
| `SOR.Game/Handlers/GameProposePresetHandler.cs` | **NEW** |
|
||||
| `SOR.Game/Handlers/GameVotePresetHandler.cs` | **NEW** |
|
||||
| `SOR.Game/Handlers/GameGetLobbyHandler.cs` | **NEW** |
|
||||
| `SOR.Game/ServiceRegistration.cs` | Register all new services + handlers |
|
||||
| `SOR.Host/Program.cs` | *(No changes — wiring stays in ServiceRegistration)* |
|
||||
| `Client/origin-client/scenes/lobby/CustomLobbyBrowser.tscn` | **NEW** |
|
||||
| `Client/origin-client/scenes/lobby/custom_lobby_browser.gd` | **NEW** |
|
||||
| `Client/origin-client/scenes/lobby/CustomLobbyRoom.tscn` | **NEW** |
|
||||
| `Client/origin-client/scenes/lobby/custom_lobby_room.gd` | **NEW** |
|
||||
| `Client/origin-client/scenes/lobby/CustomRulesEditor.tscn` | **NEW** |
|
||||
| `Client/origin-client/scenes/lobby/custom_rules_editor.gd` | **NEW** |
|
||||
| `Client/origin-client/scenes/game/game_screen.gd` | +spectator mode |
|
||||
|
||||
---
|
||||
|
||||
## Verification
|
||||
|
||||
1. **Full lobby flow**: Create lobby → second client joins → both navigate to game screen → game starts normally.
|
||||
2. **New rules applied**: Set `DrawPerTurn = 2`, play to Draw phase → confirm 2 cards drawn. Set `HandSizeCap = 5` → confirm hand is trimmed.
|
||||
3. **Turn timer**: Set `TurnTimerSeconds = 30` → leave a turn idle for 30s → confirm turn auto-ends.
|
||||
4. **Spectator**: Third client sends `game.spectate` → receives state with hand counts only → receives state updates as game progresses.
|
||||
5. **Preset save/load**: Host saves preset → Guest proposes loading it → Host votes yes → lobby rules update → both clients see new rules.
|
||||
6. **Password**: Create lobby with password → join without password → error. Join with correct password → succeeds.
|
||||
7. **Deck validation**: Set `MinDeckSize = 40` → try to join with 30-card deck → error.
|
||||
Reference in New Issue
Block a user