StoryBonusDataCache.cs 2.8 KB

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