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

@@ -1,4 +1,5 @@
using System.Reflection;
using UnityEngine;
using Wizard;
using Wizard.Battle;
using Wizard.Battle.Phase;
@@ -32,6 +33,23 @@ namespace SVSim.BattleEngine.Tests
public const int BuffAddOffense = 1;
public const int BuffAddLife = 1;
// M5 next-hardest deterministic card: a when_play SUMMON_TOKEN spell. 800134010 is an ELF
// (clan 1) cost-1 spell whose sole skill is `when_play` `summon_token=100011020` with
// `skill_target=none` and an UNGATED condition (`character=me`, trivially the caster): it
// summons exactly ONE neutral 2/2 follower TOKEN onto the caster's board — no target
// selection, no RNG (Skill_summon_token's random branch is `num >= 0 && !IsForecast`, and
// this option carries no `random_count`, so num=-1 => the deterministic literal-id path).
// The new oracle dimension over M2/M3/M4 is a BOARD-COUNT DELTA from a SKILL-CREATED card:
// a token that was never in the hand/deck appears in play. This is also the first headless
// exercise of the PUBLIC prefab card-creation path (CardCreatorBase.CreateCard,
// createNullView:false, via BattlePlayerBase.CreateNextIndexCard) — class-card construction
// hits `default: return null` and the M2-M4 hand cards used the private null-view seam, so
// the view-building creation path is genuinely new here.
public const int TokenSpellId = 800134010;
public const int SummonedTokenId = 100011020; // neutral 2/2 follower token
public const int SummonedTokenAtk = 2;
public const int SummonedTokenLife = 2;
private static bool _done;
public static void EnsureInitialized()
@@ -47,9 +65,11 @@ namespace SVSim.BattleEngine.Tests
.SetValue(null, new Wizard.Crossover());
BattleManagerBase.IsForecast = true;
// CardMaster must be non-null before construction (the leader/class card looks up id 0).
// Load the M2 vanilla follower + the M3 fixed-damage spell + the M4 self-buff follower so
// each oracle can create + look up its real stats.
HeadlessCardMaster.Load(FollowerId, SpellId, BuffFollowerId);
// Load the M2 vanilla follower + the M3 fixed-damage spell + the M4 self-buff follower +
// the M5 summon-token spell AND the token it summons so each oracle can create + look up
// real stats. The summoned token id must be present: Skill_summon_token resolves it
// through CardMaster.GetCardParameterFromId during creation.
HeadlessCardMaster.Load(FollowerId, SpellId, BuffFollowerId, TokenSpellId, SummonedTokenId);
// Master reference data (class-character list) for leader/class card resolution.
HeadlessMasterData.Install();
// Player/enemy leaders (chara ids must map to a ClassCharacterMasterData in Master).
@@ -77,6 +97,34 @@ namespace SVSim.BattleEngine.Tests
((ClassBattleCardBase)mgr.BattleEnemy.Class).InitBaseMaxLife(life);
}
// The PUBLIC prefab card-creation path (CardCreatorBase.CreateCard, createNullView:false) —
// used by anything the engine creates INTERNALLY (summons, token-draws, etc.), as opposed to
// the test's direct private null-view seam for hand cards — clones card-template prefabs held
// on BattleManagerBase.SBattleLoad. The real async battle load (CoLoad) builds these; the bare
// `new SingleBattleMgr(...)` construction path leaves SBattleLoad null (the M2 NRE was here).
// Seed it with non-null no-op CardTemplates: their `.gameObject` is a lazy shim no-op, and the
// shim's CloneObjectToParent + self-consistent object graph carry the rest. Nothing here
// computes game state — the token's authoritative stats come from CardCSVData, not the view.
public static void InitCardTemplates(BattleManagerBase mgr)
{
mgr.SBattleLoad = new SBattleLoad
{
UnitCardTemplate = new CardTemplate(),
SpellCardTemplate = new CardTemplate(),
FieldCardTemplate = new CardTemplate(),
};
// The created card's transform is positioned/parented under the battle's 3D scene-graph
// containers (CardCreatorBase.CreateCardTypeBuildInfo reads ins.CardHolder/ECardHolder/
// PCardPlace/Battle3DContainer). The real battle load instantiates these; seed non-null
// no-op GameObjects so the positioning resolves (no-op transforms; nothing rendered).
mgr.Battle3DContainer = new GameObject();
mgr.CardHolder = new GameObject();
mgr.ECardHolder = new GameObject();
mgr.PCardPlace = new GameObject();
mgr.ChoiceCardHolder = new GameObject();
mgr.EvolveCardHolder = new GameObject();
}
// The shared headless card-creation primitive. CardCreatorBase.CreateCardWithoutResources is
// the engine's own null-view creation path (CreateBase -> new *BattleCard(buildInfo).Setup(
// createNullView:true)); it's private, so reflect it rather than reimplement the 14-arg

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");
});
}
}
}