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

@@ -21,243 +21,6 @@ internal static class EnemyAIUtil
}
}
public const int TempDeckNo = 36;
public const int SERIES_ID = 25;
private const int RETRY_MAX = 100;
private const int LOOP_MAX = 10;
private static System.Random _rnd = new System.Random();
public static bool IsSameVirtualCardList(List<AIVirtualCard> right, List<AIVirtualCard> left)
{
if (right.Count != left.Count)
{
return false;
}
for (int i = 0; i < right.Count; i++)
{
if (!right[i].IsSameCard(left[i]))
{
return false;
}
}
return true;
}
public static List<AIMove> GetAllMoves(BattlePlayerPair pair)
{
List<AIMove> list = new List<AIMove>();
List<AIPlayMove> playMoves = GetPlayMoves(pair);
List<AIAttackMove> attackMoves = GetAttackMoves(pair);
List<AIEvolMove> evolveMoves = GetEvolveMoves(pair);
List<AIFusionMove> fusionMoves = GetFusionMoves(pair);
for (int i = 0; i < playMoves.Count; i++)
{
list.Add(playMoves[i]);
}
for (int j = 0; j < attackMoves.Count; j++)
{
list.Add(attackMoves[j]);
}
for (int k = 0; k < evolveMoves.Count; k++)
{
list.Add(evolveMoves[k]);
}
for (int l = 0; l < fusionMoves.Count; l++)
{
list.Add(fusionMoves[l]);
}
list.Add(new AITurnEndMove());
return list;
}
public static List<AIFusionMove> GetFusionMoves(BattlePlayerPair pair)
{
List<AIFusionMove> list = new List<AIFusionMove>();
foreach (BattleCardBase handCard in pair.Self.HandCardList)
{
if (!handCard.IsFusionable)
{
continue;
}
List<List<BattleCardBase>> targetsList = GetTargetsList(handCard.GetSelectTypeSkill(isEvolve: false, isFusion: true), pair, handCard, isFusion: true);
if (targetsList != null)
{
for (int i = 0; i < targetsList.Count; i++)
{
List<BattleCardBase> targets = targetsList[i];
list.Add(new AIFusionMove(handCard, targets));
}
}
}
return list;
}
public static List<AIEvolMove> GetEvolveMoves(BattlePlayerPair pair)
{
List<AIEvolMove> list = new List<AIEvolMove>();
foreach (BattleCardBase inPlayCard in pair.Self.InPlayCards)
{
if (!inPlayCard.IsUnit || !inPlayCard.CanEvolution(isSkill: false, isSelfBattlePlayer: true))
{
continue;
}
List<List<BattleCardBase>> targetsList = GetTargetsList(inPlayCard.EvolutionSkills, pair, inPlayCard);
if (targetsList != null)
{
for (int i = 0; i < targetsList.Count; i++)
{
List<BattleCardBase> targets = targetsList[i];
list.Add(new AIEvolMove(inPlayCard, targets));
}
}
else
{
list.Add(new AIEvolMove(inPlayCard, null));
}
}
return list;
}
public static List<AIAttackMove> GetAttackMoves(BattlePlayerPair pair)
{
List<AIAttackMove> list = new List<AIAttackMove>();
foreach (BattleCardBase inPlayCard in pair.Self.InPlayCards)
{
if (!inPlayCard.Attackable)
{
continue;
}
foreach (BattleCardBase classAndInPlayCard in pair.Opponent.ClassAndInPlayCardList)
{
if (AttackSelectControl.CanCardAttackTarget(inPlayCard, classAndInPlayCard, pair.Opponent.InPlayCards))
{
list.Add(new AIAttackMove(inPlayCard, classAndInPlayCard));
}
}
}
return list;
}
public static List<AIPlayMove> GetPlayMoves(BattlePlayerPair pair, bool isCheckOnDraw = true)
{
List<AIPlayMove> list = new List<AIPlayMove>();
foreach (BattleCardBase handCard in pair.Self.HandCardList)
{
if (!handCard.Movable(isCheckOnDraw))
{
continue;
}
IEnumerable<SkillBase> enumerable = null;
if (handCard.IsMutationPlayPp(handCard.SelfBattlePlayer.Pp))
{
Skill_transform accelerateOrCrystallizeTransformSkill = handCard.GetAccelerateOrCrystallizeTransformSkill();
if (accelerateOrCrystallizeTransformSkill != null)
{
enumerable = handCard.SelfBattlePlayer.BattleMgr.CreateTransformCardRegisterVfx(accelerateOrCrystallizeTransformSkill.SkillPrm.ownerCard, accelerateOrCrystallizeTransformSkill.TransformId, accelerateOrCrystallizeTransformSkill.SkillPrm.ownerCard.IsPlayer).GetSelectTypeSkill();
}
}
if (enumerable == null)
{
enumerable = handCard.GetSelectTypeSkill();
}
List<List<BattleCardBase>> targetsList = GetTargetsList(enumerable, pair, handCard);
if (targetsList != null)
{
for (int i = 0; i < targetsList.Count; i++)
{
List<BattleCardBase> targets = targetsList[i];
list.Add(new AIPlayMove(handCard, targets));
}
}
else
{
list.Add(new AIPlayMove(handCard, null));
}
}
return list;
}
private static List<List<BattleCardBase>> GetTargetsList(IEnumerable<SkillBase> skills, BattlePlayerPair pair, BattleCardBase card, bool isFusion = false)
{
List<SelectableInfo> selectablesList = GetSelectablesList(skills, pair, card);
Dictionary<int, List<SelectableInfo>> dictionary = new Dictionary<int, List<SelectableInfo>>();
foreach (SkillBase skill in skills)
{
if (!skill.IsChoiceType || !card.Skills.HaveChoiceTransformSkill())
{
continue;
}
IEnumerable<BattleCardBase> skillUserSelectableTargets = ActionProcessor.GetSkillUserSelectableTargets(skill, pair);
if (skillUserSelectableTargets == null)
{
continue;
}
foreach (BattleCardBase item in skillUserSelectableTargets)
{
dictionary[item.Index] = GetSelectablesList(item.GetSelectTypeSkill(), pair, item);
}
}
if (selectablesList.Count > 0)
{
List<List<BattleCardBase>> list = new List<List<BattleCardBase>>();
SetupTargetsList(0, new List<BattleCardBase>(), selectablesList, dictionary, list, isFusion);
return list;
}
return null;
}
private static List<SelectableInfo> GetSelectablesList(IEnumerable<SkillBase> skills, BattlePlayerPair pair, BattleCardBase card)
{
List<SelectableInfo> list = new List<SelectableInfo>();
foreach (SkillBase skill in skills)
{
if (skill.IsBurialRite)
{
List<BattleCardBase> burialRiteTarget = SkillPreprocessBurialRite.GetBurialRiteTarget(card.SelfBattlePlayer, card);
if (burialRiteTarget != null && burialRiteTarget.Count > 0)
{
list.Add(new SelectableInfo(burialRiteTarget, 1));
}
}
if (skill.IsUserSelectType)
{
IEnumerable<BattleCardBase> skillUserSelectableTargets = ActionProcessor.GetSkillUserSelectableTargets(skill, pair);
int num = 1;
if (skillUserSelectableTargets != null)
{
num = Mathf.Min(skill.GetSkillSelectCount(), skillUserSelectableTargets.Count());
list.Add(new SelectableInfo(new List<BattleCardBase>(skillUserSelectableTargets), num));
}
}
if (!skill.IsChoiceType)
{
continue;
}
IEnumerable<BattleCardBase> skillUserSelectableTargets2 = ActionProcessor.GetSkillUserSelectableTargets(skill, pair);
if (skillUserSelectableTargets2 == null)
{
continue;
}
List<BattleCardBase> list2 = new List<BattleCardBase>();
foreach (BattleCardBase item in skillUserSelectableTargets2)
{
card = card.SelfBattlePlayer.BattleMgr.CreateTransformCardRegisterVfx(card, item.CardId, card.SelfBattlePlayer.IsPlayer);
list2.Add(card);
}
int count = 1;
if (skill.ApplySelectFilter is SkillChoiceSelectFilter)
{
count = Math.Max(1, skill.ApplySelectFilter.CalcCount(skill.OptionValue));
}
list.Add(new SelectableInfo(list2, count));
}
return list;
}
private static void SetupTargetsList(int depth, List<BattleCardBase> currentList, List<SelectableInfo> selectablesList, Dictionary<int, List<SelectableInfo>> choiceSelectableList, List<List<BattleCardBase>> out_targetsList, bool isFusion = false)
{
if (depth == selectablesList.Count)
@@ -353,57 +116,4 @@ internal static class EnemyAIUtil
SkillCollectionBase.SetupOptionValue(item.OptionValue, pair, playCard, item);
}
}
public static List<int> GetRandomDeck(CardBasePrm.ClanType clan, int seriesRangeStart = 0, int seriesRangeEnd = 25)
{
int num = 0;
int num2 = 0;
int num3 = 40;
List<int> deck = new List<int>();
IEnumerable<CardParameter> allParameters = CardMaster.GetInstanceForBattle().GetAllParameters();
while (true)
{
for (int i = 0; i < num3; i++)
{
CardBasePrm.ClanType card_clan = clan;
if (num2 < 10)
{
if (_rnd.Next(9) == 0)
{
card_clan = CardBasePrm.ClanType.ALL;
}
}
else if (_rnd.Next(9) != 0)
{
card_clan = CardBasePrm.ClanType.ALL;
}
IEnumerable<CardParameter> source = allParameters.Where((CardParameter p) => p.Clan == card_clan && seriesRangeStart <= p.BaseCardId / 1000000 % 100 && p.BaseCardId / 1000000 % 100 <= seriesRangeEnd && p.BaseCardId / 100000000 % 10 == 1 && deck.Count((int id) => id == p.BaseCardId) < 3 && !GameMgr.GetIns().GetDataMgr().IsMaintenanceCard(p.CardId) && !GameMgr.GetIns().GetDataMgr().IsMaintenanceCard(p.BaseCardId));
if (source.Count() == 0)
{
num++;
if (num >= 100)
{
break;
}
i--;
}
else
{
CardParameter cardParameter = source.ElementAt(_rnd.Next(source.Count()));
deck.Add(cardParameter.BaseCardId);
}
}
if (deck.Count == 40)
{
break;
}
if (num2 >= 100)
{
throw new Exception($"デッキ構築するための使用可能な{clan}カードが不足している可能性があります。カード未実装フラグを解除するか、実装が進んでから再度お試しください。");
}
num2++;
num3 = 40 - deck.Count;
}
return deck;
}
}