StoryBonusDataCache.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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> 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. }