LuckyBoxBonusDataCache.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. int[][] temp = new int[5][];
  65. temp[0] = new int[] { 10332, 1 };
  66. temp[1] = new int[] { 10334, 1 };
  67. temp[2] = new int[] { 10335, 1 };
  68. temp[3] = new int[] { 10336, 1 };
  69. temp[4] = new int[] { 10338, 1 };
  70. List<ItemData> guideBonusList = ItemUtil.CreateItemDataList(temp);
  71. count = count - guideBonusList.Count;
  72. bonusList = DropOutDataCache.GetDropItemDatas(_dropOutId, count);
  73. while (guideBonusList.Count > 1)
  74. {
  75. ItemData itemData = guideBonusList[0];
  76. guideBonusList.RemoveAt(0);
  77. int index = UnityEngine.Random.Range(0, bonusList.Count);
  78. bonusList.Insert(index, itemData);
  79. }
  80. bonusList.Add(guideBonusList[0]);
  81. }
  82. else
  83. {
  84. bonusList = DropOutDataCache.GetDropItemDatas(_dropOutId, count);
  85. }
  86. int dicIndex = 0;
  87. LuckyBoxDataManager.Instance.FirstRewardList.Clear();
  88. foreach (ItemData itemData in bonusList)
  89. {
  90. if (ItemDataManager.GetItemNum(itemData.id) == 0)
  91. {
  92. LuckyBoxDataManager.Instance.FirstRewardList.Add(dicIndex, itemData);
  93. }
  94. ItemDataManager.Add(itemData.id, itemData.num);
  95. dicIndex++;
  96. }
  97. ItemDataManager.Add(_dropId, count);
  98. //100¸öÐÇм»»1¸öÂäÐÇʯ
  99. LuckyBoxCfg boxCfg0 = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[0]);
  100. LuckyBoxCfg boxCfg1 = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxIds[1]);
  101. int itemCount = ItemDataManager.GetItemNum(boxCfg0.drop);
  102. if (_dropId == boxCfg0.drop && itemCount >= 100)
  103. {
  104. ItemDataManager.Add(boxCfg1.drop, itemCount / 100);
  105. ItemDataManager.Remove(_dropId, itemCount / 100 * 100);
  106. }
  107. GetSuitItemController.TryShow(0);
  108. return bonusList;
  109. }
  110. private static void InitData(int boxId)
  111. {
  112. LuckyBoxCfg luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  113. probShow = luckyBoxCfg.probShow;
  114. _showList = GetBonusDataList(luckyBoxCfg.bonusShowArr);
  115. _dropOutId = luckyBoxCfg.bonus;
  116. _dropId = luckyBoxCfg.drop;
  117. }
  118. private static List<LuckyBoxBonusData> GetBonusDataList(int[] idsList)
  119. {
  120. List<LuckyBoxBonusData> list = new List<LuckyBoxBonusData>();
  121. foreach (int id in idsList)
  122. {
  123. BonusListCfg bonusListCfg = BonusListCfgArray.Instance.GetCfg(id);
  124. LuckyBoxBonusData luckyBoxBonusData = new LuckyBoxBonusData();
  125. luckyBoxBonusData.id = id;
  126. luckyBoxBonusData.name = bonusListCfg.name;
  127. luckyBoxBonusData.itemList = ItemUtil.CreateItemDataList(bonusListCfg.bonusListArr);
  128. list.Add(luckyBoxBonusData);
  129. }
  130. return list;
  131. }
  132. public static void CheckItemEnough(int itemId, int count, int times, Action onSuccess)
  133. {
  134. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  135. int hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  136. if (hasNum >= count)//????
  137. {
  138. Alert.Show(string.Format("是否花费{0}个{1}摘星{2}次?", count, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });
  139. }
  140. else
  141. {
  142. ItemExchangeCfg currencyRatioCfg = ItemUtil.GetCurrencyRatioCfgById(itemId);
  143. int costHasNum = ItemDataManager.GetItemNum(currencyRatioCfg.costId);
  144. int costNeedNum = ItemUtil.GetCostItemCount(itemId, count - hasNum);
  145. if (costHasNum >= costNeedNum)
  146. {
  147. if (itemId == ConstItemID.GOLD)
  148. {
  149. ItemUtil.ExchangeItemById(itemId, count - hasNum, false, onSuccess);
  150. }
  151. else
  152. {
  153. BuyTipsController.Show(itemId, count - hasNum, currencyRatioCfg.costId, costNeedNum, onSuccess);
  154. }
  155. }
  156. else
  157. {
  158. ItemUtil.ExchangeItemById(currencyRatioCfg.costId, costNeedNum - costHasNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
  159. }
  160. }
  161. }
  162. }
  163. }