ArenaSproxy.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using System;
  2. using System.Collections.Generic;
  3. using ET;
  4. namespace GFGGame
  5. {
  6. public class NoticeArebaRankChange : AMHandler<SC_RankChange>
  7. {
  8. protected override async ETTask Run(Session session, SC_RankChange message)
  9. {
  10. ArenaDataManager.Instance.Grade = message.Grade;
  11. ArenaDataManager.Instance.Rank = message.RankInGrade;
  12. ArenaDataManager.Instance.TryUpdateHighest();
  13. await ETTask.CompletedTask;
  14. }
  15. }
  16. public class NoticeArenaHistoryChange : AMHandler<SC_ArenaHistoryAdd>
  17. {
  18. protected override async ETTask Run(Session session, SC_ArenaHistoryAdd message)
  19. {
  20. ArenaHistoryData historyData = ArenaSproxy.GetArenaHistoryData(message.history);
  21. ArenaDataManager.Instance.HistoryDatas.Insert(0, historyData);
  22. ArenaDataManager.Instance.HistoryDatas.RemoveAt(ArenaDataManager.Instance.HistoryDatas.Count - 1);
  23. await ETTask.CompletedTask;
  24. }
  25. }
  26. public static class ArenaSproxy
  27. {
  28. //获取竞技场信息
  29. public static async ETTask GetArenaInfos()
  30. {
  31. S2C_GetArenaInfos response = null;
  32. response = (S2C_GetArenaInfos)await MessageHelper.SendToServer(new C2S_GetArenaInfos());
  33. if (response != null)
  34. {
  35. if (response.Error == ErrorCode.ERR_Success)
  36. {
  37. ArenaDataManager.Instance.ThemeList = response.ThemeList;
  38. // ArenaDataManager.Instance.Tag = response.Tag;
  39. ArenaDataManager.Instance.SeasonId = response.SeasonId;
  40. ArenaDataManager.Instance.Grade = response.Grade;
  41. ArenaDataManager.Instance.Rank = response.RankInGrade;
  42. ArenaDataManager.Instance.HighestGrade = response.HighestGradeOfSeason;
  43. ArenaDataManager.Instance.HighestRank = response.HighestRankInGradeOfSeason;
  44. ArenaDataManager.Instance.Clear();
  45. for (int i = 0; i < response.ThemeList.Count; i++)
  46. {
  47. FightRoleData roleData = new FightRoleData();
  48. roleData.cardId = response.DressupList.Count > i ? response.DressupList[i].CardId : 0;
  49. roleData.itemList = response.DressupList.Count > i ? response.DressupList[i].EquipIds : new List<int>();
  50. ArenaDataManager.Instance.DressupList.Add(roleData);
  51. }
  52. for (int i = 0; i < response.targets.Count; i++)
  53. {
  54. ArenaDataManager.Instance.Targets.Add(GetArenaTargetData(response.targets[i]));
  55. }
  56. }
  57. }
  58. }
  59. //刷新竞争对手
  60. public static async ETTask<bool> ReqRefreshArenaTargets()
  61. {
  62. S2C_RefreshArenaTargets response = null;
  63. response = (S2C_RefreshArenaTargets)await MessageHelper.SendToServer(new C2S_RefreshArenaTargets());
  64. if (response != null)
  65. {
  66. if (response.Error == ErrorCode.ERR_Success)
  67. {
  68. ArenaDataManager.Instance.Targets.Clear();
  69. for (int i = 0; i < response.targets.Count; i++)
  70. {
  71. ArenaDataManager.Instance.Targets.Add(GetArenaTargetData(response.targets[i]));
  72. }
  73. PromptController.Instance.ShowFloatTextPrompt("刷新成功");
  74. return true;
  75. }
  76. }
  77. return false;
  78. }
  79. //更换搭配
  80. public static async ETTask<bool> ReqChangeArenaDressup(int index, int cardId, List<int> itemList)
  81. {
  82. S2C_ChangeArenaDressup response = null;
  83. response = (S2C_ChangeArenaDressup)await MessageHelper.SendToServer(new C2S_ChangeArenaDressup() { Index = index, CardId = cardId, EquipIds = itemList });
  84. if (response != null)
  85. {
  86. if (response.Error == ErrorCode.ERR_Success)
  87. {
  88. ArenaDataManager.Instance.DressupList[index].cardId = cardId;
  89. ArenaDataManager.Instance.DressupList[index].itemList = itemList;
  90. PromptController.Instance.ShowFloatTextPrompt("保存成功");
  91. return true;
  92. }
  93. }
  94. return false;
  95. }
  96. //购买挑战次数
  97. public static async ETTask ReqBuyArenaFightTimes()
  98. {
  99. S2C_BuyArenaFightTimes response = null;
  100. response = (S2C_BuyArenaFightTimes)await MessageHelper.SendToServer(new C2S_BuyArenaFightTimes() { });
  101. if (response != null)
  102. {
  103. if (response.Error == ErrorCode.ERR_Success)
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("购买成功");
  106. }
  107. }
  108. }
  109. //检测顽疾是否能战斗
  110. public static async ETTask<bool> ReqCheckArenaFight()
  111. {
  112. S2C_ArenaFight response = null;
  113. response = (S2C_ArenaFight)await MessageHelper.SendToServer(new C2S_ArenaFight() { });
  114. if (response != null)
  115. {
  116. if (response.Error == ErrorCode.ERR_Success)
  117. {
  118. return true;
  119. }
  120. else
  121. {
  122. ArenaDataManager.Instance.Targets.Clear();
  123. for (int i = 0; i < response.targets.Count; i++)
  124. {
  125. ArenaDataManager.Instance.Targets.Add(GetArenaTargetData(response.targets[i]));
  126. }
  127. PromptController.Instance.ShowFloatTextPrompt("该玩家排名已经发生变化,请重新选择");
  128. }
  129. }
  130. return false;
  131. }
  132. //挑战
  133. public static async ETTask<bool> ReqArenaFight(bool isWin, ArenaTargetData targetData, List<long> selfFightPower, List<long> targetFightPower, List<long> myScore, List<long> targetScore)
  134. {
  135. S2C_ArenaFight response = null;
  136. response = (S2C_ArenaFight)await MessageHelper.SendToServer(new C2S_ArenaFight()
  137. {
  138. RoleId = RoleDataManager.roleId,
  139. Grade = targetData.Grade,
  140. RankInGrade = targetData.RankInGrade,
  141. Type = targetData.Type,
  142. TargetRoleId = targetData.RoleInfo.roleId,
  143. IsWin = isWin,
  144. SelfFightPower = selfFightPower,
  145. TargetFightPower = targetFightPower,
  146. SelfRandScore = myScore,
  147. TargetRandScore = targetScore,
  148. });
  149. if (response != null)
  150. {
  151. if (response.Error != ErrorCode.ERR_Success)
  152. {
  153. int lastGrade = ArenaDataManager.Instance.Grade;
  154. int lastRank = ArenaDataManager.Instance.Rank;
  155. string targetName = targetData.RoleInfo.roleName;
  156. int targetHeadId = targetData.RoleInfo.headId;
  157. string headRes = targetData.RoleInfo.headRes;
  158. ArenaDataManager.Instance.Targets.Clear();
  159. for (int i = 0; i < response.targets.Count; i++)
  160. {
  161. ArenaDataManager.Instance.Targets.Add(GetArenaTargetData(response.targets[i]));
  162. }
  163. ArenaDataManager.Instance.Grade = response.Grade;
  164. ArenaDataManager.Instance.Rank = response.RankInGrade;
  165. ArenaDataManager.Instance.TryUpdateHighest();
  166. List<ItemData> bonusList = ItemUtil.CreateItemDataList(response.rewards);
  167. if (response.Grade > ArenaDataManager.Instance.Grade)
  168. {
  169. BonusController.TryShowBonusList(bonusList, () =>
  170. {
  171. ViewManager.Show<ArenaDanUpView>(new object[] { lastGrade, ArenaDataManager.Instance.Grade, response.RewardId });
  172. });
  173. }
  174. else if (response.RankInGrade > ArenaDataManager.Instance.Rank)
  175. {
  176. BonusController.TryShowBonusList(bonusList, () =>
  177. {
  178. ViewManager.Show<ArenaRankUpView>(new object[] { lastGrade, lastRank, targetHeadId, headRes, targetName });
  179. });
  180. }
  181. else
  182. {
  183. BonusController.TryShowBonusList(bonusList);
  184. }
  185. EventAgent.DispatchEvent(ConstMessage.ARENA_FIGHT_RESULT);
  186. return true;
  187. }
  188. }
  189. return false;
  190. }
  191. //获取排行榜
  192. public static async ETTask<bool> ReqArenaRank(int rankType, int startIndex, int endIndex)
  193. {
  194. S2C_ArenaRank response = null;
  195. response = (S2C_ArenaRank)await MessageHelper.SendToServer(new C2S_ArenaRank() { RankType = rankType, StartIndex = startIndex, EndIndex = endIndex });
  196. if (response != null)
  197. {
  198. if (response.Error == ErrorCode.ERR_Success)
  199. {
  200. if (!ArenaDataManager.Instance.RankDatasDic.ContainsKey(rankType))
  201. {
  202. ArenaDataManager.Instance.RankDatasDic[rankType] = new List<ArenaTargetData>();
  203. }
  204. List<ArenaTargetData> rankDatas = ArenaDataManager.Instance.RankDatasDic[rankType];
  205. for (int i = 0; i < response.ranks.Count; i++)
  206. {
  207. rankDatas.Add(GetArenaTargetData(response.ranks[i]));
  208. }
  209. ArenaDataManager.Instance.SelfData = GetArenaTargetData(response.self);
  210. return true;
  211. }
  212. }
  213. return false;
  214. }
  215. //获取竞技场历史记录
  216. public static async ETTask ReqArenaHistory(int rankType, int startIndex, int endIndex)
  217. {
  218. S2C_ArenaHistory response = null;
  219. response = (S2C_ArenaHistory)await MessageHelper.SendToServer(new C2S_ArenaHistory() { });
  220. if (response != null)
  221. {
  222. if (response.Error == ErrorCode.ERR_Success)
  223. {
  224. ArenaDataManager.Instance.HistoryDatas.Clear();
  225. for (int i = 0; i < response.history.Count; i++)
  226. {
  227. ArenaDataManager.Instance.HistoryDatas.Add(GetArenaHistoryData(response.history[i]));
  228. }
  229. }
  230. }
  231. }
  232. //获取对手服装属性
  233. public static async ETTask ReqArenaFightAttr(long roleId, List<FightRoleData> list)
  234. {
  235. S2C_ArenaFightAttr response = null;
  236. response = (S2C_ArenaFightAttr)await MessageHelper.SendToServer(new C2S_ArenaFightAttr() { TargetRoleId = roleId });
  237. if (response != null)
  238. {
  239. if (response.Error == ErrorCode.ERR_Success)
  240. {
  241. for (int i = 0; i < response.data.Count; i++)
  242. {
  243. list[i].cardScore = response.data[i].CardScore;
  244. list[i].skillLvs = response.data[i].SkillLevel;
  245. list[i].itemScoreList = response.data[i].SuitScore;
  246. }
  247. }
  248. }
  249. }
  250. public static ArenaHistoryData GetArenaHistoryData(ArenaHistoryProto arenaHistoryProto)
  251. {
  252. ArenaHistoryData arenaHistory = new ArenaHistoryData();
  253. arenaHistory.isWin = arenaHistoryProto.IsWin;
  254. arenaHistory.IsChallenge = arenaHistoryProto.IsChallenge;
  255. arenaHistory.FightTime = arenaHistoryProto.FightTime;
  256. arenaHistory.Grade = arenaHistoryProto.Grade;
  257. arenaHistory.Rank = arenaHistoryProto.Rank;
  258. arenaHistory.targetData = GetArenaTargetData(arenaHistoryProto.target);
  259. arenaHistory.GradeChangeType = arenaHistoryProto.GradeChangeType;
  260. arenaHistory.MyScores = arenaHistoryProto.SelfRandScore;
  261. arenaHistory.TargetScores = arenaHistoryProto.TargetRandScore;
  262. arenaHistory.FightScores = arenaHistoryProto.SelfFightPower;
  263. return arenaHistory;
  264. }
  265. private static ArenaTargetData GetArenaTargetData(ArenaTargetProto arenaTargetProto)
  266. {
  267. ArenaTargetData arenaTarget = new ArenaTargetData();
  268. arenaTarget.Grade = arenaTargetProto.Grade;
  269. arenaTarget.RankInGrade = arenaTargetProto.RankInGrade;
  270. arenaTarget.Type = arenaTargetProto.Type;
  271. if (arenaTarget.Type == ArenaFightTargetType.PLAYER)
  272. {
  273. arenaTarget.RoleInfo.roleId = arenaTargetProto.RoleInfo.RoleId;
  274. arenaTarget.RoleInfo.roleName = arenaTargetProto.RoleInfo.RoleName;
  275. arenaTarget.RoleInfo.roleLv = arenaTargetProto.RoleInfo.RoleLvl;
  276. arenaTarget.RoleInfo.headId = arenaTargetProto.RoleInfo.HeadItemId;
  277. }
  278. else
  279. {
  280. ArenaRobotCfg robotCfg = ArenaRobotCfgArray.Instance.GetCfg(arenaTargetProto.RobotDressupInfo.RobotId);
  281. arenaTarget.RoleInfo.roleId = 0;
  282. arenaTarget.RoleInfo.roleName = robotCfg.gradeName;
  283. arenaTarget.RoleInfo.roleLv = robotCfg.level;
  284. arenaTarget.RoleInfo.headRes = robotCfg.targetRes;
  285. }
  286. arenaTarget.RoleDressupList.Clear();
  287. arenaTarget.RobotDressupList.Clear();
  288. for (int j = 0; j < ArenaDataManager.Instance.ThemeList.Count; j++)
  289. {
  290. if (arenaTarget.Type == ArenaFightTargetType.PLAYER)
  291. {
  292. FightRoleData roleData = GetFightRoleData(arenaTargetProto.PlayerDressupList[j], arenaTarget.RoleInfo, j);
  293. arenaTarget.RoleDressupList.Add(roleData);
  294. }
  295. else if (arenaTarget.Type == ArenaFightTargetType.ROBOT)
  296. {
  297. FightRobotData robotData = GetFightRobotData(arenaTargetProto.RobotDressupInfo, j);
  298. arenaTarget.RobotDressupList.Add(robotData);
  299. }
  300. }
  301. return arenaTarget;
  302. }
  303. private static FightRoleData GetFightRoleData(ArenaDressupProto dressupProto, OtherRoleInfoData roleInfo, int index)
  304. {
  305. FightRoleData roleData = new FightRoleData();
  306. roleData.name = roleInfo.roleName;
  307. roleData.headId = roleInfo.headId;
  308. roleData.baseScore = RoleLevelCfgArray.Instance.GetCfg(roleInfo.roleLv).baseScore;
  309. roleData.cardId = dressupProto.CardId;
  310. roleData.itemList = dressupProto.EquipIds;
  311. if (index == 0) roleData.tags = new string[1] { ArenaDataManager.Instance.Tag };
  312. return roleData;
  313. }
  314. private static FightRobotData GetFightRobotData(ArenaRobotProto robotProto, int index)
  315. {
  316. ArenaRobotCfg robotCfg = ArenaRobotCfgArray.Instance.GetCfg(robotProto.RobotId);
  317. FightRobotData robotData = new FightRobotData();
  318. robotData.name = robotCfg.gradeName;
  319. robotData.res = robotCfg.targetRes;
  320. robotData.itemScoreList = new List<int>(robotCfg.partsScoreArr);
  321. robotData.baseScore = robotCfg.baseScore;
  322. robotData.cardId = robotProto.CardIdList[index];
  323. double cardScore = (double)robotCfg.cardScore * (double)robotProto.Random / 10000 * 100;
  324. robotData.cardScore = (int)Math.Ceiling(cardScore);
  325. robotData.skillLvs.Add(robotCfg.skillLvs);
  326. robotData.showSuitId = robotProto.SuitList[index];
  327. if (index == 0)//只有第一个主题才计算标签
  328. {
  329. robotData.tags = new string[1] { ArenaDataManager.Instance.Tag };
  330. robotData.tagAddition = robotCfg.tagAddition;
  331. }
  332. return robotData;
  333. }
  334. }
  335. }