Ability system: zone-scope card picks, target-pick prompts, builder filter editor, tests
Server engine (SOR.Game): - Zone-scope card targets (Hand/Deck/Discard/AnyZone) pause with a server- enumerated candidates list (PendingTargetPick.CandidatesJson) instead of failing when the client submits player accountIds for hidden zones - Missing mandatory target picks now prompt (PendingTargetPick) rather than throwing INSUFFICIENT_TARGETS; all post-pick resume flows run with requireClientTargets so actions never silently auto-hit the first candidate - ChannelCardFromZone: Filters + InOwn/InTargetChannelRange enforced via shared IsWithinChannelConstraints (incl. player-picked tile validation) - TakeControl duration reversal via internal __ReturnControl effect; board occupant-owner kept in sync both ways - TrackedDuration gains SourceOwnerAccountId (UntilStartOfSourceOwnerTurn now anchors correctly) and IsAura (aura reapply no longer strips unrelated buffs) - RevealCards honours N for player targets; IsAllyTurn means teammate's turn; content-keyed ParseAbilities cache; AbilityValidator for save-time linting; duplicate PolyType attributes removed (converter reads base registry only) Admin builder (AbilityBuilder/CardEditor): - Full multi-filter editor (28 filter types with parameter fields) replacing the single param-less dropdown; raw-JSON ChooseOne editor per action - Cost PickMode, TriggerLimitPerGame, SourceZoneGate inputs - Save-time ability validation with error list (blocks invalid saves) Client (Godot): - Card-list picker for zone-scope target picks; OR/XOR-root abilities skip speculative upfront targeting; ally units included in team-aware highlight pools (Game.get_ally_units); state re-sync on rejected pick responses Tests: new SOR.Game.Tests project (21 passing) covering the regression suite from SOR.Abilities-Review-and-solutions.md §8 plus validator rules. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
namespace SOR.Game.Tests;
|
||||
|
||||
using SOR.Game.Abilities;
|
||||
using Xunit;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for the save-time ability validation used by the admin CardEditor.
|
||||
/// </summary>
|
||||
public sealed class AbilityValidatorTests
|
||||
{
|
||||
private const string ValidActive = """
|
||||
[{
|
||||
"Type": "Active",
|
||||
"Name": "Bolt",
|
||||
"ActionGroup": {
|
||||
"LogicOp": "And",
|
||||
"Actions": [{
|
||||
"Target": { "Scope": "Battlefield", "Type": "Unit", "Ownership": "Enemy", "Count": { "N": 1 } },
|
||||
"Effects": [ { "$type": "DealDamage", "Amount": { "Fixed": 3 } } ]
|
||||
}],
|
||||
"Groups": []
|
||||
}
|
||||
}]
|
||||
""";
|
||||
|
||||
[Fact]
|
||||
public void ValidAbility_PassesForUnitAndEffectCards()
|
||||
{
|
||||
Assert.Empty(AbilityValidator.Validate(ValidActive, "Spirit"));
|
||||
Assert.Empty(AbilityValidator.Validate(ValidActive, "Repentance"));
|
||||
Assert.Empty(AbilityValidator.Validate(null, "Spirit"));
|
||||
Assert.Empty(AbilityValidator.Validate("", "Spirit"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnparseableJson_IsRejected()
|
||||
{
|
||||
const string badEnum = """
|
||||
[{ "Type": "Passive", "ActionGroup": { "LogicOp": "And", "Actions": [{
|
||||
"Target": { "Scope": "Battlefield", "Type": "Unit", "Ownership": "ExactSelf", "Count": { "N": 1 } },
|
||||
"Effects": [ { "$type": "ModifyHealth", "Amount": { "Fixed": 1 }, "StatTarget": "Base" } ]
|
||||
}], "Groups": [] } }]
|
||||
""";
|
||||
var errors = AbilityValidator.Validate(badEnum, "Spirit");
|
||||
Assert.Single(errors);
|
||||
Assert.Contains("deserialize", errors[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnimplementedTrigger_IsRejected()
|
||||
{
|
||||
const string json = """
|
||||
[{
|
||||
"Type": "Triggered",
|
||||
"Name": "Dead Trigger",
|
||||
"TriggerEvent": { "$type": "OnStatModified", "Ownership": "Any" },
|
||||
"ActionGroup": { "LogicOp": "And", "Actions": [], "Groups": [] }
|
||||
}]
|
||||
""";
|
||||
var errors = AbilityValidator.Validate(json, "Spirit");
|
||||
Assert.Contains(errors, e => e.Contains("never fire"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TriggeredWithoutEvent_IsRejected()
|
||||
{
|
||||
const string json = """
|
||||
[{ "Type": "Triggered", "Name": "Empty", "ActionGroup": { "LogicOp": "And", "Actions": [], "Groups": [] } }]
|
||||
""";
|
||||
var errors = AbilityValidator.Validate(json, "Spirit");
|
||||
Assert.Contains(errors, e => e.Contains("no TriggerEvent"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UnimplementedEffect_IsRejected()
|
||||
{
|
||||
const string json = """
|
||||
[{
|
||||
"Type": "Active",
|
||||
"Name": "NoOp",
|
||||
"ActionGroup": { "LogicOp": "And", "Actions": [{
|
||||
"Target": { "Scope": "Battlefield", "Type": "Unit", "Ownership": "Enemy", "Count": { "N": 1 } },
|
||||
"Effects": [ { "$type": "ChannelCard", "PayCost": true } ]
|
||||
}], "Groups": [] }
|
||||
}]
|
||||
""";
|
||||
var errors = AbilityValidator.Validate(json, "Spirit");
|
||||
Assert.Contains(errors, e => e.Contains("no engine implementation"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EffectCard_RangeAndNonActive_AreRejected()
|
||||
{
|
||||
const string json = """
|
||||
[{
|
||||
"Type": "Active",
|
||||
"Name": "Ranged Smite",
|
||||
"Range": { "Min": 1, "Max": 2 },
|
||||
"ActionGroup": { "LogicOp": "And", "Actions": [{
|
||||
"Target": { "Scope": "Battlefield", "Type": "Unit", "Ownership": "Enemy", "Count": { "N": 1 } },
|
||||
"Effects": [ { "$type": "DealDamage", "Amount": { "Fixed": 1 } } ]
|
||||
}], "Groups": [] }
|
||||
},
|
||||
{
|
||||
"Type": "Passive",
|
||||
"Name": "Never Runs",
|
||||
"ActionGroup": { "LogicOp": "And", "Actions": [], "Groups": [] }
|
||||
}]
|
||||
""";
|
||||
var errors = AbilityValidator.Validate(json, "Repentance");
|
||||
Assert.Contains(errors, e => e.Contains("Remove the Range"));
|
||||
Assert.Contains(errors, e => e.Contains("only Active abilities execute"));
|
||||
|
||||
// The same definitions are fine on a battlefield unit.
|
||||
Assert.Empty(AbilityValidator.Validate(json, "Spirit"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PassiveWithOrGroup_IsRejected()
|
||||
{
|
||||
const string json = """
|
||||
[{
|
||||
"Type": "Passive",
|
||||
"Name": "Choose Buff",
|
||||
"ActionGroup": { "LogicOp": "Or", "ChooserRole": "Self", "Actions": [{
|
||||
"Target": { "Scope": "Battlefield", "Type": "Unit", "Ownership": "ExactSelf", "Count": { "N": 1 } },
|
||||
"Effects": [ { "$type": "ModifyDamage", "Amount": { "Fixed": 1 } } ]
|
||||
}], "Groups": [] }
|
||||
}]
|
||||
""";
|
||||
var errors = AbilityValidator.Validate(json, "Spirit");
|
||||
Assert.Contains(errors, e => e.Contains("OR/XOR"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user