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:
gamer147
2026-07-03 19:18:54 -04:00
parent 5c1db83967
commit 2d9a6eea4b
2045 changed files with 11704 additions and 158495 deletions

View File

@@ -10,122 +10,4 @@ using Wizard.BattleMgr;
using Wizard.Story;
namespace Wizard.Battle.Tutorial
{
public partial class TutorialBattleMgrBase
{
public partial class CustomQueue<T> { }
public partial class TutorialConstants { }
protected Queue<TutorialSingleTurnActions> playerActions;
protected TutorialSingleTurnActions currentTurnActions;
protected TutorialAction currentAction;
protected int TutorialPopupCount;
protected int TutorialImageCount;
protected List<string> TutorialDownloadPath;
protected UIButton TutoSkipBtn;
protected List<Effect> TutoEffectList;
protected ResourcesManager ResourceMgr;
public bool wasTutorialMissionFailed;
private const int REGULAR_TUTORIALS_COUNT = 3;
private readonly Vector3 tapEffectOffsetFromTurnEndButton;
private readonly Vector3 tapEffectOffsetFromMulliganSubmitButton;
private readonly int tapEffectUILayer;
private readonly int tapEffectBattleLayer;
private int currentActionNumber;
private GameObject _dragAndDropObject;
private UIAnchor _dragAndDropAnchor;
private UILabel _dragAndDropLabel;
private DialogBase _dialog;
private readonly Vector2 _dragAndDropAnchorRelativeOffsetInPlay;
private readonly Vector2 _dragAndDropAnchorRelativeOffsetMulligan;
private readonly Color _dragTextTopGradientColor;
private readonly Color _dragTextBottomGradientColor;
private readonly Color _dropTextTopGradientColor;
private readonly Color _dropTextBottomGradientColor;
protected bool IsStoryTutorial { get; set; }
protected bool DisableCustomMouse { get; set; }
public Action OnEnterMulliganAbandonZone { get; set; }
public Action OnExitMulliganAbandonZone { get; set; }
public Func<VfxBase> OnMulliganDragSuccess { get; set; }
public bool IsBattleEnd { get; set; }
public bool IsUseTutorialSkip { get; set; }
public int TutorialNumber { get; set; }
protected int PlayerCharaID { get; set; }
protected int EnemyCharaID { get; set; }
protected int EnemyClassID { get; set; }
public int GetMaxDeckCount(bool isSelf) => default!;
public TutorialBattleMgrBase(IBattleMgrContentsCreator contentsCreator) : base(contentsCreator) { }
protected virtual TouchControl CreateTouchControl() => default!;
public IInnerOptionsBuilder CreateEnemyInnerOptionsBuilder() => default!;
public void StartOpening(int FirstAttack) { }
public void SetBattleMenuBtnVisibility() { }
protected void ShowMenuButton() { }
protected void SetupEvent() { }
public void SetupBattlePlayersEvent() { }
protected void AddTutorialEffectToList(Effect effect) { }
protected void DisableAllTutorialEffects() { }
public void FinishBattle() { }
public void DisposeBattleGameObj() { }
private void LoadTutorialResources(Action callback) { }
private void StopTutorial() { }
protected void DisableSkipAndCloseCurrentDialog() { }
private void CloseCurrentDialog() { }
public void SetupCardEvent(BattleCardBase card) { }
protected void SetupInstantEndTurnConditions() { }
public void SetupEnemyAI() { }
public virtual bool IsActionTypeExecutable(TutorialAction.ActionType actionTypeToCompare) => default!;
public virtual bool IsCardSelectableDuringCurrentAction(BattleCardBase card, TutorialAction.ActionType actionType) => default!;
protected virtual bool IsCardTargetableDuringCurrentAction(BattleCardBase card, TutorialAction.ActionType actionType) => default!;
protected void DisplayTutorialPopup(float timeBeforePopupIsDisplayed, Action onCloseAction = null) { }
protected VfxBase CreateTutorialPopupVfx() => global::Wizard.Battle.View.Vfx.NullVfx.GetInstance();
protected VfxBase CreateTutorialPopupVfx(float timeBeforePopupIsDisplayed, Action onCloseAction = null) => global::Wizard.Battle.View.Vfx.NullVfx.GetInstance();
protected void DisplayTutorialRewardsPopup(float timeBeforePopupIsDisplayed) { }
protected VfxBase CreateTutorialRewardsPopupVfx(float timeBeforePopupIsDisplayed) => global::Wizard.Battle.View.Vfx.NullVfx.GetInstance();
protected void SetupStoryAfterWinPopupAction(TutorialAction tutorialAction) { }
private void OnRequestTutorialFinish() { }
protected DialogBase CreateTutorialDialog(Action onCloseAction) => default!;
protected void DisplayNiceAnimation(Vector3 spawnPosition) { }
private Vector3 ConvertBattleCameraToUICameraCoordinates(Vector3 worldPosition) => default!;
protected void SetUpWaitAction(TutorialAction TutorialAction) { }
protected VfxBase WaitActionVfx() => global::Wizard.Battle.View.Vfx.NullVfx.GetInstance();
protected void SetUpArrowAnimationEvents(TutorialAction tutorialAction, bool setupHandCardEvents = false, EffectMgr.EffectType arrowType = EffectMgr.EffectType.CMN_TUTORIAL_DRAG_1) { }
protected void SetupFingerAnimationEvents(TutorialAction tutorialAction, float rotationAroundZ = 0f, bool playAfterCurrentAnimationEnds = false) { }
protected void SetupFingerAnimationEvents(TutorialAction tutorialAction, Func<GameObject> getObjectToFollow, bool isFingerOverUI = false) { }
protected void SetupFingerAnimationEventsSetLayer(TutorialAction tutorialAction, Func<GameObject> getObjectToFollow, int layer) { }
protected void SetupFingerReleaseAnimationEvents(TutorialAction tutorialAction, bool useTargetCard1) { }
protected void ShowArrowAnimation(GameObject fromObject, GameObject toObject = null, EffectMgr.EffectType arrowtype = EffectMgr.EffectType.CMN_TUTORIAL_DRAG_1) { }
protected void HideArrowAnimation(GameObject targetObject, EffectMgr.EffectType arrowtype = EffectMgr.EffectType.CMN_TUTORIAL_DRAG_1) { }
protected void ShowFingerAnimation(Vector3 spawnPosition, float rotationAroundZ) { }
protected Effect ShowFingerAnimation(GameObject objectToFollow) => default!;
protected void ShowFingerAnimationOnTurnEndButton() { }
protected void HideFingerAnimation() { }
protected Effect HideFingerAnimation(GameObject objectBeingFollowed) => default!;
protected void ShowFingerReleaseAnimation(Vector3 spawnPosition) { }
protected void ShowFingerReleaseAnimation(GameObject objectToFollow) { }
protected void HideFingerReleaseAnimation() { }
protected void HideFingerReleaseAnimation(GameObject objectBeingFollowed) { }
private void ShowDragText(Vector2 relativeOffsetFromAnchor) { }
private void ShowDropText(Vector2 relativeOffsetFromAnchor) { }
private void HideDragAndDropText() { }
private void ShowDragAndDropText(Vector2 relativeOffsetFromAnchor, string textID, Color topGradient, Color bottomGradient) { }
protected void SetupSpellSelectEvents(TutorialAction tutorialAction) { }
protected void SetupEvolveFromDetailPanelEventChain(CustomQueue<TutorialAction> turnActions, int cardID) { }
protected void SetupEvolveDragArrowEvents(TutorialAction tutorialAction) { }
protected void SetupMulliganDragArrowEvents(TutorialAction tutorialAction) { }
protected void SetupMulliganSubmitEvents(TutorialAction tutorialAction) { }
protected VfxBase ExecuteTutorialAction(TutorialAction.ActionType actionType) => global::Wizard.Battle.View.Vfx.NullVfx.GetInstance();
protected virtual void ReportSuccessfulActionToServer() { }
public static void ReportSuccessfulActionToServer(int tutorialStep, int actionNumber) { }
public virtual void SetupNextTurnActions() { }
protected virtual VfxBase GetNextTutorialAction() => global::Wizard.Battle.View.Vfx.NullVfx.GetInstance();
protected virtual void SetupTutorialActionEvents() { }
protected virtual void SetupTutorialInstantEndTurnConditions(Action baseFunctionCall) { }
public VfxBase SetupInitialHandVfx() => global::Wizard.Battle.View.Vfx.NullVfx.GetInstance();
private BattleCardBase CreateInitialHandCard(int cardID, BattlePlayerBase battlePlayerBase) => default!;
protected virtual List<int> CreateInitialPlayerHand() => default!;
protected virtual List<int> CreateInitialEnemyHand() => default!;
protected List<int> CreatePlayerDeck() => default!;
protected List<int> CreateEnemyDeck() => default!;
protected virtual Queue<TutorialSingleTurnActions> CreatePlayerActions() => default!;
protected virtual Queue<TutorialSingleTurnActions> CreateEnemyActions() => default!;
protected virtual void InitializeDeck() { }
}
}