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:
@@ -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
|
||||
|
||||
106
SVSim.BattleEngine.Tests/SummonTokenOracleTests.cs
Normal file
106
SVSim.BattleEngine.Tests/SummonTokenOracleTests.cs
Normal 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");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,7 +299,11 @@ public partial class UIManager
|
||||
public List<UIBase_CardManager.CardObjData> getCardListObjs() => default!;
|
||||
public List<UIBase_CardManager.CardObjData> getSelectCardListObjs() => default!;
|
||||
public List<UIBase_CardManager.CardObjData> getCardList2DObjs() => default!;
|
||||
public UIBase_CardManager getUIBase_CardManager() => default!;
|
||||
// Shim fix (M5): return a non-null, field-wired no-op so the copied cosmetic helpers it
|
||||
// exposes (UIBase_CardManager.SetNumberLabelStyle/SetNameLabelStyle, read by
|
||||
// CardCreatorBase.CreateCard on the createNullView:false path) resolve headless instead of
|
||||
// NRE-ing on a null manager. Was `default!`.
|
||||
public UIBase_CardManager getUIBase_CardManager() => UnityEngine.ShimView.Create<UIBase_CardManager>();
|
||||
public void setBackScene(GameObject obj, ViewScene backScene) { }
|
||||
public TopBar CreateTopBar(GameObject obj, string titleMsg, ViewScene backScene = ViewScene.None, bool MoneyDraw = true, ChangeViewSceneParam Param = null, bool isWideMode = false) => default!;
|
||||
public void SetBackButtonParameter(ChangeViewSceneParam in_Param) { }
|
||||
|
||||
@@ -84,12 +84,19 @@ namespace UnityEngine
|
||||
|
||||
public class Component : Object
|
||||
{
|
||||
public Transform transform => null;
|
||||
public GameObject gameObject => null;
|
||||
internal GameObject _go;
|
||||
// Self-consistent no-op object graph (M5): a Component belongs to a GameObject, and
|
||||
// component.transform == component.gameObject.transform. Lazily materialize a backing
|
||||
// GameObject so the unguarded prefab/view touches on the createNullView:false card-creation
|
||||
// path (F1) resolve to non-null no-ops, and route GetComponent through that GameObject's
|
||||
// cached component model so a chained transform.Find(...).GetComponent<T>() yields the same
|
||||
// non-null instances rather than null.
|
||||
public virtual GameObject gameObject => _go ??= new GameObject();
|
||||
public virtual Transform transform => gameObject.transform;
|
||||
public string tag { get; set; }
|
||||
public T GetComponent<T>() => default;
|
||||
public T GetComponent<T>(string type) => default;
|
||||
public Component GetComponent(System.Type t) => null;
|
||||
public T GetComponent<T>() => gameObject.GetComponent<T>();
|
||||
public T GetComponent<T>(string type) => gameObject.GetComponent<T>();
|
||||
public Component GetComponent(System.Type t) => gameObject.GetComponent(t);
|
||||
public Component GetComponent(string t) => null;
|
||||
public T GetComponentInChildren<T>() => default;
|
||||
public T GetComponentInChildren<T>(bool includeInactive) => default;
|
||||
@@ -129,6 +136,10 @@ namespace UnityEngine
|
||||
|
||||
public partial class Transform : Component, IEnumerable
|
||||
{
|
||||
public Transform() { }
|
||||
internal Transform(GameObject owner) { _go = owner; }
|
||||
// A Transform IS its own transform (vs Component.transform => gameObject.transform).
|
||||
public override Transform transform => this;
|
||||
public Vector3 position { get; set; }
|
||||
public Vector3 localPosition { get; set; }
|
||||
public Vector3 localScale { get; set; } = new Vector3(1, 1, 1);
|
||||
@@ -136,9 +147,20 @@ namespace UnityEngine
|
||||
public Vector3 eulerAngles { get; set; }
|
||||
public Quaternion rotation { get; set; }
|
||||
public Quaternion localRotation { get; set; }
|
||||
public Transform parent { get; set; }
|
||||
// Lazily non-null so `someLabel.transform.parent.gameObject` (unguarded in the NORMAL
|
||||
// card-creation path) resolves; settable so real re-parenting still records.
|
||||
private Transform _parent;
|
||||
public Transform parent { get => _parent ??= new Transform(); set => _parent = value; }
|
||||
public int childCount => 0;
|
||||
public Transform Find(string n) => null;
|
||||
// Return a non-null cached child per name so Find(...).Find(...).GetComponent<UILabel>()
|
||||
// chains resolve to no-ops; cached so repeated Find of the same child is stable.
|
||||
private System.Collections.Generic.Dictionary<string, Transform> _children;
|
||||
public Transform Find(string n)
|
||||
{
|
||||
_children ??= new System.Collections.Generic.Dictionary<string, Transform>();
|
||||
if (!_children.TryGetValue(n ?? "", out var t)) { t = new GameObject(n).transform; _children[n ?? ""] = t; }
|
||||
return t;
|
||||
}
|
||||
public Transform GetChild(int i) => null;
|
||||
public void SetParent(Transform p) { }
|
||||
public void SetParent(Transform p, bool worldPositionStays) { }
|
||||
@@ -169,7 +191,7 @@ namespace UnityEngine
|
||||
public void LookAt(Vector3 p) { }
|
||||
public void LookAt(Vector3 p, Vector3 worldUp) { }
|
||||
public void DetachChildren() { }
|
||||
public Transform Find(string n, bool includeInactive) => null;
|
||||
public Transform Find(string n, bool includeInactive) => Find(n);
|
||||
public IEnumerator GetEnumerator() { yield break; }
|
||||
}
|
||||
|
||||
@@ -178,7 +200,8 @@ namespace UnityEngine
|
||||
public GameObject() { }
|
||||
public GameObject(string name) { this.name = name; }
|
||||
public GameObject(string name, params Type[] components) { this.name = name; }
|
||||
public Transform transform => null;
|
||||
private Transform _transform;
|
||||
public Transform transform => _transform ??= new Transform(this);
|
||||
public GameObject gameObject => this;
|
||||
public bool activeSelf => false;
|
||||
public bool activeInHierarchy => false;
|
||||
@@ -200,8 +223,50 @@ namespace UnityEngine
|
||||
try { inst = Activator.CreateInstance(t); }
|
||||
catch { return null; }
|
||||
_components[t] = inst;
|
||||
if (inst is Component comp) comp._go = this;
|
||||
WireComponentFields(inst);
|
||||
return inst;
|
||||
}
|
||||
// The createNullView:false card-creation path reads many view-leaf reference fields off a
|
||||
// CardTemplate component (UILabel/MeshRenderer/Transform/GameObject) UNGUARDED, plus the
|
||||
// copied NGUI cosmetic helpers (CardTemplate.SetNumberLabelStyle -> UIBase_CardManager ->
|
||||
// UIFont.material / UILabel.material) read material backing fields. The real engine wires all
|
||||
// of this from the prefab in SBattleLoad.CreateUnitCardTemplate, which we skip headless. Fill
|
||||
// any null GameObject/Component-derived view field with a no-op instance. Pure no-ops:
|
||||
// nothing here computes game state (the token's authoritative stats come from CardCSVData).
|
||||
internal const System.Reflection.BindingFlags WireFlags =
|
||||
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Instance;
|
||||
private static readonly Material _noopViewMaterial = new Material { name = "ShimNoOpMaterial" };
|
||||
// Create a no-op view-leaf instance and pre-set the NGUI material backing fields the copied
|
||||
// UIFont.material / UILabel.material getters read so they return non-null. Only mMat/mMaterial
|
||||
// are filled: blanket-filling mReplacement/mAtlas/mDynamicFont would make those getters
|
||||
// DELEGATE down a chain that re-nulls. One level deep — no recursion into the created leaf.
|
||||
private static object Materialize(Type t)
|
||||
{
|
||||
var o = Activator.CreateInstance(t);
|
||||
SetBackingMaterial(o, "mMat"); // UIFont
|
||||
SetBackingMaterial(o, "mMaterial"); // UILabel / UIWidget
|
||||
return o;
|
||||
}
|
||||
private static void SetBackingMaterial(object o, string field)
|
||||
{
|
||||
var f = o.GetType().GetField(field, WireFlags);
|
||||
if (f != null && f.FieldType == typeof(Material) && f.GetValue(o) == null)
|
||||
f.SetValue(o, _noopViewMaterial);
|
||||
}
|
||||
internal static void WireComponentFields(object inst)
|
||||
{
|
||||
foreach (var f in inst.GetType().GetFields(WireFlags))
|
||||
{
|
||||
if (f.GetValue(inst) != null) continue;
|
||||
var ft = f.FieldType;
|
||||
if (ft == typeof(GameObject) || (typeof(Component).IsAssignableFrom(ft) && !ft.IsAbstract))
|
||||
{ try { f.SetValue(inst, Materialize(ft)); } catch { } }
|
||||
else if (ft == typeof(Material))
|
||||
{ f.SetValue(inst, _noopViewMaterial); }
|
||||
}
|
||||
}
|
||||
public T GetComponent<T>() => (T)(GetOrAddComponent(typeof(T)) ?? default(T));
|
||||
public Component GetComponent(Type t) => (Component)GetOrAddComponent(t);
|
||||
public Component GetComponent(string t) => null;
|
||||
@@ -230,6 +295,19 @@ namespace UnityEngine
|
||||
|
||||
public class ScriptableObject : Object { }
|
||||
|
||||
// Factory for no-op view/manager objects that are NOT acquired via GameObject.GetComponent (e.g.
|
||||
// UIManager.getUIBase_CardManager()). Creates the instance and runs the same field-wiring the
|
||||
// component model applies, so the copied cosmetic helpers it exposes resolve headless.
|
||||
public static class ShimView
|
||||
{
|
||||
public static T Create<T>() where T : class
|
||||
{
|
||||
var o = System.Activator.CreateInstance(typeof(T));
|
||||
GameObject.WireComponentFields(o);
|
||||
return (T)o;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- rendering / physics / audio (pure no-op presentation) ----
|
||||
public class Renderer : Component
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user