Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/SealedLobby.cs
gamer147 2d9a6eea4b 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>
2026-07-03 19:18:54 -04:00

247 lines
8.2 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cute;
using UnityEngine;
namespace Wizard;
public class SealedLobby : MonoBehaviour
{
[SerializeField]
private ArenaCommonLobby _commonLobbyPrefab;
[SerializeField]
private GameObject _buttonsRoot;
[SerializeField]
private UIButton _deckEditButton;
[SerializeField]
private UIButton _deckViewButton;
[SerializeField]
private UIButton _deckCodeGenerateButton;
[SerializeField]
private UIButton _stageSelectButton;
[SerializeField]
private UIButton _retireButton;
[SerializeField]
private UISprite _incompleteDeckIcon;
[SerializeField]
private CardSelectDialog _cardSelectDialogPrefab;
private List<string> _unloadAssetList = new List<string>();
private ArenaCommonLobby _commonLobby;
private UICardList _deckViewerDialog;
private SealedData SealedData => Data.ArenaData.SealedData;
public bool IsReady => _commonLobby.IsReady;
public void Init()
{
_commonLobby = NGUITools.AddChild(base.gameObject, _commonLobbyPrefab.gameObject).GetComponent<ArenaCommonLobby>();
_commonLobby.Init(new ArenaCommonLobbyInitParam
{
ClassId = SealedData.SelectedClassId.Value,
BattleMaxNum = 5,
BattleWinNum = SealedData.BattleWinNum,
BattleResultList = SealedData.BattleResultList,
BattleButtonClickCallback = OnClickBattleButton,
RewardReceiveButtonClickCallback = OnClickRewardReceiveButton,
BattleMaintenanceType = NetworkDefine.MAINTENANCE_TYPE.ARENA_SEALED_BATTLE_MAINTENANCE
});
_buttonsRoot.transform.SetParent(_commonLobby.ButtonsRoot.transform);
_buttonsRoot.transform.localPosition = Vector3.zero;
UIEventListener.Get(_deckEditButton.gameObject).onClick = OnClickDeckEditButton;
UIEventListener.Get(_deckViewButton.gameObject).onClick = OnClickDeckViewButton;
UIEventListener.Get(_deckCodeGenerateButton.gameObject).onClick = OnClickDeckCodeGenerateButton;
UIEventListener.Get(_stageSelectButton.gameObject).onClick = OnClickStageSelectButton;
UIEventListener.Get(_retireButton.gameObject).onClick = OnClickRetireButton;
bool flag = SealedData.BattleResultList.Length >= 5;
UIManager.SetObjectToGrey(_deckEditButton.gameObject, flag);
UIManager.SetObjectToGrey(_stageSelectButton.gameObject, flag);
UIManager.SetObjectToGrey(_retireButton.gameObject, flag);
bool flag2 = !SealedData.IsCompletedDeck.Value && !flag;
_commonLobby.SetDecisionButtonToDark(flag2);
UIManager.SetObjectToGrey(_deckCodeGenerateButton.gameObject, flag2);
_incompleteDeckIcon.gameObject.SetActive(flag2 || false /* Pre-Phase-5b: headless has no maintenance card list */);
}
public void Final()
{
Toolbox.ResourcesManager.RemoveAssetGroup(_unloadAssetList);
_unloadAssetList.Clear();
_deckViewerDialog?.RemoveData();
_commonLobby.Final();
UnityEngine.Object.Destroy(_commonLobby.gameObject);
}
private void OnClickDeckEditButton(GameObject g)
{
SealedController.GoToSealedDeckEdit();
}
private void OnClickDeckViewButton(GameObject g)
{
StartCoroutine(OpenDeckViewerDialogCoroutine());
}
private IEnumerator OpenDeckViewerDialogCoroutine()
{
if (_deckViewerDialog == null)
{
_deckViewerDialog = DialogCreator.CreateDeckViewerDialog(base.gameObject);
DeckData deckData = SealedData.DeckData;
List<string> loadAssetList = _deckViewerDialog.GetLoadFileList(deckData.GetCardIdList());
UIManager uiMgr = UIManager.GetInstance();
uiMgr.createInSceneCenterLoading();
yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(loadAssetList, delegate
{
_unloadAssetList.AddRange(loadAssetList);
}));
uiMgr.closeInSceneCenterLoading();
_deckViewerDialog.SetDeck(deckData, null);
_deckViewerDialog.SetShareButtonUse(isUse: true);
_deckViewerDialog.SubmitDeckType = GenerateDeckCodeTask.SubmitDeckType.SEALED;
CardDetailUI cardDetail = _deckViewerDialog.CardDetail;
cardDetail.IsShowFlavorTextButton = true;
cardDetail.IsShowVoiceButton = true;
cardDetail.IsShowEvolutionButton = true;
}
_deckViewerDialog.SetActive(in_Active: true);
_deckViewerDialog.ResetScroll();
}
private void OnClickDeckCodeGenerateButton(GameObject g)
{
ArenaCommonLobby.GenerateDeckCode(GenerateDeckCodeTask.SubmitDeckType.SEALED, SealedData.SelectedClassId.Value, SealedData.DeckOriginalExcludedPhantomCardList, SealedData.DeckOriginalPhantomCardList);
}
private void OnClickStageSelectButton(GameObject g)
{
DialogCreator.CreateStageSelectDialog();
}
private void OnClickRetireButton(GameObject g)
{
ArenaCommonLobby.OpenRetireConfirmDialog().onPushButton1 = delegate
{
StartCoroutine(Toolbox.NetworkManager.Connect(new SealedRetireTask(), delegate
{
ReceiveReward();
}));
};
}
private void OnClickBattleButton()
{
// Pre-Phase-5b: DataMgr writes for sealed-mode deck selection (battle type, deck id,
// chara/deck data). Purely UI-driven pre-battle setup; headless never runs this
// coroutine, and Data.CurrentFormat / UIManager view change are the only observable
// outputs the surviving caller cares about.
Data.CurrentFormat = Format.Sealed;
UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.RankMatch);
}
private void OnClickRewardReceiveButton()
{
StartCoroutine(Toolbox.NetworkManager.Connect(new SealedFinishTask(), delegate
{
ReceiveReward();
}));
}
private void ReceiveReward()
{
_commonLobby.ClickProtectionCollider.gameObject.SetActive(value: true);
// Pre-Phase-5b: headless has no InputMgr
_commonLobby.TreasureBoxInfo.OpenBox(delegate
{
_commonLobby.ClickProtectionCollider.gameObject.SetActive(value: false);
// Pre-Phase-5b: headless has no InputMgr
if (SealedData.RewardCardCandidates.Count <= 0)
{
OpenRewardReceiveDialog();
}
else
{
OpenCardSelectDialog();
}
});
}
private void OpenRewardReceiveDialog()
{
DialogBase dialogBase = DialogCreator.CreateRewardReceiveDialog(SealedData.RewardList);
dialogBase.SetLayer("Loading");
dialogBase.ClickSe_Btn1 = 0;
dialogBase.OnClose = (Action)Delegate.Combine(dialogBase.OnClose, (Action)delegate
{
UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.MyPage);
});
}
private void OpenCardSelectDialog()
{
StartCoroutine(OpenCardSelectDialogCoroutine());
}
private IEnumerator OpenCardSelectDialogCoroutine()
{
UIManager uiMgr = UIManager.GetInstance();
uiMgr.createInSceneCenterLoading();
SystemText systemText = Data.SystemText;
DialogBase dialog = uiMgr.CreateDialogClose();
dialog.SetLayer("Loading");
dialog.SetSize(DialogBase.Size.M);
dialog.SetTitleLabel(systemText.Get("Sealed_RewardCardSelect_0001"));
dialog.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
dialog.onPushButton1 = (dialog.onCloseWithoutSelect = _commonLobby.TreasureBoxInfo.Reset);
CardSelectDialog dialogObject = NGUITools.AddChild(dialog.gameObject, _cardSelectDialogPrefab.gameObject).GetComponent<CardSelectDialog>();
dialogObject.Init(SealedData.RewardCardCandidates, delegate(int cardId)
{
OpenCardSelectConfirmDialog(dialog, cardId);
}, systemText.Get("Sealed_RewardCardSelect_0002"));
while (!dialogObject.IsReady)
{
yield return null;
}
uiMgr.closeInSceneCenterLoading();
}
private void OpenCardSelectConfirmDialog(DialogBase cardSelectDialog, int cardId)
{
SystemText systemText = Data.SystemText;
DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
dialogBase.SetSize(DialogBase.Size.S);
dialogBase.SetTitleLabel(systemText.Get("Sealed_RewardCardSelect_0003"));
dialogBase.SetText(systemText.Get("Sealed_RewardCardSelect_0004", CardMaster.GetInstance(FormatBehaviorManager.GetDefaultBehaviour(Format.Sealed).CardMasterId).GetCardParameterFromId(cardId).CardName));
dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
dialogBase.SetButtonText(systemText.Get("Common_0004"));
dialogBase.onPushButton1 = delegate
{
cardSelectDialog.Close();
StartCoroutine(Toolbox.NetworkManager.Connect(new SealedSelectPhantomCardTask(cardId), delegate
{
OpenRewardReceiveDialog();
}));
};
}
}