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

566 lines
16 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cute;
using LitJson;
using UnityEngine;
// TODO(engine-cleanup-pass2): 310 of 317 methods unrun in baseline
// Type: Wizard.Master
// See data_dumps/reports/engine-cleanup/live-methods.baseline.txt
namespace Wizard;
public class Master
{
public interface ReadFromCsv
{
void ReadCsvColumns(string[] columns);
}
private List<BattleInformation> _roomChaosBattleInfo;
private List<BattleInformation> _colosseumChaosBattleInfo;
private List<List<BattleInformation>> _chaosBattleInfoList;
private Dictionary<int, List<int>> _classInfomationOrder;
private Dictionary<int, List<int>> _roomClassInfomationOrder;
private Dictionary<int, List<int>> _colosseumClassInfomationOrder;
private List<Dictionary<int, List<int>>> _classInfomationOrderList;
public List<ClassCharacterMasterData> ClassCharacterList { get; private set; }
public Dictionary<int, SleeveCategory> SleeveCategoryIdDic { get; set; }
public Dictionary<int, LeaderSkinSeries> LeaderSkinSeriesIdDic { get; set; }
public SleeveMgr SleeveMgr { get; private set; }
public EmblemMgr EmblemMgr { get; private set; }
public DegreeMgr DegreeMgr { get; private set; }
public List<Item> ItemList { get; set; }
public List<GiftTransition> GiftTransitionList { get; set; }
public Dictionary<int, List<int>> ClassInfomationOrder
{
get
{
switch (DataMgr.BattleType.FreeBattle) // Pre-Phase-5b: headless has no BattleType
{
case DataMgr.BattleType.RoomTwoPick:
case DataMgr.BattleType.TwoPickBackdraft:
return _roomClassInfomationOrder;
case DataMgr.BattleType.ColosseumTwoPick:
return _colosseumClassInfomationOrder;
default:
return _classInfomationOrder;
}
}
}
private Dictionary<string, string> _crossOverClassInfomationOrder { get; set; }
public Dictionary<int, List<int>> AvatarClassInformationOrder { get; set; }
public List<string> WhenPlayEffectKeywordMaster { get; set; }
public List<PuzzleQuestData> PuzzleQuestDataList { get; private set; }
public List<TutorialAreaSelect> TutorialAreaSelectList { get; set; }
public AICardDataAssetSet AIBasicDataList { get; set; }
public AICardDataAssetSet AICommonDataList { get; set; }
public AICardDataAssetSet AIAllyCommonDataList { get; set; }
public Dictionary<string, AICardDataAssetSet> AIDeckDic { get; set; }
public List<AIPolicyDataAsset> AIStyleCommonDataList { get; set; }
public Dictionary<string, List<AIPolicyDataAsset>> AIStyleDic { get; set; }
public Dictionary<string, List<AIEmoteDataAsset>> AIEmoteDic { get; set; }
public Dictionary<string, Dictionary<ClassCharaPrm.EmotionType, Emotion>> _emotionDic { get; set; }
public PracticeAISettingDataSet PracticeAISettingList { get; set; }
public StoryAISettingDataSet QuestAISettingList { get; set; }
public List<string> AICommonFileNameList { get; set; }
public List<string> AIAllyCommonFileNameList { get; set; }
public AIDeckFileNameList AIDeckFileNameList { get; set; }
public AIEmoteFileNameList AIEmoteFileNameList { get; set; }
public AIStyleFileNameList AIStyleFileNameList { get; set; }
public IDictionary<string, string> BattleKeyWordDic { get; private set; }
public IDictionary<string, string> CardFilterKeywordReplaceDic { get; private set; }
private IDictionary<string, string> EmoteWordDic { get; set; }
private IDictionary<string, string> CardNameDic { get; set; }
private IDictionary<string, string> TribeNameDic { get; set; }
private IDictionary<string, string> SkillDescDic { get; set; }
private IDictionary<string, string> FlavourTextDic { get; set; }
private IDictionary<string, string> ItemTextDic { get; set; }
public IDictionary<string, string> SleeveTextDic { get; private set; }
private IDictionary<string, string> SleeveCategoryTextDic { get; set; }
private IDictionary<string, string> LeaderSkinProductTextDic { get; set; }
private IDictionary<string, string> LeaderSkinSeriesTextDic { get; set; }
public IDictionary<string, string> ClassCharaTextDic { get; private set; }
public IDictionary<string, string> EmblemTextDic { get; private set; }
public IDictionary<string, string> DegreeTextDic { get; private set; }
private IDictionary<string, string> DegreeAchievementTextDic { get; set; }
private Dictionary<string, string> MyPageBGTextDic { get; set; }
public CardSetNameMgr CardSetNameMgr { get; private set; }
private IDictionary<string, string> CardVoiceTextDic { get; set; }
public List<string> CardDetailVoiceIgnoreList { get; private set; }
private IDictionary<string, string> PracticeTextDic { get; set; }
private IDictionary<string, string> StorySectionTitleTextDic { get; set; }
public IDictionary<int, List<int>> RelationCardSortDic { get; private set; }
public Dictionary<int, List<int>> GleamingGemListMaster { get; set; }
public Dictionary<string, MyPageCustomBGMasterData> MyPageCustomBGMaster { get; private set; }
public List<MyPageCustomBGMasterData> MyPageCustomBGMasterList { get; private set; }
public Dictionary<int, List<int>> RadiantCrystalListMaster { get; set; }
public Dictionary<int, List<int>> GleamingGemListV2Master { get; set; }
public Dictionary<int, List<int>> RadiantCrystalListV2Master { get; set; }
public List<int> GetGleamingGemList(int classId)
{
if (GleamingGemListMaster.ContainsKey(classId))
{
return GleamingGemListMaster[classId];
}
return null;
}
public List<int> GetRadiantCrystalList(int classId)
{
if (RadiantCrystalListMaster.ContainsKey(classId))
{
return RadiantCrystalListMaster[classId];
}
return null;
}
public List<int> GetGleamingGemListV2Master(int classId)
{
if (GleamingGemListV2Master.ContainsKey(classId))
{
return GleamingGemListV2Master[classId];
}
return null;
}
public List<int> GetRadiantCrystalListV2Master(int classId)
{
if (RadiantCrystalListV2Master.ContainsKey(classId))
{
return RadiantCrystalListV2Master[classId];
}
return null;
}
public void LoadRoomChaosBattleInfo(int num)
{
if (num > 0 && _chaosBattleInfoList != null)
{
_roomChaosBattleInfo = _chaosBattleInfoList[num - 1];
}
}
public void LoadColosseumChaosBattleInfo(int num)
{
if (num > 0 && _chaosBattleInfoList != null)
{
_colosseumChaosBattleInfo = _chaosBattleInfoList[num - 1];
}
}
public void SetRoomClassInfomationOrder(int num)
{
if (num > 0 && _classInfomationOrderList != null)
{
_roomClassInfomationOrder = _classInfomationOrderList[num - 1];
}
}
public void SetColosseumClassInfomationOrder(int num)
{
if (num > 0 && _classInfomationOrderList != null)
{
_colosseumClassInfomationOrder = _classInfomationOrderList[num - 1];
}
}
public List<int> GetCrossOverClassInfoListOrNull(int mainClass, int subClass)
{
return _crossOverClassInfomationOrder.GetValueOrDefault(mainClass + "|" + subClass, null)?.Split('|').Select(int.Parse).ToList();
}
public string GetText<Type>(Type key, IDictionary<Type, string> dic)
{
if (!dic.TryGetValue(key, out var value))
{
return key.ToString();
}
return value;
}
public string GetEmoteWordText(string key)
{
return GetText(key, EmoteWordDic);
}
public string GetCardNameText(string key)
{
return GetText(key, CardNameDic);
}
public string GetTribeNameText(string key)
{
return GetText(key, TribeNameDic);
}
public string GetSkillDescText(string key)
{
return GetText(key, SkillDescDic);
}
public string GetFlavourText(string key)
{
return GetText(key, FlavourTextDic);
}
public string GetItemText(string key)
{
return GetText(key, ItemTextDic);
}
public string GetSleeveText(string key)
{
return GetText(key, SleeveTextDic);
}
public string GetSleeveCategoryText(string key)
{
return GetText(key, SleeveCategoryTextDic);
}
public string GetLeaderSkinProductText(string key)
{
return GetText(key, LeaderSkinProductTextDic);
}
public string GetLeaderSkinSeriesText(string key)
{
return GetText(key, LeaderSkinSeriesTextDic);
}
public string GetClassCharaText(string key)
{
return GetText(key, ClassCharaTextDic);
}
public string GetEmblemText(string key)
{
return GetText(key, EmblemTextDic);
}
public string GetDegreeText(string key)
{
return GetText(key, DegreeTextDic);
}
public string GetDegreeAchievementText(string key)
{
return GetText(key, DegreeAchievementTextDic);
}
public string GetCardVoiceText(string key)
{
return GetText(key, CardVoiceTextDic);
}
public string GetPracticeText(string key)
{
return GetText(key, PracticeTextDic);
}
public string GetStorySectionTitleText(string key)
{
return GetText(key, StorySectionTitleTextDic);
}
public string GetMyPageBGText(string key)
{
return GetText(key, MyPageBGTextDic);
}
public List<string> GetAllTribeNameList()
{
List<string> list = new List<string>(TribeNameDic.Count);
foreach (KeyValuePair<string, string> item in TribeNameDic)
{
list.Add(item.Value);
}
return list;
}
public void StartLoadAIBasicData()
{
AIBasicDataList = new AICardDataAssetSet();
string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath("ai/ai_basic", ResourcesManager.AssetLoadPathType.Master, isfetch: true);
List<string[]> csv = Utility.ConvertCSV_Array((Toolbox.ResourcesManager.LoadObject(assetTypePath) as TextAsset).ToString());
AIBasicDataList.ConvertCsvTextToAsset(csv);
}
public void StartLoadAICommonData(List<string> fileList)
{
AICommonDataList = new AICardDataAssetSet();
for (int i = 0; i < fileList.Count; i++)
{
string path = "ai/" + fileList[i];
string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath(path, ResourcesManager.AssetLoadPathType.Master, isfetch: true);
List<string[]> csv = Utility.ConvertCSV_Array((Toolbox.ResourcesManager.LoadObject(assetTypePath) as TextAsset).ToString());
AICommonDataList.ConvertCsvTextToAsset(csv);
}
}
public void StartLoadAIAllyCommonData(List<string> fileList)
{
AIAllyCommonDataList = new AICardDataAssetSet();
for (int i = 0; i < fileList.Count; i++)
{
string path = "ai/" + fileList[i];
string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath(path, ResourcesManager.AssetLoadPathType.Master, isfetch: true);
List<string[]> csv = Utility.ConvertCSV_Array((Toolbox.ResourcesManager.LoadObject(assetTypePath) as TextAsset).ToString());
AIAllyCommonDataList.ConvertCsvTextToAsset(csv);
}
}
public void StartLoadAIDeckData(int deckID)
{
if (AIDeckDic == null)
{
AIDeckDic = new Dictionary<string, AICardDataAssetSet>();
}
string text = "ai/" + AIDeckFileNameList.GetFileName(deckID);
if (!AIDeckDic.ContainsKey(text))
{
LoadAIDeckData(text);
}
}
private void LoadAIDeckData(string fileName)
{
string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath(fileName, ResourcesManager.AssetLoadPathType.Master, isfetch: true);
AICardDataAssetSet aICardDataAssetSet = new AICardDataAssetSet();
List<string[]> csv = Utility.ConvertCSV_Array((Toolbox.ResourcesManager.LoadObject(assetTypePath) as TextAsset).ToString());
aICardDataAssetSet.ConvertCsvTextToAsset(csv);
AIDeckDic.Add(fileName, aICardDataAssetSet);
}
public void StartLoadAIStyleData(int styleID)
{
if (AIStyleDic == null)
{
AIStyleDic = new Dictionary<string, List<AIPolicyDataAsset>>();
}
string fileName = AIStyleFileNameList.GetFileName(styleID);
if (fileName != null && !(fileName == ""))
{
string text = "ai/" + fileName;
if (!AIStyleDic.ContainsKey(text))
{
LoadAIStyleData(text);
}
}
}
private void LoadAIStyleData(string fileName)
{
string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath(fileName, ResourcesManager.AssetLoadPathType.Master, isfetch: true);
List<AIPolicyDataAsset> list = new List<AIPolicyDataAsset>();
foreach (string[] item in Utility.ConvertCSV_Array((Toolbox.ResourcesManager.LoadObject(assetTypePath) as TextAsset).ToString()))
{
list.Add(new AIPolicyDataAsset(item));
}
AIStyleDic.Add(fileName, list);
}
public void StartLoadAIEmoteData(int emoteID)
{
if (AIEmoteDic == null)
{
AIEmoteDic = new Dictionary<string, List<AIEmoteDataAsset>>();
}
string fileName = AIEmoteFileNameList.GetFileName(emoteID);
if (fileName != null && !(fileName == ""))
{
string text = "ai/" + fileName;
if (!AIEmoteDic.ContainsKey(text))
{
LoadAIEmoteData(text);
}
}
}
private void LoadAIEmoteData(string fileName)
{
string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath(fileName, ResourcesManager.AssetLoadPathType.Master, isfetch: true);
List<AIEmoteDataAsset> list = new List<AIEmoteDataAsset>();
foreach (string[] item in Utility.ConvertCSV_Array((Toolbox.ResourcesManager.LoadObject(assetTypePath) as TextAsset).ToString()))
{
list.Add(new AIEmoteDataAsset(item));
}
AIEmoteDic.Add(fileName, list);
}
private void RegisterAIDeckCsvFilePath(List<string> aiPaths, int deckID)
{
string fileName = AIDeckFileNameList.GetFileName(deckID);
if (AIDeckDic == null || !AIDeckDic.ContainsKey(fileName))
{
aiPaths.Add(Toolbox.ResourcesManager.GetAssetTypePath(fileName, ResourcesManager.AssetLoadPathType.Master));
}
}
private void RegisterAICommonCsvFilePaths(List<string> aiPaths)
{
for (int i = 0; i < AICommonFileNameList.Count; i++)
{
aiPaths.Add(Toolbox.ResourcesManager.GetAssetTypePath(AICommonFileNameList[i], ResourcesManager.AssetLoadPathType.Master));
}
}
private void RegisterAIAllyCommonCsvFilePaths(List<string> aiPaths)
{
for (int i = 0; i < AIAllyCommonFileNameList.Count; i++)
{
aiPaths.Add(Toolbox.ResourcesManager.GetAssetTypePath(AIAllyCommonFileNameList[i], ResourcesManager.AssetLoadPathType.Master));
}
}
private void RegisterAIEmoteCsvFilePath(List<string> aiPaths, int emoteID)
{
string fileName = AIEmoteFileNameList.GetFileName(emoteID);
if (fileName != null && !(fileName == "") && (AIEmoteDic == null || !AIEmoteDic.ContainsKey(fileName)))
{
aiPaths.Add(Toolbox.ResourcesManager.GetAssetTypePath(fileName, ResourcesManager.AssetLoadPathType.Master));
}
}
private void RegisterAIStyleCsvFilePath(List<string> aiPaths, int styleID)
{
string fileName = AIStyleFileNameList.GetFileName(styleID);
if (fileName != null && !(fileName == "") && (AIStyleDic == null || !AIStyleDic.ContainsKey(fileName)))
{
aiPaths.Add(Toolbox.ResourcesManager.GetAssetTypePath(fileName, ResourcesManager.AssetLoadPathType.Master));
}
}
public void LoadAICsv(AICsvLoadingInfo info, Action callBack)
{
List<string> aiPaths = new List<string>();
RegisterAICommonCsvPath(aiPaths);
RegisterAIIndividualCsvPath(aiPaths, info);
Toolbox.ResourcesManager.StartCoroutine_LoadAssetGroupSync(aiPaths, delegate
{
StartLoadAIBasicAndCommonData();
StartLoadAIIndividualData(info);
/* Pre-Phase-5b: RegisterAllAIData dropped */
Toolbox.ResourcesManager.RemoveAssetGroup(aiPaths);
callBack.Call();
});
}
private void RegisterAICommonCsvPath(List<string> aiPaths)
{
aiPaths.Add(Toolbox.ResourcesManager.GetAssetTypePath("ai_basic", ResourcesManager.AssetLoadPathType.Master));
if (AICommonDataList == null)
{
RegisterAICommonCsvFilePaths(aiPaths);
}
if (AIAllyCommonDataList == null)
{
RegisterAIAllyCommonCsvFilePaths(aiPaths);
}
}
private void RegisterAIIndividualCsvPath(List<string> aiPaths, AICsvLoadingInfo info)
{
if (info.DeckId >= 0)
{
RegisterAIDeckCsvFilePath(aiPaths, info.DeckId);
}
RegisterAIStyleCsvFilePath(aiPaths, info.StyleId);
RegisterAIEmoteCsvFilePath(aiPaths, info.EmoteId);
}
private void StartLoadAIBasicAndCommonData()
{
if (AIBasicDataList == null)
{
StartLoadAIBasicData();
}
if (AICommonDataList == null)
{
StartLoadAICommonData(AICommonFileNameList);
}
if (AIAllyCommonDataList == null)
{
StartLoadAIAllyCommonData(AIAllyCommonFileNameList);
}
}
private void StartLoadAIIndividualData(AICsvLoadingInfo info)
{
if (info.DeckId >= 0)
{
StartLoadAIDeckData(info.DeckId);
}
StartLoadAIEmoteData(info.EmoteId);
StartLoadAIStyleData(info.StyleId);
}
}