LuckyBoxDataManager.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 int[] luckyBoxIds = new int[] { 1, 2, 3 };//奖池列表
  17. public int startTime = 1635157620;
  18. public int endTime = 1704038400;
  19. public List<ItemData> RewardList
  20. {
  21. get { return _rewardsList; }
  22. set
  23. {
  24. _rewardsList = value;
  25. _firstRewardsList.Clear();
  26. int dicIndex = 0;
  27. foreach (ItemData itemData in _rewardsList)
  28. {
  29. if (ItemDataManager.GetItemNum(itemData.id) == 1)
  30. {
  31. _firstRewardsList.Add(dicIndex, itemData);
  32. }
  33. dicIndex++;
  34. }
  35. }
  36. }
  37. public Dictionary<int, ItemData> FirstRewardList
  38. {
  39. get { return _firstRewardsList; }
  40. set { _firstRewardsList = value; }
  41. }
  42. //获取首次获得的服装的列表
  43. public List<ItemData> GetFirstClothingList()
  44. {
  45. ItemData[] cardArray = new ItemData[LuckyBoxDataManager.Instance.FirstRewardList.Count];
  46. LuckyBoxDataManager.Instance.FirstRewardList.Values.CopyTo(cardArray, 0);
  47. List<ItemData> cardList = new List<ItemData>(cardArray);
  48. return cardList;
  49. }
  50. public void CheckItemEnough(int boxId, int times, Action onSuccess)
  51. {
  52. int costId = LuckyBoxCfgArray.Instance.GetCfg(boxId).costID;
  53. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(costId);
  54. int costNum = GetCostNum(boxId, times);
  55. int hasNum = ItemDataManager.GetItemNum(itemCfg.id);
  56. if (hasNum >= costNum)
  57. {
  58. Alert.Show(string.Format("是否花费{0}个{1}摘星{2}次?", costNum, itemCfg.name, times)).SetLeftButton(true).SetRightButton(true, "确定", (object data) => { onSuccess(); });
  59. }
  60. else
  61. {
  62. int needNum = costNum - hasNum;
  63. ItemExchangeCfgArray.Instance.GetMoneyIdAndNum(costId, ItemDataManager.GetItemExchangeTimes(costId), needNum, out int costItemId, out int costItemNeedNum, out int buyNum);
  64. int costHasNum = ItemDataManager.GetItemNum(costItemId);
  65. if (costHasNum >= costItemNeedNum)//购买消耗品的道具足够,提示购买
  66. {
  67. if (costId == ConstItemID.GOLD)
  68. {
  69. ItemUtil.ExchangeItemById(costId, needNum, false, onSuccess);
  70. }
  71. else
  72. {
  73. BuyTipsController.Show(costId, needNum, onSuccess);
  74. }
  75. }
  76. else//购买消耗品的道具不足,提示购买 购买消耗品的道具
  77. {
  78. ItemUtil.ExchangeItemById(costItemId, needNum, true, null, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED, true);
  79. }
  80. }
  81. }
  82. private int GetCostNum(int boxId, int times)
  83. {
  84. LuckyBoxCfg cfg = LuckyBoxCfgArray.Instance.GetCfg(boxId);
  85. if (times == LuckyBoxDataManager.ONCE_TIME)
  86. {
  87. return cfg.costNum;
  88. }
  89. else if (times == LuckyBoxDataManager.TEN_TIME)
  90. {
  91. return cfg.costNumTen;
  92. }
  93. return 0;
  94. }
  95. }
  96. }