LuckyBoxBonusDataCache.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using System;
  4. namespace GFGGame
  5. {
  6. public class LuckyBoxBonusDataCache
  7. {
  8. private static int _currentBoxId;
  9. private static int _currentSelectId;
  10. public static int currentBoxId
  11. {
  12. get
  13. {
  14. return _currentBoxId;
  15. }
  16. set
  17. {
  18. if (_currentBoxId != value)
  19. {
  20. _currentBoxId = value;
  21. InitData(_currentBoxId);
  22. }
  23. }
  24. }
  25. public static int currentSelectId
  26. {
  27. get
  28. {
  29. return _currentSelectId;
  30. }
  31. set
  32. {
  33. _currentSelectId = value;
  34. }
  35. }
  36. public static string probShow;
  37. private static List<LuckyBoxBonusData> _showList;
  38. private static int _dropOutId;
  39. private static int _dropId;
  40. public static int GetOwnedCount()
  41. {
  42. int count = 0;
  43. foreach (LuckyBoxBonusData luckyBoxBonusData in _showList)
  44. {
  45. foreach (ItemData itemData in luckyBoxBonusData.itemList)
  46. {
  47. if (ItemDataManager.GetItemNum(itemData.id) > 0)
  48. {
  49. count++;
  50. }
  51. }
  52. }
  53. return count;
  54. }
  55. public static List<LuckyBoxBonusData> GetCurrentShowList()
  56. {
  57. return _showList.GetRange(0, _showList.Count);
  58. }
  59. public static List<ItemData> GetBonusList(int count, bool isGuide = false)
  60. {
  61. List<ItemData> bonusList = null;
  62. if (isGuide)
  63. {
  64. List<ItemData> guideBonusList = ItemUtil.CreateItemDataList("10332*1;10334*1;10335*1;10336*1;10338*1");
  65. count = count - guideBonusList.Count;
  66. bonusList = DropOutDataCache.GetDropItemDatas(_dropOutId, count);
  67. while (guideBonusList.Count > 1)
  68. {
  69. ItemData itemData = guideBonusList[0];
  70. guideBonusList.RemoveAt(0);
  71. int index = UnityEngine.Random.Range(0, bonusList.Count);
  72. bonusList.Insert(index, itemData);
  73. }
  74. bonusList.Add(guideBonusList[0]);
  75. }
  76. else
  77. {
  78. bonusList = DropOutDataCache.GetDropItemDatas(_dropOutId, count);
  79. }
  80. int dicIndex = 0;
  81. LuckyBoxDataManager.Instance.FirstRewardList.Clear();
  82. foreach (ItemData itemData in bonusList)
  83. {
  84. if (ItemDataManager.GetItemNum(itemData.id) == 0)
  85. {
  86. LuckyBoxDataManager.Instance.FirstRewardList.Add(dicIndex, itemData);
  87. }
  88. ItemDataManager.Add(itemData.id, itemData.num);
  89. dicIndex++;
  90. }
  91. ItemDataManager.Add(_dropId, count);
  92. //100¸öÐÇм»»1¸öÂäÐÇʯ
  93. LuckyBoxCfg boxCfg0 = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[0]);
  94. LuckyBoxCfg boxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[1]);
  95. int itemCount = ItemDataManager.GetItemNum(boxCfg0.drop);
  96. if (_dropId == boxCfg0.drop && itemCount >= 100)
  97. {
  98. ItemDataManager.Add(boxCfg1.drop, itemCount / 100);
  99. ItemDataManager.Remove(_dropId, itemCount / 100 * 100);
  100. }
  101. GetSuitItemController.TryShow(0);
  102. return bonusList;
  103. }
  104. private static void InitData(int boxId)
  105. {
  106. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  107. probShow = luckyBoxCfg.probShow;
  108. _showList = GetBonusDataList(luckyBoxCfg.bonusShowArr);
  109. _dropOutId = luckyBoxCfg.bonus;
  110. _dropId = luckyBoxCfg.drop;
  111. }
  112. private static List<LuckyBoxBonusData> GetBonusDataList(int[] idsList)
  113. {
  114. List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();
  115. foreach (int id in idsList)
  116. {
  117. BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(id);
  118. LuckyBoxBonusData luckyBoxBonusData = new LuckyBoxBonusData();
  119. luckyBoxBonusData.id = id;
  120. luckyBoxBonusData.name = bonusListCfg.name;
  121. luckyBoxBonusData.itemList = ItemUtil.CreateItemDataList(bonusListCfg.bonusListArr);
  122. list.Add(luckyBoxBonusData);
  123. }
  124. return list;
  125. }
  126. public static void CheckItemEnough(int itemId, int count, int times, Action onSuccess)
  127. {
  128. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  129. int hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  130. if (hasNum >= count)//????
  131. {
  132. Alert.Show(string.Format("是否花费{0}个{1}摘星{2}次?", count, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });
  133. }
  134. else
  135. {
  136. CurrencyRatioCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(itemId);
  137. int costHasNum = ItemDataManager.GetItemNum(currencyRatioCfg.costId);
  138. int costNeedNum = ItemUtil.GetCostItemCount(itemId, count - hasNum);
  139. if (costHasNum >= costNeedNum)
  140. {
  141. if (itemId == ConstItemID.GOLD)
  142. {
  143. ItemUtil.ExchangeItemById(itemId, count - hasNum, false, onSuccess);
  144. }
  145. else
  146. {
  147. BuyTipsController.Show(itemId, count - hasNum, currencyRatioCfg.costId, costNeedNum, onSuccess);
  148. }
  149. }
  150. else
  151. {
  152. ItemUtil.ExchangeItemById(currencyRatioCfg.costId, costNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
  153. }
  154. }
  155. }
  156. }
  157. }