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<int>() 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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -948,9 +948,13 @@
|
||||
var typeKey = eff["$type"]?.GetValue<string>() ?? "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<int>() on a
|
||||
// JsonObject throws InvalidOperationException, so we branch on the node kind.
|
||||
int ReadFixed(string key, int def = 1) =>
|
||||
eff[key]?["Fixed"]?.GetValue<int>() ?? eff[key]?.GetValue<int>() ?? def;
|
||||
eff[key] is JsonObject o
|
||||
? o["Fixed"]?.GetValue<int>() ?? def
|
||||
: eff[key]?.GetValue<int>() ?? def;
|
||||
string ReadRef(string key) =>
|
||||
eff[key]?["Ref"]?.GetValue<string>() ?? "";
|
||||
void ReadValueExpr(string key) { d.Amount = ReadFixed(key); d.AmountRef = ReadRef(key); }
|
||||
|
||||
@@ -482,6 +482,13 @@ public static class AbilitySystem
|
||||
[state.Players[ctx.ActorId]],
|
||||
TargetOwnership.Enemy =>
|
||||
state.Players.Values.Where(p => p.AccountId != ctx.ActorId).Cast<object>().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<object>().ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user