feat(battle-engine-port): M5 COMPLETE — summon_token spell resolves headless (board-count delta oracle)

Card 800134010 (clan-1 cost-1 ungated spell, summon_token=100011020): a when_play
summon places one new neutral 2/2 follower token on the caster board. New oracle
dimension = board-count + token-identity delta from a SKILL-CREATED card. 5/5 green;
engine 0 errors; check_drift clean; zero new Engine copies.

This is the first headless run of the PUBLIC prefab card-creation path
(CardCreatorBase.CreateCard, createNullView:false) — engine-internal card creation
(summon/draw/token) has no null-view path in solo mode, unlike the M2-M4 hand-card
seam. Built that path headless:
- Self-consistent no-op Unity object graph (UnityShim.cs): Component.gameObject/
  transform, GameObject.transform, Transform.parent/Find now lazily non-null +
  cached; GetComponent routed through the GameObject component model.
- Targeted NGUI material backing-field wiring (UIFont.mMat / UILabel.mMaterial) so
  the copied material getters return non-null via their simple branch (blanket/deep
  wiring would make them delegate down a re-nulling chain).
- getUIBase_CardManager() default! -> field-wired no-op via new ShimView.Create<T>().
- Test-side seeds: SBattleLoad card templates + 3D scene GameObjects (InitCardTemplates).

Load-bearing proof: swapping to the M3 non-summoning spell fails the board-count
(Expected 2, was 1) + token-not-found assertions; reverted to green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-06 03:19:12 -04:00
parent b13cfa0fad
commit 62a28fe2d4
4 changed files with 249 additions and 13 deletions

View File

@@ -0,0 +1,106 @@
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Wizard;
using Wizard.Battle;
namespace SVSim.BattleEngine.Tests
{
// M5 (next-hardest deterministic card): a when_play SUMMON_TOKEN spell resolves to correct
// authoritative state HEADLESS via the same IsForecast/IsRecovery + ActionProcessor path the
// M2 vanilla follower / M3 fixed-damage spell / M4 self-buff follower proved (design §5 / DP4 +
// M3+ resume recipe). The new oracle dimension over M2-M4 is a BOARD-COUNT DELTA from a
// SKILL-CREATED card: the spell's `summon_token=100011020` must place exactly one NEW follower
// token (id 100011020, a neutral 2/2) onto the caster's board — a card that was never in the
// hand or deck. This is the first headless run of the PUBLIC prefab card-creation path
// (CardCreatorBase.CreateCard, createNullView:false), so it stresses the view shim in a way the
// earlier null-view-seam milestones did not.
[TestFixture]
public class SummonTokenOracleTests
{
private static void SetPrivateField(object obj, string name, object value)
{
var t = obj.GetType();
var f = t.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
while (f == null && t.BaseType != null) { t = t.BaseType; f = t.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic); }
Assert.That(f, Is.Not.Null, $"field {name} not found on {obj.GetType().Name}");
f.SetValue(obj, value);
}
[Test]
public void Summon_token_spell_places_a_new_token_on_the_board()
{
HeadlessEngineEnv.EnsureInitialized();
BattleManagerBase.IsForecast = true; // suppress VFX registration (F1)
var mgr = new SingleBattleMgr(new HeadlessContentsCreator());
mgr.IsRecovery = true; // collapse wait delays to 0 (F1)
var player = mgr.BattlePlayer;
var enemy = mgr.BattleEnemy;
// Minimal opponent/turn wiring (see M2-M4 oracles): opponent refs + active turn flag.
// The summon resolves onto the active player's own board (`summon_side` defaults to self).
SetPrivateField(player, "_opponentBattlePlayer", enemy);
SetPrivateField(enemy, "_opponentBattlePlayer", player);
player.IsSelfTurn = true;
enemy.IsSelfTurn = false;
// Seed leader life: this spell deals no damage, but the play-legality gate still rejects a
// play when a leader reads as a 0-life game-over state (M3 learning).
HeadlessEngineEnv.InitLeaderLife(mgr);
// Seed the card-template prefabs the engine's internal (createNullView:false) summon
// creation path clones — the bare construction path leaves SBattleLoad null.
HeadlessEngineEnv.InitCardTemplates(mgr);
var cardParam = CardMaster.GetInstanceForBattle().GetCardParameterFromId(HeadlessEngineEnv.TokenSpellId);
// Place the summon-token spell in the active player's hand with PP to spare; empty board.
var card = HeadlessEngineEnv.CreateHeadlessHandCard(HeadlessEngineEnv.TokenSpellId, 1, isPlayer: true, mgr);
player.HandCardList.Add(card);
player.Pp = 10;
// Pre-state snapshot. ClassAndInPlayCardList holds the leader (index 0) on an empty board.
int ppBefore = player.Pp;
int handBefore = player.HandCardList.Count;
int playerInplayBefore = player.ClassAndInPlayCardList.Count;
int enemyHandBefore = enemy.HandCardList.Count;
int enemyInplayBefore = enemy.ClassAndInPlayCardList.Count;
int enemyLeaderLifeBefore = enemy.ClassAndInPlayCardList[0].Life;
// Resolve the play through the real engine.
var pair = mgr.GetBattlePlayerPair(isPlayer: true);
var ap = new ActionProcessor(pair);
Assert.DoesNotThrow(() => ap.PlayCard(card, selectedCards: null),
"ActionProcessor.PlayCard threw on a summon-token spell");
// Oracle: the board-count delta + summoned token identity is the new M5 dimension; the rest
// are the §5 spell-shaped invariants proven by M3.
Assert.Multiple(() =>
{
// Primary M5 assertion: exactly one NEW card is on the player's board (the summoned
// token), and it is the token id with its CardCSVData base stats — proving the skill
// CREATED a card, not just moved the played one.
Assert.That(player.ClassAndInPlayCardList.Count, Is.EqualTo(playerInplayBefore + 1),
"player board count not +1 (the summoned token did not land)");
var token = player.ClassAndInPlayCardList
.SingleOrDefault(c => c.CardId == HeadlessEngineEnv.SummonedTokenId);
Assert.That(token, Is.Not.Null, "summoned token (id 100011020) not found on the board");
Assert.That(token.Atk, Is.EqualTo(HeadlessEngineEnv.SummonedTokenAtk), "token atk != base");
Assert.That(token.Life, Is.EqualTo(HeadlessEngineEnv.SummonedTokenLife), "token life != base");
// The summoned token is NOT the played card.
Assert.That(token, Is.Not.SameAs(card), "summoned token is the played spell itself");
// Cost paid.
Assert.That(player.Pp, Is.EqualTo(ppBefore - cardParam.Cost), "PP not reduced by exactly cost");
// The spell leaves hand and (being a spell) does NOT itself occupy the board.
Assert.That(player.HandCardList, Does.Not.Contain(card), "spell still in hand");
Assert.That(player.HandCardList.Count, Is.EqualTo(handBefore - 1), "hand count not -1");
Assert.That(player.ClassAndInPlayCardList, Does.Not.Contain(card), "spell wrongly placed on the board");
// Opponent unchanged (the summon targets the caster's own board).
Assert.That(enemy.HandCardList.Count, Is.EqualTo(enemyHandBefore), "opponent hand changed");
Assert.That(enemy.ClassAndInPlayCardList.Count, Is.EqualTo(enemyInplayBefore), "opponent board changed");
Assert.That(enemy.ClassAndInPlayCardList[0].Life, Is.EqualTo(enemyLeaderLifeBefore), "opponent leader life changed");
});
}
}
}