LuckyBoxDataManager.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. using System;
  2. using System.Collections.Generic;
  3. namespace GFGGame
  4. {
  5. public class LuckyBoxDataManager : SingletonBase<LuckyBoxDataManager>
  6. {
  7. // public const int BOX_ID_1 = 1;
  8. public const int BOX_ID_2 = 2;//常驻奖池2
  9. public const int BOX_ID_3 = 3;//常驻奖池2
  10. public const int ONCE_TIME = 1;
  11. public const int TEN_TIME = 10;
  12. private List<ItemData> _rewardsList;//当前奖励,每次抽奖后刷新
  13. private Dictionary<int, ItemData> _firstRewardsList = new Dictionary<int, ItemData>();//首次获得的奖励
  14. private Dictionary<int, List<LuckyBoxBonusData>> _dicShowList = new Dictionary<int, List<LuckyBoxBonusData>>();
  15. public List<int> luckyBoxIds = new List<int>();//奖池列表
  16. public int RotatingId = 0;//轮换活动id。0为未开启
  17. public long startTime = 1668873600000;
  18. public long endTime = 1672156799000;
  19. public int times = 0;
  20. public int luckyBoxId;
  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 = 2;
  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. public void InitData(int boxId)
  61. {
  62. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  63. if (!_dicShowList.ContainsKey(boxId))
  64. {
  65. _dicShowList[boxId] = InitBonusDataList(luckyBoxCfg.dropId);
  66. }
  67. }
  68. private List<LuckyBoxBonusData> InitBonusDataList(int dropId)
  69. {
  70. Dictionary<int, LuckyBoxBonusData> dic = new Dictionary<int, LuckyBoxBonusData>();
  71. AddToBonusDataDic(dropId, dic);
  72. List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();
  73. foreach (var t in dic)
  74. {
  75. list.Add(t.Value);
  76. }
  77. list.Sort(CompareBonusData);
  78. return list;
  79. }
  80. private void AddToBonusDataDic(int dropId, Dictionary<int, LuckyBoxBonusData> dic)
  81. {
  82. List<DropOutCfg> cfgs = DropOutCfgArray.Instance.GetCfgsByid(dropId);
  83. if (cfgs == null)
  84. {
  85. return;
  86. }
  87. foreach (DropOutCfg cfg in cfgs)
  88. {
  89. if (cfg.item > ConstItemID.MAX_ITEM_ID)//掉落id
  90. {
  91. AddToBonusDataDic(cfg.item, dic);
  92. }
  93. else
  94. {
  95. var group = cfg.group;
  96. if (cfg.group <= 0)
  97. {
  98. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cfg.item);
  99. if (itemCfg == null || itemCfg.suitId <= 0 && itemCfg.showSuitId <= 0)
  100. {
  101. continue;
  102. }
  103. group = itemCfg.suitId == 0 ? itemCfg.showSuitId : itemCfg.suitId;
  104. }
  105. LuckyBoxBonusData luckyBoxBonusData = GetBonusData(group, dic);
  106. if (luckyBoxBonusData == null)
  107. {
  108. continue;
  109. }
  110. luckyBoxBonusData.itemList.Add(ItemUtil.createItemData(cfg.item, 1));
  111. }
  112. }
  113. }
  114. private LuckyBoxBonusData GetBonusData(int group, Dictionary<int, LuckyBoxBonusData> dic)
  115. {
  116. dic.TryGetValue(group, out LuckyBoxBonusData luckyBoxBonusData);
  117. if (luckyBoxBonusData != null)
  118. {
  119. return luckyBoxBonusData;
  120. }
  121. luckyBoxBonusData = new LuckyBoxBonusData();
  122. luckyBoxBonusData.id = group;
  123. BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(group);
  124. if (bonusListCfg != null)
  125. {
  126. luckyBoxBonusData.name = bonusListCfg.name;
  127. luckyBoxBonusData.order = bonusListCfg.sort;
  128. }
  129. else
  130. {
  131. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(group);
  132. if (suitCfg == null)
  133. {
  134. return null;
  135. }
  136. luckyBoxBonusData.name = suitCfg.name;
  137. luckyBoxBonusData.order = 9999;
  138. }
  139. dic.Add(group, luckyBoxBonusData);
  140. return luckyBoxBonusData;
  141. }
  142. public int CompareBonusData(LuckyBoxBonusData a, LuckyBoxBonusData b)
  143. {
  144. if (b.order < a.order)
  145. {
  146. return 1;
  147. }
  148. if (b.order > a.order)
  149. {
  150. return -1;
  151. }
  152. return a.id - b.id;
  153. }
  154. public void GetOwnedCount(int boxId, out int count, out int totalCount)
  155. {
  156. count = 0;
  157. totalCount = 0;
  158. foreach (LuckyBoxBonusData luckyBoxBonusData in _dicShowList[boxId])
  159. {
  160. foreach (ItemData itemData in luckyBoxBonusData.itemList)
  161. {
  162. if (ItemDataManager.GetItemNum(itemData.id) > 0)
  163. {
  164. count++;
  165. }
  166. totalCount++;
  167. }
  168. }
  169. }
  170. public List<LuckyBoxBonusData> GetCurrentShowList(int boxId)
  171. {
  172. return _dicShowList[boxId];
  173. }
  174. // //获取首次获得的服装的列表
  175. // public List<ItemData> GetFirstClothingList()
  176. // {
  177. // ItemData[] cardArray = new ItemData[LuckyBoxDataManager.Instance.FirstRewardList.Count];
  178. // LuckyBoxDataManager.Instance.FirstRewardList.Values.CopyTo(cardArray, 0);
  179. // List<ItemData> cardList = new List<ItemData>(cardArray);
  180. // return cardList;
  181. // }
  182. public void CheckItemEnough(int boxId, int times, Action onSuccess)
  183. {
  184. int costId = LuckyBoxCfgArray.Instance.GetCfg(boxId).costID;
  185. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(costId);
  186. int costNum = GetCostNum(boxId, times);
  187. long hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  188. if (hasNum >= costNum)
  189. {
  190. AlertUI.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });
  191. }
  192. else
  193. {
  194. long needNum = costNum - hasNum;
  195. // ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(costId, ItemDataManager.GetItemExchangeTimes(costId), times, out int costItemId, out int costItemNeedNum, out int buyNum);
  196. ItemExchangeCfg itemExchangeCfg = ItemExchangeCfgArray.Instance.GetCfg(costId);
  197. int exchangedTimes = ItemDataManager.GetItemExchangeTimes(costId);
  198. int costItemNeedNum = 0;
  199. int costbuyNum = 0;
  200. int buyNum = 0;
  201. for (var i = exchangedTimes + 1; i <= exchangedTimes + times; i++)
  202. {
  203. ItemExchangeCfgArray.Instance.GetCostAndBuyNum(itemExchangeCfg, i, out int _costNum, out int _buyNum);
  204. costItemNeedNum += _costNum;
  205. costbuyNum += _buyNum;
  206. buyNum += itemExchangeCfg.num;
  207. if (buyNum >= needNum) break;
  208. }
  209. long costHasNum = ItemDataManager.GetItemNum(itemExchangeCfg.costId);
  210. if (costHasNum >= costItemNeedNum)//购买消耗品的道具足够,提示购买
  211. {
  212. if (costId == ConstItemID.GOLD)
  213. {
  214. ItemUtil.ExchangeItemById(costId, needNum, false, onSuccess);
  215. }
  216. else
  217. {
  218. BuyTipsController.Show(costId, needNum, onSuccess);
  219. }
  220. }
  221. else//购买消耗品的道具不足,提示购买 购买消耗品的道具
  222. {
  223. ItemUtil.ExchangeItemById(itemExchangeCfg.costId, costItemNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
  224. }
  225. }
  226. }
  227. private int GetCostNum(int boxId, int times)
  228. {
  229. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  230. if (times == LuckyBoxDataManager.ONCE_TIME)
  231. {
  232. return cfg.costNum;
  233. }
  234. else if (times == LuckyBoxDataManager.TEN_TIME)
  235. {
  236. return cfg.costNumTen;
  237. }
  238. return 0;
  239. }
  240. }
  241. }