LuckyBoxDataManager.cs 5.9 KB

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