Files
SVSimServer/SVSim.BattleEngine/Engine/NetworkOperationCollection.cs
gamer147 2d9a6eea4b 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>
2026-07-03 19:18:54 -04:00

243 lines
7.9 KiB
C#

using System;
using System.Collections.Generic;
using Wizard;
using Wizard.Battle.View.Vfx;
public class NetworkOperationCollection : NetworkOperationCollectionBase
{
private bool _sendEcho;
private bool _isTurnStart;
private int _playCardIndexToEcho = -1;
private NetworkBattleDefine.PlayActionType _actionTypeToEcho;
private bool _isReceivedBattleFinish;
public NetworkOperationCollection(NetworkBattleManagerBase networkBattleMgr, OperateMgr operateMgr, NetworkBattleReceiver.ReceiveData receivedData, NetworkBattleData networkBattleData, bool isPlayer)
: base(networkBattleMgr, operateMgr, receivedData, networkBattleData, isPlayer)
{
}
public override void RetryOperation()
{
_networkBattleMgr.NetworkSender.EmitRetry(_receivedData.receiveUri);
}
public override void SwapOperation(Func<List<int>, VfxBase> OnReceiveOpponentMulligan, Func<List<int>, VfxBase> OnReceivePlayerMulligan)
{
RegisterSequentialVfx(OperatePlayerMulligan(_receivedData, OnReceivePlayerMulligan));
}
public override void SecondMulliganOperation(Func<List<int>, VfxBase> OnReceiveOpponentMulligan, Func<List<int>, VfxBase> OnReceivePlayerMulligan, Func<VfxBase> OnEndMulligan)
{
LocalLog.AccumulateLastTraceLog("SecondMulliganOperation" + _networkBattleData.isOppoMulliganEnd);
RegisterSequentialVfx(OperatePlayerMulligan(_receivedData, OnReceivePlayerMulligan));
RegisterSequentialVfx(OperateOppoMulligan(_receivedData, OnReceiveOpponentMulligan));
if (_networkBattleData.isOppoMulliganEnd)
{
RegisterSequentialVfx(OnEndMulligan.GetAllFuncVfxResults());
}
}
public override void TurnStartOperation(NetworkBattleDefine.NetworkBattleURI lastReceivedUri, int lastReceivedTime)
{
if (_networkBattleMgr.InstanceNetworkAgent.GetTurnState() || _networkBattleMgr.BattleEnemy.IsExtraTurn || _networkBattleData.isEnemyFirstTurn)
{
if (_networkBattleMgr.BattleEnemy.IsExtraTurn)
{
RegisterSequentialVfx(_networkBattleMgr.ControlTurnStartPlayer());
}
else
{
RegisterSequentialVfx(_networkBattleMgr.ControlTurnStartOpponent());
}
_sendEcho = true;
_isTurnStart = true;
}
if (lastReceivedUri == NetworkBattleDefine.NetworkBattleURI.Judge && _networkBattleData.GetReceiveData().NodeResultCode == NetworkBattleDefine.ReceiveNodeResultCode.CurrentBattleError)
{
string[] obj = new string[6]
{
"#732070_",
(_isReceivedBattleFinish ? 1 : 0).ToString(),
"_",
null,
null,
null
};
int result = (int)_receivedData.result;
obj[3] = result.ToString();
obj[4] = "_";
obj[5] = lastReceivedTime.ToString();
LocalLog.AccumulateTraceLog(string.Concat(obj));
}
}
public override void TurnEndWithSkillActivationOperation(PlayHandCardReflection networkPlayCardAction, InPlayCardReflection networkInPlayAction)
{
if (_networkBattleData.nowReceiveUri != NetworkBattleDefine.NetworkBattleURI.TurnEndActions)
{
_networkBattleData.isReceiveTurnEndAction = true;
RegisterSequentialVfx(_operateMgr.TurnEndOperation(isPlayer: false));
_sendEcho = true;
}
}
public override void TurnEndOperation(PlayHandCardReflection networkPlayCardAction, InPlayCardReflection networkInPlayAction)
{
if (_networkBattleData.nowReceiveUri != NetworkBattleDefine.NetworkBattleURI.TurnEnd)
{
if (_networkBattleMgr.JudgeCurrentFinishStatus() == NetworkBattleReceiver.RESULT_CODE.NotFinish && !_networkBattleData.isReceiveTurnEndAction)
{
RegisterSequentialVfx(_operateMgr.TurnEndOperation(isPlayer: false));
}
_networkBattleData.isReceiveTurnEndAction = false;
_networkBattleMgr.SendJudge();
}
else
{
LocalLog.AccumulateLastTraceLog("AlreadyTurnEndSend");
}
}
public override void TurnEndFinalOperation()
{
_networkBattleMgr.SendJudge();
}
public override void JudgeOperation()
{
if (_networkBattleMgr.JudgeCurrentFinishStatus() != NetworkBattleReceiver.RESULT_CODE.NotFinish)
{
_networkBattleMgr.BattleFinishReceiveAfterFinishBattleSend(NetworkBattleSender.JUDGE_RESULT_STATUS.BattleFinishToJudge);
}
else
{
RegisterSequentialVfx(_networkBattleMgr.ControlTurnStartPlayer());
}
}
public override void PlayHandCardOperation(PlayHandCardReflection networkPlayCardAction, List<int> choiceIdList = null, bool isChoice = false)
{
CommonPlayHandCardOperation(networkPlayCardAction, _networkBattleMgr.BattleEnemy, isPlayer: false, _receivedData.OpponentTargetDataList, choiceIdList, isChoice);
}
public override void PlaySkillSelectHandCardOperation(PlayHandCardReflection networkPlayCardAction, List<int> choiceIdList = null)
{
SetupNetworkPlayCardAction(networkPlayCardAction, _receivedData.OpponentTargetDataList);
RegisterSequentialVfx(InstantVfx.Create(delegate
{
networkPlayCardAction.PlayAction(isPlayer: false, choiceIdList);
}));
}
public override void InPlayActionOperation(PlayHandCardReflection networkPlayCardAction, InPlayCardReflection networkInPlayAction)
{
LocalLog.AccumulateLastTraceLog("PlayActionsReceive");
switch (_receivedData.actionType)
{
case NetworkBattleDefine.PlayActionType.PLAY_HAND:
if (!_receivedData.IsChoiceBrave)
{
PlayHandCardOperation(networkPlayCardAction, _receivedData.choiceIdList, _receivedData.IsChoice);
}
else
{
ChoiceBraveOperation(networkPlayCardAction, _receivedData.choiceIdList);
}
break;
case NetworkBattleDefine.PlayActionType.PLAY_HAND_SELECT:
if (!_receivedData.IsChoiceBrave)
{
PlaySkillSelectHandCardOperation(networkPlayCardAction, _receivedData.choiceIdList);
}
else
{
ChoiceBraveOperation(networkPlayCardAction, _receivedData.choiceIdList);
}
break;
case NetworkBattleDefine.PlayActionType.ATTACK:
case NetworkBattleDefine.PlayActionType.EVOLUTION:
case NetworkBattleDefine.PlayActionType.EVOLUTION_SELECT:
networkInPlayAction.ReadySetting(_receivedData.OpponentTargetDataList, _receivedData.actionType, _receivedData.playCardIndex);
networkInPlayAction.Play(_isPlayer, _receivedData.choiceIdList, _receivedData.IsChoice);
_sendEcho = true;
_playCardIndexToEcho = _receivedData.playCardIndex;
break;
case NetworkBattleDefine.PlayActionType.FUSION:
FusionCardOperation(networkPlayCardAction, isPlayer: false, _receivedData.OpponentTargetDataList);
break;
}
_actionTypeToEcho = _receivedData.actionType;
}
public override void RetireOperation()
{
_networkBattleMgr.ReceiveRetire(_receivedData.isWin);
}
public override void ChatStampOperation()
{
ClassCharaPrm.EmotionType oppoChatStamp = (ClassCharaPrm.EmotionType)_receivedData.oppoChatStamp;
if (!ClassCharaPrm.IsEvolutionEmotionType(oppoChatStamp))
{
VfxBase vfx = _networkBattleMgr.BattleEnemy.Emotion.PlayEmotion(oppoChatStamp, 1.5f);
}
}
public override void DataInconsistencyBattleEndOperation()
{
JudgeEndTypeToLose(_receivedData.judgeEndType);
}
public override void TouchOperation()
{
}
public override void SelectSkillOperation(PlayHandCardReflection networkPlayCardAction, InPlayCardReflection networkInPlayAction)
{
}
public override void SelectObjectOperation()
{
}
public override void TurnEndReady()
{
}
public override void SlideObject()
{
}
public override void BattleFinishOperation()
{
_isReceivedBattleFinish = true;
_networkBattleMgr.JudgeResultReceive(_receivedData.result);
}
public override void MaintenanceOperation()
{
}
public override void JudgeResultOperation()
{
_networkBattleMgr.JudgeResultReceive(_receivedData.result);
}
public override void WriteOperationToTraceLog()
{
LocalLog.AccumulateLastTraceLog("StartOperateURI:" + _receivedData.dataUri);
}
public override void SendEcho()
{
if (_sendEcho)
{
_networkBattleMgr.SendEcho(_playCardIndexToEcho, _actionTypeToEcho, isNotActiveSeq: false, _isTurnStart);
}
}
}