StorySProxy.cs 6.9 KB

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