StoryBonusDataCache.cs 3.4 KB

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