using System; using System.Collections.Generic; using ET; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; using YooAsset; using GFGGame.Launcher; using System.Collections; using System.Linq; using cfg.GfgCfg; namespace GFGGame { public class LuckyBoxDataManager : SingletonBase { public const int BOX_ID_2 = 2; //常驻奖池2 public const int BOX_ID_3 = 3; //常驻奖池2 public const int ONCE_TIME = 1; public const int TEN_TIME = 10; public const int FIFTY_TIME = 50; public const float ANIMATION_TIME = 1.2f; //翻牌获得物品展示时间 public bool CHECK_TIPS_OPEN = false; //提示弹窗是否打开 public bool OPEN_LUCKY_DISCONT = false; //抽奖满20次幸运折扣弹窗是否打开 private List _rewardsList; //当前奖励,每次抽奖后刷新 private Dictionary _firstRewardsList = new Dictionary(); //首次获得的奖励 private Dictionary> _dicShowList = new Dictionary>(); public List luckyBoxIds = new List(); //奖池列表 public int RotatingId = 0; //轮换活动id。0为未开启 public long startTime = 1668873600000; public long endTime = 1672156799000; public List KsActivityId = new List(); //活动ids--只存放开启中的许愿池活动id public List VsStatus = new List(); //true已进行许愿 false未进行许愿 //存储奖池免费时间,大于存储时间免费 public Dictionary luckyBoxFreeTimeMillDic = new Dictionary(); //存储奖池摘星次数 public Dictionary luckyBoxPlayTimesDic = new Dictionary(); public int luckyBoxIndex; public GameObject _ui = null; public AssetOperationHandle handle = null; public RawFileOperationHandle videoHandle = null; public List BlindBoxReward = new List(); public List RewardList { get { return _rewardsList; } set { _rewardsList = value; _firstRewardsList.Clear(); int dicIndex = 0; foreach (ItemData itemData in _rewardsList) { if (ItemDataManager.GetItemNum(itemData.id) == 1) { _firstRewardsList.Add(dicIndex, itemData); } dicIndex++; } } } public Dictionary FirstRewardList { get { return _firstRewardsList; } set { _firstRewardsList = value; } } private int _currentBoxId = 2; public int currentBoxId { get { return _currentBoxId; } set { if (_currentBoxId != value) { _currentBoxId = value; // InitData(_currentBoxId); } } } public void InitServerData(S2C_GetLuckyBoxInfo response) { luckyBoxFreeTimeMillDic.Clear(); int count = response.KsLuckyBoxId.Count; for (var i = 0; i < count; i++) { luckyBoxFreeTimeMillDic[response.KsLuckyBoxId[i]] = response.VsFreeTime[i]; } luckyBoxPlayTimesDic.Clear(); count = response.KsPlayedId.Count; for (var i = 0; i < count; i++) { luckyBoxPlayTimesDic[response.KsPlayedId[i]] = response.VsPlayedTimes[i]; } } public void UpdatePlayTimes(int luckyBoxId, long playTimes) { luckyBoxPlayTimesDic.TryGetValue(luckyBoxId, out long times); times += playTimes; luckyBoxPlayTimesDic[luckyBoxId] = times; } public long GetPlayTimes(int luckyBoxId) { luckyBoxPlayTimesDic.TryGetValue(luckyBoxId, out long times); return times; } public void UpdateFreeTime(int luckyBoxId, long freeTimeMill) { luckyBoxFreeTimeMillDic[luckyBoxId] = freeTimeMill; EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_FREE_TIME_CHANGED); } //返回奖池免费时间,如果是0,则不免费,大约0并且当前时间大于存储时间则免费 public long GetFreeTime(int luckyBoxId) { luckyBoxFreeTimeMillDic.TryGetValue(luckyBoxId, out var freeTime); return freeTime; } public void InitData(int boxId) { LuckyBoxCfg luckyBoxCfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId); if (!_dicShowList.ContainsKey(boxId)) { _dicShowList[boxId] = InitBonusDataList(luckyBoxCfg.DropId); } } private List InitBonusDataList(int dropId) { Dictionary dic = new Dictionary(); AddToBonusDataDic(dropId, dic); List list = new List(); foreach (var t in dic) { list.Add(t.Value); } list.Sort(CompareBonusData); return list; } private void AddToBonusDataDic(int dropId, Dictionary dic) { List cfgs = CommonDataManager.Tables.TblDropOutCfg.DataList.Where(a => a.Id == dropId).ToList(); if (cfgs == null) { return; } foreach (DropOutCfg cfg in cfgs) { if (cfg.Item > ConstItemID.MAX_ITEM_ID) //掉落id { AddToBonusDataDic(cfg.Item, dic); } else { var group = cfg.Group; if (cfg.Group <= 0) { ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(cfg.Item); if (itemCfg == null || itemCfg.SuitId <= 0) { continue; } group = itemCfg.SuitId; } LuckyBoxBonusData luckyBoxBonusData = GetBonusData(group, dic); if (luckyBoxBonusData == null) { continue; } luckyBoxBonusData.itemList.Add(ItemUtil.createItemData(cfg.Item, 1)); } } } private LuckyBoxBonusData GetBonusData(int group, Dictionary dic) { dic.TryGetValue(group, out LuckyBoxBonusData luckyBoxBonusData); if (luckyBoxBonusData != null) { return luckyBoxBonusData; } luckyBoxBonusData = new LuckyBoxBonusData(); luckyBoxBonusData.id = group; BonusListCfg bonusListCfg = CommonDataManager.Tables.TblBonusListCfg.GetOrDefault(group); if (bonusListCfg != null) { luckyBoxBonusData.name = bonusListCfg.Name; luckyBoxBonusData.order = bonusListCfg.Sort; } else { SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(group); if (suitCfg == null) { return null; } luckyBoxBonusData.name = suitCfg.Name; luckyBoxBonusData.order = 9999; } dic.Add(group, luckyBoxBonusData); return luckyBoxBonusData; } public int CompareBonusData(LuckyBoxBonusData a, LuckyBoxBonusData b) { if (b.order < a.order) { return 1; } if (b.order > a.order) { return -1; } return a.id - b.id; } public void GetOwnedCount(int boxId, out int count, out int totalCount) { count = 0; totalCount = 0; foreach (LuckyBoxBonusData luckyBoxBonusData in _dicShowList[boxId]) { foreach (ItemData itemData in luckyBoxBonusData.itemList) { if (ItemDataManager.GetItemNum(itemData.id) > 0) { count++; } totalCount++; } } } public List GetCurrentShowList(int boxId) { return _dicShowList[boxId]; } // //获取首次获得的服装的列表 // public List GetFirstClothingList() // { // ItemData[] cardArray = new ItemData[LuckyBoxDataManager.Instance.FirstRewardList.Count]; // LuckyBoxDataManager.Instance.FirstRewardList.Values.CopyTo(cardArray, 0); // List cardList = new List(cardArray); // return cardList; // } public void CheckItemEnough(int boxId, int times, Action onSuccess) { int costId = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId).CostID; ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(costId); int costNum = GetCostNum(boxId, times); long hasNum = ItemDataManager.GetItemNum(itemCfg.Id); long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId); if (freeTime > 0 && freeTime < TimeHelper.ServerNow() && times == LuckyBoxDataManager.ONCE_TIME) { onSuccess(); } else if (hasNum >= costNum) { if (LuckyBoxDataManager.Instance.CHECK_TIPS_OPEN == false) AlertUI.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.Name, times)).SetLeftButton(true) .SetRightButton(true, "确定", (object data) => { onSuccess(); }).SetShowCheck(true); else onSuccess(); } else { long needNum = costNum - hasNum; // ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(costId, ItemDataManager.GetItemExchangeTimes(costId), times, out int costItemId, out int costItemNeedNum, out int buyNum); ItemExchangeCfg itemExchangeCfg = CommonDataManager.Tables.TblItemExchangeCfg.GetOrDefault(costId); int exchangedTimes = ItemDataManager.GetItemExchangeTimes(costId); int costItemNeedNum = 0; int costbuyNum = 0; int buyNum = 0; for (var i = exchangedTimes + 1; i <= exchangedTimes + times; i++) { ItemExchangeCfgArray.Instance.GetCostAndBuyNum(itemExchangeCfg, i, out int _costNum, out int _buyNum); costItemNeedNum += _costNum; costbuyNum += _buyNum; buyNum += itemExchangeCfg.Num; if (buyNum >= needNum) break; } long costHasNum = ItemDataManager.GetItemNum(itemExchangeCfg.CostId); if (costHasNum >= costItemNeedNum) //购买消耗品的道具足够,提示购买 { if (costId == ConstItemID.GOLD) { ItemUtil.ExchangeItemById(costId, needNum, false, onSuccess); } else { if (LuckyBoxDataManager.Instance.CHECK_TIPS_OPEN == false) BuyTipsController.Show(costId, needNum, onSuccess, true); else { OnBuyItem(costId, needNum, onSuccess); } } } else //购买消耗品的道具不足,提示购买 购买消耗品的道具 { ItemUtil.ExchangeItemById(itemExchangeCfg.CostId, costItemNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true); } } } private async void OnBuyItem(int itemId, long count, Action onSuccess = null) { var _result = await ItemExchangeSProxy.ItemExchange(itemId, count); if (_result) BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(itemId, count), onSuccess); } private int GetCostNum(int boxId, int times) { LuckyBoxCfg cfg = CommonDataManager.Tables.TblLuckyBoxCfg.GetOrDefault(boxId); if (times == LuckyBoxDataManager.ONCE_TIME) { return cfg.CostNum; } else if (times == LuckyBoxDataManager.TEN_TIME) { return cfg.CostNumTen; } else if (times == LuckyBoxDataManager.FIFTY_TIME) { return cfg.CostNumfifty; } return 0; } public bool RedBtnLeft(int curIndex) { int index = curIndex - 1; for (int i = index; i >= BOX_ID_2 - 1; i--) { int boxId = LuckyBoxDataManager.Instance.luckyBoxIds[i]; long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId); if (freeTime > 0 && freeTime - TimeHelper.ServerNow() < 0) return true; if (index == 1 && RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy)) return true; } return false; } public bool RedBtnRight(int curIndex) { var luckyBoxIds = LuckyBoxDataManager.Instance.luckyBoxIds; for (int i = curIndex + 1; i < luckyBoxIds.Count; i++) { int boxId = luckyBoxIds[i]; long freeTime = LuckyBoxDataManager.Instance.GetFreeTime(boxId); if (freeTime > 0 && freeTime - TimeHelper.ServerNow() < 0) return true; if (curIndex == 1 && RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy)) return true; } return false; } //天市垣开服活动是否开启 public bool GetActLimitTsyOpen() { int activityId = ActivityDataManager.Instance.GetCurOpenActiveByType(ConstLimitTimeActivityType.ActLimitTsy); var activityCfg = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(activityId); long endTime = 0; if (activityCfg != null) endTime = TimeUtil.DateTimeToTimestamp(activityCfg.EndTime); long curTime = TimeHelper.ServerNow(); if (endTime < curTime) return false; return true; } } }