From 2c737458a8aeab0010470826b8ca63a7e9a1f64d Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 22 Mar 2026 10:21:35 -0400 Subject: [PATCH] Fix ability builder crash + implement TargetOwnership.Target for Player targets - AbilityBuilder.razor: ReadFixed now checks if the JSON node is a JsonObject before calling GetValue() on it. Previously, a ValueExpr like {"Ref":"Target.SpCost"} caused an InvalidOperationException that was swallowed silently by ParseJson's catch block, leaving the builder showing no abilities. - AbilitySystem.cs: TargetOwnership.Target on Player-type selectors now resolves to the owner of the last CardInstance in ctx.ResolvedTargets. This enables abilities like Bounce: Action 1 returns a spirit to hand, Action 2 targets that spirit's owner (Ownership:Target) to refund its channel cost via a Ref value. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor | 8 ++++++-- Server/src/SOR.Game/Abilities/AbilitySystem.cs | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor index 9abd4dd..4b03178 100644 --- a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor +++ b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor @@ -948,9 +948,13 @@ var typeKey = eff["$type"]?.GetValue() ?? "DealDamage"; var d = new EffectDraft { TypeKey = typeKey }; - // ValueExpr helpers + // ValueExpr helpers — eff[key] may be a raw JsonValue (legacy) or a JsonObject + // with a "Fixed" int field or a "Ref" string field. Calling GetValue() on a + // JsonObject throws InvalidOperationException, so we branch on the node kind. int ReadFixed(string key, int def = 1) => - eff[key]?["Fixed"]?.GetValue() ?? eff[key]?.GetValue() ?? def; + eff[key] is JsonObject o + ? o["Fixed"]?.GetValue() ?? def + : eff[key]?.GetValue() ?? def; string ReadRef(string key) => eff[key]?["Ref"]?.GetValue() ?? ""; void ReadValueExpr(string key) { d.Amount = ReadFixed(key); d.AmountRef = ReadRef(key); } diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 9883603..8d32288 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -482,6 +482,13 @@ public static class AbilitySystem [state.Players[ctx.ActorId]], TargetOwnership.Enemy => state.Players.Values.Where(p => p.AccountId != ctx.ActorId).Cast().ToList(), + // Target: resolve the owner of the last CardInstance selected in a prior action. + // Used for abilities like Bounce (return a spirit, then refund its SP cost to its owner). + TargetOwnership.Target when + ctx.ResolvedTargets.Count > 0 && + ctx.ResolvedTargets.Values.Last().FirstOrDefault() is CardInstance lastCard && + FindCardOwner(state, lastCard.InstanceId) is { } owner => + [(object)owner], _ => state.Players.Values.Cast().ToList(), }; }