StoryBonusDataCache.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections.Generic;
  2. using System.Collections;
  3. // using System;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class StoryBonusDataCache
  8. {
  9. private static Dictionary<int, StoryBonusData> _bonusDic = new Dictionary<int, StoryBonusData>();
  10. public static List<ItemData> GetBonusList(int levelID, bool hasOnce, bool doRandom = false)
  11. {
  12. StoryBonusData bonusData = GetBonusData(levelID);
  13. List<ItemData> bonusList = new List<ItemData>();
  14. if (hasOnce)
  15. {
  16. bonusList.AddRange(bonusData.bonusOnce);
  17. }
  18. else
  19. {
  20. if (bonusData.bonusRandom != null && bonusData.bonusRandom.Count > 0)
  21. {
  22. if (doRandom)
  23. {
  24. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  25. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  26. if(fightCfg != null)
  27. {
  28. List<ItemData> randomList = DropOutDataCache.GetDropItemDatas(fightCfg.bonusRandomArr, true);
  29. bonusList.AddRange(randomList);
  30. }
  31. }
  32. else
  33. {
  34. bonusList.AddRange(bonusData.bonusRandom);
  35. }
  36. }
  37. }
  38. if (bonusData.bonusBase != null)
  39. {
  40. bonusList.AddRange(bonusData.bonusBase);
  41. }
  42. return bonusList;
  43. }
  44. public static List<ItemData> GetBaseBonusList(int levelID)
  45. {
  46. StoryBonusData bonusData = GetBonusData(levelID);
  47. if (bonusData.bonusBase != null)
  48. {
  49. return bonusData.bonusBase;
  50. }
  51. return null;
  52. }
  53. public static List<ItemData> GetChapterBonusList(int chapterID, int index)
  54. {
  55. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterID);
  56. int[][] bonus = chapterCfg.bonus1Arr;
  57. if (index == 1)
  58. {
  59. bonus = chapterCfg.bonus2Arr;
  60. }
  61. else if (index == 2)
  62. {
  63. bonus = chapterCfg.bonus3Arr;
  64. }
  65. return ItemUtil.CreateItemDataList(bonus);
  66. }
  67. public static StoryBonusData GetBonusData(int levelID)
  68. {
  69. StoryBonusData bonusData = null;
  70. if (!_bonusDic.ContainsKey(levelID))
  71. {
  72. bonusData = new StoryBonusData();
  73. _bonusDic.Add(levelID, bonusData);
  74. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  75. bonusData.bonusOnce = ItemUtil.CreateItemDataList(levelCfg.bonusOnceArr, true);
  76. if (levelCfg.fightID != null && levelCfg.fightID.Length > 0)
  77. {
  78. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  79. bonusData.bonusBase = ItemUtil.CreateItemDataList(fightCfg.bonusBaseArr);
  80. bonusData.bonusRandom = DropOutDataCache.GetDropItemDatas(fightCfg.bonusRandomArr, false);
  81. }
  82. }
  83. else
  84. {
  85. bonusData = _bonusDic[levelID];
  86. }
  87. return bonusData;
  88. }
  89. }
  90. }