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

264 lines
8.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Cute;
using UnityEngine;
namespace Wizard;
public class DeckSelectUIDialog
{
public enum eFormatChangeUIType
{
SingleFormat,
NormalFormatOnly,
WithPrerotation,
WithCrossover,
WithMyRotation,
UseOtherCategory
}
private static readonly Vector2 FORMAT_CHANGE_UI_POSITION = new Vector3(-508f, 65f);
private DeckSelectUIDialogTitle _deckSelectDialogTitleUI;
private DeckGroupListData _deckGroupListData;
private bool _isVisibleCreateNew;
private DeckSelectUI _deckSelectUI;
private static readonly Format[] OTHER_CATEGORY_FORMATS = new Format[5]
{
Format.Crossover,
Format.PreRotation,
Format.MyRotation,
Format.Avatar,
Format.Max
};
private static readonly Dictionary<FormatChangeUI.FormatCategory, Format> FORMAT_CATEGORY_TO_FORMAT = new Dictionary<FormatChangeUI.FormatCategory, Format>
{
{
FormatChangeUI.FormatCategory.Rotation,
Format.Rotation
},
{
FormatChangeUI.FormatCategory.Unlimited,
Format.Unlimited
},
{
FormatChangeUI.FormatCategory.PreRotation,
Format.PreRotation
},
{
FormatChangeUI.FormatCategory.Crossover,
Format.Crossover
},
{
FormatChangeUI.FormatCategory.Other,
Format.Max
},
{
FormatChangeUI.FormatCategory.Hof,
Format.Hof
},
{
FormatChangeUI.FormatCategory.Windfall,
Format.Windfall
},
{
FormatChangeUI.FormatCategory.MyRotation,
Format.MyRotation
},
{
FormatChangeUI.FormatCategory.Avatar,
Format.Avatar
}
};
public DialogBase Dialog { get; private set; }
public static DeckSelectUIDialog Create(string dialogTitle, DeckGroupListData deckGroupListData, Format defaultFormat, eFormatChangeUIType formatChangeUIType, bool isVisibleCreateNew, Action<DialogBase, DeckData> OnSelectDeck, DeckSelectUI.InitOptions initOptions = null)
{
if (defaultFormat == Format.All)
{
defaultFormat = (Format)PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LAST_SELECT_DECK_FORMAT);
}
if (formatChangeUIType == eFormatChangeUIType.UseOtherCategory && IsIncludeInOtherCategory(defaultFormat))
{
defaultFormat = Format.Max;
bool num = PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.LAST_BATTLE_IS_TRIALDECK);
bool flag = PlayerPrefsWrapper.GetBool(PlayerPrefsWrapper.LAST_BATTLE_IS_DEFDECK);
if (!num && !flag)
{
Format[] oTHER_CATEGORY_FORMATS = OTHER_CATEGORY_FORMATS;
foreach (Format format in oTHER_CATEGORY_FORMATS)
{
if (deckGroupListData.IsExistDeckListByFormat(format))
{
defaultFormat = format;
break;
}
}
}
}
if (formatChangeUIType != eFormatChangeUIType.SingleFormat && !deckGroupListData.IsExistDeckListByFormat(defaultFormat))
{
defaultFormat = deckGroupListData.DeckGroupList.FirstOrDefault((DeckGroup deckGroup) => deckGroup.DeckDataList.Any((DeckData deck) => !deck.IsNoCard()))?.DeckFormat ?? Format.Rotation;
}
FormatChangeUI.FormatCategory formatCategoryByFormat = GetFormatCategoryByFormat(defaultFormat, formatChangeUIType == eFormatChangeUIType.UseOtherCategory);
DeckSelectUIDialog deckSelectUIDialog = new DeckSelectUIDialog(dialogTitle, deckGroupListData, defaultFormat, formatCategoryByFormat, formatChangeUIType, isVisibleCreateNew, OnSelectDeck, initOptions);
deckSelectUIDialog.CreateFormatChangeUI(formatCategoryByFormat, formatChangeUIType);
return deckSelectUIDialog;
}
private DeckSelectUIDialog(string dialogTitle, DeckGroupListData deckGroupListData, Format format, FormatChangeUI.FormatCategory formatCategory, eFormatChangeUIType formatChangeUIType, bool isVisibleCreateNew, Action<DialogBase, DeckData> OnSelectDeck, DeckSelectUI.InitOptions initOptions)
{
DeckSelectUIDialog deckSelectUIDialog = this;
_isVisibleCreateNew = isVisibleCreateNew;
_deckGroupListData = deckGroupListData;
Dialog = UIManager.GetInstance().CreateDialogClose();
Dialog.SetTitleLabel(dialogTitle);
Dialog.SetSize(DialogBase.Size.XL);
Dialog.SetButtonLayout(DialogBase.ButtonLayout.NONE);
Dialog.SetActive(inActive: false);
int? longTextPositionOverride = initOptions?.LongTextTitlePosition;
_deckSelectDialogTitleUI = DeckSelectUIDialogTitle.Create(Dialog, dialogTitle, format, formatChangeUIType != eFormatChangeUIType.SingleFormat, longTextPositionOverride);
List<DeckGroup> deckGroupList = GetDeckGroupList(formatCategory);
GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("UI/DeckList/DeckSelectUI/DeckSelectUI")) as GameObject;
_deckSelectUI = gameObject.GetComponent<DeckSelectUI>();
_deckSelectUI.gameObject.SetActive(value: false);
_deckSelectUI.Initialize(deckGroupList, format, isVisibleCreateNew, delegate(DeckData deck)
{
OnSelectDeck.Call(deckSelectUIDialog.Dialog, deck);
}, delegate(Format changeFormat)
{
deckSelectUIDialog._deckSelectDialogTitleUI.UpdateFormatObj(changeFormat);
}, delegate
{
deckSelectUIDialog.Dialog.SetActive(inActive: true);
deckSelectUIDialog._deckSelectUI.gameObject.SetActive(value: true);
}, initOptions);
Dialog.SetObj(_deckSelectUI.gameObject);
_deckSelectUI.gameObject.GetComponent<UIPanel>().alpha = 1f;
}
public void Close()
{
if (Dialog != null)
{
Dialog.Close();
}
}
public static string GetTitleByBattleType(DataMgr.BattleType battleType)
{
string result = string.Empty;
switch (battleType)
{
case DataMgr.BattleType.FreeBattle:
result = Data.SystemText.Get("Battle_0005");
break;
case DataMgr.BattleType.RankBattle:
result = Data.SystemText.Get("Battle_0006");
break;
case DataMgr.BattleType.RoomBattle:
case DataMgr.BattleType.RoomTwoPick:
result = Data.SystemText.Get("Battle_0007");
break;
case DataMgr.BattleType.ColosseumNormal:
case DataMgr.BattleType.ColosseumHof:
result = Data.SystemText.Get("Battle_0488");
break;
}
return result;
}
private void CreateFormatChangeUI(FormatChangeUI.FormatCategory defaultFormatCategory, eFormatChangeUIType formatChangeUIType)
{
if (formatChangeUIType != eFormatChangeUIType.SingleFormat)
{
FormatChangeUI.FormatCategory anotherFormatCategory = FormatChangeUI.FormatCategory.Invalid;
switch (formatChangeUIType)
{
case eFormatChangeUIType.NormalFormatOnly:
anotherFormatCategory = FormatChangeUI.FormatCategory.Invalid;
break;
case eFormatChangeUIType.UseOtherCategory:
anotherFormatCategory = FormatChangeUI.FormatCategory.Other;
break;
case eFormatChangeUIType.WithPrerotation:
anotherFormatCategory = FormatChangeUI.FormatCategory.PreRotation;
break;
case eFormatChangeUIType.WithCrossover:
anotherFormatCategory = FormatChangeUI.FormatCategory.Crossover;
break;
case eFormatChangeUIType.WithMyRotation:
anotherFormatCategory = FormatChangeUI.FormatCategory.MyRotation;
break;
}
FormatChangeUI formatChangeUI = FormatChangeUI.Create(defaultFormatCategory, anotherFormatCategory, OnClickChangeFormatBtn);
Dialog.AttachObjToTitleLabel(formatChangeUI.gameObject, FORMAT_CHANGE_UI_POSITION);
}
}
private void OnClickChangeFormatBtn(FormatChangeUI.FormatCategory formatCategory)
{
Format formatByFormatCategory = GetFormatByFormatCategory(formatCategory);
_deckSelectUI.gameObject.SetActive(value: false);
List<DeckGroup> deckGroupList = GetDeckGroupList(formatCategory);
_deckSelectUI.UpdateDeckView(deckGroupList, formatByFormatCategory, _isVisibleCreateNew, delegate
{
_deckSelectUI.gameObject.SetActive(value: true);
});
}
private List<DeckGroup> GetDeckGroupList(FormatChangeUI.FormatCategory formatCategory)
{
List<DeckGroup> list = new List<DeckGroup>();
if (formatCategory == FormatChangeUI.FormatCategory.Other)
{
Format[] oTHER_CATEGORY_FORMATS = OTHER_CATEGORY_FORMATS;
foreach (Format format in oTHER_CATEGORY_FORMATS)
{
list.AddRange(_deckGroupListData.SelectDeckGroupList(format));
}
}
else
{
Format formatByFormatCategory = GetFormatByFormatCategory(formatCategory);
list.AddRange(_deckGroupListData.SelectDeckGroupList(formatByFormatCategory));
}
return list;
}
private static Format GetFormatByFormatCategory(FormatChangeUI.FormatCategory formatCategory)
{
return FORMAT_CATEGORY_TO_FORMAT[formatCategory];
}
private static FormatChangeUI.FormatCategory GetFormatCategoryByFormat(Format format, bool useOtherCategory)
{
if (useOtherCategory && IsIncludeInOtherCategory(format))
{
return FormatChangeUI.FormatCategory.Other;
}
FormatChangeUI.FormatCategory result = FormatChangeUI.FormatCategory.Invalid;
foreach (KeyValuePair<FormatChangeUI.FormatCategory, Format> item in FORMAT_CATEGORY_TO_FORMAT)
{
if (item.Value == format)
{
result = item.Key;
break;
}
}
return result;
}
private static bool IsIncludeInOtherCategory(Format format)
{
return OTHER_CATEGORY_FORMATS.Any((Format f) => f == format);
}
}