LuckyBoxDataManager.cs 5.9 KB

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