StorySProxy.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public class StorySProxy
  9. {
  10. //请求剧情关卡数据
  11. public static async ETTask GetStoryInfos()
  12. {
  13. M2C_GetStoryInfos response = null;
  14. response = (M2C_GetStoryInfos)await MessageHelper.SendToServer(new C2M_GetStoryInfos());
  15. if(response != null)
  16. {
  17. if(response.Error == ErrorCode.ERR_Success)
  18. {
  19. InstanceZonesDataManager.InitScoreList(response.ksScore, response.vsScore);
  20. InstanceZonesDataManager.InitStarList(response.ksStar, response.vsStar);
  21. StoryDataManager.InitBoxBonusStates(response.ksBonusState, response.vsBonusState);
  22. InstanceZonesDataManager.InitLevelPass(response.ksPass, response.VsPass);
  23. }
  24. }
  25. }
  26. //完成剧情对话关卡
  27. public static async ETTask FinishStoryDialogLevel(int levelCfgId)
  28. {
  29. M2C_FinishStoryDialog response = null;
  30. response = (M2C_FinishStoryDialog)await MessageHelper.SendToServer(new C2M_FinishStoryDialog()
  31. {
  32. LevelCfgId = levelCfgId
  33. });
  34. if (response != null)
  35. {
  36. if (response.Error == ErrorCode.ERR_Success)
  37. {
  38. List<ItemData> bonusList = StoryBonusDataCache.GetBonusList(response.LevelCfgId, true, true);
  39. BonusController.TryShowBonusList(bonusList);
  40. InstanceZonesDataManager.TrySetLevelPass(response.LevelCfgId);
  41. FunctionOpenDataManager.Instance.CheckHasChapterFunOpen(response.LevelCfgId);//首次通过要检查是否有功能开启
  42. InstanceZonesController.OnFinishStoryLevel(levelCfgId, true, true);
  43. return;
  44. }
  45. }
  46. InstanceZonesController.OnFinishStoryLevel(levelCfgId, false, false);
  47. }
  48. //完成剧情战斗关卡
  49. public static async ETTask FinishStoryFightLevel(int levelCfgId, int score, int npcScore, bool useRecomend)
  50. {
  51. M2C_FinishStoryFightLevel response = null;
  52. response = (M2C_FinishStoryFightLevel)await MessageHelper.SendToServer(new C2M_FinishStoryFightLevel()
  53. {
  54. LevelCfgId = levelCfgId,
  55. Score = score,
  56. NpcScore = npcScore,
  57. UseRecommend = useRecomend
  58. });
  59. if(response != null)
  60. {
  61. if(response.Error == ErrorCode.ERR_Success)
  62. {
  63. //更新数据
  64. InstanceZonesDataManager.TryUpdateScore(response.LevelCfgId, response.Score);
  65. InstanceZonesDataManager.TryUpdateLevelStar(response.LevelCfgId, response.Star);
  66. CalculateHelper.GetStoryChapterLevel(response.LevelCfgId, out var chapter, out var level);
  67. StoryDataManager.UpdateBoxBonusStates(chapter, response.BoxStates);
  68. //展示奖励
  69. List<ItemData> bonusList = StoryBonusDataCache.GetBonusList(response.LevelCfgId, response.HasOnceBonus);
  70. if(response.RandomBonusList != null)
  71. {
  72. foreach(var item in response.RandomBonusList)
  73. {
  74. var itemData = ItemUtil.createItemData(item.ConfigId, item.Count);
  75. bonusList.Add(itemData);
  76. }
  77. }
  78. if(response.HasOnceBonus)
  79. {
  80. //首次通过要检查是否有功能开启
  81. FunctionOpenDataManager.Instance.CheckHasChapterFunOpen(response.LevelCfgId);
  82. }
  83. InstanceZonesDataManager.TrySetLevelPass(response.LevelCfgId);
  84. ViewManager.Show(ViewName.STORY_FIGHT_RESULT_VIEW, new StoryFightResultData
  85. {
  86. Result = true,
  87. Score = response.Score,
  88. FirstPass = response.HasOnceBonus,
  89. Star = response.Star,
  90. BonusList = bonusList
  91. }, null, true);
  92. return;
  93. }
  94. }
  95. InstanceZonesController.OnFinishStoryLevel(levelCfgId, false, false);
  96. }
  97. //剧情战斗关卡失败,更新最高分
  98. public static async ETTask StoryFightLevelFail(int levelCfgId, int score)
  99. {
  100. M2C_FinishStoryFightLevelFail response = null;
  101. response = (M2C_FinishStoryFightLevelFail)await MessageHelper.SendToServer(new C2M_FinishStoryFightLevelFail()
  102. {
  103. LevelCfgId = levelCfgId,
  104. Score = score,
  105. });
  106. if (response != null)
  107. {
  108. if (response.Error == ErrorCode.ERR_Success)
  109. {
  110. InstanceZonesDataManager.TryUpdateScore(response.LevelCfgId, response.Score);
  111. }
  112. }
  113. }
  114. //快速完成关卡战斗
  115. public static async ETTask FinishStoryFightQuickly(int levelCfgId, int times)
  116. {
  117. M2C_FinishStoryFightQuickly response = null;
  118. response = (M2C_FinishStoryFightQuickly)await MessageHelper.SendToServer(new C2M_FinishStoryFightQuickly()
  119. {
  120. LevelCfgId = levelCfgId,
  121. times = times
  122. });
  123. if (response != null)
  124. {
  125. if (response.Error == ErrorCode.ERR_Success)
  126. {
  127. List<List<ItemData>> bonusLists = new List<List<ItemData>>();
  128. List<ItemData> allList = new List<ItemData>();
  129. foreach(var proto in response.RandomBonusList)
  130. {
  131. var itemData = ItemUtil.createItemData(proto.ConfigId, proto.Count);
  132. allList.Add(itemData);
  133. }
  134. var index = 0;
  135. for(int i = 0; i < response.BonusLengths.Count; ++i)
  136. {
  137. var len = response.BonusLengths[i];
  138. var baseBonusList = StoryBonusDataCache.GetBaseBonusList(response.LevelCfgId);
  139. List<ItemData> bonusList = new List<ItemData>();
  140. if (baseBonusList != null)
  141. {
  142. bonusList.AddRange(baseBonusList);
  143. }
  144. if (len > 0)
  145. {
  146. bonusList.AddRange(allList.GetRange(index, len));
  147. }
  148. bonusLists.Add(bonusList);
  149. index += len;
  150. }
  151. EventAgent.DispatchEvent(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, bonusLists);
  152. }
  153. }
  154. }
  155. }
  156. }