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

174 lines
6.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using LitJson;
namespace Wizard;
public class PackInfoTask : BaseTask
{
public class PackFirstTransition
{
private int _serialId;
public int PackId { get; private set; }
public PackFirstTransition(int serialId, int packId)
{
_serialId = serialId;
PackId = packId;
}
public bool IsUpdate()
{
int value = PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.PACK_FIRST_TRANSITION_SERIAL_ID);
return _serialId != value;
}
public void SaveViewed()
{
PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.PACK_FIRST_TRANSITION_SERIAL_ID, _serialId);
}
}
public class PackInfoTaskParam : BaseParam
{
}
public bool NeedsFooterBadgeIcon;
public PackFirstTransition PackFirstTransitionData { get; private set; }
public PackInfoTask(ApiType.Type apiType)
{
base.type = apiType;
}
public void SetParameter()
{
PackInfoTaskParam packInfoTaskParam = new PackInfoTaskParam();
base.Params = packInfoTaskParam;
}
protected override int Parse()
{
int num = base.Parse();
if (num != 1)
{
return num;
}
Data.PackInfo.dataList.Clear();
JsonData jsonData = base.ResponseData["data"]["pack_config_list"];
for (int i = 0; i < jsonData.Count; i++)
{
JsonData jsonData2 = jsonData[i];
PackConfig packConfig = new PackConfig();
packConfig.PackId = jsonData2["parent_gacha_id"].ToInt();
packConfig.BasePackId = jsonData2["base_pack_id"].ToInt();
packConfig.GachaType = jsonData2["gacha_type"].ToInt();
packConfig.ExpirtyInfo = new ShopExpirtyInfo(jsonData2["sales_period_info"]);
if (jsonData2["gacha_detail"] != null)
{
string text = jsonData2["gacha_detail"].ToString();
packConfig.Description = text.Replace("\\n", "\n");
}
packConfig.Category = (PackCategory)Enum.ToObject(typeof(PackCategory), jsonData2["pack_category"].ToInt());
packConfig.RemainTime = new RemainTime(jsonData2["complete_date"].ToString(), base.ResponseData["data_headers"]["servertime"].ToDouble());
packConfig.IsHideNotEnoughBuy = jsonData2["is_hide"].ToBoolean();
packConfig.OpenCount = jsonData2["open_count"].ToInt();
packConfig.OpenCountLimit = jsonData2["open_count_limit"].ToInt();
if (jsonData2.TryGetValue("selected_class_id", out var value))
{
packConfig.SelectedClassId = value.ToInt();
}
if (jsonData2.TryGetValue("set_number", out var value2))
{
packConfig.RemainStepupOpenCount = value2.ToInt();
}
if (jsonData2.TryGetValue("total_set_number", out var value3))
{
packConfig.TotalStepupOpenCount = value3.ToInt();
}
int num2 = ((packConfig.IsSpecialCardPack && packConfig.PackId >= 90001 && !GachaUI.IsTsStepupPackId(packConfig.PackId)) ? 90002 : packConfig.PackId);
packConfig.Title = Data.Master.CardSetNameMgr.Get(num2.ToString()).LongName;
if (jsonData2.Keys.Contains("sleeve_id"))
{
packConfig.SleeveId = jsonData2["sleeve_id"].ToInt();
}
else
{
packConfig.SleeveId = 3000011;
}
packConfig.SpecialSleeveId = (jsonData2.Keys.Contains("special_sleeve_id") ? jsonData2["special_sleeve_id"].ToInt() : 3000011);
if (jsonData2["override_draw_effect_pack_id"] != null)
{
packConfig.OverrideDrawEffectPackId = jsonData2["override_draw_effect_pack_id"].ToInt();
}
if (jsonData2["override_ui_effect_pack_id"] != null)
{
packConfig.OverrideUIEffectPackId = jsonData2["override_ui_effect_pack_id"].ToInt();
}
packConfig.TsExchangePosterId = jsonData2.GetValueOrDefault("poster_type", 0);
JsonData jsonData3 = jsonData2["cardpack_banner_list"];
for (int j = 0; j < jsonData3.Count; j++)
{
PackBannerData packBannerData = new PackBannerData();
packBannerData.BannerFileName = jsonData3[j]["banner_name"].ToString();
packBannerData.BannerTitle = Data.SystemText.Get(jsonData3[j]["dialog_title"].ToString());
packConfig.ListPackBanner.Add(packBannerData);
}
if (jsonData2["gacha_point"] != null)
{
packConfig.GachaPointData = new GachaPointData(jsonData2["gacha_point"]);
}
packConfig.IsNew = jsonData2["is_new"].ToBoolean();
JsonData jsonData4 = jsonData2["child_gacha_info"];
for (int k = 0; k < jsonData4.Count; k++)
{
JsonData jsonData5 = jsonData4[k];
PackChildGachaInfo packChildGachaInfo = new PackChildGachaInfo();
packChildGachaInfo.GachaId = jsonData5["gacha_id"].ToInt();
packChildGachaInfo.PackType = (GachaUI.CardPackType)jsonData5["type_detail"].ToInt();
packChildGachaInfo.Cost = jsonData5["cost"].ToInt();
if (jsonData5.Keys.Contains("item_id"))
{
packChildGachaInfo.UserGoodsId = jsonData5["item_id"].ToLong();
}
if (jsonData5.Keys.Contains("is_daily_single"))
{
packChildGachaInfo.IsDailySingle = jsonData5["is_daily_single"].ToBoolean();
}
else
{
packChildGachaInfo.IsDailySingle = false;
}
packChildGachaInfo.PackCountBuyPer = jsonData5.GetValueOrDefault("daily_free_gacha_count", 0);
packChildGachaInfo.CampaignName = jsonData5.GetValueOrDefault("campaign_name", "");
packChildGachaInfo.AvailableCount = jsonData5.GetValueOrDefault("purchase_limit_count", 0);
packChildGachaInfo.OverrideIncreaseGachaPoint = jsonData5.GetValueOrDefault("override_increase_gacha_point", 0);
if (jsonData5.Keys.Contains("free_gacha_campaign_id"))
{
packChildGachaInfo.FreeGachaCampaignId = jsonData5["free_gacha_campaign_id"].ToInt();
}
packConfig.ChildGachaInfoList.Add(packChildGachaInfo);
}
packConfig.IsPrerelease = jsonData2["is_pre_release"].ToBoolean();
if (packConfig.IsPrerelease)
{
packConfig.PrereleasePurchaseInfo = new PrereleasePurchaseInfo(jsonData2["pre_release_gacha_info"], base.ResponseData["data_headers"]["servertime"].ToDouble());
}
packConfig.SetSpecialPackRewardsList(jsonData2);
Data.PackInfo.dataList.Add(packConfig);
}
if (base.ResponseData["data"].Keys.Contains("pack_first_transition_data"))
{
JsonData jsonData6 = base.ResponseData["data"]["pack_first_transition_data"];
int serialId = jsonData6["serial_id"].ToInt();
int packId = jsonData6["pack_id"].ToInt();
PackFirstTransitionData = new PackFirstTransition(serialId, packId);
}
NeedsFooterBadgeIcon = Data.PackInfo.dataList.Any((PackConfig config) => config.ChildGachaInfoList.Any((PackChildGachaInfo child) => child.AvailableCount > 0));
return num;
}
}