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

@@ -20,16 +20,6 @@ public class DeckData
Unknown
}
public const int DEFAULT_DECK_ID_OFFSET = 90;
private const string LEADER_SKIN_ID_KEY = "leader_skin_id";
public const string CARD_ID_ARRAY_KEY = "card_id_array";
public const int DEFAULT_SLEEVE_ID = 3000011;
public const int UNSET_SKIN_ID = 0;
private int _deckId;
private string _deckName;
@@ -85,18 +75,6 @@ public class DeckData
}
}
public bool IsOutOfRotationFormat
{
get
{
if (Format == Format.Rotation || Format == Format.PreRotation)
{
return DeckCopyFormat == Format.Unlimited;
}
return false;
}
}
public DeckData(Format format = Format.Max, DeckAttributeType deckAttributeType = DeckAttributeType.Invalid)
{
_skinId = 0;
@@ -241,41 +219,6 @@ public class DeckData
return IsUsable(out reason, canUseNonPossessionCard);
}
public bool IsDisplayable()
{
if (!IsUsable())
{
return false;
}
Dictionary<int, int> cardNumDict = GetCardNumDict();
DataMgr dataMgr = GameMgr.GetIns().GetDataMgr();
foreach (KeyValuePair<int, int> item in cardNumDict)
{
int possessionCardNum = dataMgr.GetPossessionCardNum(item.Key, isIncludingSpotCard: true);
if (possessionCardNum == 0)
{
return false;
}
if (item.Value > possessionCardNum)
{
return false;
}
}
return true;
}
public bool HasResurgentCard()
{
foreach (int cardId in _cardIdList)
{
if (CardMaster.GetInstance(FormatBehaviorManager.GetDefaultBehaviour(Format).CardMasterId).GetCardParameterFromId(cardId).IsResurgentCard)
{
return true;
}
}
return false;
}
public int GetDeckClassID()
{
return _deckClassId;
@@ -312,28 +255,6 @@ public class DeckData
_cardIdList = list;
}
public Dictionary<int, int> GetCardNumDict()
{
Dictionary<int, int> dictionary = new Dictionary<int, int>();
if (IsNoCard())
{
return dictionary;
}
for (int i = 0; i < _cardIdList.Count; i++)
{
int key = _cardIdList[i];
if (dictionary.ContainsKey(key))
{
dictionary[key]++;
}
else
{
dictionary.Add(key, 1);
}
}
return dictionary;
}
public bool IsNoCard()
{
return _cardIdList == null;
@@ -356,16 +277,9 @@ public class DeckData
public int GetSkinId(bool isDefaultSkin = false)
{
if (isDefaultSkin)
{
return GameMgr.GetIns().GetDataMgr().GetCharaPrmByClassId(GetDeckClassID(), isCurrentChara: false)
.skin_id;
}
if (_skinId == 0)
{
return GameMgr.GetIns().GetDataMgr().GetCharaPrmByClassId(GetDeckClassID())
.skin_id;
}
// Pre-Phase-5b: fell back to the class's default chara prm skin_id when _skinId was
// zero (or when the default was explicitly requested). Callers are all UI (deck-list
// display, avatar-dialog, avatar-battle info) so returning 0 headless is safe.
return _skinId;
}
@@ -378,15 +292,6 @@ public class DeckData
return defaultValue;
}
private string GetJsonString(JsonData deckData, string key, string defaultValue)
{
if (deckData.Keys.Contains(key))
{
return deckData[key].ToString();
}
return defaultValue;
}
private bool GetJsonBool(JsonData deckData, string key, bool defaultValue)
{
if (deckData.Keys.Contains(key))
@@ -491,7 +396,9 @@ public class DeckData
IsMaintenanceDeck = false;
if (_cardIdList != null)
{
IsMaintenanceDeck = _cardIdList.Any((int c) => GameMgr.GetIns().GetDataMgr().IsMaintenanceCard(c));
// Pre-Phase-5b: probed DataMgr.IsMaintenanceCard for each id; headless has no
// maintenance card list so no card is ever considered under maintenance.
IsMaintenanceDeck = false;
}
}
@@ -501,19 +408,11 @@ public class DeckData
return CreateMyRotationClassName(_deckClassId, info);
}
public static string GetClassName(int classType, string rotationId)
{
MyRotationInfo myRotationInfo = Data.MyRotationAllInfo.Get(rotationId);
if (myRotationInfo != null)
{
return CreateMyRotationClassName(classType, myRotationInfo);
}
return GameMgr.GetIns().GetDataMgr().GetClanNameByKey(classType);
}
public static string CreateMyRotationClassName(int classType, MyRotationInfo info)
{
return Data.SystemText.Get("MyRotation_ID_02", GameMgr.GetIns().GetDataMgr().GetClanNameByKey(classType), info.LastPackText);
// Pre-Phase-5b: threaded DataMgr.GetClanNameByKey for the class-name substitution.
// Headless has no class-name map; substitute the class type as a raw string.
return Data.SystemText.Get("MyRotation_ID_02", classType.ToString(), info.LastPackText);
}
public bool IsVisibleRandomIcon()
@@ -526,52 +425,8 @@ public class DeckData
{
return true;
}
if (GameMgr.GetIns().GetDataMgr().GetClassPrm(GetDeckClassID())
.IsRandomLeaderSkin)
{
return _skinId == 0;
}
// Pre-Phase-5b: probed DataMgr.GetClassPrm(...).IsRandomLeaderSkin. Headless has no
// class prm map so no class is treated as random-skin-eligible.
return false;
}
public MyRotationInfo GetMyRotationInfoFromCardList()
{
int num = int.MinValue;
MyRotationInfo result = null;
CardMaster instance = CardMaster.GetInstance(FormatBehaviorManager.GetDefaultBehaviour(Format.MyRotation).CardMasterId);
foreach (int cardId in GetCardIdList())
{
CardParameter cardParameterFromId = instance.GetCardParameterFromId(cardId);
MyRotationInfo myRotationInfoFromPack = GetMyRotationInfoFromPack(cardParameterFromId.CardSetId);
if (myRotationInfoFromPack != null && int.Parse(myRotationInfoFromPack.Id) >= num)
{
result = myRotationInfoFromPack;
num = int.Parse(myRotationInfoFromPack.Id);
}
}
return result;
}
public MyRotationInfo GetMyRotationInfoFromPack(string packId)
{
int num = int.MinValue;
MyRotationInfo myRotationInfo = null;
foreach (MyRotationInfo myRotationInfo2 in Data.MyRotationAllInfo.MyRotationInfoList)
{
if (!(packId != myRotationInfo2.LastPackId) && int.Parse(myRotationInfo2.Id) >= num)
{
num = int.Parse(myRotationInfo2.Id);
myRotationInfo = myRotationInfo2;
}
}
if (myRotationInfo == null)
{
if (GetDeckClassID() != 8)
{
return Data.MyRotationAllInfo.FirstPackInfo;
}
return Data.MyRotationAllInfo.FirstPackInfoNemesis;
}
return myRotationInfo;
}
}