StoryBonusDataCache.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections.Generic;
  2. using System.Collections;
  3. using cfg.GfgCfg;
  4. using ET;
  5. // using System;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class StoryBonusDataCache
  10. {
  11. private static Dictionary<int, StoryBonusData> _bonusDic = new Dictionary<int, StoryBonusData>();
  12. public static List<ItemData> GetBonusList(int levelID, bool hasOnce, bool showRandom = false)
  13. {
  14. StoryBonusData bonusData = GetBonusData(levelID);
  15. List<ItemData> bonusList = new List<ItemData>();
  16. if (hasOnce)
  17. {
  18. bonusList.AddRange(bonusData.bonusOnce);
  19. }
  20. if (bonusData.bonusBase != null)
  21. {
  22. bonusList.AddRange(bonusData.bonusBase);
  23. }
  24. if (showRandom)
  25. {
  26. if (bonusData.bonusRandom != null && bonusData.bonusRandom.Count > 0)
  27. {
  28. bonusList.AddRange(bonusData.bonusRandom);
  29. }
  30. }
  31. return bonusList;
  32. }
  33. public static List<ItemData> GetBaseBonusList(int levelID)
  34. {
  35. StoryBonusData bonusData = GetBonusData(levelID);
  36. if (bonusData.bonusBase != null)
  37. {
  38. return bonusData.bonusBase;
  39. }
  40. return null;
  41. }
  42. public static List<ItemData> GetChapterBonusList(int chapterID, int index)
  43. {
  44. StoryChapterCfg chapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(chapterID);
  45. List<ItemParamProto> bonus = chapterCfg.Bonus1.ToGfgGameItemParam();
  46. if (index == 1)
  47. {
  48. bonus = chapterCfg.Bonus2.ToGfgGameItemParam();
  49. }
  50. else if (index == 2)
  51. {
  52. bonus = chapterCfg.Bonus3.ToGfgGameItemParam();
  53. }
  54. return ItemUtil.CreateItemDataList(bonus);
  55. }
  56. public static int GetChapterBonusStar(int chapterID, int index)
  57. {
  58. StoryChapterCfg chapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(chapterID);
  59. int star = chapterCfg.BonusStar1;
  60. if (index == 1)
  61. {
  62. star = chapterCfg.BonusStar2;
  63. }
  64. else if (index == 2)
  65. {
  66. star = chapterCfg.BonusStar3;
  67. }
  68. return star;
  69. }
  70. public static StoryBonusData GetBonusData(int levelID)
  71. {
  72. StoryBonusData bonusData = null;
  73. if (!_bonusDic.ContainsKey(levelID))
  74. {
  75. bonusData = new StoryBonusData();
  76. _bonusDic.Add(levelID, bonusData);
  77. StoryLevelCfg levelCfg = CommonDataManager.Tables.TblStoryLevelCfg.GetOrDefault(levelID);
  78. bonusData.bonusOnce = ItemUtil.CreateItemDataList(levelCfg.BonusOnce.ToGfgGameItemParam(), true);
  79. if (levelCfg.FightID != null && levelCfg.FightID.Length > 0)
  80. {
  81. StoryFightCfg fightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(levelCfg.FightID));
  82. bonusData.bonusBase = ItemUtil.CreateItemDataList(fightCfg.BonusBase.ToGfgGameItemParam());
  83. bonusData.bonusRandom = DropOutDataCache.GetDropItemDatas(fightCfg.BonusRandom, false);
  84. }
  85. }
  86. else
  87. {
  88. bonusData = _bonusDic[levelID];
  89. }
  90. return bonusData;
  91. }
  92. }
  93. }