LuckyBoxDataManager.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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[] { 1, 2, 3 };//奖池列表
  18. public long startTime = 1668873600000;
  19. public long endTime = 1674144000000;
  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 = 2;
  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. }
  69. private List<LuckyBoxBonusData> GetBonusDataList(int[] idsList)
  70. {
  71. List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();
  72. foreach (int id in idsList)
  73. {
  74. BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(id);
  75. LuckyBoxBonusData luckyBoxBonusData = new LuckyBoxBonusData();
  76. luckyBoxBonusData.id = id;
  77. luckyBoxBonusData.name = bonusListCfg.name;
  78. luckyBoxBonusData.itemList = ItemUtil.CreateItemDataList(bonusListCfg.bonusListArr);
  79. list.Add(luckyBoxBonusData);
  80. }
  81. return list;
  82. }
  83. public int GetOwnedCount(int boxId)
  84. {
  85. int count = 0;
  86. foreach (LuckyBoxBonusData luckyBoxBonusData in _dicShowList[boxId])
  87. {
  88. foreach (ItemData itemData in luckyBoxBonusData.itemList)
  89. {
  90. if (ItemDataManager.GetItemNum(itemData.id) > 0)
  91. {
  92. count++;
  93. }
  94. }
  95. }
  96. return count;
  97. }
  98. public List<LuckyBoxBonusData> GetCurrentShowList(int boxId)
  99. {
  100. return _dicShowList[boxId];
  101. }
  102. // //获取首次获得的服装的列表
  103. // public List<ItemData> GetFirstClothingList()
  104. // {
  105. // ItemData[] cardArray = new ItemData[LuckyBoxDataManager.Instance.FirstRewardList.Count];
  106. // LuckyBoxDataManager.Instance.FirstRewardList.Values.CopyTo(cardArray, 0);
  107. // List<ItemData> cardList = new List<ItemData>(cardArray);
  108. // return cardList;
  109. // }
  110. public void CheckItemEnough(int boxId, int times, Action onSuccess)
  111. {
  112. int costId = LuckyBoxCfgArray.Instance.GetCfg(boxId).costID;
  113. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(costId);
  114. int costNum = GetCostNum(boxId, times);
  115. int hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  116. if (hasNum >= costNum)
  117. {
  118. AlertUI.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });
  119. }
  120. else
  121. {
  122. int needNum = costNum - hasNum;
  123. // ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(costId, ItemDataManager.GetItemExchangeTimes(costId), times, out int costItemId, out int costItemNeedNum, out int buyNum);
  124. ItemExchangeCfg itemExchangeCfg = ItemExchangeCfgArray.Instance.GetCfg(costId);
  125. int exchangedTimes = ItemDataManager.GetItemExchangeTimes(costId);
  126. int costItemNeedNum = 0;
  127. int costbuyNum = 0;
  128. int buyNum = 0;
  129. for (var i = exchangedTimes + 1; i <= exchangedTimes + times; i++)
  130. {
  131. ItemExchangeCfgArray.Instance.GetCostAndBuyNum(itemExchangeCfg, i, out int _costNum, out int _buyNum);
  132. costItemNeedNum += _costNum;
  133. costbuyNum += _buyNum;
  134. buyNum += itemExchangeCfg.num;
  135. if (buyNum >= needNum) break;
  136. }
  137. int costHasNum = ItemDataManager.GetItemNum(itemExchangeCfg.costId);
  138. if (costHasNum >= costItemNeedNum)//购买消耗品的道具足够,提示购买
  139. {
  140. if (costId == ConstItemID.GOLD)
  141. {
  142. ItemUtil.ExchangeItemById(costId, needNum, false, onSuccess);
  143. }
  144. else
  145. {
  146. BuyTipsController.Show(costId, needNum, onSuccess);
  147. }
  148. }
  149. else//购买消耗品的道具不足,提示购买 购买消耗品的道具
  150. {
  151. ItemUtil.ExchangeItemById(itemExchangeCfg.costId, costItemNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
  152. }
  153. }
  154. }
  155. private int GetCostNum(int boxId, int times)
  156. {
  157. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  158. if (times == LuckyBoxDataManager.ONCE_TIME)
  159. {
  160. return cfg.costNum;
  161. }
  162. else if (times == LuckyBoxDataManager.TEN_TIME)
  163. {
  164. return cfg.costNumTen;
  165. }
  166. return 0;
  167. }
  168. }
  169. }