| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 | using System.Collections.Generic;using UnityEngine;using System;namespace GFGGame{    public class LuckyBoxBonusDataCache    {        private static int _currentBoxId;        private static int _currentSelectId;        public static int currentBoxId        {            get            {                return _currentBoxId;            }            set            {                if (_currentBoxId != value)                {                    _currentBoxId = value;                    InitData(_currentBoxId);                }            }        }        public static int currentSelectId        {            get            {                return _currentSelectId;            }            set            {                _currentSelectId = value;            }        }        public static string probShow;        private static List<LuckyBoxBonusData> _showList;        private static int _dropOutId;        private static int _dropId;        public static 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 static List<LuckyBoxBonusData> GetCurrentShowList()        {            return _showList.GetRange(0, _showList.Count);        }        public static List<ItemData> GetBonusList(int count, bool isGuide = false)        {            List<ItemData> bonusList = null;            if (isGuide)            {                List<ItemData> guideBonusList = ItemUtil.CreateItemDataList("10070*1;10071*1;10072*1");                count = count - guideBonusList.Count;                bonusList = DropOutDataCache.GetDropItemDatas(_dropOutId, count);                while (guideBonusList.Count > 1)                {                    ItemData itemData = guideBonusList[0];                    guideBonusList.RemoveAt(0);                    int index = UnityEngine.Random.Range(0, bonusList.Count);                    bonusList.Insert(index, itemData);                }                bonusList.Add(guideBonusList[0]);            }            else            {                bonusList = DropOutDataCache.GetDropItemDatas(_dropOutId, count);            }            int dicIndex = 0;            LuckyBoxDataManager.Instance.FirstRewardList.Clear();            foreach (ItemData itemData in bonusList)            {                if (ItemDataManager.GetItemNum(itemData.id) == 0)                {                    LuckyBoxDataManager.Instance.FirstRewardList.Add(dicIndex, itemData);                }                ItemDataManager.Add(itemData.id, itemData.num);                dicIndex++;            }            ItemDataManager.Add(_dropId, count);            //100¸öÐÇм»»1¸öÂäÐÇʯ            LuckyBoxCfg boxCfg0 = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[0]);            LuckyBoxCfg boxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[1]);            int itemCount = ItemDataManager.GetItemNum(boxCfg0.drop);            if (_dropId == boxCfg0.drop && itemCount >= 100)            {                ItemDataManager.Add(boxCfg1.drop, itemCount / 100);                ItemDataManager.Remove(_dropId, itemCount / 100 * 100);            }            GetSuitItemController.TryShow(0);            return bonusList;        }        private static void InitData(int boxId)        {            LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);            probShow = luckyBoxCfg.probShow;            _showList = GetBonusDataList(luckyBoxCfg.bonusShowArr);            _dropOutId = luckyBoxCfg.bonus;            _dropId = luckyBoxCfg.drop;        }        private static 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 static void CheckItemEnough(int itemId, int count, int times, Action onSuccess)        {            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);            int hasNum = ItemDataManager.GetItemNum(itemCfg.id);            if (hasNum >= count)//????            {                Alert.Show(string.Format("是否花费{0}个{1}摘星{2}次?", count, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });            }            else            {                CurrencyRatioCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(itemId);                int costHasNum = ItemDataManager.GetItemNum(currencyRatioCfg.costId);                int costNeedNum = ItemUtil.GetCostItemCount(itemId, count - hasNum);                if (costHasNum >= costNeedNum)                {                    if (itemId == ConstItemID.GOLD)                    {                        ItemUtil.ExchangeItemById(itemId, count - hasNum, false, onSuccess);                    }                    else                    {                        BuyTipsController.Show(itemId, count - hasNum, currencyRatioCfg.costId, costNeedNum, onSuccess);                    }                }                else                {                    ItemUtil.ExchangeItemById(currencyRatioCfg.costId, costNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);                }            }        }    }}
 |