StoryBonusDataCache.cs 2.9 KB

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