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

@@ -11,10 +11,7 @@ public class DataMgr
{
public enum SpecialBattleResultType
{
None,
Belphomet,
Nerva
}
None }
public class SpecialBattleSetting
{
@@ -157,7 +154,9 @@ public class DataMgr
public int m_EnemyAIEmoteId;
public int m_EnemyAIMaxLife;
// Default 20 mirrors the historic AITestGlobal.AI_MAX_LIFE static default. Callers that don't
// invoke SetEnemyAI (e.g. non-AI test fixtures) still get a sensible enemy leader HP.
public int m_EnemyAIMaxLife = 20;
public bool m_EnemyAIUseInnerEmote = true;
@@ -173,8 +172,6 @@ public class DataMgr
private bool _isDirtyPossessionCardDict;
public const int PRACTICE_DIFFICULTY_DEGREE_EASY = 400001;
public BattleType m_BattleType = BattleType.None;
public TwoPickFormat TwoPickFormat;
@@ -183,20 +180,12 @@ public class DataMgr
private static string[] ClanNameTextIdList = new string[9] { "Common_0104", "Common_0105", "Common_0106", "Common_0107", "Common_0108", "Common_0109", "Common_0110", "Common_0111", "Common_0112" };
public static readonly string[] TribeNameTextIdList = new string[18]
{
"TN_ALL", "TN_指揮官", "TN_兵士", "TN_土の印", "TN_マナリア", "TN_アーティファクト", "TN_財宝", "TN_機械", "TN_料理", "TN_レヴィオン",
"TN_自然", "TN_宴楽", "TN_ヒーロー", "TN_武装", "TN_チェス", "TN_八獄", "TN_学園", ""
};
public DeckAttributeType LastSelectDeckAttributeType { private get; set; }
public int PracticeDifficultyDegreeId { get; set; }
public int Practice3DfieldId { get; set; }
public DeckData _roomTwoPickDeckData { get; set; }
public List<int> FavoriteCardList { get; private set; }
public DeckGroupListData CurrentDeckListParamData { get; set; }
@@ -217,8 +206,6 @@ public class DataMgr
public BossRushBattleData BossRushBattleData { get; private set; }
public int PracticePuzzleGroupId { get; set; }
public int PuzzleQuestId { get; set; }
public int PuzzleDifficulty { get; set; }
@@ -270,88 +257,6 @@ public class DataMgr
RecoveryData = recoveryData;
}
public void CacheSingleRecovryData()
{
if (RecoveryRecordManagerBase.IsExistsSingleRecoveryFile())
{
RecoveryData = RecoveryOperationInfo.ReadRecoveryFile(OperationRecorderBase.RecordDirectoryPath + "recovery_single.json");
}
}
public static bool IsNetworkBattleType(BattleType battleType)
{
switch (battleType)
{
case BattleType.FreeBattle:
case BattleType.RankBattle:
case BattleType.TwoPick:
case BattleType.RoomBattle:
case BattleType.RoomTwoPick:
case BattleType.TwoPickBackdraft:
case BattleType.ColosseumNormal:
case BattleType.ColosseumTwoPick:
case BattleType.ColosseumHof:
case BattleType.Sealed:
case BattleType.ColosseumWindFall:
case BattleType.Gathering:
case BattleType.CompetitionNormal:
case BattleType.CompetitionTwoPick:
return true;
default:
return false;
}
}
public bool IsColosseumBattleType()
{
BattleType battleType = m_BattleType;
if ((uint)(battleType - 8) <= 1u || battleType == BattleType.ColosseumHof || battleType == BattleType.ColosseumWindFall)
{
return true;
}
return false;
}
public bool IsCompetitionBattleType()
{
BattleType battleType = m_BattleType;
if (battleType == BattleType.CompetitionNormal || battleType == BattleType.CompetitionTwoPick)
{
return true;
}
return false;
}
public static bool IsTwoPickBattleType(BattleType battleType)
{
switch (battleType)
{
case BattleType.TwoPick:
case BattleType.RoomTwoPick:
case BattleType.TwoPickBackdraft:
case BattleType.ColosseumTwoPick:
case BattleType.CompetitionTwoPick:
return true;
default:
return false;
}
}
public static bool IsEnableFormatIconBattleType(BattleType battleType)
{
switch (battleType)
{
case BattleType.FreeBattle:
case BattleType.RankBattle:
case BattleType.RoomBattle:
case BattleType.ColosseumNormal:
case BattleType.CompetitionNormal:
return true;
default:
return false;
}
}
public bool IsDipslayHighRankFormat()
{
switch (m_BattleType)
@@ -380,11 +285,6 @@ public class DataMgr
}
}
public bool IsTwoPickBattleType()
{
return IsTwoPickBattleType(m_BattleType);
}
public bool IsQuestBattleType()
{
return IsQuestBattleType(m_BattleType);
@@ -399,34 +299,6 @@ public class DataMgr
return false;
}
public bool IsFormatEnableBattleType()
{
switch (m_BattleType)
{
case BattleType.TwoPick:
case BattleType.Story:
case BattleType.Practice:
case BattleType.ColosseumTwoPick:
case BattleType.ColosseumHof:
case BattleType.Sealed:
case BattleType.ColosseumWindFall:
case BattleType.Quest:
case BattleType.BossRushQuest:
case BattleType.SecretBossQuest:
return false;
default:
if (Data.CurrentFormat == Format.Avatar)
{
return false;
}
if (IsTwoPickBattleType() || Data.CurrentFormat == Format.Max || Data.CurrentFormat == Format.PreRotation || Data.CurrentFormat == Format.Windfall || Data.CurrentFormat == Format.MyRotation || Data.CurrentFormat == Format.TwoPick)
{
return false;
}
return true;
}
}
public bool IsRoomBattleType()
{
BattleType battleType = m_BattleType;
@@ -437,15 +309,6 @@ public class DataMgr
return false;
}
public static bool IsSingleBattleType(BattleType battleType)
{
if ((uint)(battleType - 4) <= 1u || battleType == BattleType.Quest || (uint)(battleType - 45) <= 1u)
{
return true;
}
return false;
}
public DataMgr()
{
_possessionCardDict = new Dictionary<int, int>();
@@ -456,10 +319,6 @@ public class DataMgr
PracticeDifficultyDegreeId = 400001;
}
public void PrintAIDataLibraryOnlyDebug()
{
}
public void Load()
{
LoadClassData();
@@ -606,11 +465,6 @@ public class DataMgr
_enemyMyRotationInfo = Data.MyRotationAllInfo.Get(myRotationId);
}
public void SetEnemyAvatarBattleInfo(string id)
{
_enemyAvatarBattleInfo = Data.AvatarBattleAllInfo.Get(id);
}
public void ClearEnemyAvatarBattleInfo()
{
_enemyAvatarBattleInfo = null;
@@ -670,24 +524,12 @@ public class DataMgr
}
}
public void SetStoryAILogicAndDeckData(int classId, int enemyAiId)
{
StoryAISettingData settingData = Data.Master.StoryAISettingList.GetSettingData(enemyAiId);
SetCurrentEnemyDeckDataFromAIDeck(classId, -1, settingData.LogicLevel, 20, settingData.DeckId, settingData.StyleId, settingData.EmoteId, settingData.UseInnerEmote, enemyAiId);
}
public void SetQuestAILogicAndDeckData(int classId, int enemyAiId)
{
StoryAISettingData settingData = Data.Master.QuestAISettingList.GetSettingData(enemyAiId);
SetCurrentEnemyDeckDataFromAIDeck(classId, -1, settingData.LogicLevel, 20, settingData.DeckId, settingData.StyleId, settingData.EmoteId, settingData.UseInnerEmote, enemyAiId);
}
public void SetRankMatchAILogicAndDeckData(int enemyAiId)
{
RankMatchAISettingData settingData = Data.Master.RankMatchAISettingList.GetSettingData(enemyAiId);
SetCurrentEnemyDeckDataFromAIDeck(settingData.ClassId, -1, 2, 20, settingData.DeckId, settingData.StyleId, -1, useInnerEmote: false, enemyAiId);
}
public void SetCurrentEnemyDeckDataFromAIDeck(int classID, int difficulty, int logicLevel, int maxLife, int deckId, int styleId, int emoteId, bool useInnerEmote, int enemyAiID = -1, List<int> specialAbilityIdList = null)
{
if (classID == 0)
@@ -701,7 +543,6 @@ public class DataMgr
m_EnemyAILogicLevel = logicLevel;
m_EnemyAIMaxLife = maxLife;
m_EnemyAIUseInnerEmote = useInnerEmote;
AITestGlobal.AI_MAX_LIFE = maxLife;
AI_LOGIC_LV logicLv = AI_LOGIC_LV.STRONG;
switch (logicLevel)
{
@@ -731,7 +572,6 @@ public class DataMgr
m_EnemyAILogicLevel = logicLevel;
m_EnemyAIMaxLife = maxLife;
m_EnemyAIUseInnerEmote = useInnerEmote;
AITestGlobal.AI_MAX_LIFE = m_EnemyAIMaxLife;
AI_LOGIC_LV logicLv = AI_LOGIC_LV.STRONG;
switch (logicLevel)
{
@@ -768,39 +608,6 @@ public class DataMgr
}
}
public void SetUserOwnCardData(IDictionary<int, int> userowncarddata)
{
_possessionCardDict = userowncarddata;
SetDirtyPossessionCardDict();
}
public void SetClassPrm(JsonData userClassCharaList, JsonData userRankMatchList)
{
Dictionary<int, ClassCharaPrm> dictionary = new Dictionary<int, ClassCharaPrm>();
for (int i = 0; i < userClassCharaList.Count; i++)
{
JsonData jsonData = userClassCharaList[i];
int num = jsonData["class_id"].ToInt();
if (num < 1 || 9 <= num)
{
continue;
}
ClassCharaPrm classCharaPrm = new ClassCharaPrm();
classCharaPrm.SetParamWithUserClassJson(jsonData);
for (int j = 0; j < userRankMatchList.Count; j++)
{
JsonData jsonData2 = userRankMatchList[j];
if (jsonData2["class_id"].ToInt() == num)
{
classCharaPrm.SetClassCharaWin(jsonData2["win"].ToInt());
classCharaPrm.SetClassCharaBattleCount(jsonData2["match_count"].ToInt());
}
}
dictionary.Add(num, classCharaPrm);
}
_classPrmDict = dictionary;
}
public void SetSoroPlay3DFieldID(int fieldID)
{
_soroPlay3DFieldId = fieldID;
@@ -822,11 +629,6 @@ public class DataMgr
SpecialBattleSettingInfo = null;
}
public void ResetStorySpecialBattleResultSkipFlag()
{
SkipStorySpecialBattleResult = SpecialBattleResultType.None;
}
private static Dictionary<int, int> ParseIdOverrideText(string idOverrideText)
{
if (string.IsNullOrEmpty(idOverrideText))
@@ -874,25 +676,6 @@ public class DataMgr
return "";
}
public static string GetTribeNameByKey(int tribeType)
{
if (tribeType >= TribeNameTextIdList.Length)
{
return "";
}
string text = TribeNameTextIdList[tribeType];
if (string.IsNullOrEmpty(text))
{
return "";
}
return Data.Master.GetTribeNameText(text);
}
public IDictionary<int, ClassCharaPrm> GetClassPrmDictionary()
{
return _classPrmDict;
}
public ClassCharaPrm GetClassPrm(int classId)
{
return _classPrmDict[classId];
@@ -932,21 +715,6 @@ public class DataMgr
return _playerSubClassId;
}
public bool TryGetPlayerSubClassId(out int subClassId)
{
subClassId = GetPlayerSubClassId();
return IsValidSubClass(subClassId);
}
private static bool IsValidSubClass(int subClassId)
{
if (subClassId > 0)
{
return subClassId != 10;
}
return false;
}
public bool TryGetPlayerMyRotationInfo(out MyRotationInfo myRotationInfo)
{
myRotationInfo = _playerMyRotationInfo;
@@ -964,11 +732,6 @@ public class DataMgr
return GetCharaPrmByCharaId(GetPlayerCharaId());
}
public ClassCharacterMasterData GetPlayerSubCharaData()
{
return GetCharaPrmByCharaId(GetPlayerSubClassId());
}
public int GetPlayerClassId()
{
return GetPlayerCharaData().class_id;
@@ -984,16 +747,6 @@ public class DataMgr
return GetAbleSleeveId(_playerSleeveId);
}
public int GetPlayerBattleSkillReverse()
{
return GetPlayerCharaData().battle_skin_reverse;
}
public Dictionary<ClassCharaPrm.EmotionType, Emotion> GetPlayerEmotionData()
{
return Data.Master._emotionDic[GetPlayerEmotionId()];
}
public string GetPlayerEmotionId()
{
if (!(_playerEmotionId == ""))
@@ -1008,11 +761,6 @@ public class DataMgr
_playerEmotionId = id;
}
public Dictionary<ClassCharaPrm.EmotionType, Emotion> GetEnemyEmotionData()
{
return Data.Master._emotionDic[GetEnemyEmotionId()];
}
public string GetEnemyEmotionId()
{
if (!(_enemyEmotionId == ""))
@@ -1041,25 +789,14 @@ public class DataMgr
return _enemySubClassId;
}
public bool TryGetEnemySubClassId(out int subClassId)
{
subClassId = GetEnemySubClassId();
return IsValidSubClass(subClassId);
}
public ClassCharacterMasterData GetEnemyCharaData()
{
return GetCharaPrmByCharaId(GetEnemyCharaId());
}
public ClassCharacterMasterData GetEnemySubCharaData()
{
return GetCharaPrmByCharaId(GetEnemySubClassId());
}
public int GetEnemyClassId()
{
if (GameMgr.GetIns().IsPuzzleQuest)
if (false /* Pre-Phase-5b: IsPuzzleQuest const-false */)
{
return PuzzleEnemyClass;
}
@@ -1092,21 +829,11 @@ public class DataMgr
return GetAbleSleeveId(_enemySleeveId);
}
public int GetEnemyBattleSkillReverse()
{
return GetEnemyCharaData().battle_skin_reverse;
}
public bool IsHighRankSkinPlayer()
{
return GetPlayerCharaData().IsHighRank;
}
public bool IsHighRankSkinEnemy()
{
return GetEnemyCharaData().IsHighRank;
}
public bool Is3DSkin(bool isPlayer)
{
if (isPlayer)
@@ -1125,33 +852,6 @@ public class DataMgr
return GetEnemyCharaData().IsEvolveSkin;
}
public int GetEvolutionDelayFrame(bool isPlayer)
{
if (isPlayer)
{
return GetPlayerCharaData().EvolutionDelayFrame;
}
return GetEnemyCharaData().EvolutionDelayFrame;
}
public bool IsSelectEmptyDeck()
{
if (_selectDeckId != -1)
{
return false;
}
return true;
}
public int GetSelectDeckId()
{
if (_selectDeckId == 0)
{
return PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LAST_BATTLE_DECK_ID);
}
return _selectDeckId;
}
public IList<int> GetCurrentDeckData()
{
return _currentDeckCardIdList;
@@ -1228,27 +928,6 @@ public class DataMgr
return GetPossessionBaseCardNum(baseCardId, GetUserOwnCardData(isIncludingSpotCard), cardMasterId);
}
public void UpdatePossessionCardNum(int cardId, int num)
{
GetUserOwnCardData(isIncludingSpotCard: false)[cardId] = num;
SetDirtyPossessionCardDict();
}
public void RemovePossessionCard(int cardId)
{
IDictionary<int, int> userOwnCardData = GetUserOwnCardData(isIncludingSpotCard: false);
if (userOwnCardData.ContainsKey(cardId))
{
userOwnCardData[cardId] = 0;
SetDirtyPossessionCardDict();
}
}
public List<int> GetPossessionCardIdList(bool isIncludingSpotCard)
{
return GetUserOwnCardData(isIncludingSpotCard).Keys.ToList();
}
public Dictionary<int, int> GetPossessionBaseCardDictionary(bool isIncludingSpotCard, CardMaster.CardMasterId cardMasterId)
{
CardMaster instance = CardMaster.GetInstance(cardMasterId);