Squashes 146 commits from battle-engine-extraction. Net: 2,045 files changed, +11,896 / -158,687 lines. Ships engine passes 4-7 (dead-code cull, view-layer stub, receive-path shrink) plus the Phase-5 AsyncLocal ambient deletion that turns concurrent battles into a type-system property rather than a scope contract. ## What landed **Passes 4-7 (chunks 1-34):** Extended the Phase-4 const-false collapse into a cascading cull across the skill graph, view layer, and receive-path periphery. Six mode flags (IsWatchBattle/IsReplayBattle/IsAdmin/IsAdminWatch/IsPuzzleQuest/ IsAINetwork) became `const false`, every guarded block deleted. Field*.cs subclass ctors + BackGroundBase + ObjectChecker culled to no-ops. Mulligan family reworked to take a mgr param through IMulliganMgr.InitMulligan. Emotion/Recovery/Resource clusters null-stubbed. Prediction/OperationSimulator/ skill filters converted from static ambient reads to per-mgr reads via SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr / ins.BattleMgr / this.BattleMgr. **Phase-5 ambient rip (chunks 35-47):** Deleted BattleAmbient / BattleAmbient- Context / TestBattleScope in full. Every per-battle mutable slot now lives on the mgr instance itself: mgr.InstanceIsForecast / InstanceIsRandomDraw / InstanceRecoveryInfo / InstanceViewerId / InstanceNetworkAgent / GameMgr BattleManagerBase.GetIns() returns null unconditionally; the residual static flags + 3 façades (Certification.ViewerId, Data.BattleRecoveryInfo, ToolboxGame.RealTimeNetworkAgent) are null-tolerant defaults kept for the handful of engine-internal readers that still reference their types. Zero BattleAmbient references anywhere in engine + node + tests. Added pre-seeded GameMgr ctor overload threaded through the mgr chain (BattleManagerBase → SingleBattleMgr / NetworkBattleManagerBase → NetworkStandard- BattleMgr → HeadlessBattleMgr / HeadlessNetworkBattleMgr). Fixtures build a GameMgr, seed it via HeadlessEngineEnv.SeedCharaIds/SeedNetUser, and pass it to the mgr's ctor — no ambient reach. Node side (SVSim.BattleNode/SessionBattleEngine): _ctx replaced with a plain GameMgr field; 34 `using var _ambient = BattleAmbient.Enter(_ctx)` scope wraps ripped from every accessor and mutator; EngineGlobalInit.WirePerSessionGameMgr takes GameMgr as a param and runs from SessionBattleEngine.SetupInternal BEFORE mgr construction. Test side: TestBattleScope deleted; 18 fixture [SetUp]s migrated to `HeadlessEngineEnv.EnsureProcessGlobals()`; MultiInstanceEngineTests rewritten around per-mgr construction (GetIns() → null is the pinned invariant). ## Regression fixes - **chunk-48** (MulliganCtrl): chunk-35's `= null` stubs on card lookups broke the live receive-driven Deal path (BattlePlayerBase.DrawCard NRE'd downstream of NetworkPlayerMulliganCtrl.StartMulliganVfx). Restored the three lookups via `_battlePlayer.BattleMgr.GetBattleCardIdx`. Engine tests were satisfied by the WireMulliganPhase seam; unit tests exposed the live-path gap. ## Ship state - SVSim.BattleEngine.Tests: 56/56 pass, 2 skip - SVSim.UnitTests: 1554/1554 pass (was 1523/31-fail before chunk 48) - Solution build: 0 source warnings (40 pre-existing NU1902 MessagePack CVEs in SVSim.EmulatedEntrypoint, unrelated) - Sequential PVP smoke: verified live (two back-to-back battles, no regression on cleanup/spinup) - Concurrent PVP smoke: verified live Adds tools/engine-port/ClosureAnalyzer/ — the Roslyn transitive-type-closure analyzer needed to make future cascade cleanup safe (per feedback memory "Engine cleanup needs closure tool" from the 2026-06-28 pass-3 failure). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
103 lines
5.9 KiB
C#
103 lines
5.9 KiB
C#
using System.Reflection;
|
|
using NUnit.Framework;
|
|
using Wizard;
|
|
using Wizard.Battle;
|
|
|
|
namespace SVSim.BattleEngine.Tests
|
|
{
|
|
// M4 (next-hardest deterministic card): a when_play SELF-BUFF follower resolves to correct
|
|
// authoritative state HEADLESS via the same IsForecast/IsRecovery + ActionProcessor path the M2
|
|
// vanilla follower and M3 fixed-damage spell proved (design §5 / DP4 + M3 resume recipe). The new
|
|
// oracle dimension over M2/M3 is the PLAYED CARD'S OWN STAT DELTA: the fanfare `powerup`
|
|
// `add_offense=1&add_life=1` to `target=self` must raise the follower's Atk and Life by exactly
|
|
// those amounts over its CardCSVData base — a self-buff, so no target selection is involved.
|
|
[TestFixture]
|
|
public class BuffFollowerOracleTests
|
|
{
|
|
|
|
[SetUp] public void SetUp() => HeadlessEngineEnv.EnsureProcessGlobals();
|
|
|
|
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 Self_buff_fanfare_raises_own_atk_and_life()
|
|
{
|
|
BattleManagerBase.IsForecast = true; // suppress VFX registration (F1)
|
|
var mgr = HeadlessEngineEnv.NewSeededSingleBattleMgr();
|
|
mgr.IsRecovery = true; // collapse wait delays to 0 (F1)
|
|
|
|
var player = mgr.BattlePlayer;
|
|
var enemy = mgr.BattleEnemy;
|
|
|
|
// Minimal opponent/turn wiring (see M2/M3 oracles): opponent refs + active turn flag. The
|
|
// self-buff's target resolver (`character=me&target=self`) reads the active player's own
|
|
// in-play card, so the turn flag must be set before the fanfare sweeps.
|
|
SetPrivateField(player, "_opponentBattlePlayer", enemy);
|
|
SetPrivateField(enemy, "_opponentBattlePlayer", player);
|
|
player.IsSelfTurn = true;
|
|
enemy.IsSelfTurn = false;
|
|
|
|
// Seed leader life so neither leader reads as a 0-life game-over state that silently blocks
|
|
// the play (M3 learning); this card deals no damage but the play-legality gate still checks it.
|
|
HeadlessEngineEnv.InitLeaderLife(mgr);
|
|
|
|
// The card's fanfare is gated on `play_count>2` (cards.json skill_condition for 103111050).
|
|
// The engine reads this from BattlePlayerBase.GetCurrentTurnPlayCount(); seed it past the
|
|
// threshold via the public AddCurrentTrunPlayCount so the powerup actually fires. (Without
|
|
// this the card resolves to the board but takes no buff — the delta-vs-base oracle is what
|
|
// distinguishes "buff applied" from "fanfare silently gated out".)
|
|
player.AddCurrentTrunPlayCount(5);
|
|
|
|
var cardParam = CardMaster.GetInstanceForBattle().GetCardParameterFromId(HeadlessEngineEnv.BuffFollowerId);
|
|
|
|
// Place the self-buff follower in the active player's hand with PP to spare; empty board.
|
|
var card = HeadlessEngineEnv.CreateHeadlessHandCard(HeadlessEngineEnv.BuffFollowerId, 1, isPlayer: true, mgr);
|
|
player.HandCardList.Add(card);
|
|
player.Pp = 10;
|
|
|
|
// Pre-state snapshot.
|
|
int ppBefore = player.Pp;
|
|
int handBefore = player.HandCardList.Count;
|
|
int inplayBefore = 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 self-buff fanfare follower");
|
|
|
|
// Oracle: the own-stat delta is the new M4 dimension; the rest are the §5 follower invariants.
|
|
Assert.Multiple(() =>
|
|
{
|
|
// Primary M4 assertion: the fanfare powerup raised the follower's own stats by exactly
|
|
// the buff amounts over its CardCSVData base (1/1 -> 2/2).
|
|
Assert.That(card.Atk, Is.EqualTo(cardParam.Atk + HeadlessEngineEnv.BuffAddOffense),
|
|
"follower atk != base + fanfare add_offense");
|
|
Assert.That(card.Life, Is.EqualTo(cardParam.Life + HeadlessEngineEnv.BuffAddLife),
|
|
"follower life != base + fanfare add_life");
|
|
// Cost paid.
|
|
Assert.That(player.Pp, Is.EqualTo(ppBefore - cardParam.Cost), "PP not reduced by exactly cost");
|
|
// Follower moved hand -> board.
|
|
Assert.That(player.HandCardList, Does.Not.Contain(card), "card still in hand");
|
|
Assert.That(player.HandCardList.Count, Is.EqualTo(handBefore - 1), "hand count not -1");
|
|
Assert.That(player.ClassAndInPlayCardList, Contains.Item(card), "card not in play");
|
|
Assert.That(player.ClassAndInPlayCardList.Count, Is.EqualTo(inplayBefore + 1), "in-play count not +1");
|
|
// Opponent unchanged (the buff targets self, not the opponent).
|
|
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");
|
|
});
|
|
}
|
|
}
|
|
}
|