| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 | using System;using System.Collections;using System.Collections.Generic;using UnityEngine;namespace GFGGame{    public class LuckyBoxDataManager : SingletonBase<LuckyBoxDataManager>    {        public const int BOX_ID_1 = 1;        public const int BOX_ID_2 = 2;        public const int BOX_ID_3 = 3;        public const int ONCE_TIME = 1;        public const int TEN_TIME = 10;        private List<ItemData> _rewardsList;//当前奖励,每次抽奖后刷新        private Dictionary<int, ItemData> _firstRewardsList = new Dictionary<int, ItemData>();//首次获得的奖励        public string probShow;        private List<LuckyBoxBonusData> _showList;        public int[] luckyBoxIds = new int[] { 1, 2, 3 };//奖池列表        public int startTime = 1635157620;        public int endTime = 1704038400;        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;        public int currentBoxId        {            get            {                return _currentBoxId;            }            set            {                if (_currentBoxId != value)                {                    _currentBoxId = value;                    InitData(_currentBoxId);                }            }        }        private void InitData(int boxId)        {            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            probShow = luckyBoxCfg.probShow;            _showList = GetBonusDataList(luckyBoxCfg.bonusShowArr);        }        private List<LuckyBoxBonusData> GetBonusDataList(int[] idsList)        {            List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();            foreach (int id in idsList)            {                BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(id);                LuckyBoxBonusData luckyBoxBonusData = new LuckyBoxBonusData();                luckyBoxBonusData.id = id;                luckyBoxBonusData.name = bonusListCfg.name;                luckyBoxBonusData.itemList = ItemUtil.CreateItemDataList(bonusListCfg.bonusListArr);                list.Add(luckyBoxBonusData);            }            return list;        }        public int GetOwnedCount()        {            int count = 0;            foreach (LuckyBoxBonusData luckyBoxBonusData in _showList)            {                foreach (ItemData itemData in luckyBoxBonusData.itemList)                {                    if (ItemDataManager.GetItemNum(itemData.id) > 0)                    {                        count++;                    }                }            }            return count;        }        public List<LuckyBoxBonusData> GetCurrentShowList()        {            return _showList.GetRange(0, _showList.Count);        }        //获取首次获得的服装的列表        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);            int hasNum = ItemDataManager.GetItemNum(itemCfg.id);            if (hasNum >= costNum)            {                Alert.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });            }            else            {                int needNum = costNum - hasNum;                ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(costId, ItemDataManager.GetItemExchangeTimes(costId), needNum, out int costItemId, out int costItemNeedNum, out int buyNum);                int costHasNum = ItemDataManager.GetItemNum(costItemId);                if (costHasNum >= costItemNeedNum)//购买消耗品的道具足够,提示购买                {                    if (costId == ConstItemID.GOLD)                    {                        ItemUtil.ExchangeItemById(costId, needNum, false, onSuccess);                    }                    else                    {                        BuyTipsController.Show(costId, needNum, onSuccess);                    }                }                else//购买消耗品的道具不足,提示购买 购买消耗品的道具                {                    ItemUtil.ExchangeItemById(costItemId, 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;        }    }}
 |