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

@@ -13,38 +13,9 @@ public class BattleKeywordInfoListMgr : MonoBehaviour
private static readonly string[] KEYWORD_PATTERNS = new string[2] { "\\[u\\]\\[(ffcd45|524522)\\](?<KEYWORD>.*?)\\[-\\]\\[/u\\]", "\\[b\\](?<KEYWORD>.*?)\\[/b\\]" };
private static readonly string KEYWORD_TITLE_REMOVE_PATTERN = "<<\\{me.hand_self.count\\}\\+\\d\\?\\?>>";
private const int LABEL_KEYWORD = 0;
private const int LABEL_DESC = 1;
private const int LINE_SPRITE = 0;
private const int PADDING_OBJECT = 1;
private const int LINE_SPRITE_OFFSET = -12;
private const int CLASS_EFFECT_TABLE_PADDING_Y = 30;
private const int CLASS_EFFECT_FONT_SIZE = 21;
[SerializeField]
public UIScrollView ScrollView;
[SerializeField]
private NguiObjs SkillInfo;
[SerializeField]
public UITable _table;
[SerializeField]
private UIPanel _panel;
private IList<NguiObjs> SkillInfoList = new List<NguiObjs>();
private Action ResetTableFinishAction;
public static IList<string> GetKeywords(CardParameter cardParameter)
{
return GetKeywords(cardParameter.SkillDescription + cardParameter.EvoSkillDescription);
@@ -67,309 +38,6 @@ public class BattleKeywordInfoListMgr : MonoBehaviour
return list;
}
public void SetKeywordInfos(IList<string> currentWords, CardMaster.CardMasterId cardMasterId)
{
List<string> list = new List<string>();
for (int i = 0; i < currentWords.Count; i++)
{
string keywordTitle = string.Empty;
string skillinfo = string.Empty;
string text = currentWords[i];
string valueOrDefault = Data.Master.BattleKeywordReplaceDic.GetValueOrDefault(text, text);
if (GetKeywordData(valueOrDefault, cardMasterId, out keywordTitle, out skillinfo) && !list.Contains(keywordTitle))
{
AddKeywordInfo(keywordTitle, skillinfo, LabelDefine.TEXT_COLOR_KEYWORD, cardMasterId);
list.Add(keywordTitle);
}
}
StartCoroutine(RepositionTable());
}
public void SetBuffInfos(List<int> baseCardID, List<string> buff)
{
string empty = string.Empty;
for (int i = 0; i < baseCardID.Count; i++)
{
empty = ((CardMaster.GetInstanceForBattle().GetCardParameterFromId(baseCardID[i]).CardName != null && !(CardMaster.GetInstanceForBattle().GetCardParameterFromId(baseCardID[i]).CardName == string.Empty)) ? CardMaster.GetInstanceForBattle().GetCardParameterFromId(baseCardID[i]).CardName : Data.SystemText.Get("BattleLog_0097"));
AddKeywordInfo(empty, buff[i], LabelDefine.TEXT_COLOR_NORMAL, CardMaster.BatttleCardMasterId);
}
StartCoroutine(RepositionTable());
}
public IEnumerator RepositionTable()
{
yield return null;
_table.Reposition();
ScrollView.verticalScrollBar.value = 0f;
ScrollView.ResetPosition();
if (ResetTableFinishAction != null)
{
ResetTableFinishAction();
}
}
public void AddKeywordInfo(string keyword, string desc, Color32 keywordColor, CardMaster.CardMasterId cardMasterId, bool isClassEffect = false, Action onClickCardName = null, bool isKeyWordDisp = true)
{
NguiObjs nguiObjs = UnityEngine.Object.Instantiate(SkillInfo);
keyword = Regex.Replace(keyword, KEYWORD_TITLE_REMOVE_PATTERN, "");
if (isClassEffect)
{
nguiObjs.labels[0].fontSize = 21;
nguiObjs.labels[1].fontSize = 21;
}
nguiObjs.transform.parent = _table.transform;
nguiObjs.labels[0].text = keyword;
nguiObjs.labels[0].color = keywordColor;
nguiObjs.labels[1].SetWrapText(desc);
nguiObjs.transform.localScale = new Vector3(1f, 1f, 1f);
nguiObjs.gameObject.name = SkillInfoList.Count.ToString();
nguiObjs.gameObject.SetActive(value: true);
if (isClassEffect)
{
GameObject gameObject = new GameObject("paddingObject");
gameObject.transform.SetParent(nguiObjs.labels[0].gameObject.transform);
gameObject.transform.localPosition = Vector3.zero;
gameObject.transform.localScale = Vector3.one;
UISprite uISprite = gameObject.AddComponent<UISprite>();
uISprite.alpha = 0f;
uISprite.height = 30;
gameObject.transform.localPosition = new Vector3(nguiObjs.labels[0].width / 2, gameObject.transform.localPosition.y);
nguiObjs.objs.Add(gameObject);
if (SkillInfoList.Count == 0)
{
gameObject.SetActive(value: false);
}
BoxCollider boxCollider = nguiObjs.labels[1].gameObject.AddComponent<BoxCollider>();
boxCollider.size = new Vector3(nguiObjs.labels[1].width, nguiObjs.labels[1].height);
boxCollider.center = new Vector3(nguiObjs.labels[1].width / 2, -nguiObjs.labels[1].height / 2);
List<string> keyWordList = BattlePlayerView.GetKeyWordList(nguiObjs.labels[1].text);
UIEventListener uIEventListener = UIEventListener.Get(nguiObjs.labels[1].gameObject);
uIEventListener.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(uIEventListener.onClick, (UIEventListener.VoidDelegate)delegate
{
if (keyWordList.Count == 0)
{
onClickCardName();
}
else
{
BattlePlayerView.CreateClassEffectPanel(keyWordList, cardMasterId);
}
});
BattlePlayerView.SetKeyWordColor(nguiObjs.labels[1].gameObject, nguiObjs.labels[1]);
BoxCollider boxCollider2 = nguiObjs.labels[0].gameObject.AddComponent<BoxCollider>();
boxCollider2.size = new Vector3(nguiObjs.labels[0].width, nguiObjs.labels[0].height);
boxCollider2.center = new Vector3(nguiObjs.labels[0].width / 2, -nguiObjs.labels[0].height / 2);
BattlePlayerView.SetLabelColorEvent(nguiObjs.labels[0]);
UIEventListener uIEventListener2 = UIEventListener.Get(nguiObjs.labels[0].gameObject);
uIEventListener2.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(uIEventListener2.onClick, (UIEventListener.VoidDelegate)delegate
{
onClickCardName();
});
if (!isKeyWordDisp)
{
nguiObjs.labels[0].gameObject.SetActive(value: false);
nguiObjs.labels[1].transform.localPosition = new Vector3(nguiObjs.labels[1].transform.localPosition.x, nguiObjs.labels[0].transform.localPosition.y);
SkillInfoList[SkillInfoList.Count - 1].objs[0].SetActive(value: false);
}
boxCollider.gameObject.AddComponent<UIDragScrollView>().scrollView = ScrollView;
boxCollider2.gameObject.AddComponent<UIDragScrollView>().scrollView = ScrollView;
UILabel uILabel = nguiObjs.labels[1];
uILabel.topAnchor.target = null;
uILabel.bottomAnchor.target = null;
uILabel.leftAnchor.target = null;
uILabel.rightAnchor.target = null;
UISprite component = nguiObjs.objs[0].GetComponent<UISprite>();
component.topAnchor.target = null;
component.bottomAnchor.target = null;
component.leftAnchor.target = null;
component.rightAnchor.target = null;
component.transform.localPosition = new Vector3(component.transform.localPosition.x, uILabel.transform.localPosition.y - (float)uILabel.height + -12f);
}
SkillInfoList.Add(nguiObjs);
}
public void RemoveKeyWord(int index)
{
bool activeSelf = SkillInfoList[index].labels[0].gameObject.activeSelf;
UnityEngine.Object.Destroy(SkillInfoList[index].gameObject);
if (SkillInfoList.Count > index + 1)
{
if (!SkillInfoList[index + 1].labels[0].gameObject.activeSelf)
{
Vector3 localPosition = SkillInfoList[index + 1].labels[1].transform.localPosition;
if (activeSelf)
{
SkillInfoList[index + 1].labels[0].gameObject.SetActive(value: true);
}
SkillInfoList[index + 1].labels[1].transform.localPosition = new Vector3(localPosition.x, SkillInfoList[index + 1].labels[0].transform.localPosition.y - (float)SkillInfoList[index + 1].labels[0].height);
SkillInfoList[index + 1].objs[0].transform.localPosition = new Vector3(SkillInfoList[index + 1].objs[0].transform.localPosition.x, -72 - SkillInfoList[index + 1].labels[1].height + -12);
}
}
else if (index - 1 > 0)
{
bool flag = false;
bool flag2 = false;
if (SkillInfoList[index - 1].labels[0].gameObject.activeSelf)
{
flag = true;
if (index + 1 < SkillInfoList.Count && !SkillInfoList[index + 1].labels[0].gameObject.activeSelf)
{
flag2 = true;
}
}
if (flag && !flag2)
{
SkillInfoList[index - 1].objs[0].SetActive(value: true);
}
}
SkillInfoList.RemoveAt(index);
if (SkillInfoList.Count != 0)
{
SkillInfoList[0].objs[1].SetActive(value: false);
}
if (base.gameObject.activeInHierarchy)
{
StartCoroutine(RepositionTable());
}
}
public void AddKeywordInfo(BattleCardBase card, string keyword, string desc, Color32 keywordColor)
{
NguiObjs nguiObjs = UnityEngine.Object.Instantiate(SkillInfo);
nguiObjs.transform.parent = _table.transform;
nguiObjs.labels[0].text = keyword;
nguiObjs.labels[0].color = keywordColor;
nguiObjs.labels[1].SetWrapText(desc);
nguiObjs.transform.localScale = new Vector3(1f, 1f, 1f);
nguiObjs.gameObject.name = SkillInfoList.Count.ToString();
nguiObjs.gameObject.SetActive(value: true);
UIRect[] componentsInChildren = nguiObjs.gameObject.GetComponentsInChildren<UIRect>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
componentsInChildren[i].ResetAndUpdateAnchors();
}
SkillInfoList.Add(nguiObjs);
}
public void SetScrollView(DialogBase dia)
{
UIPanel component = ScrollView.GetComponent<UIPanel>();
GameObject gameObject = dia.WindowSprite.gameObject;
GameObject gameObject2 = dia.titleLine.gameObject;
component.topAnchor.target = gameObject2.transform;
component.topAnchor.relative = 0f;
component.topAnchor.absolute = -10;
component.bottomAnchor.target = gameObject.transform;
component.bottomAnchor.relative = 0f;
component.bottomAnchor.absolute = 25;
component.leftAnchor.target = gameObject.transform;
component.leftAnchor.relative = 0f;
component.leftAnchor.absolute = 25;
component.rightAnchor.target = gameObject.transform;
component.rightAnchor.relative = 1f;
component.rightAnchor.absolute = -25;
gameObject.GetComponent<UIDragScrollView>().scrollView = ScrollView;
component.UpdateAnchors();
}
private bool GetKeywordData(string skill, CardMaster.CardMasterId cardMasterId, out string keywordTitle, out string skillinfo)
{
keywordTitle = string.Empty;
skillinfo = string.Empty;
if (Data.Master.BattleKeyWordDic.ContainsKey(skill))
{
string skillToLower = skill.ToLower();
KeyValuePair<string, string> keyValuePair = Data.Master.BattleKeyWordDic.First((KeyValuePair<string, string> data) => data.Key.ToLower() == skillToLower);
keywordTitle = keyValuePair.Key;
skillinfo = keyValuePair.Value;
List<int> cardIdsInDesc = GetCardIdsInDesc(skillinfo);
if (cardIdsInDesc.Count > 0)
{
skillinfo = string.Empty;
for (int num = 0; num < cardIdsInDesc.Count; num++)
{
CardParameter cardParameterFromId = CardMaster.GetInstance(cardMasterId).GetCardParameterFromId(cardIdsInDesc[num]);
if (num > 0)
{
skillinfo += "\n";
skillinfo += Data.SystemText.Get("Card_0198_BattleKeyWord_01", cardParameterFromId.CardName);
skillinfo += "\n";
}
skillinfo += GetCardDescText(cardParameterFromId);
}
}
skillinfo = skillinfo.Trim();
return true;
}
return false;
}
public static string GetCardDescText(CardParameter param)
{
string empty = string.Empty;
string clanNameByKey = GameMgr.GetIns().GetDataMgr().GetClanNameByKey((int)param.Clan);
string cardTypeName = CardBasePrm.GetCardTypeName(param.CharType);
empty = ((!(param.TribeName == "ALL")) ? (Data.SystemText.Get("Card_0200_BattleKeyWord_03", param.Cost.ToString(), clanNameByKey, param.TribeName, cardTypeName) + "\n") : (Data.SystemText.Get("Card_0199_BattleKeyWord_02", param.Cost.ToString(), clanNameByKey, cardTypeName) + "\n"));
if (param.CharType == CardBasePrm.CharaType.NORMAL || param.CharType == CardBasePrm.CharaType.EVOLUTION)
{
if (!param.IsEvolveChoiceCard)
{
empty = empty + Data.SystemText.Get("Card_0201_BattleKeyWord_04", param.Atk.ToString(), param.Life.ToString()) + "\n";
if (param.ConvertedSkillDescription != string.Empty)
{
empty = empty + ConvertKeywordsInText(param.ConvertedSkillDescription) + "\n";
}
}
empty = empty + Data.SystemText.Get("Card_0202_BattleKeyWord_05") + "\n";
empty = empty + Data.SystemText.Get("Card_0201_BattleKeyWord_04", param.EvoAtk.ToString(), param.EvoLife.ToString()) + "\n";
if (param.ConvertedEvoSkillDescription != string.Empty)
{
empty = empty + ConvertKeywordsInText(param.ConvertedEvoSkillDescription) + "\n";
}
}
else
{
empty = empty + ConvertKeywordsInText(param.ConvertedSkillDescription) + "\n";
}
return empty;
}
private static string ConvertKeywordsInText(string skilldisc)
{
List<string> list = new List<string>();
List<string> list2 = new List<string>();
for (int i = 0; i < KEYWORD_PATTERNS.Length; i++)
{
foreach (Match item2 in Regex.Matches(skilldisc, KEYWORD_PATTERNS[i]))
{
string item = Regex.Escape(item2.Value);
if (list.Contains(item))
{
continue;
}
string value = item2.Groups["KEYWORD"].Value;
if (Data.Master.BattleKeyWordDic.ContainsKey(value))
{
List<int> cardIdsInDesc = GetCardIdsInDesc(Data.Master.BattleKeyWordDic[value]);
list.Add(item);
if (cardIdsInDesc.Count > 0)
{
list2.Add(Data.SystemText.Get("Card_0203_BattleKeyWord_06", value));
}
else
{
list2.Add(value);
}
}
}
}
for (int j = 0; j < list.Count; j++)
{
skilldisc = Regex.Replace(skilldisc, list[j], list2[j]);
}
return Global.ConvertToWithoutBBCode(skilldisc);
}
public static List<int> GetCardIdsInDesc(string desc)
{
string text = "KEYWORD";
@@ -386,36 +54,6 @@ public class BattleKeywordInfoListMgr : MonoBehaviour
return list;
}
public List<string> GetKeyWordNameList()
{
List<string> list = new List<string>(SkillInfoList.Count);
for (int i = 0; i < SkillInfoList.Count; i++)
{
list.Add(SkillInfoList[i].labels[0].text);
}
return list;
}
public IList<NguiObjs> GetSkillInfoList()
{
return SkillInfoList;
}
public float GetScrollViewSizeY()
{
return ScrollView.GetComponent<UIPanel>().GetViewSize().y;
}
public void SetResetTableFinishAction(Action inAction)
{
ResetTableFinishAction = inAction;
}
public void SetKeyWordFocus(float inScrollBarValue)
{
ScrollView.verticalScrollBar.value = inScrollBarValue;
}
public void SetPanelDepth(int depth)
{
_panel.depth = depth;