StoryBonusDataCache.cs 3.0 KB

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