Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/GachaResultBuyCardPack.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

514 lines
14 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Cute;
using UnityEngine;
namespace Wizard;
public class GachaResultBuyCardPack : UIBase
{
private readonly int[] MAX_COLUMN_RARELITY = new int[4] { 8, 8, 8, 8 };
private readonly Vector3 GRID_LOCAL_POSITION = Vector3.up * -6f;
private readonly Vector3 GRID_ONLY_ONE_LOCAL_POSITION = Vector3.up * -15f;
private readonly Vector3 NEW_LABEL_POSITION = Vector3.up * -150f;
private bool m_isCenterLoading;
[SerializeField]
private UIButton m_buttonNext;
[SerializeField]
private UIButton m_buttonPrev;
[SerializeField]
private UIGrid gridLegendary;
[SerializeField]
private UIGrid gridGold;
[SerializeField]
private UIGrid gridSilver;
[SerializeField]
private UIGrid gridBronze;
[SerializeField]
private GameObject cardObjPool;
[SerializeField]
private GameObject parentLegendary;
[SerializeField]
private GameObject parentGold;
[SerializeField]
private GameObject parentSilver;
[SerializeField]
private GameObject parentBronze;
[SerializeField]
private UILabel labelLegendary;
[SerializeField]
private UILabel labelGold;
[SerializeField]
private UILabel labelSilver;
[SerializeField]
private UILabel labelBronze;
[SerializeField]
private GameObject m_RarityParentRow1;
[SerializeField]
private GameObject m_RarityParentRow2;
[SerializeField]
private UIToggle m_IndicatorBase;
[SerializeField]
private UITexture _particleTexture;
private List<List<CardPack>> m_CardPackListPerPage = new List<List<CardPack>>();
private Dictionary<int, List<UIBase_CardManager.CardObjData>> m_Page_LoadedCard_Dictionary = new Dictionary<int, List<UIBase_CardManager.CardObjData>>();
private Dictionary<int, int> m_CardId_Num_Dictionary = new Dictionary<int, int>();
private List<string> m_LoadedAssetPathList = new List<string>();
private int currentPage;
private List<int> _specialEffectCardList = new List<int>();
private List<UIToggle> m_IndicaatorList = new List<UIToggle>();
private CardDetailUI m_cardDetailUI;
private bool m_isInitLoadFinish;
private bool _isLoadEffectFinish;
private List<string> _loadEffectList = new List<string>();
private List<GameObject> _effectList = new List<GameObject>();
private bool _isWaitingEffectMaterial;
private UIParticleEffectGroup _particleGroup;
public bool IsFlickEnable { get; set; }
public bool IsLoading { get; private set; }
public List<string> _loadedAssetPathList => m_LoadedAssetPathList;
public bool IsDialogCloseStart { get; set; }
public void Init(List<CardPack> cardPackList, CardDetailUI cardDetailUI)
{
m_cardDetailUI = cardDetailUI;
IsFlickEnable = true;
List<CardPack> list = new List<CardPack>();
for (int i = 0; i < cardPackList.Count; i++)
{
int card_id = cardPackList[i].card_id;
if (m_CardId_Num_Dictionary.ContainsKey(card_id))
{
m_CardId_Num_Dictionary[card_id]++;
continue;
}
m_CardId_Num_Dictionary.Add(card_id, 1);
list.Add(cardPackList[i]);
}
foreach (CardPack cardPack in cardPackList)
{
if (cardPack.IsFreePackLeaderSkin)
{
_specialEffectCardList.Add(cardPack.card_id);
}
}
List<CardPack> list2 = new List<CardPack>();
list2.AddRange(SortCardList(list.FindAll((CardPack m) => m.rarity == 4)));
list2.AddRange(SortCardList(list.FindAll((CardPack m) => m.rarity == 3)));
list2.AddRange(SortCardList(list.FindAll((CardPack m) => m.rarity == 2)));
list2.AddRange(SortCardList(list.FindAll((CardPack m) => m.rarity == 1)));
DividCardListEachPages(list2);
GameObject gameObject = m_IndicatorBase.transform.parent.gameObject;
if (m_CardPackListPerPage.Count <= 1)
{
gameObject.SetActive(value: false);
return;
}
gameObject.SetActive(value: true);
m_IndicaatorList.Add(m_IndicatorBase);
for (int num = 1; num < m_CardPackListPerPage.Count; num++)
{
m_IndicaatorList.Add(NGUITools.AddChild(gameObject, m_IndicatorBase.gameObject).GetComponent<UIToggle>());
}
gameObject.GetComponent<UIGrid>().Reposition();
}
public IEnumerator ViewCardList(int page)
{
currentPage = page;
if (page > 1)
{
m_buttonPrev.gameObject.SetActive(value: true);
}
else
{
m_buttonPrev.gameObject.SetActive(value: false);
}
if (page < m_CardPackListPerPage.Count)
{
m_buttonNext.gameObject.SetActive(value: true);
}
else
{
m_buttonNext.gameObject.SetActive(value: false);
}
if (m_IndicaatorList.Count > 1)
{
m_IndicaatorList[page - 1].value = true;
}
RemoveCardObjFromGrid(gridLegendary);
RemoveCardObjFromGrid(gridGold);
RemoveCardObjFromGrid(gridSilver);
RemoveCardObjFromGrid(gridBronze);
if (m_Page_LoadedCard_Dictionary.ContainsKey(page))
{
CompleteLoadCard();
}
else if (IsLoading)
{
SetCenterLoading(isVisible: true);
labelLegendary.gameObject.SetActive(value: false);
labelGold.gameObject.SetActive(value: false);
labelSilver.gameObject.SetActive(value: false);
labelBronze.gameObject.SetActive(value: false);
while (IsLoading)
{
yield return null;
}
CompleteLoadCard();
}
else
{
yield return StartCoroutine(LoadCardList(page, CompleteLoadCard));
}
}
private void CompleteLoadCard()
{
AddCardObjToGrid(m_Page_LoadedCard_Dictionary[currentPage]);
SetCenterLoading(isVisible: false);
if (m_Page_LoadedCard_Dictionary.Count < m_CardPackListPerPage.Count && m_Page_LoadedCard_Dictionary.Count == currentPage && !IsLoading)
{
StartCoroutine(LoadCardList(currentPage + 1, delegate
{
m_isInitLoadFinish = true;
}));
}
}
protected override void OnDestroy()
{
base.OnDestroy();
DisposeEffect();
}
private IEnumerator LoadEffect()
{
if (!_isLoadEffectFinish)
{
_loadEffectList.Add(Toolbox.ResourcesManager.GetAssetTypePath("gch_result_skin_1", ResourcesManager.AssetLoadPathType.Effect2D));
yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(_loadEffectList, delegate
{
}));
_isLoadEffectFinish = true;
}
}
private void DisposeEffect()
{
if (_loadEffectList.Count != 0)
{
Toolbox.ResourcesManager.RemoveAssetGroup(_loadEffectList);
_loadEffectList.Clear();
ReleaseParticleEffectGroup();
}
}
private IEnumerator LoadCardList(int page, Action callback = null)
{
if (m_Page_LoadedCard_Dictionary.ContainsKey(page))
{
callback.Call();
yield break;
}
IsLoading = true;
if (_specialEffectCardList.Count > 0)
{
yield return LoadEffect();
}
while (_isWaitingEffectMaterial)
{
yield return null;
}
List<int> idList = m_CardPackListPerPage[page - 1].ConvertAll((CardPack conv) => conv.card_id);
yield return null;
UIManager.GetInstance().CardLoadGachaPack(base.gameObject, idList, 24, is2D: true);
while (!UIManager.GetInstance().getUIBase_CardManager().getCreateEndFlag() || !UIManager.GetInstance().getUIBase_CardManager().isAssetAllReady)
{
yield return null;
}
List<UIBase_CardManager.CardObjData> cardList2DObjs = UIManager.GetInstance().getCardList2DObjs();
m_Page_LoadedCard_Dictionary.Add(page, cardList2DObjs);
m_LoadedAssetPathList.AddRange(Toolbox.ResourcesManager.CardListAssetPathList);
Toolbox.ResourcesManager.CardListAssetPathList.Clear();
Toolbox.ResourcesManager.Card2DAssetPathList.Clear();
for (int num = 0; num < cardList2DObjs.Count; num++)
{
GameObject cardObj = cardList2DObjs[num].CardObj;
CardListTemplate component = cardObj.GetComponent<CardListTemplate>();
component.SetNum(m_CardId_Num_Dictionary[cardList2DObjs[num].ids]);
cardObj.AddComponent<BoxCollider>().size = component._cardTexture.localSize;
UIEventListener.Get(cardObj).onClick = m_cardDetailUI.OnPushCardDetailOn;
cardObj.transform.parent = cardObjPool.transform;
cardObj.transform.localPosition = Vector3.zero;
cardObj.SetActive(value: false);
cardObj.SetActive(value: true);
}
IsLoading = false;
callback.Call();
}
private void SetCenterLoading(bool isVisible)
{
m_isCenterLoading = isVisible;
if (isVisible)
{
UIManager.GetInstance().createInSceneCenterLoading();
}
else
{
UIManager.GetInstance().closeInSceneCenterLoading();
}
}
private List<CardPack> SortCardList(List<CardPack> cardList)
{
List<int> idList = cardList.ConvertAll((CardPack conv) => conv.card_id);
idList = UIManager.GetInstance().getUIBase_CardManager().SortIDList(idList, CardMaster.CardMasterId.Default);
cardList = idList.ConvertAll((int conv) => cardList.Find((CardPack find) => find.card_id == conv));
return cardList;
}
private void DividCardListEachPages(List<CardPack> cardPackList)
{
List<CardPack> list = new List<CardPack>();
int rarity = cardPackList[0].rarity;
int num = 1;
int num2 = 0;
for (int i = 0; i < cardPackList.Count; i++)
{
if (cardPackList[i].rarity <= MAX_COLUMN_RARELITY.Length)
{
num2++;
if (rarity != cardPackList[i].rarity)
{
num++;
num2 = 1;
rarity = cardPackList[i].rarity;
}
else if (num2 > MAX_COLUMN_RARELITY[rarity - 1])
{
num++;
num2 = 1;
}
if (num > 2)
{
num = 1;
m_CardPackListPerPage.Add(list);
list = new List<CardPack>();
list.Add(cardPackList[i]);
}
else
{
list.Add(cardPackList[i]);
}
}
}
if (list.Count > 0)
{
m_CardPackListPerPage.Add(list);
}
}
private void RemoveCardObjFromGrid(UIGrid gridObj)
{
List<Transform> childList = gridObj.GetChildList();
for (int i = 0; i < childList.Count; i++)
{
childList[i].transform.parent = cardObjPool.transform;
childList[i].transform.localPosition = Vector3.zero;
}
}
private void ReleaseParticleEffectGroup()
{
if (_particleGroup != null)
{
UIParticleEffectManager.Instance.Remove(_particleGroup);
_particleGroup = null;
}
}
private void AddCardObjToGrid(List<UIBase_CardManager.CardObjData> cardObjList)
{
bool flag = false;
bool flag2 = false;
bool flag3 = false;
bool flag4 = false;
foreach (GameObject effect in _effectList)
{
UnityEngine.Object.Destroy(effect);
}
_effectList.Clear();
ReleaseParticleEffectGroup();
for (int i = 0; i < cardObjList.Count; i++)
{
CardParameter cardParameterFromId = CardMaster.GetInstance(CardMaster.CardMasterId.Default).GetCardParameterFromId(cardObjList[i].ids);
GameObject cardObj = cardObjList[i].CardObj;
switch (cardParameterFromId.Rarity)
{
case 1:
flag = true;
gridBronze.AddChild(cardObj.transform);
cardObj.transform.localScale = Vector3.one * 0.55f;
break;
case 2:
flag2 = true;
gridSilver.AddChild(cardObj.transform);
cardObj.transform.localScale = Vector3.one * 0.55f;
break;
case 3:
flag3 = true;
gridGold.AddChild(cardObj.transform);
cardObj.transform.localScale = Vector3.one * 0.55f;
break;
case 4:
flag4 = true;
gridLegendary.AddChild(cardObj.transform);
cardObj.transform.localScale = Vector3.one * 0.55f;
break;
}
if (_specialEffectCardList.Contains(cardObjList[i].ids))
{
_isWaitingEffectMaterial = true;
if (_particleGroup == null)
{
_particleGroup = UIParticleEffectManager.Instance.CreateNewGroup(_particleTexture);
}
Effect2dCreateParam param = new Effect2dCreateParam
{
Parent = cardObj.gameObject,
EffectName = "gch_result_skin_1",
InitActive = false,
UnloadAssetList = _loadEffectList,
MaterialSetEndCallback = delegate
{
_isWaitingEffectMaterial = false;
}
};
_particleGroup.StartEffect(param, isEnableUpdateReposition: true);
}
cardObj.transform.localPosition += Vector3.back;
if (false /* Pre-Phase-5b: no new-card state headless */)
{
cardObj.GetComponent<CardListTemplate>()._newLabel.transform.localPosition = NEW_LABEL_POSITION;
}
cardObj.SetActive(value: true);
}
SystemText systemText = Data.SystemText;
labelLegendary.gameObject.SetActive(flag4);
if (flag4)
{
labelLegendary.text = systemText.Get("Card_Rarity_0004");
}
labelGold.gameObject.SetActive(flag3);
if (flag3)
{
labelGold.text = systemText.Get("Card_Rarity_0003");
}
labelSilver.gameObject.SetActive(flag2);
if (flag2)
{
labelSilver.text = systemText.Get("Card_Rarity_0002");
}
labelBronze.gameObject.SetActive(flag);
if (flag)
{
labelBronze.text = systemText.Get("Card_Rarity_0001");
}
UIGrid uIGrid = null;
if (flag4)
{
parentLegendary.transform.parent = m_RarityParentRow1.transform;
parentLegendary.transform.localPosition = Vector3.zero;
uIGrid = gridLegendary;
}
else if (flag3)
{
parentGold.transform.parent = m_RarityParentRow1.transform;
parentGold.transform.localPosition = Vector3.zero;
uIGrid = gridGold;
}
else if (flag2)
{
parentSilver.transform.parent = m_RarityParentRow1.transform;
parentSilver.transform.localPosition = Vector3.zero;
uIGrid = gridSilver;
}
else
{
parentBronze.transform.parent = m_RarityParentRow1.transform;
parentBronze.transform.localPosition = Vector3.zero;
uIGrid = gridBronze;
}
if ((flag && flag2) || (flag && flag3) || (flag && flag4))
{
parentBronze.transform.parent = m_RarityParentRow2.transform;
parentBronze.transform.localPosition = Vector3.zero;
uIGrid.transform.localPosition = GRID_LOCAL_POSITION;
gridBronze.transform.localPosition = GRID_LOCAL_POSITION;
}
else if ((flag2 && flag3) || (flag2 && flag4))
{
parentSilver.transform.parent = m_RarityParentRow2.transform;
parentSilver.transform.localPosition = Vector3.zero;
uIGrid.transform.localPosition = GRID_LOCAL_POSITION;
gridSilver.transform.localPosition = GRID_LOCAL_POSITION;
}
else if (flag3 && flag4)
{
parentGold.transform.parent = m_RarityParentRow2.transform;
parentGold.transform.localPosition = Vector3.zero;
uIGrid.transform.localPosition = GRID_LOCAL_POSITION;
gridGold.transform.localPosition = GRID_LOCAL_POSITION;
}
else
{
uIGrid.transform.localPosition = GRID_ONLY_ONE_LOCAL_POSITION;
}
}
}