using System.Collections.Generic; using cfg; using asap.core; using GameCore; using System.Linq; using UnityEngine; using System; using UnityEngine.Assertions; public class EventBingoTableContext { private readonly EventBingoInit _tableInit; private readonly TbEventBingoMiniDrop _tableMiniDrop; private readonly PlayerItemData _playerItemData; private readonly TbEventBingoMain _tableMain; private readonly TbEventBingoCollectingTarget _tableTask; private readonly TbEventBingoConfig _tableConfig; private readonly FishingEvent _tableEvent; private readonly FishingEventCycleItem _tableCycleItem; 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; _tableTask = GContext.container.Resolve().TbEventBingoCollectingTarget; _tableConfig = GContext.container.Resolve().TbEventBingoConfig; } public void GetMinorDropData(System.Random rng, out List reachableRewards, out List unreachableRewards) { reachableRewards = new List(); unreachableRewards = new List(); var dropStrat = FtMathUtils.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(); var initSeedPools = GContext.container.Resolve().TbEventBingoConfig.DataMap; roundCount += 1; if (initSeedPools.Keys.Contains(roundCount)) { var pool = initSeedPools[roundCount].SeedID; var seed = pool[rng.Next(pool.Count)]; Debug.Log($"[EventBingo] Pick init seed{seed} in round {roundCount}"); return seed; } var seedSetup = FtMathUtils.PickRandomItemWithWeight(_tableMain.DataList, rng, idx => _tableMain.DataList[idx].Weight); 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(); var initSeedPools = GContext.container.Resolve().TbEventBingoConfig.DataMap; roundCount += 1; if (initSeedPools.Keys.Contains(roundCount)) { var pool = initSeedPools[roundCount].SeedID; var seed = pool[rng.Next(pool.Count)]; Debug.Log($"[EventBingo] Pick init seed{seed} in round {roundCount}"); return (seed, 0); } var seedSetup = FtMathUtils.PickRandomItemWithWeight(_tableMain.DataList, rng, idx => _tableMain.DataList[idx].Weight); var seedList = seedSetup.SeedID.OrderBy(x => rng.Next()).ToList(); var res = seedList.FirstOrDefault(); 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 EventBingoProgressTaskData GetTaskData() { return GetTaskData(_tableInit.TargetID); } public EventBingoProgressTaskData GetTaskData(int taskId, int progress = 0) { var task = _tableTask.GetOrDefault(taskId); if (task == null) { Debug.LogError($"[EventBingo] Task not found: {taskId}."); return null; } return new EventBingoProgressTaskData { TaskId = taskId, Progress = progress, Reward = _playerItemData.GetItemDataByDropId(task.DropID)[0], TargetProgress = task.TokenRequired, NextTaskId = task.NextTask }; } public int GetTaskRewardDropId(int taskId) { return _tableTask.Get(taskId).DropID; } public List GetBingoRewards(int bingo, int roundCount) { var bingoId = _tableInit.BingoTypeID[bingo - 1]; var bingoConfig = _tableMain.GetOrDefault(bingoId); // var initRoundCount = _tableConfig.DataList.Count; var roundConfigCount = bingoConfig.DropID.Count; // var bingoRewardConfigIdx = (roundCount - initRoundCount) % roundConfigCount; var bingoRewardConfigIdx = roundCount % roundConfigCount; bingoRewardConfigIdx = Mathf.Max(0, bingoRewardConfigIdx); var dropId = bingoConfig.DropID[bingoRewardConfigIdx]; return _playerItemData.GetItemDataByDropId(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() { ChainPackPanel = _tableInit.ChainPackPanel, InfoPanel = _tableInit.InfoPanel }; } public int GetPackId() { return _tableInit.PackId; } public ItemData GetProgressTaskFinalReward() { var firstTask = _tableInit.TargetID; EventBingoCollectingTarget lastTask = null; foreach (var task in _tableTask.DataList) { if (task.NextTask == firstTask) { lastTask = task; break; } } if (lastTask == null) { Debug.LogWarning("[EventBingo] No final reward found."); return null; } return _playerItemData.GetItemDataByDropId(lastTask.DropID)[0]; } 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; } }