MatchingCompetitionSproxy.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. if (matchingPhotoWorksData.IsUp)
  208. {
  209. matchingPhotoWorksData.Ntexture = null;
  210. }
  211. MatchingCompetitionDataManager.Instance._currentRankList[index] = matchingPhotoWorksData;
  212. }
  213. }
  214. //排序
  215. MatchingCompetitionDataManager.Instance._currentRankList.Sort((a, b) =>
  216. {
  217. // 假设列表项具有一个名为 'score' 的属性,你想要按照分数进行排序
  218. if (a.JudgingInfo.Score > b.JudgingInfo.Score)
  219. {
  220. return -1; // a在b之前
  221. }
  222. else if (a.JudgingInfo.Score < b.JudgingInfo.Score)
  223. {
  224. return 1; // b在a之前
  225. }
  226. else
  227. {
  228. return 0; // a和b相同
  229. }
  230. });
  231. Timers.inst.StartCoroutine(
  232. MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._currentRankList));
  233. //推送事件
  234. if (isPushEvent)
  235. {
  236. EventAgent.DispatchEvent(ConstMessage.REQ_CURRENT_RANK);
  237. }
  238. return true;
  239. }
  240. //获取往期作品集
  241. public static async ETTask<bool> ReqBeforeWorks()
  242. {
  243. var response = (S2C_GetPreviousWorksCollection)await MessageHelper.SendToServer(new C2S_GetPreviousWorksCollection { });
  244. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  245. MatchingCompetitionDataManager.Instance._BeforeWorksList.Clear();
  246. foreach (var item in response.WorksCollectionList)
  247. {
  248. MatchingWorksData data = new MatchingWorksData();
  249. data.WorksInfo = item;
  250. MatchingCompetitionDataManager.Instance._BeforeWorksList.Add(data);
  251. }
  252. Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._BeforeWorksList));
  253. return true;
  254. }
  255. //获取往期作品排行榜
  256. public static async ETTask<bool> ReqBeforeRank(int id)
  257. {
  258. var response = (S2C_GetOldJudgingRoundRankList)await MessageHelper.SendToServer(new C2S_GetOldJudgingRoundRankList { JudgingRoundOpenId = id});
  259. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  260. MatchingCompetitionDataManager.Instance._BeforeRankList.Clear();
  261. foreach (var item in response.JudgingRoundRoleInfoList)
  262. {
  263. MatchingPhotoWorksData data = new MatchingPhotoWorksData();
  264. data.RoleId = item.RoleId;
  265. data.JudgingInfo = item;
  266. MatchingCompetitionDataManager.Instance._BeforeRankList.Add(data);
  267. }
  268. Timers.inst.StartCoroutine(MatchingPhotoHelper.Download(MatchingCompetitionDataManager.Instance._BeforeRankList));
  269. return true;
  270. }
  271. //搭配赛相册系协议
  272. public static async ETTask<bool> ReqMatchingPhotoData()
  273. {
  274. var response = (S2C_GetJudgingRoundWorksList)await MessageHelper.SendToServer(new C2S_GetJudgingRoundWorksList { });
  275. if (!(response is { Error: ErrorCode.ERR_Success })) return false;
  276. MatchingCompetitionDataManager.Instance.MatchingPhotoInfos.Clear();
  277. foreach (var item in response.JudgingRoundRoleInfoList)
  278. {
  279. PoemPhotoData photoData = new PoemPhotoData();
  280. photoData.PictureId = item.WorksId;
  281. photoData.CreationTime = item.CreationTime;
  282. photoData.ToppingStatus = item.ToppingStatus;
  283. photoData.PictureTempUrl = item.PictureTempUrl;
  284. MatchingCompetitionDataManager.Instance.MatchingPhotoInfos.Add(photoData);
  285. }
  286. Timers.inst.StartCoroutine(PictureStorageHelper.Download(MatchingCompetitionDataManager.Instance.MatchingPhotoInfos));
  287. return true;
  288. }
  289. //修改图片锁定状态
  290. public static async ETTask<bool> ReqChangeLockingState(long pictureId, bool state, int sourceType)
  291. {
  292. S2C_UpJudgingRoundWorksLockingStatus response = null;
  293. response = (S2C_UpJudgingRoundWorksLockingStatus)await MessageHelper.SendToServer(new C2S_UpJudgingRoundWorksLockingStatus() { WorksId = pictureId, Status = state });
  294. if (response != null)
  295. {
  296. if (response.Error == ErrorCode.ERR_Success)
  297. {
  298. PoemPhotoDataManager.Instance.ChangeLockingState(response.WorksId, response.Status, sourceType);
  299. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  300. return true;
  301. }
  302. }
  303. return false;
  304. }
  305. //修改图片置顶状态
  306. public static async ETTask<bool> ReqChangeToppingState(long pictureId, bool state, int sourceType)
  307. {
  308. S2C_UpJudgingRoundWorksToppingStatus response = null;
  309. response = (S2C_UpJudgingRoundWorksToppingStatus)await MessageHelper.SendToServer(new C2S_UpJudgingRoundWorksToppingStatus() { WorksId = pictureId, Status = state });
  310. if (response != null)
  311. {
  312. if (response.Error == ErrorCode.ERR_Success)
  313. {
  314. PoemPhotoDataManager.Instance.ChangeToppingState(response.WorksId, response.Status, sourceType);
  315. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  316. return true;
  317. }
  318. }
  319. return false;
  320. }
  321. //批量删除玩家相册
  322. public static async ETTask<bool> ReqRemovedPhoto(List<long> pictureIds, int sourceType)
  323. {
  324. S2C_RemovedJudgingRoundWorks response = null;
  325. response = (S2C_RemovedJudgingRoundWorks)await MessageHelper.SendToServer(new C2S_RemovedJudgingRoundWorks() { WorksIds = pictureIds });
  326. if (response != null)
  327. {
  328. if (response.Error == ErrorCode.ERR_Success)
  329. {
  330. PoemPhotoDataManager.Instance.Remove(response.WorksIds, sourceType);
  331. EventAgent.DispatchEvent(ConstMessage.POEM_PHOTO_INFOS_CHANGE);
  332. return true;
  333. }
  334. }
  335. return false;
  336. }
  337. }
  338. }