StoryBonusDataCache.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 int GetChapterBonusStar(int chapterID, int index)
  55. {
  56. StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterID);
  57. int star = chapterCfg.bonusStar1;
  58. if (index == 1)
  59. {
  60. star = chapterCfg.bonusStar2;
  61. }
  62. else if (index == 2)
  63. {
  64. star = chapterCfg.bonusStar3;
  65. }
  66. return star;
  67. }
  68. public static StoryBonusData GetBonusData(int levelID)
  69. {
  70. StoryBonusData bonusData = null;
  71. if (!_bonusDic.ContainsKey(levelID))
  72. {
  73. bonusData = new StoryBonusData();
  74. _bonusDic.Add(levelID, bonusData);
  75. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(levelID);
  76. bonusData.bonusOnce = ItemUtil.CreateItemDataList(levelCfg.bonusOnceArr, true);
  77. if (levelCfg.fightID != null && levelCfg.fightID.Length > 0)
  78. {
  79. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  80. bonusData.bonusBase = ItemUtil.CreateItemDataList(fightCfg.bonusBaseArr);
  81. bonusData.bonusRandom = DropOutDataCache.GetDropItemDatas(fightCfg.bonusRandomArr, false);
  82. }
  83. }
  84. else
  85. {
  86. bonusData = _bonusDic[levelID];
  87. }
  88. return bonusData;
  89. }
  90. }
  91. }