123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- using System;
- using System.Collections.Generic;
- using ET;
- namespace GFGGame
- {
- public class LuckyBoxDataManager : SingletonBase<LuckyBoxDataManager>
- {
- 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 float ANIMATION_TIME = 1.2f; //翻牌获得物品展示时间
- private List<ItemData> _rewardsList;//当前奖励,每次抽奖后刷新
- private Dictionary<int, ItemData> _firstRewardsList = new Dictionary<int, ItemData>();//首次获得的奖励
- private Dictionary<int, List<LuckyBoxBonusData>> _dicShowList = new Dictionary<int, List<LuckyBoxBonusData>>();
- public List<int> luckyBoxIds = new List<int>();//奖池列表
- public int RotatingId = 0;//轮换活动id。0为未开启
- public long startTime = 1668873600000;
- public long endTime = 1672156799000;
- public List<int> KsActivityId = new List<int>(); //活动ids--只存放开启中的许愿池活动id
- public List<bool> VsStatus = new List<bool>(); //true已进行许愿 false未进行许愿
- //存储奖池免费时间,大于存储时间免费
- public Dictionary<int, long> luckyBoxFreeTimeMillDic = new Dictionary<int, long>();
- public int times = 0;
- public int luckyBoxIndex;
- public List<ItemData> 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<int, ItemData> 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];
- }
- }
- 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 = LuckyBoxCfgArray.Instance.GetCfg(boxId);
- if (!_dicShowList.ContainsKey(boxId))
- {
- _dicShowList[boxId] = InitBonusDataList(luckyBoxCfg.dropId);
- }
- }
- private List<LuckyBoxBonusData> InitBonusDataList(int dropId)
- {
- Dictionary<int, LuckyBoxBonusData> dic = new Dictionary<int, LuckyBoxBonusData>();
- AddToBonusDataDic(dropId, dic);
- List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();
- foreach (var t in dic)
- {
- list.Add(t.Value);
- }
- list.Sort(CompareBonusData);
- return list;
- }
- private void AddToBonusDataDic(int dropId, Dictionary<int, LuckyBoxBonusData> dic)
- {
- List<DropOutCfg> cfgs = DropOutCfgArray.Instance.GetCfgsByid(dropId);
- 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 = ItemCfgArray.Instance.GetCfg(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<int, LuckyBoxBonusData> dic)
- {
- dic.TryGetValue(group, out LuckyBoxBonusData luckyBoxBonusData);
- if (luckyBoxBonusData != null)
- {
- return luckyBoxBonusData;
- }
- luckyBoxBonusData = new LuckyBoxBonusData();
- luckyBoxBonusData.id = group;
- BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(group);
- if (bonusListCfg != null)
- {
- luckyBoxBonusData.name = bonusListCfg.name;
- luckyBoxBonusData.order = bonusListCfg.sort;
- }
- else
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(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<LuckyBoxBonusData> GetCurrentShowList(int boxId)
- {
- return _dicShowList[boxId];
- }
- // //获取首次获得的服装的列表
- // public List<ItemData> GetFirstClothingList()
- // {
- // ItemData[] cardArray = new ItemData[LuckyBoxDataManager.Instance.FirstRewardList.Count];
- // LuckyBoxDataManager.Instance.FirstRewardList.Values.CopyTo(cardArray, 0);
- // List<ItemData> cardList = new List<ItemData>(cardArray);
- // return cardList;
- // }
- public void CheckItemEnough(int boxId, int times, Action onSuccess)
- {
- int costId = LuckyBoxCfgArray.Instance.GetCfg(boxId).costID;
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(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)
- {
- AlertUI.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { 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 = ItemExchangeCfgArray.Instance.GetCfg(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
- {
- BuyTipsController.Show(costId, needNum, onSuccess);
- }
- }
- else//购买消耗品的道具不足,提示购买 购买消耗品的道具
- {
- ItemUtil.ExchangeItemById(itemExchangeCfg.costId, costItemNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
- }
- }
- }
- private int GetCostNum(int boxId, int times)
- {
- LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
- if (times == LuckyBoxDataManager.ONCE_TIME)
- {
- return cfg.costNum;
- }
- else if (times == LuckyBoxDataManager.TEN_TIME)
- {
- return cfg.costNumTen;
- }
- 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 = ActivityOpenCfgArray.Instance.GetCfg(activityId);
- long endTime = 0;
- if (activityCfg != null)
- endTime = TimeUtil.DateTimeToTimestamp(activityCfg.endTime);
- long curTime = TimeHelper.ServerNow();
- if (endTime < curTime)
- return false;
- return true;
- }
- }
- }
|