using cfg; using asap.core; using System.Linq; using GameCore; using System.Collections.Generic; using UnityEngine; using System; /// /// Utility to get table data. Can only be used when event is active. /// public class EventLuckMagicTableContext { private FishingEvent _tableEvent; private EventLuckMagic _tableMain; private EventLuckMagicDrop[] _tableBlockDrops; private TbEventLuckMagicLevel _tableRings; private HashSet _roadSignIds; private PlayerItemData _playerItemData; private FishingEventCycleItem3 _tableCycle; private EventPackManager _packData; private Tables _tables; private EventLuckMagicTableContext() { } public static EventLuckMagicTableContext ReadTables(int eventId) { var ctx = new EventLuckMagicTableContext(); ctx._tables = GContext.container.Resolve(); var tables = ctx._tables; var redirectId = tables.TbFishingEvent[eventId].RedirectID; var cycleId = tables.TbFishingEventCycleItem3[redirectId].RedirectID; ctx._tableEvent = tables.TbFishingEvent[eventId]; ctx._tableMain = tables.TbEventLuckMagic[cycleId]; ctx._tableCycle = tables.TbFishingEventCycleItem3[cycleId]; ctx._tableRings = tables.TbEventLuckMagicLevel; ctx._roadSignIds = ctx._tableRings.DataList.Select(x => x.TurnItem).ToHashSet(); ctx._tableBlockDrops = tables.TbEventLuckMagicDrop.DataList.OrderBy(x => x.ID).ToArray(); ctx._playerItemData = GContext.container.Resolve(); ctx._packData = tables.TbEventPackManager[ctx._tableMain.PackId]; return ctx; } public void GetBlocksInfo(out List infos) { infos = new List(); foreach (var bd in _tableBlockDrops) { var info = new EventLuckMagicBlockInfo(); info.RingType = (EEventLuckMagicRingType)(bd.ID / 100 % 10 /* - 1 */); info.Reward = new ItemData(bd.Item, bd.Count); _playerItemData.ItemTransition(info.Reward); info.Weight = bd.Weight; info.TableId = bd.ID; infos.Add(info); } } public void GetRingsInfo(out int[] costs, out int[] roadSignIds) { costs = _tableRings.DataList.Select(x => x.CostNumber).ToArray(); roadSignIds = _tableRings.DataList.Select(x => x.TurnItem).ToArray(); } public bool IsRewardRoadSign(EEventLuckMagicRingType ringType, int rewardId) { if (!_tableRings.DataMap.TryGetValue((int)ringType, out var ring)) { Debug.Log($"[EventLuckMagic] No table data found for ring type {ringType}"); return false; } return ring.TurnItem == rewardId; } public bool IsRewardRoadSign(int rewardId, out int expireDuration, out int drop, out int[] weightConfig) { var res = _roadSignIds.Contains(rewardId); // Debug.Log($"[EventLuckMagic] {res}: {rewardId} is road sign?"); if (res) { var line = _tableRings.DataList.Where(x => x.TurnItem == rewardId).First(); expireDuration = line.TurnTime; drop = line.TurnDrop; weightConfig = line.TurnConfig.ToArray(); } else { expireDuration = 0; drop = 0; weightConfig = null; } return res; } public bool IsRewardProgressItem(int rewardId, int roundCount, out int drop) { var idSeven = _tableMain.TargetRewardItem1; var idHeart = _tableMain.TargetRewardItem2; if (rewardId == idSeven) { drop = GetTaskRewardDropId(roundCount, true); return true; } else if (rewardId == idHeart) { drop = GetTaskRewardDropId(roundCount, false); return true; } drop = 0; return false; } public EEventLuckMagicItemType JudgeItemId(int rewardId) { if (rewardId == _tableMain.TargetRewardItem1) { return EEventLuckMagicItemType.UpperTaskItem; } else if (rewardId == _tableMain.TargetRewardItem2) { return EEventLuckMagicItemType.LowerTaskItem; } return EEventLuckMagicItemType.None; } public bool IsRewardSpecial(int rewardId) { return IsRewardRoadSign(rewardId, out _, out _, out _) || IsRewardProgressItem(rewardId, 0, out _); } public Dictionary GetTaskInfo(int roundCount) { return new Dictionary() { { _tableMain.TargetRewardItem1, _playerItemData.GetItemDataByDropId(_tableMain.TargetRewardDrop1[roundCount < _tableMain.TargetRewardDrop1.Count ? roundCount : _tableMain.TargetRewardDrop1.Count - 1])[0] }, { _tableMain.TargetRewardItem2, _playerItemData.GetItemDataByDropId(_tableMain.TargetRewardDrop2[roundCount < _tableMain.TargetRewardDrop2.Count ? roundCount : _tableMain.TargetRewardDrop2.Count - 1])[0] }, }; } public int GetTicketRedPointThreshold() { return _tableCycle.RedDot; } public Tuple GetEventStartTimeAndEndTime() { try { var et = System.DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime); var st = System.DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).StartTime); return new Tuple(st, et); } catch (System.Exception e) { Debug.LogError(e); return new Tuple(System.DateTime.MinValue, System.DateTime.MinValue); } } public EventChainPackInfo GetChainPackInfo() { var chianList = GContext.container.Resolve().TbEventPackManager[_tableMain.PackId].VIPPackList[0]; var expireTime = new System.DateTime(); try { expireTime = System.DateTime.Parse((_tableEvent.TimeDefinition as LimitedTime).EndTime); } catch (System.Exception e) { Debug.Log($"[EventLuckMagic] {e.Message}\n{e.StackTrace}"); return null; } var chainListIdSet = chianList.ToHashSet(); var packs = GContext.container.Resolve().TbPack.DataList.Where(p => chainListIdSet.Contains(p.ID)).ToArray();//? return new EventChainPackInfo() { ChainList = chianList, ExpireTime = expireTime, Packs = packs, RedPointKey = "eventluckmagic.pack" }; } public int GetWelcomeGift() { return _tableCycle.WelcomeGift; } public LackOfCommonItemPopupPanelInfo GetLackOfTicketPanelInfo() { var res = new LackOfCommonItemPopupPanelInfo(); res.reward = new ItemData(_tableMain.Item, _tableMain.BuyCount); res.Cost = _tableMain.Price; res.CurrencyId = 1005; return res; } public EventLuckMagicInfo GetInfoPanelInfo() { var res = new EventLuckMagicInfo(); GetBlocksInfo(out var list); res.Blocks = list .Where(b => b.RingType == EEventLuckMagicRingType.InnerRing) .Select(b => b.Reward) .ToArray(); res.TaskRewardUpper = _playerItemData.GetItemDataByDropId(GetTaskRewardDropId(0, true))[0]; res.TaskRewardLower = _playerItemData.GetItemDataByDropId(GetTaskRewardDropId(0, false))[0]; res.TicketNameKey = GContext.container.Resolve().TbItem[_tableMain.Item].Name_l10n_key; return res; } public string GetIcon() { return _tableMain.Icon; } /// /// Get the right reward drop Id for the right task in the right round /// /// Starts at 0 /// Upper or Lower task /// the drop id public int GetTaskRewardDropId(int roundCount, bool isUpperTask) { List rewardDropIdList; rewardDropIdList = isUpperTask ? _tableMain.TargetRewardDrop1 : _tableMain.TargetRewardDrop2; return rewardDropIdList[roundCount < rewardDropIdList.Count ? roundCount : rewardDropIdList.Count - 1]; } public ItemData GetTaskReward(int roundCount, bool isUpperTask) { return _playerItemData.GetItemDataByDropId(GetTaskRewardDropId(roundCount, isUpperTask))[0]; } public List GetFirstLuckyTaskIdList() { return _tableMain.TaskRound1; } public List GetLastLuckyTaskIdList() { return _tableMain.TaskRound2; } public int GetPackId() { return _tableMain.PackId; } public int EventId => _tableEvent.ID; public int PackId => _tableMain.PackId; public EventLuckMagicPanelUrlData GetUiPanelUrls() { var res = new EventLuckMagicPanelUrlData(); res.TriplePackPanelUrl = _packData.Panel; return res; } } public class EventLuckMagicBlockInfo { public EEventLuckMagicRingType RingType { get; set; } public ItemData Reward { get; set; } public int Weight { get; set; } public int TableId { get; set; } } public enum EEventLuckMagicItemType { UpperTaskItem, LowerTaskItem, None } public class EventLuckMagicPanelUrlData { public string TriplePackPanelUrl{ get; set; } }