LuckyBoxDataManager.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class LuckyBoxDataManager : SingletonBase<LuckyBoxDataManager>
  8. {
  9. public const int BOX_ID_1 = 1;
  10. public const int BOX_ID_2 = 2;
  11. public const int BOX_ID_3 = 3;
  12. public const int ONCE_TIME = 1;
  13. public const int TEN_TIME = 10;
  14. private List<ItemData> _rewardsList;//当前奖励,每次抽奖后刷新
  15. private Dictionary<int, ItemData> _firstRewardsList = new Dictionary<int, ItemData>();//首次获得的奖励
  16. private Dictionary<int, List<LuckyBoxBonusData>> _dicShowList = new Dictionary<int, List<LuckyBoxBonusData>>();
  17. public int[] luckyBoxIds = new int[] { 2, 3 };//奖池列表
  18. public long startTime = 1635157620;
  19. public long endTime = 1704038400;
  20. public int times = 0;
  21. public int luckyBoxId;
  22. public List<ItemData> RewardList
  23. {
  24. get { return _rewardsList; }
  25. set
  26. {
  27. _rewardsList = value;
  28. _firstRewardsList.Clear();
  29. int dicIndex = 0;
  30. foreach (ItemData itemData in _rewardsList)
  31. {
  32. if (ItemDataManager.GetItemNum(itemData.id) == 1)
  33. {
  34. _firstRewardsList.Add(dicIndex, itemData);
  35. }
  36. dicIndex++;
  37. }
  38. }
  39. }
  40. public Dictionary<int, ItemData> FirstRewardList
  41. {
  42. get { return _firstRewardsList; }
  43. set { _firstRewardsList = value; }
  44. }
  45. private int _currentBoxId;
  46. public int currentBoxId
  47. {
  48. get
  49. {
  50. return _currentBoxId;
  51. }
  52. set
  53. {
  54. if (_currentBoxId != value)
  55. {
  56. _currentBoxId = value;
  57. // InitData(_currentBoxId);
  58. }
  59. }
  60. }
  61. public void InitData(int boxId)
  62. {
  63. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  64. if (!_dicShowList.ContainsKey(boxId))
  65. {
  66. _dicShowList[boxId] = GetBonusDataList(luckyBoxCfg.bonusShowArr);
  67. }
  68. // _showList = GetBonusDataList(luckyBoxCfg.bonusShowArr);
  69. }
  70. private List<LuckyBoxBonusData> GetBonusDataList(int[] idsList)
  71. {
  72. List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();
  73. foreach (int id in idsList)
  74. {
  75. BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(id);
  76. LuckyBoxBonusData luckyBoxBonusData = new LuckyBoxBonusData();
  77. luckyBoxBonusData.id = id;
  78. luckyBoxBonusData.name = bonusListCfg.name;
  79. luckyBoxBonusData.itemList = ItemUtil.CreateItemDataList(bonusListCfg.bonusListArr);
  80. list.Add(luckyBoxBonusData);
  81. }
  82. return list;
  83. }
  84. public int GetOwnedCount(int boxId)
  85. {
  86. int count = 0;
  87. foreach (LuckyBoxBonusData luckyBoxBonusData in _dicShowList[boxId])
  88. {
  89. foreach (ItemData itemData in luckyBoxBonusData.itemList)
  90. {
  91. if (ItemDataManager.GetItemNum(itemData.id) > 0)
  92. {
  93. count++;
  94. }
  95. }
  96. }
  97. return count;
  98. }
  99. public List<LuckyBoxBonusData> GetCurrentShowList(int boxId)
  100. {
  101. return _dicShowList[boxId];
  102. }
  103. // //获取首次获得的服装的列表
  104. // public List<ItemData> GetFirstClothingList()
  105. // {
  106. // ItemData[] cardArray = new ItemData[LuckyBoxDataManager.Instance.FirstRewardList.Count];
  107. // LuckyBoxDataManager.Instance.FirstRewardList.Values.CopyTo(cardArray, 0);
  108. // List<ItemData> cardList = new List<ItemData>(cardArray);
  109. // return cardList;
  110. // }
  111. public void CheckItemEnough(int boxId, int times, Action onSuccess)
  112. {
  113. int costId = LuckyBoxCfgArray.Instance.GetCfg(boxId).costID;
  114. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(costId);
  115. int costNum = GetCostNum(boxId, times);
  116. int hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  117. if (hasNum >= costNum)
  118. {
  119. AlertUI.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });
  120. }
  121. else
  122. {
  123. int needNum = costNum - hasNum;
  124. // ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(costId, ItemDataManager.GetItemExchangeTimes(costId), times, out int costItemId, out int costItemNeedNum, out int buyNum);
  125. ItemExchangeCfg itemExchangeCfg = ItemExchangeCfgArray.Instance.GetCfg(costId);
  126. int exchangedTimes = ItemDataManager.GetItemExchangeTimes(costId);
  127. int costItemNeedNum = 0;
  128. int costbuyNum = 0;
  129. int buyNum = 0;
  130. for (var i = exchangedTimes + 1; i <= exchangedTimes + times; i++)
  131. {
  132. ItemExchangeCfgArray.Instance.GetCostAndBuyNum(itemExchangeCfg, i, out int _costNum, out int _buyNum);
  133. costItemNeedNum += _costNum;
  134. costbuyNum += _buyNum;
  135. buyNum += itemExchangeCfg.num;
  136. if (buyNum >= needNum) break;
  137. }
  138. int costHasNum = ItemDataManager.GetItemNum(itemExchangeCfg.costId);
  139. if (costHasNum >= costItemNeedNum)//购买消耗品的道具足够,提示购买
  140. {
  141. if (costId == ConstItemID.GOLD)
  142. {
  143. ItemUtil.ExchangeItemById(costId, needNum, false, onSuccess);
  144. }
  145. else
  146. {
  147. BuyTipsController.Show(costId, needNum, onSuccess);
  148. }
  149. }
  150. else//购买消耗品的道具不足,提示购买 购买消耗品的道具
  151. {
  152. ItemUtil.ExchangeItemById(itemExchangeCfg.costId, costItemNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
  153. }
  154. }
  155. }
  156. private int GetCostNum(int boxId, int times)
  157. {
  158. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  159. if (times == LuckyBoxDataManager.ONCE_TIME)
  160. {
  161. return cfg.costNum;
  162. }
  163. else if (times == LuckyBoxDataManager.TEN_TIME)
  164. {
  165. return cfg.costNumTen;
  166. }
  167. return 0;
  168. }
  169. }
  170. }