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

280 lines
9.5 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Wizard.Battle.UI;
using Wizard.Battle.View.Vfx;
public abstract class SkillBaseCopy : SkillBase
{
public string SkillType = "";
public override bool IsAllowDestroyTarget => true;
public List<SkillBase> CopiedSkillList { get; private set; } = new List<SkillBase>();
public SkillBaseCopy(SkillParameter skillPrm, string option)
: base(skillPrm, option)
{
}
public abstract bool IsRemain();
public override VfxWithLoading Start(CallParameter parameter)
{
SkillType = base.OptionValue.GetString(SkillFilterCreator.ContentKeyword.ability, "NONE");
bool isRemain = IsRemain();
BattleCardBase ownerCard = base.SkillPrm.ownerCard;
if (SkillType == "NONE")
{
return NullVfxWithLoading.GetInstance();
}
ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create();
foreach (BattleCardBase targetCard in parameter.targetCards)
{
if (IsSkillMasterCopy(SkillType))
{
parallelVfxPlayer.Register(CopyMaster(ownerCard, targetCard, SkillType, isRemain));
}
else
{
parallelVfxPlayer.Register(CopySkill(ownerCard, targetCard, SkillType, isRemain));
}
}
VfxWithLoadingSequential vfxWithLoadingSequential = VfxWithLoadingSequential.Create();
vfxWithLoadingSequential.RegisterToMainVfx(parallelVfxPlayer);
vfxWithLoadingSequential.RegisterVfxWithLoading(CreateSkillEffect(base.SkillPrm.resourceMgr, parameter.targetCards));
return vfxWithLoadingSequential;
}
private VfxBase CopyMaster(BattleCardBase owner, BattleCardBase target, string skillType, bool isRemain)
{
ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create();
BattleCardBase targetCard = target;
IEnumerable<BattleCardBase> previousCopiedCardList = owner.GetCopiedCardList;
SkillBase skillBase = target.NormalSkills.Where((SkillBase s) => s is SkillBaseCopy).FirstOrDefault();
BattleCardBase.CopySkillInfo copySkillInfo = base.SkillPrm.ownerCard.CopySkill(targetCard, skillType, isRemain);
parallelVfxPlayer.Register(copySkillInfo.Vfx);
if (!isRemain)
{
if (!targetCard.Skills.Any((SkillBase s) => s.SkillPrm.buildInfo._previousSkillOwner != null))
{
targetCard.RemoveBuffInfo((BuffInfo b) => b.IsCopied);
}
BuffInfo buffLose = AddBuffInfoIfNeeded(targetCard);
BuffInfoContainer buffInfoLose = new BuffInfoContainer(targetCard, buffLose, -1, "", null, 0L);
copySkillInfo.NewCopySkill.buffInfoContainer.Add(buffInfoLose);
targetCard.OnRemoveFromInPlayAfterOneTime += delegate
{
targetCard.RemoveBuffInfo(buffLose);
copySkillInfo.NewCopySkill.buffInfoContainer.Remove(buffInfoLose);
return NullVfx.GetInstance();
};
}
CopiedSkillList.AddRange(copySkillInfo.CopiedSkillList);
IEnumerable<BattleCardBase> source = owner.GetCopiedCardList.Where((BattleCardBase b) => !previousCopiedCardList.Contains(b));
if (source.Any())
{
BattleCardBase previousOwner = source.First();
BuffInfo buffCopy = AddBuffInfoIfNeeded(owner, previousOwner);
buffCopy.IsCopied = true;
buffCopy.SetPreviousOwner(previousOwner);
BuffInfoContainer buffInfoContainer = skillBase?.GetBuffInfoContainer().FirstOrDefault((BuffInfoContainer b) => b._buffInfo.PreviousOwner != null && b._buffInfo.PreviousOwner.CardId == previousOwner.CardId);
if (previousOwner.CardId != target.CardId && skillBase != null && buffInfoContainer != null)
{
buffCopy.IsCopiedEvolutionSkill = buffInfoContainer._buffInfo.IsCopiedEvolutionSkill;
}
else
{
buffCopy.IsCopiedEvolutionSkill = copySkillInfo.IsEvolutionSkill;
}
BuffInfoContainer buffInfoRob = new BuffInfoContainer(owner, buffCopy, -1, "", null, 0L);
copySkillInfo.NewCopySkill.buffInfoContainer.Add(buffInfoRob);
buffCopy.IsPlayer = previousOwner.IsPlayer;
owner.OnRemoveFromInPlayAfterOneTime += delegate
{
owner.RemoveBuffInfo(buffCopy);
copySkillInfo.NewCopySkill.buffInfoContainer.Remove(buffInfoRob);
return NullVfx.GetInstance();
};
owner.BuffInfoList.RemoveAll((BuffInfo b) => copySkillInfo.AttachBuffs.Contains(b));
owner.BuffInfoList.AddRange(copySkillInfo.AttachBuffs);
}
if (IsBattleLog && (copySkillInfo.AttachBuffs.Any() || copySkillInfo.CopiedSkillList.Any()))
{
BattleLogManager.GetInstance().AddLogCopiedSkill(target, this, isRemain);
}
return parallelVfxPlayer;
}
private bool IsBuffSkill<SkillType>(SkillBase skill)
{
if (skill is SkillType || IsCopySkill(skill, this.SkillType))
{
return true;
}
if (skill is Skill_attach_skill skill_attach_skill && skill_attach_skill.GetAttachSkills().Any((SkillBase s) => s is SkillType))
{
return true;
}
return false;
}
private bool IsBaseSkill<SkillType>(SkillBase skill)
{
if (!(skill is SkillType))
{
return false;
}
if (!base.IsAllResidentTiming)
{
return false;
}
if (!(skill.ApplyingTargetFilter is SkillTargetSelfFilter))
{
return false;
}
return true;
}
private VfxBase CopySkill(BattleCardBase owner, BattleCardBase target, string skillType, bool isRemain)
{
ParallelVfxPlayer parallelVfxPlayer = ParallelVfxPlayer.Create();
_ = owner.GetCopiedCardList;
target.NormalSkills.Where((SkillBase s) => s is SkillBaseCopy).FirstOrDefault();
bool flag = false;
BuffInfo buffInfo = null;
SkillBase skillBase = null;
switch (skillType)
{
case "drain":
if (target.SkillApplyInformation.IsDrain)
{
parallelVfxPlayer.Register(owner.SkillApplyInformation.GiveDrain());
flag = true;
buffInfo = target.BuffInfoList.FirstOrDefault((BuffInfo b) => IsBuffSkill<Skill_drain>(b.SkillFrom));
skillBase = target.Skills.FirstOrDefault((SkillBase s) => IsBaseSkill<Skill_drain>(s));
}
break;
case "killer":
if (target.SkillApplyInformation.IsKiller)
{
parallelVfxPlayer.Register(owner.SkillApplyInformation.GiveKiller());
flag = true;
buffInfo = target.BuffInfoList.FirstOrDefault((BuffInfo b) => IsBuffSkill<Skill_killer>(b.SkillFrom));
skillBase = target.Skills.FirstOrDefault((SkillBase s) => IsBaseSkill<Skill_killer>(s));
}
break;
case "rush":
if (target.SkillApplyInformation.IsRush)
{
parallelVfxPlayer.Register(owner.SkillApplyInformation.GiveRush(new RushInfo(target, string.Empty)));
flag = true;
buffInfo = target.BuffInfoList.FirstOrDefault((BuffInfo b) => IsBuffSkill<Skill_rush>(b.SkillFrom));
skillBase = target.Skills.FirstOrDefault((SkillBase s) => IsBaseSkill<Skill_rush>(s));
}
break;
case "quick":
if (target.SkillApplyInformation.IsQuick)
{
parallelVfxPlayer.Register(owner.SkillApplyInformation.GiveQuick());
flag = true;
buffInfo = target.BuffInfoList.FirstOrDefault((BuffInfo b) => IsBuffSkill<Skill_quick>(b.SkillFrom));
skillBase = target.Skills.FirstOrDefault((SkillBase s) => IsBaseSkill<Skill_quick>(s));
}
break;
case "guard":
if (target.SkillApplyInformation.IsGuard)
{
parallelVfxPlayer.Register(owner.SkillApplyInformation.GiveGuard(new GuardInfo(target, string.Empty)));
flag = true;
buffInfo = target.BuffInfoList.FirstOrDefault((BuffInfo b) => IsBuffSkill<Skill_guard>(b.SkillFrom));
skillBase = target.Skills.FirstOrDefault((SkillBase s) => IsBaseSkill<Skill_guard>(s));
}
break;
}
if (flag)
{
BattleCardBase battleCardBase = null;
bool flag2;
bool isPlayer;
if (buffInfo != null)
{
flag2 = buffInfo.IsEvolutionSkill;
SkillBase skillFrom = buffInfo.SkillFrom;
if (skillFrom is SkillBaseCopy)
{
battleCardBase = buffInfo.PreviousOwner;
isPlayer = buffInfo.IsPlayer;
}
else
{
battleCardBase = skillFrom.SkillPrm.ownerCard;
isPlayer = skillFrom.SkillPrm.ownerCard.IsPlayer;
}
}
else
{
bool flag3 = target.IsEvolution;
if (skillBase != null)
{
flag3 = target.EvolutionSkills.Contains(skillBase);
}
flag2 = flag3;
battleCardBase = target;
isPlayer = target.IsPlayer;
}
BuffInfo buffCopy = AddBuffInfoIfNeeded(owner, battleCardBase);
buffCopy.IsCopied = true;
if (skillBase != null && !(skillBase is Skill_attach_skill) && !(skillBase is SkillBaseCopy))
{
skillBase.SetOnLoseEvent(owner, buffCopy, null);
}
else
{
owner.OnLoseSkillOneTime += (SkillBase loseSkill, SkillProcessor skillProcessOneTime, BattleCardBase card) => card.SkillApplyInformation.AllSkillEffectStop();
}
BuffInfo buffInfo2 = buffCopy;
bool isCopiedEvolutionSkill = (buffCopy.IsEvolutionSkill = flag2);
buffInfo2.IsCopiedEvolutionSkill = isCopiedEvolutionSkill;
buffCopy.SetPreviousOwner(battleCardBase);
buffCopy.IsPlayer = isPlayer;
owner.OnRemoveFromInPlayAfterOneTime += delegate
{
owner.RemoveBuffInfo(buffCopy);
return NullVfx.GetInstance();
};
if (IsBattleLog)
{
BattleLogManager.GetInstance().AddLogCopiedSkill(target, this, isRemain);
}
}
return parallelVfxPlayer;
}
private static bool IsCopySkill(SkillBase skill, string type)
{
if (skill is SkillBaseCopy skillBaseCopy)
{
return skillBaseCopy.SkillType == type;
}
return false;
}
private static bool IsSkillMasterCopy(string skillType)
{
switch (skillType)
{
case "when_destroy":
case "when_fight":
case "when_attack":
return true;
default:
return false;
}
}
public override VfxWithLoading Stop(SkillProcessor skillProcessor)
{
return NullVfxWithLoading.GetInstance();
}
}