StoryBonusDataCache.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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<string, StoryBonusData> _bonusDic = new Dictionary<string, StoryBonusData>();
  10. public static List<ItemData> GetBonusList(string 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. if (bonusData.bonusBase != null)
  19. {
  20. bonusList.AddRange(bonusData.bonusBase);
  21. }
  22. if (bonusData.bonusRandom != null && bonusData.bonusRandom.Count > 0)
  23. {
  24. if (doRandom)
  25. {
  26. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  27. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  28. List<ItemData> randomList = DropOutDataCache.GetDropItemDatas(fightCfg.bonusRandomArr, true);
  29. bonusList.AddRange(randomList);
  30. }
  31. else
  32. {
  33. bonusList.AddRange(bonusData.bonusRandom);
  34. }
  35. }
  36. return bonusList;
  37. }
  38. public static List<ItemData> GetChapterBonusList(int chapterID, int index)
  39. {
  40. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterID);
  41. int[][] bonus = chapterCfg.bonus1Arr;
  42. if (index == 1)
  43. {
  44. bonus = chapterCfg.bonus2Arr;
  45. }
  46. else if (index == 2)
  47. {
  48. bonus = chapterCfg.bonus3Arr;
  49. }
  50. return ItemUtil.CreateItemDataList(bonus);
  51. }
  52. public static StoryBonusData GetBonusData(string levelID)
  53. {
  54. StoryBonusData bonusData = null;
  55. if (!_bonusDic.ContainsKey(levelID))
  56. {
  57. bonusData = new StoryBonusData();
  58. _bonusDic.Add(levelID, bonusData);
  59. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  60. bonusData.bonusOnce = ItemUtil.CreateItemDataList(levelCfg.bonusOnceArr, true);
  61. if (levelCfg.fightID != null && levelCfg.fightID.Length > 0)
  62. {
  63. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  64. bonusData.bonusBase = ItemUtil.CreateItemDataList(fightCfg.bonusBaseArr);
  65. bonusData.bonusRandom = DropOutDataCache.GetDropItemDatas(fightCfg.bonusRandomArr, false);
  66. }
  67. }
  68. else
  69. {
  70. bonusData = _bonusDic[levelID];
  71. }
  72. return bonusData;
  73. }
  74. }
  75. }