Files
SVSimServer/SVSim.BattleEngine/Engine/SkillPreprocessBurialRite.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

159 lines
7.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Wizard;
using Wizard.Battle;
using Wizard.Battle.UI;
using Wizard.Battle.View.Vfx;
public class SkillPreprocessBurialRite : SkillPreprocessBase
{
private readonly BattleCardBase _ownerCard;
private readonly SkillBase _skill;
private bool _isInvoked;
public SkillPreprocessBurialRite(SkillBase skill, BattleCardBase ownerCard)
{
_skill = skill;
_ownerCard = ownerCard;
}
public override bool IsRight(BattlePlayerReadOnlyInfoPair playerInfoPair, SkillConditionCheckerOption option, bool PreexecutionCheck = false)
{
if (_isInvoked)
{
return true;
}
IBattlePlayerReadOnlyInfo readOnlySelf = playerInfoPair.ReadOnlySelf;
int num = readOnlySelf.SkillInfoInPlayCards.Count();
BattleCardBase originalCard = ((_ownerCard.TransformInfo.Type != BattleCardBase.TransformType.Metamorphose) ? _ownerCard.TransformInfo.OriginalCard : null);
int num2 = readOnlySelf.SkillInfoHandCards.Count((IReadOnlyBattleCardInfo s) => s != _ownerCard && s != originalCard && s.IsUnit);
int burialRiteCount = _ownerCard.GetBurialRiteCount(playerInfoPair, option, isPrePlay: false);
int num3 = 5 - burialRiteCount;
if (num <= num3)
{
return num2 >= burialRiteCount;
}
return false;
}
public override bool IsRightPrePlay(BattlePlayerReadOnlyInfoPair playerInfoPair, SkillConditionCheckerOption option, bool PreexecutionCheck = false)
{
if (_isInvoked)
{
return true;
}
IBattlePlayerReadOnlyInfo readOnlySelf = playerInfoPair.ReadOnlySelf;
int num = readOnlySelf.SkillInfoInPlayCards.Count();
BattleCardBase originalCard = ((_ownerCard.TransformInfo.Type != BattleCardBase.TransformType.Metamorphose) ? _ownerCard.TransformInfo.OriginalCard : null);
int num2 = readOnlySelf.SkillInfoHandCards.Count((IReadOnlyBattleCardInfo s) => s != _ownerCard && s != originalCard && s.IsUnit);
int burialRiteCount = _ownerCard.GetBurialRiteCount(playerInfoPair, option, isPrePlay: true);
int num3 = ((_ownerCard.IsInplay || _ownerCard.IsSpell) ? (5 - burialRiteCount) : (5 - burialRiteCount - 1));
if (num <= num3 && num2 >= burialRiteCount)
{
if (!_ownerCard.IsSpell && _skill.OnWhenEvolveStart == 0)
{
return !_ownerCard.SelfBattlePlayer.Class.SkillApplyInformation.IsCantActivateFanfareUnit;
}
return true;
}
return false;
}
public override VfxBase Start(BattlePlayerPair playerPair, SkillBase skill, SkillProcessor skillProcessor, SkillOptionValue optionValue, SkillConditionCheckerOption checkerOption)
{
SequentialVfxPlayer sequentialVfxPlayer = SequentialVfxPlayer.Create();
if (skill != _ownerCard.Skills.LastOrDefault((SkillBase s) => s.CheckCondition(playerPair, checkerOption, isPrePlay: true) && s.PreprocessList.Any((SkillPreprocessBase p) => p is SkillPreprocessBurialRite)))
{
return sequentialVfxPlayer;
}
if (_isInvoked)
{
return sequentialVfxPlayer;
}
if (skill.OptionValue.HasInfoByName(SkillFilterCreator.ContentKeyword.save_burial_rite_target))
{
skill.SkillPrm.ownerCard.SkillApplyInformation.SaveBurialRiteTargetList(checkerOption.BurialRiteCards);
for (int num = 0; num < checkerOption.BurialRiteCards.Count; num++)
{
CardParameter baseParameter = checkerOption.BurialRiteCards.ElementAt(num).BaseParameter;
BuffInfo buffInfo = new BuffInfo(baseParameter.CardId, baseParameter.NormalCardId, skill);
buffInfo.IsSaveBurialRiteSkill = true;
buffInfo.TargetCard = checkerOption.BurialRiteCards.ElementAt(num);
_ownerCard.AddBuffInfo(buffInfo);
}
}
SkillBaseSummon.SummonedCardsList summonedCardsList = new SkillBaseSummon.SummonedCardsList();
foreach (BattleCardBase burialRiteCard in checkerOption.BurialRiteCards)
{
summonedCardsList.AddCardToSummonedCards(burialRiteCard, overrideSummonEffect: true);
sequentialVfxPlayer.Register(burialRiteCard.LoseSkill());
burialRiteCard.IsSelectedDuringSelectingBurialRiteTarget = false;
if (!burialRiteCard.SelfBattlePlayer.BattleMgr.IsRecovery)
{
burialRiteCard.SelfBattlePlayer.BurialRiteOrDiscardCardHandIndexList.Add(burialRiteCard.SelfBattlePlayer.HandCardList.IndexOf(burialRiteCard));
}
}
BattlePlayerBase.SummonInfo summonInfo = new BattlePlayerBase.SummonInfo(summonedCardsList.Any((BattleCardBase c) => c.IsPlayer), summonedCardsList, SkillBaseSummon.SUMMON_TYPE.HAND);
BattlePlayerBase self = playerPair.Self;
BattlePlayerBase.SummonInfo summonInfo2 = summonInfo;
VfxWithLoadingSequential vfx = self.CardManagement(null, skillProcessor, BattlePlayerBase.CARD_MANAGEMENT.SUMMON, isRandom: false, null, null, skill, summonInfo2) as VfxWithLoadingSequential;
sequentialVfxPlayer.Register(vfx);
foreach (BattleCardBase item in summonedCardsList)
{
ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create();
parallelVfxPlayer.Register(Skill_summon_card.RemoveHandCardFromViewVfx(item, playerPair.Self, isBurialRite: true));
parallelVfxPlayer.Register(item.StopSpellCharge());
sequentialVfxPlayer.Register(parallelVfxPlayer);
}
sequentialVfxPlayer.Register(InstantVfx.Create(delegate
{
_ownerCard.SelfBattlePlayer.BurialRiteOrDiscardCardHandIndexList.Clear();
}));
StartPickMultiCardVfx vfx2 = new StartPickMultiCardVfx(summonedCardsList, _ownerCard.ResourceMgr, _ownerCard.IsPlayer, isToken: true);
sequentialVfxPlayer.Register(vfx2);
_ownerCard.SelfBattlePlayer.CallOnSummonCards(_ownerCard, checkerOption.BurialRiteCards, _ownerCard.IsPlayer, isDeckSelf: false, isIgnoreVoice: false, isBurialRite: true);
_ownerCard.SelfBattlePlayer.CallOnSkillDestroyOrBanish(_ownerCard, isBurialRite: true);
ParallelVfxPlayer parallelVfxPlayer2 = ParallelVfxPlayer.Create();
foreach (BattleCardBase item2 in summonedCardsList)
{
item2.SelfBattlePlayer.GameBurialRiteCards.Add(item2);
item2.SelfBattlePlayer.TurnBurialRiteCards.Add(item2);
item2.SelfBattlePlayer.StartSkillWhenBurialRiteOther(item2, skillProcessor);
SequentialVfxPlayer sequentialVfxPlayer2 = SequentialVfxPlayer.Create();
item2.FlagCardAsDestroyedBySkill();
item2.DeathTypeInfo.BurialRite = true;
sequentialVfxPlayer2.Register(item2.SkillApplyInformation.AllSkillEffectStop());
sequentialVfxPlayer2.Register(item2.SelfBattlePlayer.CardManagement(item2, skillProcessor, BattlePlayerBase.CARD_MANAGEMENT.DESTROY, isRandom: false, null, null, skill));
parallelVfxPlayer2.Register(sequentialVfxPlayer2);
}
if (!_ownerCard.SelfBattlePlayer.BattleMgr.IsVirtualBattle)
{
BattleLogManager.GetInstance().AddLogSkillDeath(summonedCardsList.ToList(), skill);
}
sequentialVfxPlayer.Register(parallelVfxPlayer2);
return sequentialVfxPlayer;
}
public static List<BattleCardBase> GetBurialRiteTarget(BattlePlayerBase self, BattleCardBase ownerCard)
{
List<BattleCardBase> list = new List<BattleCardBase>();
List<BattleCardBase> handCardList = self.HandCardList;
for (int i = 0; i < handCardList.Count; i++)
{
BattleCardBase battleCardBase = handCardList[i];
if (ownerCard.Index != battleCardBase.Index && battleCardBase.IsUnit)
{
list.Add(battleCardBase);
}
}
return list;
}
public void SetInvoked()
{
_isInvoked = true;
}
}