InstanceZonesSProxy.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 InstanceZonesSProxy
  9. {
  10. //请求剧情关卡数据
  11. public static async ETTask GetInstanceZonesInfos()
  12. {
  13. M2C_GetInstanceZonesInfos response = null;
  14. response = (M2C_GetInstanceZonesInfos)await MessageHelper.SendToServer(new C2M_GetInstanceZonesInfos());
  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. InstanceZonesDataManager.InitLevelPass(response.ksPass, response.VsPass);
  22. }
  23. }
  24. }
  25. //完成剧情对话关卡
  26. public static async ETTask FinishStoryDialogLevel(int levelCfgId)
  27. {
  28. M2C_FinishInstanceZonesDialog response = null;
  29. response = (M2C_FinishInstanceZonesDialog)await MessageHelper.SendToServer(new C2M_FinishInstanceZonesDialog()
  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. InstanceZonesDataManager.TrySetLevelPass(response.LevelCfgId);
  40. FunctionOpenDataManager.Instance.CheckHasChapterFunOpen(response.LevelCfgId);//首次通过要检查是否有功能开启
  41. InstanceZonesController.OnFinishStoryLevel(levelCfgId, true, true);
  42. return;
  43. }
  44. }
  45. InstanceZonesController.OnFinishStoryLevel(levelCfgId, false, false);
  46. }
  47. //完成剧情战斗关卡
  48. public static async ETTask FinishStoryFightLevel(int levelCfgId, int score, int npcScore, bool useRecomend)
  49. {
  50. M2C_FinishInstanceZonesFightLevel response = null;
  51. response = (M2C_FinishInstanceZonesFightLevel)await MessageHelper.SendToServer(new C2M_FinishInstanceZonesFightLevel()
  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. InstanceZonesDataManager.TryUpdateScore(response.LevelCfgId, response.Score);
  64. InstanceZonesDataManager.TryUpdateLevelStar(response.LevelCfgId, response.Star);
  65. //展示奖励
  66. List<ItemData> bonusList = StoryBonusDataCache.GetBonusList(response.LevelCfgId, response.HasOnceBonus);
  67. if (response.RandomBonusList != null)
  68. {
  69. foreach (var item in response.RandomBonusList)
  70. {
  71. var itemData = ItemUtil.createItemData(item.ConfigId, item.Count);
  72. bonusList.Add(itemData);
  73. }
  74. }
  75. if (response.HasOnceBonus)
  76. {
  77. //首次通过要检查是否有功能开启
  78. FunctionOpenDataManager.Instance.CheckHasChapterFunOpen(response.LevelCfgId);
  79. }
  80. InstanceZonesDataManager.TrySetLevelPass(response.LevelCfgId);
  81. ViewManager.Show(ViewName.STORY_FIGHT_RESULT_VIEW, new StoryFightResultData
  82. {
  83. Result = true,
  84. Score = response.Score,
  85. FirstPass = response.HasOnceBonus,
  86. Star = response.Star,
  87. BonusList = bonusList
  88. }, null, true);
  89. return;
  90. }
  91. }
  92. InstanceZonesController.OnFinishStoryLevel(levelCfgId, false, false);
  93. }
  94. //剧情战斗关卡失败,更新最高分
  95. public static async ETTask StoryFightLevelFail(int levelCfgId, int score)
  96. {
  97. M2C_FinishInstanceZonesFightLevelFail response = null;
  98. response = (M2C_FinishInstanceZonesFightLevelFail)await MessageHelper.SendToServer(new C2M_FinishInstanceZonesFightLevelFail()
  99. {
  100. LevelCfgId = levelCfgId,
  101. Score = score,
  102. });
  103. if (response != null)
  104. {
  105. if (response.Error == ErrorCode.ERR_Success)
  106. {
  107. InstanceZonesDataManager.TryUpdateScore(response.LevelCfgId, response.Score);
  108. }
  109. }
  110. }
  111. //快速完成关卡战斗
  112. public static async ETTask FinishStoryFightQuickly(int levelCfgId, int times)
  113. {
  114. M2C_FinishInstanceZonesFightQuickly response = null;
  115. response = (M2C_FinishInstanceZonesFightQuickly)await MessageHelper.SendToServer(new C2M_FinishInstanceZonesFightQuickly()
  116. {
  117. LevelCfgId = levelCfgId,
  118. Times = times
  119. });
  120. if (response != null)
  121. {
  122. if (response.Error == ErrorCode.ERR_Success)
  123. {
  124. List<List<ItemData>> bonusLists = new List<List<ItemData>>();
  125. List<ItemData> allList = new List<ItemData>();
  126. foreach (var proto in response.RandomBonusList)
  127. {
  128. var itemData = ItemUtil.createItemData(proto.ConfigId, proto.Count);
  129. allList.Add(itemData);
  130. }
  131. var index = 0;
  132. for (int i = 0; i < response.BonusLengths.Count; ++i)
  133. {
  134. var len = response.BonusLengths[i];
  135. var baseBonusList = StoryBonusDataCache.GetBaseBonusList(response.LevelCfgId);
  136. List<ItemData> bonusList = new List<ItemData>();
  137. if (baseBonusList != null)
  138. {
  139. bonusList.AddRange(baseBonusList);
  140. }
  141. if (len > 0)
  142. {
  143. bonusList.AddRange(allList.GetRange(index, len));
  144. }
  145. bonusLists.Add(bonusList);
  146. index += len;
  147. }
  148. EventAgent.DispatchEvent(ConstMessage.STORY_FIGHT_QUICKLY_SUCCESS, bonusLists);
  149. }
  150. }
  151. }
  152. }
  153. }