engine cleanup passes 4-7 + multi-instancing ambient rip
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>
This commit is contained in:
@@ -9,8 +9,6 @@ using Wizard.Battle.View.Vfx;
|
||||
|
||||
public class Prediction
|
||||
{
|
||||
public static bool _isFeatureEnabled;
|
||||
|
||||
protected VfxMgr _vfxMgr;
|
||||
|
||||
protected IBattleResourceMgr _battleResourceManager;
|
||||
@@ -39,36 +37,22 @@ public class Prediction
|
||||
_selectCards.Clear();
|
||||
}
|
||||
|
||||
private bool IsEnabled()
|
||||
{
|
||||
if (_isFeatureEnabled)
|
||||
{
|
||||
return PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.SHOW_PREDICTION_ICONS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// _isFeatureEnabled was a `public static bool` default-false with no writers anywhere in the
|
||||
// codebase — dead in headless and never toggled by the client build we ported from. Collapsed
|
||||
// to a constant-false so per-battle isolation isn't polluted by a process-wide flag.
|
||||
private bool IsEnabled() => false;
|
||||
|
||||
public void TurnEnd()
|
||||
{
|
||||
if (IsEnabled())
|
||||
{
|
||||
_pair = BattleManagerBase.GetIns().GetBattlePlayerPair(isPlayer: true);
|
||||
_pair = _pair.Self.BattleMgr.GetBattlePlayerPair(isPlayer: true);
|
||||
BattlePlayerPair randomAll = TurnEnd(_pair, SimulationSelection.All);
|
||||
BattlePlayerPair randomNone = TurnEnd(_pair, SimulationSelection.None);
|
||||
Display(randomAll, randomNone);
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack(BattleCardBase attackCard, BattleCardBase targetCard)
|
||||
{
|
||||
if (IsEnabled())
|
||||
{
|
||||
_pair = BattleManagerBase.GetIns().GetBattlePlayerPair(isPlayer: true);
|
||||
BattlePlayerPair forecastPair = OperationSimulator.Attack(_pair, attackCard, targetCard, isPrediction: true);
|
||||
Simulate(forecastPair);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (IsEnabled())
|
||||
@@ -92,79 +76,6 @@ public class Prediction
|
||||
}
|
||||
}
|
||||
|
||||
public void Evolve(BattleCardBase card)
|
||||
{
|
||||
if (IsEnabled() && !card.EvolutionSkills.HasEvolutionSkillWithSelection)
|
||||
{
|
||||
BattlePlayerPair randomAll = Evolve(_pair, card, null, SimulationSelection.All);
|
||||
BattlePlayerPair randomNone = Evolve(_pair, card, null, SimulationSelection.None);
|
||||
Display(randomAll, randomNone);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddSelectCard(BattleCardBase targetCard)
|
||||
{
|
||||
_selectCards.Add(targetCard);
|
||||
}
|
||||
|
||||
public void SkillSelect(BattleCardBase actCard, BattleCardBase targetCard, bool isEvolve)
|
||||
{
|
||||
if (IsEnabled())
|
||||
{
|
||||
List<BattleCardBase> list = _selectCards.ToList();
|
||||
list.Add(targetCard);
|
||||
BattlePlayerPair randomAll;
|
||||
BattlePlayerPair randomNone;
|
||||
if (isEvolve)
|
||||
{
|
||||
randomAll = Evolve(_pair, actCard, list, SimulationSelection.All);
|
||||
randomNone = Evolve(_pair, actCard, list, SimulationSelection.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
randomAll = Play(_pair, actCard, list, SimulationSelection.All);
|
||||
randomNone = Play(_pair, actCard, list, SimulationSelection.None);
|
||||
}
|
||||
Display(randomAll, randomNone);
|
||||
}
|
||||
}
|
||||
|
||||
public void SkillSelectTransform(BattleCardBase actCard, BattleCardBase transformCard, BattleCardBase targetCard)
|
||||
{
|
||||
if (IsEnabled())
|
||||
{
|
||||
List<BattleCardBase> list = _selectCards.ToList();
|
||||
list.Add(targetCard);
|
||||
list.Insert(0, transformCard);
|
||||
BattlePlayerPair randomAll = Play(_pair, actCard, list, SimulationSelection.All);
|
||||
BattlePlayerPair randomNone = Play(_pair, actCard, list, SimulationSelection.None);
|
||||
Display(randomAll, randomNone);
|
||||
}
|
||||
}
|
||||
|
||||
public void SkillSelectClear()
|
||||
{
|
||||
_selectCards.Clear();
|
||||
}
|
||||
|
||||
private void Simulate(BattlePlayerPair forecastPair)
|
||||
{
|
||||
if (IsEnabled())
|
||||
{
|
||||
ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create();
|
||||
parallelVfxPlayer.Register(ClearView(_pair));
|
||||
if ((FindUsedRandomSkillOriginalCard(_pair.Self, forecastPair.Self) ?? FindUsedRandomSkillOriginalCard(_pair.Opponent, forecastPair.Opponent)) != null)
|
||||
{
|
||||
parallelVfxPlayer.Register(ForecastRandomSkillUseMessageVfx.Create(_battleResourceManager));
|
||||
}
|
||||
AddCardToWarning(_pair.Self, forecastPair.Self);
|
||||
AddCardToWarning(_pair.Opponent, forecastPair.Opponent);
|
||||
parallelVfxPlayer.Register(UpdatePlayerView(_pair.Self, forecastPair.Self, _battleResourceManager));
|
||||
parallelVfxPlayer.Register(UpdatePlayerView(_pair.Opponent, forecastPair.Opponent, _battleResourceManager));
|
||||
_vfxMgr.RegisterSequentialVfx(parallelVfxPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldDisplayWarningMessage(BattlePlayerPair randomAll, BattlePlayerPair randomNone)
|
||||
{
|
||||
if (FindUsedRandomSkillOriginalCard(_pair.Self, randomAll.Self) != null)
|
||||
@@ -190,7 +101,7 @@ public class Prediction
|
||||
parallelVfxPlayer.Register(ClearView(_pair));
|
||||
if (ShouldDisplayWarningMessage(randomAll, randomNone))
|
||||
{
|
||||
parallelVfxPlayer.Register(ForecastRandomSkillUseMessageVfx.Create(_battleResourceManager));
|
||||
parallelVfxPlayer.Register(NullVfx.GetInstance());
|
||||
}
|
||||
AddCardToWarning(_pair.Self, randomAll.Self);
|
||||
AddCardToWarning(_pair.Opponent, randomAll.Opponent);
|
||||
@@ -211,18 +122,18 @@ public class Prediction
|
||||
BattleCardBase origin = classAndInPlayCardList[i];
|
||||
if (randomAll.PredictionWarningCards.Any((BattleCardBase x) => x.EquelsID(origin)) || randomNone.PredictionWarningCards.Any((BattleCardBase x) => x.EquelsID(origin)))
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastRandomSkillUseCardVfx(origin.BattleCardView, _battleResourceManager));
|
||||
parallelVfxPlayer.Register(NullVfx.GetInstance());
|
||||
}
|
||||
if (randomNone.CemeteryList.Any((BattleCardBase x) => x.EquelsID(origin)))
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastDeathIconAttachVfx(origin.BattleCardView, _battleResourceManager));
|
||||
parallelVfxPlayer.Register(NullVfx.GetInstance());
|
||||
continue;
|
||||
}
|
||||
if (randomNone.BanishList.Any((BattleCardBase x) => x.EquelsID(origin)))
|
||||
{
|
||||
if (!randomNone.ClassAndInPlayCardList.Any((BattleCardBase x) => x.EquelsID(origin)))
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastBanishIconAttachVfx(origin.BattleCardView, _battleResourceManager));
|
||||
parallelVfxPlayer.Register(NullVfx.GetInstance());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -232,56 +143,11 @@ public class Prediction
|
||||
int damage = origin.Life - battleCardBase.Life;
|
||||
if (battleCardBase.IsDead)
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastDeathIconAttachVfx(origin.BattleCardView, _battleResourceManager));
|
||||
parallelVfxPlayer.Register(NullVfx.GetInstance());
|
||||
}
|
||||
else if (battleCardBase.HasMoreDamageThan(origin))
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastDamageIconAttachVfx(damage, origin.BattleCardView, _battleResourceManager));
|
||||
}
|
||||
}
|
||||
}
|
||||
return parallelVfxPlayer;
|
||||
}
|
||||
|
||||
private static VfxBase UpdatePlayerView(BattlePlayerBase originalBattlePlayer, BattlePlayerBase forecastedBattlePlayer, IBattleResourceMgr resourceMgr)
|
||||
{
|
||||
ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create();
|
||||
List<BattleCardBase> classAndInPlayCardList = originalBattlePlayer.ClassAndInPlayCardList;
|
||||
for (int i = 0; i < classAndInPlayCardList.Count; i++)
|
||||
{
|
||||
BattleCardBase originalCard = classAndInPlayCardList[i];
|
||||
if (forecastedBattlePlayer.PredictionWarningCards.Any((BattleCardBase x) => x.EquelsID(originalCard)))
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastRandomSkillUseCardVfx(originalCard.BattleCardView, resourceMgr));
|
||||
}
|
||||
if (forecastedBattlePlayer.CemeteryList.FindFromCardId(originalCard) != null && forecastedBattlePlayer.PredictionCemeteryRandomCards.FindFromCardId(originalCard) == null)
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastDeathIconAttachVfx(originalCard.BattleCardView, resourceMgr));
|
||||
continue;
|
||||
}
|
||||
if (forecastedBattlePlayer.BanishList.FindFromCardId(originalCard) != null)
|
||||
{
|
||||
if (forecastedBattlePlayer.ClassAndInPlayCardList.FindFromCardId(originalCard) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (forecastedBattlePlayer.PredictionBanishRandomCards.FindFromCardId(originalCard) == null)
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastBanishIconAttachVfx(originalCard.BattleCardView, resourceMgr));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
BattleCardBase battleCardBase = forecastedBattlePlayer.ClassAndInPlayCardList.FindFromCardId(originalCard);
|
||||
if (battleCardBase != null && forecastedBattlePlayer.PredictionDamageRandomCards.FindFromCardId(originalCard) == null)
|
||||
{
|
||||
int damage = originalCard.Life - battleCardBase.Life;
|
||||
if (battleCardBase.IsDead)
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastDeathIconAttachVfx(originalCard.BattleCardView, resourceMgr));
|
||||
}
|
||||
else if (battleCardBase.HasMoreDamageThan(originalCard))
|
||||
{
|
||||
parallelVfxPlayer.Register(new ForecastDamageIconAttachVfx(damage, originalCard.BattleCardView, resourceMgr));
|
||||
parallelVfxPlayer.Register(NullVfx.GetInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -317,7 +183,7 @@ public class Prediction
|
||||
ClearCardListView(pair.Self.ClassAndInPlayCardList);
|
||||
ClearCardListView(pair.Self.HandCardList);
|
||||
ClearCardListView(pair.Opponent.ClassAndInPlayCardList);
|
||||
return HideForecastRandomSkillUseMessageVfx.Create();
|
||||
return NullVfx.GetInstance();
|
||||
}
|
||||
|
||||
private static BattleCardBase FindUsedRandomSkillOriginalCard(BattlePlayerBase originalBattlePlayer, BattlePlayerBase forecastBattlePlayer)
|
||||
@@ -419,23 +285,23 @@ public class Prediction
|
||||
|
||||
private static BattlePlayerPair TurnEnd(BattlePlayerPair sourcePair, SimulationSelection random)
|
||||
{
|
||||
BattleManagerBase.IsForecast = true;
|
||||
bool isRecovery = BattleManagerBase.GetIns().IsRecovery;
|
||||
BattleManagerBase.GetIns().IsRecovery = true;
|
||||
sourcePair.Self.BattleMgr.InstanceIsForecast = true;
|
||||
bool isRecovery = sourcePair.Self.BattleMgr.IsRecovery;
|
||||
sourcePair.Self.BattleMgr.IsRecovery = true;
|
||||
BattlePlayerPair battlePlayerPair = sourcePair.VirtualClone(CloneActualFlags.All);
|
||||
ChangeFilters(battlePlayerPair, random);
|
||||
CloneSkillsPreprocessAndBuffInfo(sourcePair, battlePlayerPair);
|
||||
battlePlayerPair.Self.GetTurnEndSkillProcess().Process(battlePlayerPair);
|
||||
BattleManagerBase.GetIns().IsRecovery = isRecovery;
|
||||
BattleManagerBase.IsForecast = false;
|
||||
sourcePair.Self.BattleMgr.IsRecovery = isRecovery;
|
||||
sourcePair.Self.BattleMgr.InstanceIsForecast = false;
|
||||
return battlePlayerPair;
|
||||
}
|
||||
|
||||
private static BattlePlayerPair Play(BattlePlayerPair sourcePair, IBattleCardUniqueID playCardId, List<BattleCardBase> skillTargets, SimulationSelection random)
|
||||
{
|
||||
BattleManagerBase.IsForecast = true;
|
||||
bool isRecovery = BattleManagerBase.GetIns().IsRecovery;
|
||||
BattleManagerBase.GetIns().IsRecovery = true;
|
||||
sourcePair.Self.BattleMgr.InstanceIsForecast = true;
|
||||
bool isRecovery = sourcePair.Self.BattleMgr.IsRecovery;
|
||||
sourcePair.Self.BattleMgr.IsRecovery = true;
|
||||
BattlePlayerPair battlePlayerPair = sourcePair.VirtualClone(CloneActualFlags.All);
|
||||
ChangeFilters(battlePlayerPair, random);
|
||||
CloneSkillsPreprocessAndBuffInfo(sourcePair, battlePlayerPair);
|
||||
@@ -447,26 +313,8 @@ public class Prediction
|
||||
battlePlayerPair.Self.SetupActionProcessorEvent(actionProcessor);
|
||||
battlePlayerPair.Opponent.SetupActionProcessorEvent(actionProcessor);
|
||||
actionProcessor.PlayCard(card, first, second);
|
||||
BattleManagerBase.GetIns().IsRecovery = isRecovery;
|
||||
BattleManagerBase.IsForecast = false;
|
||||
return battlePlayerPair;
|
||||
}
|
||||
|
||||
private static BattlePlayerPair Evolve(BattlePlayerPair sourcePair, IBattleCardUniqueID evolutionCardId, List<BattleCardBase> skillTargets, SimulationSelection random)
|
||||
{
|
||||
BattleManagerBase.IsForecast = true;
|
||||
bool isRecovery = BattleManagerBase.GetIns().IsRecovery;
|
||||
BattleManagerBase.GetIns().IsRecovery = true;
|
||||
BattlePlayerPair battlePlayerPair = sourcePair.VirtualClone(CloneActualFlags.All);
|
||||
ChangeFilters(battlePlayerPair, random);
|
||||
CloneSkillsPreprocessAndBuffInfo(sourcePair, battlePlayerPair);
|
||||
Tuple<BattleCardBase[], List<int>> tuple = OperationSimulator.Evolve_GetTargetsAndChoice(battlePlayerPair, skillTargets);
|
||||
BattleCardBase[] first = tuple.first;
|
||||
List<int> second = tuple.second;
|
||||
BattleCardBase card = battlePlayerPair.Self.ClassAndInPlayCardList.FindFromCardId(evolutionCardId);
|
||||
new ActionProcessor(battlePlayerPair).Evolution(card, first, second);
|
||||
BattleManagerBase.GetIns().IsRecovery = isRecovery;
|
||||
BattleManagerBase.IsForecast = false;
|
||||
sourcePair.Self.BattleMgr.IsRecovery = isRecovery;
|
||||
sourcePair.Self.BattleMgr.InstanceIsForecast = false;
|
||||
return battlePlayerPair;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user