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

@@ -136,34 +136,6 @@ public class NetworkBattleGenericTool
return list;
}
public static bool IsAttachedSkill(SkillBase skill)
{
ISkillApplyInformation skillApplyInformation = skill.SkillPrm.ownerCard.SkillApplyInformation;
if (skillApplyInformation != null && skillApplyInformation.AttachedSkillsInfo != null && skillApplyInformation.AttachedSkillsInfo.AttachedSkills != null && skillApplyInformation.AttachedSkillsInfo.AttachedSkills.ToList().Count > 0)
{
foreach (SkillBase attachedSkill in skillApplyInformation.AttachedSkillsInfo.AttachedSkills)
{
if (attachedSkill == skill)
{
return true;
}
}
}
return false;
}
public static SkillBase SearchPublishedSkillCountToSkill(BattleCardBase card, int skillId)
{
foreach (SkillBase skill in card.Skills)
{
if (GetPublishSkillCount(skill) == skillId)
{
return skill;
}
}
return null;
}
public static int GetSkillIndex(SkillBase skill)
{
int num = 0;
@@ -373,7 +345,7 @@ public class NetworkBattleGenericTool
public static int GetSkillMovementNum(SkillBase skillBase)
{
if (GameMgr.GetIns().IsAINetwork)
if (skillBase.SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr.GameMgr.IsAINetwork)
{
return -1;
}
@@ -383,7 +355,7 @@ public class NetworkBattleGenericTool
public static int GetPublishSkillCount(SkillBase skill)
{
int result = -1;
if (GameMgr.GetIns().IsAINetwork)
if (skill.SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr.GameMgr.IsAINetwork)
{
return result;
}
@@ -393,7 +365,7 @@ public class NetworkBattleGenericTool
if (skill.PublishedActiveSkillCount == -1)
{
BattleCardBase skillCard = skill.SkillPrm.ownerCard;
SkillBase skillBase = BattleManagerBase.GetIns().PublishedSkillList.FindAll((SkillBase x) => x.GetType() == skill.GetType() && x.SkillTimingText == skill.SkillTimingText).FindLast((SkillBase x) => x.SkillPrm.ownerCard.Index == skillCard.Index && x.SkillPrm.ownerCard.IsPlayer == skillCard.IsPlayer);
SkillBase skillBase = skill.SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr.PublishedSkillList.FindAll((SkillBase x) => x.GetType() == skill.GetType() && x.SkillTimingText == skill.SkillTimingText).FindLast((SkillBase x) => x.SkillPrm.ownerCard.Index == skillCard.Index && x.SkillPrm.ownerCard.IsPlayer == skillCard.IsPlayer);
if (skillBase != null)
{
result = skillBase.PublishedActiveSkillCount;
@@ -495,15 +467,6 @@ public class NetworkBattleGenericTool
return true;
}
private static bool IsTargetDeckOrHand(ISkillTargetFilter applyingTargetFilter)
{
if (!(applyingTargetFilter is SkillTargetDeckFilter) && !(applyingTargetFilter is SkillTargetHandFilter))
{
return applyingTargetFilter is SkillTargetHandOtherSelfFilter;
}
return true;
}
private static bool IsOnlyAllCardFilter(List<ISkillCardFilter> applyCardFilterList)
{
for (int i = 0; i < applyCardFilterList.Count; i++)
@@ -518,7 +481,7 @@ public class NetworkBattleGenericTool
public static void SettingRegisterTargetGroupAndInsert()
{
List<RegisterActionBase> registerDataList = (BattleManagerBase.GetIns() as NetworkBattleManagerBase).RegisterActionManager.RegisterDataList;
List<RegisterActionBase> registerDataList = new List<RegisterActionBase>(); // Pre-Phase-5b: SettingRegisterTargetGroupAndInsert is unreachable headless
foreach (RegisterLotCardBase item in registerDataList.FindAll((RegisterActionBase x) => x is RegisterLotCardBase).ConvertAll((RegisterActionBase x) => x as RegisterLotCardBase))
{
RegisterActionBase registerActionBase = null;
@@ -582,7 +545,7 @@ public class NetworkBattleGenericTool
public static RegisterLotCardBase MakeRegisterLotAndRandomAdvance(SkillBase skillBase, IEnumerable<BattleCardBase> cards, SkillConditionCheckerOption checkerOption)
{
NetworkBattleManagerBase networkBattleManagerBase = BattleManagerBase.GetIns() as NetworkBattleManagerBase;
NetworkBattleManagerBase networkBattleManagerBase = skillBase.SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr as NetworkBattleManagerBase;
List<CardDataModel> unapprovedList = networkBattleManagerBase.networkBattleData.GetReceiveData().unapprovedList;
NetworkExecutionInfoCreator networkExec = skillBase._executionInfoCreator as NetworkExecutionInfoCreator;
int num = 0;
@@ -650,7 +613,7 @@ public class NetworkBattleGenericTool
{
return NullVfx.GetInstance();
}
NetworkBattleManagerBase networkBattleManagerBase = BattleManagerBase.GetIns() as NetworkBattleManagerBase;
NetworkBattleManagerBase networkBattleManagerBase = skillBase.SkillPrm.ownerCard.SelfBattlePlayer.BattleMgr as NetworkBattleManagerBase;
int skillMovementNum = GetSkillMovementNum(skillBase);
foreach (BattleCardBase card in cards)
{
@@ -761,92 +724,4 @@ public class NetworkBattleGenericTool
}
return false;
}
public static string FindDictionaryURI(Dictionary<string, object> data)
{
if (data.ContainsKey("uri"))
{
return data["uri"].ToString();
}
return "";
}
public static void CreateLoadAndPlayEffectVfxLastTurnLog()
{
CreateLoadAndPlayEffectVfxCheckLog(isLastTurn: true);
}
public static void CreateLoadAndPlayEffectVfxClientInfoLog()
{
CreateLoadAndPlayEffectVfxCheckLog(isLastTurn: false);
}
private static void CreateLoadAndPlayEffectVfxCheckLog(bool isLastTurn)
{
try
{
BattleManagerBase ins = BattleManagerBase.GetIns();
if (ins == null)
{
return;
}
foreach (LoadAndPlayEffectVfx item in ins.VfxMgr.GetSequentialVfxQueues().ToList().FindAll((VfxBase x) => x is LoadAndPlayEffectVfx)
.ConvertAll((VfxBase x) => x as LoadAndPlayEffectVfx))
{
if (item.LoadingVfx != null && item.LoadingVfx is SkillBase.WaitEffectLoadVfx)
{
SkillBase.WaitEffectLoadVfx waitEffectLoadVfx = item.LoadingVfx as SkillBase.WaitEffectLoadVfx;
if (waitEffectLoadVfx.LoadVfx != null)
{
string log = "LoadVfxIsEnd=" + waitEffectLoadVfx.LoadVfx.IsEnd;
if (isLastTurn)
{
LocalLog.AccumulateLastTraceLog(log);
}
else
{
LocalLog.AccumulateTraceLog(log);
}
}
}
string log2 = "loadEffect.LoadFileName=" + item.LoadFileName;
if (isLastTurn)
{
LocalLog.AccumulateLastTraceLog(log2);
}
else
{
LocalLog.AccumulateTraceLog(log2);
}
if (item.WaitLoadEffectAndSetSeVfxData != null)
{
string log3 = "WaitLoadEffectAndSetSeVfxData Step" + item.WaitLoadEffectAndSetSeVfxData.NowStep;
if (isLastTurn)
{
LocalLog.AccumulateLastTraceLog(log3);
}
else
{
LocalLog.AccumulateTraceLog(log3);
}
}
if (item.PlayEffectAndSeVfxData != null)
{
string log4 = "PlayEffectAndSeVfxData Step" + item.PlayEffectAndSeVfxData.NowStep;
if (isLastTurn)
{
LocalLog.AccumulateLastTraceLog(log4);
}
else
{
LocalLog.AccumulateTraceLog(log4);
}
}
}
}
catch
{
LocalLog.AccumulateLastTraceLog("VfxCheckLog Error");
}
}
}