MatchingCompetitionSproxy.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. using ET;
  2. using GFGGame;
  3. using FairyGUI;
  4. using UnityEngine;
  5. using UnityEngine.Networking;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. namespace ET
  9. {
  10. public class M2C_NoticeMatchingStateHandler : AMHandler<S2C_PushJudgingRoundInfo>
  11. {
  12. protected override async ETTask Run(Session session, S2C_PushJudgingRoundInfo message)
  13. {
  14. MatchingCompetitionDataManager.Instance.MatchingCompetitionSeason = message.JudgingRoundOpenId;
  15. MatchingCompetitionDataManager.Instance.MatchingEndTimes = message.PhaseEndTime;
  16. MatchingCompetitionDataManager.Instance.MatchingState = message.PhaseType;
  17. //await MatchingCompetitionSproxy.ReqMatchingCompetitionInfo();
  18. await ETTask.CompletedTask;
  19. }
  20. }
  21. }
  22. namespace GFGGame
  23. {
  24. public class MatchingCompetitionSproxy
  25. {
  26. //获取搭配评选赛信息
  27. public static async ETTask<bool> ReqMatchingCompetitionInfo()
  28. {
  29. S2C_GetJudgingRoundInfo response = (S2C_GetJudgingRoundInfo)await MessageHelper.SendToServer(new C2S_GetJudgingRoundInfo { });
  30. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  31. MatchingCompetitionDataManager.Instance.MatchingCompetitionSeason = response.JudgingRoundOpenId;
  32. MatchingCompetitionDataManager.Instance.MatchingState = response.PhaseType;
  33. MatchingCompetitionDataManager.Instance.MatchingEndTimes = response.PhaseEndTime;
  34. MatchingCompetitionDataManager.Instance.MatchingRemainingTimes = response.Num;
  35. if(response.MyWorks != null)
  36. {
  37. MatchingCompetitionDataManager.Instance.myWorks = response.MyWorks;
  38. MatchingCompetitionDataManager.Instance.WorksID = response.MyWorks.WorksId;
  39. MatchingCompetitionDataManager.Instance.AllDressIDInfoList = response.MyWorks.CollocationInfoList;
  40. }
  41. else
  42. {
  43. MatchingCompetitionDataManager.Instance.myWorks.Score = 0;
  44. MatchingCompetitionDataManager.Instance.AllDressIDInfoList = new List<CollocationInfo>();
  45. }
  46. if(response.MyWorks != null && response.MyWorks.PictureTempUrl != "")
  47. {
  48. Timers.inst.StartCoroutine(MatchingPhotoHelper.DownloadMyself(response.MyWorks.PictureTempUrl));
  49. }
  50. MatchingCompetitionDataManager.Instance.AnalysisInfoToList();
  51. return true;
  52. }
  53. //获取搭配作品信息
  54. //public static async ETTask<bool> ReqMatchingCompetitionDressData()
  55. //{
  56. // var response = (S2C_RequestUpLoadJudgingRoundWorks)await MessageHelper.SendToServer(new C2S_RequestUpLoadJudgingRoundWorks {});
  57. // if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  58. // return true;
  59. //}
  60. //获取一个热门推荐的玩家
  61. public static async ETTask<bool> ReqGetOnePlayers()
  62. {
  63. var response = (S2C_GetOnePlayers)await MessageHelper.SendToServer(new C2S_GetOnePlayers { });
  64. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  65. MatchingOneDataManager.Instance.OneRoleInfo.JudgingInfo = response.JudgingRoundRole;
  66. if (response.JudgingRoundRole == null)
  67. {
  68. return false;
  69. }
  70. Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingOneDataManager.Instance.OneRoleInfo));
  71. MatchingOneDataManager.Instance.AnalysisInfoToList();
  72. return true;
  73. }
  74. //上传作品信息
  75. public static async ETTask<object[]> UpLoadMatchingCompetitionDressData()
  76. {
  77. MatchingCompetitionDataManager.Instance.ConvertInfoToList();
  78. var response = (S2C_RequestUpLoadJudgingRoundWorks)await MessageHelper.SendToServer(new C2S_RequestUpLoadJudgingRoundWorks
  79. {
  80. PictureType = 1,
  81. BagId = MatchingCompetitionDataManager.Instance.DressUpBgID,
  82. ActionId = MatchingCompetitionDataManager.Instance.MathingDressDate.actionId,
  83. CollocationInfoList = MatchingCompetitionDataManager.Instance.AllDressIDInfoList
  84. });
  85. if (!(response is { Error: ErrorCode.ERR_Success })) return null;
  86. MatchingCompetitionDataManager.Instance.WorksID = response.WorksId;
  87. MatchingCompetitionDataManager.Instance.TempPictureUrl = response.TempPictureUrl;
  88. return new object[] { response.TempPictureUrl, response.WorksId };
  89. }
  90. //通知服务端上传成功
  91. public static async ETTask<bool> UploadSuccess()
  92. {
  93. var response = (S2C_NoticeJudgingRoundWorksUploaded)await MessageHelper.SendToServer(new C2S_NoticeJudgingRoundWorksUploaded
  94. {
  95. WorksId = MatchingCompetitionDataManager.Instance.WorksID
  96. }) ;
  97. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  98. return true;
  99. }
  100. //获取两个评选推荐的玩家
  101. public static async ETTask<bool> ReqGetTwoPlayers()
  102. {
  103. var response = (S2C_GetTwoPlayers)await MessageHelper.SendToServer(new C2S_GetTwoPlayers { });
  104. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  105. if(response.JudgingRoundRoleInfoList == null || response.JudgingRoundRoleInfoList.Count < 2)
  106. {
  107. return false;
  108. }
  109. MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo = response.JudgingRoundRoleInfoList[0];
  110. if(response.JudgingRoundRoleInfoList[0] != null)
  111. {
  112. Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingLeftDataManager.Instance.LeftRoleInfo));
  113. }
  114. MatchingLeftDataManager.Instance.AnalysisInfoToList();
  115. MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo = response.JudgingRoundRoleInfoList[1];
  116. if (response.JudgingRoundRoleInfoList[1] != null)
  117. {
  118. Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingRightDataManager.Instance.RightRoleInfo));
  119. }
  120. MatchingRightDataManager.Instance.AnalysisInfoToList();
  121. return true;
  122. }
  123. //选择搭配作品
  124. public static async ETTask<bool> ReqCheckMatchingCompetitionWork(long workID,long anotherWorkId )
  125. {
  126. var response = (S2C_SelFavoriteWorks)await MessageHelper.SendToServer(new C2S_SelFavoriteWorks
  127. {
  128. WorksId = workID,
  129. AnotherWorksId = anotherWorkId
  130. }) ;
  131. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  132. if (response.JudgingRoundRoleInfoList == null || response.JudgingRoundRoleInfoList.Count < 2)
  133. {
  134. return false;
  135. }
  136. MatchingCompetitionDataManager.Instance.MatchingRemainingTimes = response.Num;
  137. MatchingCompetitionDataManager.Instance.SpecialBonusList = response.SpecialBonusList;
  138. if (MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo.WorksId == workID)
  139. {
  140. MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo = response.JudgingRoundRoleInfoList[0];
  141. MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo = response.JudgingRoundRoleInfoList[1];
  142. }
  143. else
  144. {
  145. MatchingLeftDataManager.Instance.LeftRoleInfo.JudgingInfo = response.JudgingRoundRoleInfoList[1];
  146. MatchingRightDataManager.Instance.RightRoleInfo.JudgingInfo = response.JudgingRoundRoleInfoList[0];
  147. }
  148. BonusController.TryShowBonusList(ItemUtil.CreateItemDataList(response.BonusList));
  149. return true;
  150. }
  151. //获取当前排行榜
  152. public static async ETTask<bool> ReqCurrentRank(bool isPushEvent = false)
  153. {
  154. var response =
  155. (S2C_GetCurJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetCurJudgingRoundRankList
  156. { });
  157. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  158. //需要从缓存里清理的数据
  159. List<long> delRoleIds = new List<long>();
  160. foreach (var item in MatchingCompetitionDataManager.Instance._currentRankList)
  161. {
  162. if (response.JudgingRoundRoleInfoList.All(a => a.RoleId != item.RoleId))
  163. {
  164. delRoleIds.Add(item.RoleId);
  165. }
  166. }
  167. //执行清理
  168. if (delRoleIds.Count != 0)
  169. {
  170. foreach (var roleId in delRoleIds)
  171. {
  172. var itemToRemove =
  173. MatchingCompetitionDataManager.Instance._currentRankList.FirstOrDefault(item =>
  174. item.RoleId == roleId);
  175. if (itemToRemove != null)
  176. {
  177. MatchingCompetitionDataManager.Instance._currentRankList.Remove(itemToRemove);
  178. }
  179. }
  180. }
  181. foreach (var judgingRoundRoleInfo in response.JudgingRoundRoleInfoList)
  182. {
  183. MatchingPhotoWorksData matchingPhotoWorksData =
  184. MatchingCompetitionDataManager.Instance._currentRankList.FirstOrDefault(a =>
  185. a.RoleId == judgingRoundRoleInfo.RoleId);
  186. if (matchingPhotoWorksData == null)
  187. {
  188. matchingPhotoWorksData = new MatchingPhotoWorksData
  189. {
  190. RoleId = judgingRoundRoleInfo.RoleId,
  191. JudgingInfo = judgingRoundRoleInfo
  192. };
  193. MatchingCompetitionDataManager.Instance._currentRankList.Add(matchingPhotoWorksData);
  194. }
  195. else
  196. {
  197. int index = MatchingCompetitionDataManager.Instance._currentRankList
  198. .IndexOf(matchingPhotoWorksData);
  199. if (matchingPhotoWorksData.JudgingInfo != null)
  200. {
  201. string newTempFileName = StringUtil.GetUrlFileName(matchingPhotoWorksData.JudgingInfo.PictureTempUrl);
  202. string oldTempFileName = StringUtil.GetUrlFileName(judgingRoundRoleInfo.PictureTempUrl);
  203. matchingPhotoWorksData.IsUp = newTempFileName != oldTempFileName;
  204. }
  205. matchingPhotoWorksData.JudgingInfo = judgingRoundRoleInfo;
  206. matchingPhotoWorksData.RoleId = judgingRoundRoleInfo.RoleId;
  207. MatchingCompetitionDataManager.Instance._currentRankList[index] = matchingPhotoWorksData;
  208. }
  209. }
  210. //排序
  211. MatchingCompetitionDataManager.Instance._currentRankList.Sort((a, b) =>
  212. {
  213. // 假设列表项具有一个名为 'score' 的属性,你想要按照分数进行排序
  214. if (a.JudgingInfo.Score > b.JudgingInfo.Score)
  215. {
  216. return -1; // a在b之前
  217. }
  218. else if (a.JudgingInfo.Score < b.JudgingInfo.Score)
  219. {
  220. return 1; // b在a之前
  221. }
  222. else
  223. {
  224. return 0; // a和b相同
  225. }
  226. });
  227. Timers.inst.StartCoroutine(
  228. MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._currentRankList));
  229. //推送事件
  230. if (isPushEvent)
  231. {
  232. EventAgent.DispatchEvent(ConstMessage.REQ_CURRENT_RANK);
  233. }
  234. return true;
  235. }
  236. //获取往期作品集
  237. public static async ETTask<bool> ReqBeforeWorks()
  238. {
  239. var response = (S2C_GetPreviousWorksCollection)await MessageHelper.SendToServer(new C2S_GetPreviousWorksCollection { });
  240. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  241. MatchingCompetitionDataManager.Instance._BeforeWorksList.Clear();
  242. foreach (var item in response.WorksCollectionList)
  243. {
  244. MatchingWorksData data = new MatchingWorksData();
  245. data.WorksInfo = item;
  246. MatchingCompetitionDataManager.Instance._BeforeWorksList.Add(data);
  247. }
  248. Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._BeforeWorksList));
  249. return true;
  250. }
  251. //获取往期作品排行榜
  252. public static async ETTask<bool> ReqBeforeRank(int id)
  253. {
  254. var response = (S2C_GetOldJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetOldJudgingRoundRankList { JudgingRoundOpenId = id});
  255. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  256. MatchingCompetitionDataManager.Instance._BeforeRankList.Clear();
  257. foreach (var item in response.JudgingRoundRoleInfoList)
  258. {
  259. MatchingPhotoWorksData data = new MatchingPhotoWorksData();
  260. data.RoleId = item.RoleId;
  261. data.JudgingInfo = item;
  262. MatchingCompetitionDataManager.Instance._BeforeRankList.Add(data);
  263. }
  264. Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._BeforeRankList));
  265. return true;
  266. }
  267. //搭配赛相册系协议
  268. public static async ETTask<bool> ReqMatchingPhotoData()
  269. {
  270. var response = (S2C_GetJudgingRoundWorksList)await MessageHelper.SendToServer(new C2S_GetJudgingRoundWorksList { });
  271. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  272. MatchingCompetitionDataManager.Instance.MatchingPhotoInfos.Clear();
  273. foreach (var item in response.JudgingRoundRoleInfoList)
  274. {
  275. PoemPhotoData photoData = new PoemPhotoData();
  276. photoData.PictureId = item.WorksId;
  277. photoData.CreationTime = item.CreationTime;
  278. photoData.ToppingStatus = item.ToppingStatus;
  279. photoData.PictureTempUrl = item.PictureTempUrl;
  280. MatchingCompetitionDataManager.Instance.MatchingPhotoInfos.Add(photoData);
  281. }
  282. Timers.inst.StartCoroutine(PictureStorageHelper.Download(MatchingCompetitionDataManager.Instance.MatchingPhotoInfos));
  283. return true;
  284. }
  285. //修改图片锁定状态
  286. public static async ETTask<bool> ReqChangeLockingState(long pictureId, bool state, int sourceType)
  287. {
  288. S2C_UpJudgingRoundWorksLockingStatus response = null;
  289. response = (S2C_UpJudgingRoundWorksLockingStatus)await MessageHelper.SendToServer(new C2S_UpJudgingRoundWorksLockingStatus() { WorksId = pictureId, Status = state });
  290. if (response != null)
  291. {
  292. if (response.Error == ErrorCode.ERR_Success)
  293. {
  294. PoemPhotoDataManager.Instance.ChangeLockingState(response.WorksId, response.Status, sourceType);
  295. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  296. return true;
  297. }
  298. }
  299. return false;
  300. }
  301. //修改图片置顶状态
  302. public static async ETTask<bool> ReqChangeToppingState(long pictureId, bool state, int sourceType)
  303. {
  304. S2C_UpJudgingRoundWorksToppingStatus response = null;
  305. response = (S2C_UpJudgingRoundWorksToppingStatus)await MessageHelper.SendToServer(new C2S_UpJudgingRoundWorksToppingStatus() { WorksId = pictureId, Status = state });
  306. if (response != null)
  307. {
  308. if (response.Error == ErrorCode.ERR_Success)
  309. {
  310. PoemPhotoDataManager.Instance.ChangeToppingState(response.WorksId, response.Status, sourceType);
  311. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  312. return true;
  313. }
  314. }
  315. return false;
  316. }
  317. //批量删除玩家相册
  318. public static async ETTask<bool> ReqRemovedPhoto(List<long> pictureIds, int sourceType)
  319. {
  320. S2C_RemovedJudgingRoundWorks response = null;
  321. response = (S2C_RemovedJudgingRoundWorks)await MessageHelper.SendToServer(new C2S_RemovedJudgingRoundWorks() { WorksIds = pictureIds });
  322. if (response != null)
  323. {
  324. if (response.Error == ErrorCode.ERR_Success)
  325. {
  326. PoemPhotoDataManager.Instance.Remove(response.WorksIds, sourceType);
  327. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  328. return true;
  329. }
  330. }
  331. return false;
  332. }
  333. }
  334. }