using System.Collections.Generic; using cfg; using asap.core; using GameCore; using System.Linq; using UnityEngine; using System; using UnityEngine.Assertions; using System.ComponentModel; public class EventBingoTableContext { private readonly EventBingoInit _tableInit; private readonly TbEventBingoMiniDrop _tableMiniDrop; private readonly PlayerItemData _playerItemData; private readonly TbEventBingoMain _tableMain; private readonly FishingEvent _tableEvent; private readonly FishingEventCycleItem _tableCycleItem; private readonly TbEventBingoRoundInit _tableRoundInit; public EventBingoTableContext(int eventId) { _playerItemData = GContext.container.Resolve(); _tableEvent = GContext.container.Resolve().TbFishingEvent[eventId]; var redirectId = _tableEvent.RedirectID; _tableCycleItem = GContext.container.Resolve().TbFishingEventCycleItem[redirectId]; var cycleId = _tableCycleItem.RedirectID; _tableInit = GContext.container.Resolve().TbEventBingoInit[cycleId]; _tableMiniDrop = GContext.container.Resolve().TbEventBingoMiniDrop; _tableMain = GContext.container.Resolve().TbEventBingoMain; _tableRoundInit = GContext.container.Resolve().TbEventBingoRoundInit; } public void GetMinorDropData(System.Random rng, out List reachableRewards, out List unreachableRewards) { reachableRewards = new List(); unreachableRewards = new List(); var dropStrat = FtUtils.PickRandomItemWithWeight(_tableMiniDrop.DataList, rng, x => _tableMiniDrop.DataList[x].Weight); Assert.IsTrue(dropStrat.DropCount == dropStrat.MiniDropCount1 + dropStrat.MiniDropCount2 && dropStrat.DropCount <= dropStrat.Count, $"[EventBingo] dropStrat {dropStrat.Id} invalid."); Debug.Log($"[EventBingo] MiniDropId: {dropStrat.Id}."); int i = 0; while (i < dropStrat.MiniDropCount1) { reachableRewards.Add(new ItemData(dropStrat.MiniItem1, 1)); i++; } while (i < dropStrat.DropCount) { reachableRewards.Add(new ItemData(dropStrat.MiniItem2, 1)); i++; } while (i < dropStrat.Count) { var reward = _playerItemData.GetRandomItemDataByDropId(rng, dropStrat.DropID); if (reward != null) unreachableRewards.Add(reward); else Debug.LogWarning($"[EventBingo] MiniDrop reward not found for drop Id {dropStrat.DropID}."); i++; } } public int PickSeed(int roundCount, int? lordOfSeeds = null, int notThisSeed = -1) { System.Random rng; if (lordOfSeeds != null) rng = new System.Random(lordOfSeeds.Value); else rng = new System.Random(); roundCount += 1; var roundInfo = GetRoundInfo(roundCount); var seedSetupIndex = FtUtils.PickRandomItemWithWeight(roundInfo.SeedList, rng, idx => roundInfo.Weight[idx]); var seedSetup = _tableMain[seedSetupIndex]; var seedList = seedSetup.SeedID.OrderBy(x => rng.Next()).ToList(); var res = seedList.FirstOrDefault(x => x != notThisSeed); Debug.Log($"[EventBingo] Selected seed: {res}."); return res; } public (int seed, int bingo) PickSeedValidation(int roundCount, int? lordOfSeeds = null) { System.Random rng; if (lordOfSeeds != null) rng = new System.Random(lordOfSeeds.Value); else rng = new System.Random(); roundCount += 1; var roundInfo = GetRoundInfo(roundCount); var seedSetupIndex = FtUtils.PickRandomItemWithWeight(roundInfo.SeedList, rng, idx => roundInfo.Weight[idx]); var seedSetup = _tableMain[seedSetupIndex]; var seedList = seedSetup.SeedID.OrderBy(x => rng.Next()).ToList(); var res = seedList.First(); Debug.Log($"[EventBingo] Selected seed: {res}."); return (res, seedSetup.BingoType); } public void GetRandomItemIcon(out int iconIdx, out string iconUrl) { var urlList = _tableInit.ItemResource; iconIdx = UnityEngine.Random.Range(0, urlList.Count); iconUrl = urlList[iconIdx]; } public string GetItemIconByIdx(int iconId) { var urlList = _tableInit.ItemResource; if (iconId < 0 || iconId >= urlList.Count) return urlList[0]; return urlList[iconId]; } public List GetBingoRewards(int bingo, int roundCount) { roundCount += 1; var roundInfo = GetRoundInfo(roundCount); var dropId = roundInfo.Drop[bingo - 1]; var model = GContext.container.Resolve(); return _playerItemData.GetItemDataByDropIdLureInflation(model.InflationRate, dropId); } public Tuple GetTimeLimit() { try { var et = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime); var st = DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).StartTime); return new Tuple(st, et); } catch (Exception e) { Debug.Log($"[EventBingo] Time Parse Error:"); Debug.LogError(e); return new Tuple(DateTime.MinValue, DateTime.MinValue); } } public string GetEntranceIcon() { return _tableInit.Icon; } public int GetRedPointThreshold() { return _tableCycleItem.RedDot; } public int GetWelcomeGift() { return _tableCycleItem.WelcomeGift; } public EventBingoUiData GetUiData() { return new EventBingoUiData() { NeoNormalPackPanel = GContext.container.Resolve().TbEventPackManager[_tableInit.PackId].Panel, InfoPanel = _tableInit.InfoPanel }; } public int GetPackId() { return _tableInit.PackId; } public string GetPackPanel() { return "";//_tableInit.PackPanel; } public string GetNumberSfxUrl(int number) { var res = GContext.container.Resolve().TbEventBingoVoice.DataMap.TryGetValue(number, out var s); if (res) return s.Count; else { Debug.LogWarning($"[EventBingo] Number {number} is not included in voice resource table"); return ""; } } public string GetTicketNameKey() { var ticketId = _tableCycleItem.ItemId; return GContext.container.Resolve().TbItem.Get(ticketId).Name_l10n_key; } private EventBingoRoundInit GetRoundInfo(int roundCount) { var roundInfoList = _tableInit.BingoTypeID.Select(id => _tableRoundInit[id]); try { return roundInfoList.First(i => i.Round.Contains(roundCount)); } catch { return roundInfoList.Last(); } } public int GetBattlePassId() { return _tableInit.BattlePassID; } }