LuckyBoxDataManager.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. public string probShow;
  17. private List<LuckyBoxBonusData> _showList;
  18. public int[] luckyBoxIds = new int[] { 1, 2, 3 };//奖池列表
  19. public int startTime = 1635157620;
  20. public int endTime = 1704038400;
  21. public List<ItemData> RewardList
  22. {
  23. get { return _rewardsList; }
  24. set
  25. {
  26. _rewardsList = value;
  27. _firstRewardsList.Clear();
  28. int dicIndex = 0;
  29. foreach (ItemData itemData in _rewardsList)
  30. {
  31. if (ItemDataManager.GetItemNum(itemData.id) == 1)
  32. {
  33. _firstRewardsList.Add(dicIndex, itemData);
  34. }
  35. dicIndex++;
  36. }
  37. }
  38. }
  39. public Dictionary<int, ItemData> FirstRewardList
  40. {
  41. get { return _firstRewardsList; }
  42. set { _firstRewardsList = value; }
  43. }
  44. private int _currentBoxId;
  45. public int currentBoxId
  46. {
  47. get
  48. {
  49. return _currentBoxId;
  50. }
  51. set
  52. {
  53. if (_currentBoxId != value)
  54. {
  55. _currentBoxId = value;
  56. InitData(_currentBoxId);
  57. }
  58. }
  59. }
  60. private void InitData(int boxId)
  61. {
  62. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  63. probShow = luckyBoxCfg.probShow;
  64. _showList = GetBonusDataList(luckyBoxCfg.bonusShowArr);
  65. }
  66. private List<LuckyBoxBonusData> GetBonusDataList(int[] idsList)
  67. {
  68. List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();
  69. foreach (int id in idsList)
  70. {
  71. BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(id);
  72. LuckyBoxBonusData luckyBoxBonusData = new LuckyBoxBonusData();
  73. luckyBoxBonusData.id = id;
  74. luckyBoxBonusData.name = bonusListCfg.name;
  75. luckyBoxBonusData.itemList = ItemUtil.CreateItemDataList(bonusListCfg.bonusListArr);
  76. list.Add(luckyBoxBonusData);
  77. }
  78. return list;
  79. }
  80. public int GetOwnedCount()
  81. {
  82. int count = 0;
  83. foreach (LuckyBoxBonusData luckyBoxBonusData in _showList)
  84. {
  85. foreach (ItemData itemData in luckyBoxBonusData.itemList)
  86. {
  87. if (ItemDataManager.GetItemNum(itemData.id) > 0)
  88. {
  89. count++;
  90. }
  91. }
  92. }
  93. return count;
  94. }
  95. public List<LuckyBoxBonusData> GetCurrentShowList()
  96. {
  97. return _showList.GetRange(0, _showList.Count);
  98. }
  99. //获取首次获得的服装的列表
  100. public List<ItemData> GetFirstClothingList()
  101. {
  102. ItemData[] cardArray = new ItemData[LuckyBoxDataManager.Instance.FirstRewardList.Count];
  103. LuckyBoxDataManager.Instance.FirstRewardList.Values.CopyTo(cardArray, 0);
  104. List<ItemData> cardList = new List<ItemData>(cardArray);
  105. return cardList;
  106. }
  107. public void CheckItemEnough(int boxId, int times, Action onSuccess)
  108. {
  109. int costId = LuckyBoxCfgArray.Instance.GetCfg(boxId).costID;
  110. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(costId);
  111. int costNum = GetCostNum(boxId, times);
  112. int hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  113. if (hasNum >= costNum)
  114. {
  115. Alert.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });
  116. }
  117. else
  118. {
  119. int needNum = costNum - hasNum;
  120. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(costId, ItemDataManager.GetItemExchangeTimes(costId), needNum, out int costItemId, out int costItemNeedNum, out int buyNum);
  121. int costHasNum = ItemDataManager.GetItemNum(costItemId);
  122. if (costHasNum >= costItemNeedNum)//购买消耗品的道具足够,提示购买
  123. {
  124. if (costId == ConstItemID.GOLD)
  125. {
  126. ItemUtil.ExchangeItemById(costId, needNum, false, onSuccess);
  127. }
  128. else
  129. {
  130. BuyTipsController.Show(costId, needNum, onSuccess);
  131. }
  132. }
  133. else//购买消耗品的道具不足,提示购买 购买消耗品的道具
  134. {
  135. ItemUtil.ExchangeItemById(costItemId, costItemNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
  136. }
  137. }
  138. }
  139. private int GetCostNum(int boxId, int times)
  140. {
  141. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  142. if (times == LuckyBoxDataManager.ONCE_TIME)
  143. {
  144. return cfg.costNum;
  145. }
  146. else if (times == LuckyBoxDataManager.TEN_TIME)
  147. {
  148. return cfg.costNumTen;
  149. }
  150. return 0;
  151. }
  152. }
  153. }