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>
315 lines
9.5 KiB
C#
315 lines
9.5 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Wizard;
|
|
|
|
public abstract class AISituationInfo
|
|
{
|
|
public AISelectedTargetInfoSet SelectedTargets;
|
|
|
|
public List<AIVirtualCard> BounceCardList;
|
|
|
|
public AISimulationPreprocessRecorder PreprocessRecorder;
|
|
|
|
public List<BattleCardRealTargetInformation> RealTargetInformationList;
|
|
|
|
public AIVirtualCard Actor { get; protected set; }
|
|
|
|
public AIVirtualCard OriginalCard { get; protected set; }
|
|
|
|
public AIVirtualCard ActionTarget => SelectedTargets.Get(0)?.FirstTarget;
|
|
|
|
public AIVirtualCard SecondActionTarget => SelectedTargets.Get(1)?.FirstTarget;
|
|
|
|
public AIOperationType ActionType { get; private set; }
|
|
|
|
public AIVirtualCard CurrentCheckCard { get; private set; }
|
|
|
|
public AIDiscardInfo DiscardInfo { get; private set; }
|
|
|
|
public AISkillProcessInfoCollection ProcessCollection { get; private set; }
|
|
|
|
public AISkillProcessInformation CurrentSkillProcessInfo { get; private set; }
|
|
|
|
public bool IsLatestAction { get; private set; }
|
|
|
|
public AISituationInfo(AIVirtualCard actor, AIVirtualCard target, AIVirtualCard secondTarget = null, AIOperationType type = AIOperationType.ATTACK)
|
|
{
|
|
Actor = actor;
|
|
OriginalCard = actor;
|
|
ActionType = type;
|
|
SelectedTargets = new AISelectedTargetInfoSet();
|
|
ProcessCollection = new AISkillProcessInfoCollection();
|
|
if (target != null)
|
|
{
|
|
SelectedTargets.Set(new AISelectedTargetInfo(target, TargetSelectType.Default), 0);
|
|
}
|
|
if (secondTarget != null)
|
|
{
|
|
SelectedTargets.Set(new AISelectedTargetInfo(secondTarget, TargetSelectType.Default), 1);
|
|
}
|
|
PreprocessRecorder = new AISimulationPreprocessRecorder();
|
|
IsLatestAction = false;
|
|
RealTargetInformationList = null;
|
|
}
|
|
|
|
public AISituationInfo(AIVirtualCard actor, AIOperationType type, AISelectedTargetInfoSet selectedTargetInfoSet)
|
|
{
|
|
Actor = actor;
|
|
OriginalCard = actor;
|
|
ActionType = type;
|
|
ProcessCollection = new AISkillProcessInfoCollection();
|
|
if (selectedTargetInfoSet == null)
|
|
{
|
|
SelectedTargets = new AISelectedTargetInfoSet();
|
|
}
|
|
else
|
|
{
|
|
SelectedTargets = selectedTargetInfoSet;
|
|
}
|
|
PreprocessRecorder = new AISimulationPreprocessRecorder();
|
|
IsLatestAction = false;
|
|
RealTargetInformationList = null;
|
|
}
|
|
|
|
public void SetActor(AIVirtualCard newActor)
|
|
{
|
|
Actor = newActor;
|
|
}
|
|
|
|
public AISelectedTargetInfo GetSituationTarget(AIScriptTokenArgType whichTarget)
|
|
{
|
|
switch (whichTarget)
|
|
{
|
|
case AIScriptTokenArgType.SELECTED_TARGET:
|
|
case AIScriptTokenArgType.TARGET_SELECT:
|
|
return SelectedTargets.Get(0);
|
|
case AIScriptTokenArgType.SECOND_SELECTED_TARGET:
|
|
case AIScriptTokenArgType.SECOND_TARGET_SELECT:
|
|
return SelectedTargets.Get(1);
|
|
case AIScriptTokenArgType.CHOICED_TARGET:
|
|
return SelectedTargets.GetChoiceInfo();
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public AISelectedTargetInfo GetBurialRiteTarget()
|
|
{
|
|
if (SelectedTargets != null && SelectedTargets.PreprocessTarget != null && SelectedTargets.PreprocessTarget.Type == TargetSelectType.BurialRite)
|
|
{
|
|
return SelectedTargets.PreprocessTarget;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public AISelectedTargetInfo GetChoiceTarget()
|
|
{
|
|
if (SelectedTargets != null && SelectedTargets.HasChoiceTarget)
|
|
{
|
|
return SelectedTargets.ChoiceTarget;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public bool IsFirstTarget(AIVirtualCard card)
|
|
{
|
|
if (ActionTarget != null && ActionTarget.IsSameCard(card))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool IsSecondTarget(AIVirtualCard card)
|
|
{
|
|
if (SecondActionTarget != null && SecondActionTarget.IsSameCard(card))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool IsTargetExists(AIScriptTokenArgType whichTarget)
|
|
{
|
|
return whichTarget switch
|
|
{
|
|
AIScriptTokenArgType.TARGET_SELECT => SelectedTargets.IsTargetExist(0),
|
|
AIScriptTokenArgType.SECOND_TARGET_SELECT => SelectedTargets.IsTargetExist(1),
|
|
_ => false,
|
|
};
|
|
}
|
|
|
|
public void SetTarget(AISelectedTargetInfo info, AIScriptTokenArgType whichTarget)
|
|
{
|
|
switch (whichTarget)
|
|
{
|
|
case AIScriptTokenArgType.TARGET_SELECT:
|
|
SelectedTargets.Set(info, 0);
|
|
break;
|
|
case AIScriptTokenArgType.SECOND_TARGET_SELECT:
|
|
SelectedTargets.Set(info, 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void SetMultipleTargetsInInfo(List<AIVirtualCard> targets, TargetSelectType type, AIRemovalType removalType, AIScriptTokenArgType whichTarget)
|
|
{
|
|
AISelectedTargetInfo info = new AISelectedTargetInfo(targets, type, removalType);
|
|
SetTarget(info, whichTarget);
|
|
}
|
|
|
|
public void SetSingleTargetInInfo(AIVirtualCard target, TargetSelectType type, AIScriptTokenArgType whichTarget)
|
|
{
|
|
AISelectedTargetInfo info = ((target != null) ? new AISelectedTargetInfo(target, type) : null);
|
|
SetTarget(info, whichTarget);
|
|
}
|
|
|
|
public void SetChoicedTargetInInfo(AIVirtualCard target)
|
|
{
|
|
AISelectedTargetInfo choiceTarget = ((target != null) ? new AISelectedTargetInfo(target, TargetSelectType.Choice) : null);
|
|
SelectedTargets.SetChoiceTarget(choiceTarget);
|
|
}
|
|
|
|
public void SetChoicedMultipleTargetInInfo(List<AIVirtualCard> targets)
|
|
{
|
|
AISelectedTargetInfo choiceTarget = ((targets != null) ? new AISelectedTargetInfo(targets, TargetSelectType.Choice) : null);
|
|
SelectedTargets.SetChoiceTarget(choiceTarget);
|
|
}
|
|
|
|
public void SetDiscardInfo(AIDiscardInfo info)
|
|
{
|
|
DiscardInfo = info;
|
|
}
|
|
|
|
public bool IsSameSituation(AISituationInfo situation)
|
|
{
|
|
if (ActionType != situation.ActionType || !Actor.IsSameCard(situation.Actor))
|
|
{
|
|
return false;
|
|
}
|
|
if (!SelectedTargets.IsDuplicate(situation.SelectedTargets))
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void SetExecutingSkillProcess(AISkillProcessInformation processInfo)
|
|
{
|
|
CurrentSkillProcessInfo = processInfo;
|
|
}
|
|
|
|
public AISkillProcessInformation RegisterNewProcessInfo(AIVirtualCard triggerCard, AISituationTriggerInformation.TriggerType triggerType)
|
|
{
|
|
AISkillProcessInformation aISkillProcessInformation = new AISkillProcessInformation(new AISituationTriggerInformation(triggerCard, triggerType));
|
|
ProcessCollection.RegisterProcess(aISkillProcessInformation);
|
|
return aISkillProcessInformation;
|
|
}
|
|
|
|
public AISkillProcessInformation RegisterNewPreprocessProcessInfo(AIVirtualCard triggerCard, AISituationTriggerInformation.TriggerType triggerType)
|
|
{
|
|
AISkillProcessInformation aISkillProcessInformation = new AISkillProcessInformation(new AISituationTriggerInformation(triggerCard, triggerType));
|
|
ProcessCollection.RegisterPreprocessProcessInfo(aISkillProcessInformation);
|
|
return aISkillProcessInformation;
|
|
}
|
|
|
|
public void ExecuteAllSkillProcess()
|
|
{
|
|
ProcessCollection.ExecuteAllProcess(this);
|
|
}
|
|
|
|
public void SetCurrentCheckCard(AIVirtualCard card)
|
|
{
|
|
CurrentCheckCard = card;
|
|
}
|
|
|
|
public void ResetCurrentCheckCard()
|
|
{
|
|
CurrentCheckCard = null;
|
|
}
|
|
|
|
public void RegisterRealTargetInfo(List<BattleCardRealTargetInformation> info)
|
|
{
|
|
RealTargetInformationList = info;
|
|
}
|
|
|
|
public bool IsRealSkillTarget(AIVirtualCard target, AIVirtualCard owner)
|
|
{
|
|
if (RealTargetInformationList == null || RealTargetInformationList.Count <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
for (int i = 0; i < RealTargetInformationList.Count; i++)
|
|
{
|
|
BattleCardRealTargetInformation battleCardRealTargetInformation = RealTargetInformationList[i];
|
|
if (owner.IsEqual(battleCardRealTargetInformation.SkillOwner) && battleCardRealTargetInformation.IsTarget(target))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public AIVirtualCardRealTargetInformation DequeueRealTargetInfo(AIVirtualCard owner, AIVirtualField field)
|
|
{
|
|
if (RealTargetInformationList == null || RealTargetInformationList.Count <= 0)
|
|
{
|
|
return null;
|
|
}
|
|
AIVirtualField.AIVirtualFieldSearchCardOption searchOption = new AIVirtualField.AIVirtualFieldSearchCardOption
|
|
{
|
|
IsOutputCannotFindError = true,
|
|
IsSearchFromDeck = true,
|
|
IsSearchFromBeforeLatestActionDeck = true
|
|
};
|
|
BattleCardRealTargetInformation battleCardRealTargetInformation = null;
|
|
for (int i = 0; i < RealTargetInformationList.Count; i++)
|
|
{
|
|
BattleCardRealTargetInformation battleCardRealTargetInformation2 = RealTargetInformationList[i];
|
|
if (owner.IsEqual(battleCardRealTargetInformation2.SkillOwner))
|
|
{
|
|
battleCardRealTargetInformation = battleCardRealTargetInformation2;
|
|
break;
|
|
}
|
|
}
|
|
if (battleCardRealTargetInformation != null)
|
|
{
|
|
RealTargetInformationList.Remove(battleCardRealTargetInformation);
|
|
return battleCardRealTargetInformation.CreateAIVirtualTargetInformation(field, owner, searchOption);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public List<int> GetTokenIdListFromDequeuedRealTargetInfo(AIVirtualCard owner, AITokenType tokenType)
|
|
{
|
|
if (RealTargetInformationList == null || RealTargetInformationList.Count <= 0)
|
|
{
|
|
return null;
|
|
}
|
|
for (int i = 0; i < RealTargetInformationList.Count; i++)
|
|
{
|
|
BattleCardRealTargetInformation battleCardRealTargetInformation = RealTargetInformationList[i];
|
|
if (owner.IsEqual(battleCardRealTargetInformation.SkillOwner))
|
|
{
|
|
List<int> result = battleCardRealTargetInformation.DequeueFirstTargetInfoAndCreateTokenIdList(owner, tokenType);
|
|
if (!battleCardRealTargetInformation.HasAnyTarget)
|
|
{
|
|
RealTargetInformationList.Remove(battleCardRealTargetInformation);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void SetLatestActionSimulationParameter()
|
|
{
|
|
IsLatestAction = true;
|
|
}
|
|
|
|
public void SetLatestActionSimulationParameterFromPreAction(AISituationInfo preAction)
|
|
{
|
|
IsLatestAction = preAction.IsLatestAction;
|
|
}
|
|
}
|