FriendSProxy.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. using GFGGame;
  2. using ET;
  3. using System.Collections.Generic;
  4. namespace ET
  5. {
  6. //推送好友每日重置
  7. public class NoticeFriendDailyReset : AMHandler<S2C_NoticeFriendDailyReset>
  8. {
  9. protected override async ETTask Run(Session session, S2C_NoticeFriendDailyReset message)
  10. {
  11. FriendSProxy.ReqAllFriendInfos().Coroutine();
  12. await ETTask.CompletedTask;
  13. }
  14. }
  15. //推送其他玩家信息变化
  16. public class NoticeRoleInfoChanged : AMHandler<S2C_NoticeFriendInfo>
  17. {
  18. protected override async ETTask Run(Session session, S2C_NoticeFriendInfo message)
  19. {
  20. OtherRoleInfoData roleInfo = new OtherRoleInfoData();
  21. roleInfo.roleId = message.RoleInfo.RoleId;
  22. roleInfo.roleLv = message.RoleInfo.RoleLvl;
  23. roleInfo.roleName = message.RoleInfo.RoleName;
  24. roleInfo.offlineTimeSec = message.RoleInfo.OfflineTimeSec;
  25. roleInfo.headId = message.RoleInfo.HeadItemId;
  26. roleInfo.headBorderId = message.RoleInfo.HeadBorderItemId;
  27. roleInfo.leagueName = message.RoleInfo.LeagueName;
  28. roleInfo.itemList = new List<int>();
  29. for(int i=0;i< message.RoleInfo.ItemList.Count; i++)
  30. {
  31. roleInfo.itemList.Add(message.RoleInfo.ItemList[i]);
  32. }
  33. roleInfo.suitCollect = message.RoleInfo.SuitCollect;
  34. roleInfo.cardCollect = message.RoleInfo.CardCollect;
  35. roleInfo.achievementTaskCollect = message.RoleInfo.AchievementTaskCollect;
  36. roleInfo.roleExp = message.RoleInfo.RoleExp;
  37. FriendDataManager.Instance.ChangeFriendInfo(roleInfo);
  38. EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);
  39. await ETTask.CompletedTask;
  40. }
  41. }
  42. //推送申请添加好友信息
  43. public class NoticeApplyForFriend : AMHandler<S2C_NoticeApplyForFriend>
  44. {
  45. protected override async ETTask Run(Session session, S2C_NoticeApplyForFriend message)
  46. {
  47. if(FriendDataManager.Instance.CheckInApplyList(message.FriendInfo.RoleInfo.RoleId))
  48. {
  49. return;
  50. }
  51. OtherRoleInfoData roleInfo = new OtherRoleInfoData();
  52. roleInfo.roleId = message.FriendInfo.RoleInfo.RoleId;
  53. roleInfo.roleName = message.FriendInfo.RoleInfo.RoleName;
  54. roleInfo.roleLv = message.FriendInfo.RoleInfo.RoleLvl;
  55. roleInfo.offlineTimeSec = message.FriendInfo.RoleInfo.OfflineTimeSec;
  56. roleInfo.headId = message.FriendInfo.RoleInfo.HeadItemId;
  57. roleInfo.headBorderId = message.FriendInfo.RoleInfo.HeadBorderItemId;
  58. FriendInfoData friendInfo = new FriendInfoData();
  59. friendInfo.roleInfo = roleInfo;
  60. friendInfo.type = message.FriendInfo.Type;
  61. friendInfo.giveGiftState = message.FriendInfo.GiveGiftState;
  62. friendInfo.takeGiftState = message.FriendInfo.TakeGiftState;
  63. FriendDataManager.Instance.AddApplyData(friendInfo);
  64. EventAgent.DispatchEvent(ConstMessage.FRIEND_APPLY_CHANGE);
  65. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  66. await ETTask.CompletedTask;
  67. }
  68. }
  69. //推送新增好友
  70. public class NoticeAddFriends : AMHandler<S2C_NoticeAddFriends>
  71. {
  72. protected override async ETTask Run(Session session, S2C_NoticeAddFriends message)
  73. {
  74. for (int i = 0; i < message.FriendList.Count; i++)
  75. {
  76. OtherRoleInfoData roleInfo = new OtherRoleInfoData();
  77. roleInfo.roleId = message.FriendList[i].RoleInfo.RoleId;
  78. roleInfo.roleName = message.FriendList[i].RoleInfo.RoleName;
  79. roleInfo.roleLv = message.FriendList[i].RoleInfo.RoleLvl;
  80. roleInfo.offlineTimeSec = message.FriendList[i].RoleInfo.OfflineTimeSec;
  81. roleInfo.headId = message.FriendList[i].RoleInfo.HeadItemId;
  82. roleInfo.headBorderId = message.FriendList[i].RoleInfo.HeadBorderItemId;
  83. FriendInfoData friendInfo = new FriendInfoData();
  84. friendInfo.roleInfo = roleInfo;
  85. friendInfo.type = message.FriendList[i].Type;
  86. friendInfo.giveGiftState = message.FriendList[i].GiveGiftState;
  87. friendInfo.takeGiftState = message.FriendList[i].TakeGiftState;
  88. FriendDataManager.Instance.AddFriend(friendInfo);
  89. FriendDataManager.Instance.RemoveApplyData(message.FriendList[i].RoleInfo.RoleId);
  90. }
  91. EventAgent.DispatchEvent(ConstMessage.FRIEND_ADD);
  92. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  93. await ETTask.CompletedTask;
  94. }
  95. }
  96. //推送删除好友
  97. public class NoticeDeleteFriend : AMHandler<S2C_NoticeDeleteFriend>
  98. {
  99. protected override async ETTask Run(Session session, S2C_NoticeDeleteFriend message)
  100. {
  101. FriendDataManager.Instance.RemoveFriend(message.FriendId);
  102. EventAgent.DispatchEvent(ConstMessage.FRIEND_REMOVE);
  103. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  104. await ETTask.CompletedTask;
  105. }
  106. }
  107. //推送领取赠送状态
  108. public class NoticeTakeGiftStates : AMHandler<S2C_NoticeTakeGiftStates>
  109. {
  110. protected override async ETTask Run(Session session, S2C_NoticeTakeGiftStates message)
  111. {
  112. FriendDataManager.Instance.ChangeTakeGiftStates(message.FriendId, message.TakeGiftState);
  113. EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);
  114. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  115. await ETTask.CompletedTask;
  116. }
  117. }
  118. }
  119. namespace GFGGame
  120. {
  121. public static class FriendSProxy
  122. {
  123. //请求所有好友信息
  124. public static async ETTask<bool> ReqAllFriendInfos()
  125. {
  126. S2C_GetAllFriendInfos response = null;
  127. response = (S2C_GetAllFriendInfos)await MessageHelper.SendToServer(new C2S_GetAllFriendInfos());
  128. if (response != null)
  129. {
  130. if (response.Error == ErrorCode.ERR_Success)
  131. {
  132. FriendDataManager.Instance.ClearAddFriend();
  133. for (int i = 0; i < response.FriendList.Count; i++)
  134. {
  135. OtherRoleInfoData roleInfo = new OtherRoleInfoData();
  136. roleInfo.roleId = response.FriendList[i].RoleInfo.RoleId;
  137. roleInfo.roleName = response.FriendList[i].RoleInfo.RoleName;
  138. roleInfo.roleLv = response.FriendList[i].RoleInfo.RoleLvl;
  139. roleInfo.offlineTimeSec = response.FriendList[i].RoleInfo.OfflineTimeSec;
  140. roleInfo.headId = response.FriendList[i].RoleInfo.HeadItemId;
  141. roleInfo.headBorderId = response.FriendList[i].RoleInfo.HeadBorderItemId;
  142. FriendInfoData friendInfo = new FriendInfoData();
  143. friendInfo.roleInfo = roleInfo;
  144. friendInfo.type = response.FriendList[i].Type;
  145. friendInfo.giveGiftState = response.FriendList[i].GiveGiftState;
  146. friendInfo.takeGiftState = response.FriendList[i].TakeGiftState;
  147. if (response.FriendList[i].Type == FriendType.Good)
  148. {
  149. FriendDataManager.Instance.AddFriend(friendInfo);
  150. }
  151. else if (response.FriendList[i].Type == FriendType.Apply)
  152. {
  153. if (!FriendDataManager.Instance.CheckInApplyList(friendInfo.roleInfo.roleId))
  154. {
  155. FriendDataManager.Instance.AddApplyData(friendInfo);
  156. }
  157. }
  158. }
  159. EventAgent.DispatchEvent(ConstMessage.FRIEND_ADD);
  160. return true;
  161. }
  162. }
  163. return false;
  164. }
  165. //赠送
  166. public static async ETTask<bool> ReqGiveGiftToFriend(long friendId)
  167. {
  168. S2C_GiveGiftToFriend response = null;
  169. response = (S2C_GiveGiftToFriend)await MessageHelper.SendToServer(new C2S_GiveGiftToFriend() { FriendId = friendId });
  170. if (response != null)
  171. {
  172. if (response.Error == ErrorCode.ERR_Success)
  173. {
  174. FriendDataManager.Instance.ChangeGiveGiftStates(response.FriendId, response.GiveGiftState);
  175. PromptController.Instance.ShowFloatTextPrompt(string.Format("赠送好友体力*{0}", GlobalCfgArray.globalCfg.onceGivePowerCount));
  176. EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);
  177. return true;
  178. }
  179. }
  180. return false;
  181. }
  182. //一键赠送
  183. public static async ETTask<bool> ReqGiveGiftToAllFriend()
  184. {
  185. S2C_GiveGiftToAllFriends response = null;
  186. response = (S2C_GiveGiftToAllFriends)await MessageHelper.SendToServer(new C2S_GiveGiftToAllFriends());
  187. if (response != null)
  188. {
  189. if (response.Error == ErrorCode.ERR_Success)
  190. {
  191. for (int i = 0; i < response.FriendIds.Count; i++)
  192. {
  193. FriendDataManager.Instance.ChangeGiveGiftStates(response.FriendIds[i], response.GiveGiftStates[i]);
  194. }
  195. if (response.FriendIds.Count > 0)
  196. {
  197. PromptController.Instance.ShowFloatTextPrompt(string.Format("送出{0}份体力", response.FriendIds.Count));
  198. }
  199. else
  200. {
  201. PromptController.Instance.ShowFloatTextPrompt("无好友可赠送体力");
  202. }
  203. EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);
  204. return true;
  205. }
  206. }
  207. return false;
  208. }
  209. //领取并赠送赠送
  210. public static async ETTask<bool> ReqTakeGiftFromFriend(long friendId)
  211. {
  212. S2C_TakeGiftFromFriend response = null;
  213. response = (S2C_TakeGiftFromFriend)await MessageHelper.SendToServer(new C2S_TakeGiftFromFriend() { FriendId = friendId });
  214. if (response != null)
  215. {
  216. if (response.Error == ErrorCode.ERR_Success)
  217. {
  218. FriendDataManager.Instance.ChangeGiveTakeGiftStates(response.FriendId, response.GiveGiftState, response.TakeGiftState);
  219. PromptController.Instance.ShowFloatTextPrompt(string.Format("领取成功,获得体力*{0}", GlobalCfgArray.globalCfg.onceGivePowerCount));
  220. EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);
  221. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  222. return true;
  223. }
  224. }
  225. return false;
  226. }
  227. //一键领取并赠送
  228. public static async ETTask<bool> ReqTakeGiftFromAllFriend()
  229. {
  230. S2C_TakeGiftFromAllFriend response = null;
  231. response = (S2C_TakeGiftFromAllFriend)await MessageHelper.SendToServer(new C2S_TakeGiftFromAllFriend());
  232. if (response != null)
  233. {
  234. if (response.Error == ErrorCode.ERR_Success)
  235. {
  236. for (int i = 0; i < response.FriendIds.Count; i++)
  237. {
  238. FriendDataManager.Instance.ChangeGiveTakeGiftStates(response.FriendIds[i], response.GiveGiftStates[i], response.TakeGiftStates[i]);
  239. }
  240. if (FriendDataManager.Instance.Count >= FriendDataManager.Instance.maxGetPowerCount)
  241. {
  242. PromptController.Instance.ShowFloatTextPrompt("今日体力已全部领取");
  243. }
  244. else
  245. {
  246. PromptController.Instance.ShowFloatTextPrompt(string.Format("已领取{0}体力", response.FriendIds.Count * GlobalCfgArray.globalCfg.onceGivePowerCount));
  247. }
  248. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  249. EventAgent.DispatchEvent(ConstMessage.FRIEND_REFRESH);
  250. return true;
  251. }
  252. }
  253. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  254. return false;
  255. }
  256. //请求搜索其他玩家
  257. public static async ETTask<bool> ReqSearchRole(long roleID, string roleName)
  258. {
  259. S2C_SearchRole response = null;
  260. response = (S2C_SearchRole)await MessageHelper.SendToServer(new C2S_SearchRole() { RoleId = roleID, RoleName = roleName });
  261. if (response != null)
  262. {
  263. if (response.Error == ErrorCode.ERR_Success)
  264. {
  265. FriendDataManager.Instance.ClearSearchDatas();
  266. for (int i = 0; i < response.RoleList.Count; i++)
  267. {
  268. OtherRoleInfoData roleInfo = new OtherRoleInfoData();
  269. roleInfo.roleId = response.RoleList[i].RoleId;
  270. roleInfo.roleName = response.RoleList[i].RoleName;
  271. roleInfo.roleLv = response.RoleList[i].RoleLvl;
  272. roleInfo.offlineTimeSec = response.RoleList[i].OfflineTimeSec;
  273. roleInfo.headId = response.RoleList[i].HeadItemId;
  274. roleInfo.headBorderId = response.RoleList[i].HeadBorderItemId;
  275. FriendDataManager.Instance.AddSearchData(roleInfo);
  276. }
  277. return true;
  278. }
  279. }
  280. return false;
  281. }
  282. //请求推荐好友
  283. public static async ETTask<bool> ReqRecommendFriends(long roleId = 1 )
  284. {
  285. S2C_GetRecommendFriends response = null;
  286. response = (S2C_GetRecommendFriends)await MessageHelper.SendToServer(new C2S_GetRecommendFriends() { RoleId = roleId });
  287. if (response != null)
  288. {
  289. if (response.Error == ErrorCode.ERR_Success)
  290. {
  291. FriendDataManager.Instance.ClearRecommendDatas();
  292. for (int i = 0; i < response.RoleList.Count; i++)
  293. {
  294. OtherRoleInfoData roleInfo = new OtherRoleInfoData();
  295. roleInfo.roleId = response.RoleList[i].RoleId;
  296. roleInfo.roleName = response.RoleList[i].RoleName;
  297. roleInfo.roleLv = response.RoleList[i].RoleLvl;
  298. roleInfo.offlineTimeSec = response.RoleList[i].OfflineTimeSec;
  299. roleInfo.headId = response.RoleList[i].HeadItemId;
  300. roleInfo.headBorderId = response.RoleList[i].HeadBorderItemId;
  301. FriendDataManager.Instance.AddRecommendData(roleInfo);
  302. }
  303. return true;
  304. }
  305. }
  306. return false;
  307. }
  308. //申请添加好友
  309. public static async ETTask<bool> ReqApplyForFriend(long friendId)
  310. {
  311. S2C_RequestApplyForFriend response = null;
  312. response = (S2C_RequestApplyForFriend)await MessageHelper.SendToServer(new C2S_RequestApplyForFriend() { FriendId = friendId });
  313. if (response != null)
  314. {
  315. if (response.Error == ErrorCode.ERR_Success)
  316. {
  317. return true;
  318. }
  319. }
  320. return false;
  321. }
  322. //同意添加好友
  323. public static async ETTask<bool> ReqAcceptApplyForFriend(long friendId)
  324. {
  325. S2C_AcceptApplyForFriend response = null;
  326. response = (S2C_AcceptApplyForFriend)await MessageHelper.SendToServer(new C2S_AcceptApplyForFriend() { FriendId = friendId });
  327. if (response != null)
  328. {
  329. if (response.Error == ErrorCode.ERR_Success)
  330. {
  331. // FriendDataManager.Instance.RemoveApplyData(roleId);
  332. return true;
  333. }
  334. }
  335. return false;
  336. }
  337. //拒绝添加好友
  338. public static async ETTask<bool> ReqRefuseApplyForFriend(long friendId)
  339. {
  340. S2C_RefuseApplyForFriend response = null;
  341. response = (S2C_RefuseApplyForFriend)await MessageHelper.SendToServer(new C2S_RefuseApplyForFriend() { FriendId = friendId });
  342. if (response != null)
  343. {
  344. if (response.Error == ErrorCode.ERR_Success)
  345. {
  346. FriendDataManager.Instance.RemoveApplyData(friendId);
  347. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  348. EventAgent.DispatchEvent(ConstMessage.FRIEND_APPLY_CHANGE);
  349. return true;
  350. }
  351. }
  352. return false;
  353. }
  354. //一键同意添加好友
  355. public static async ETTask<bool> ReqAcceptAllApplyForFriend()
  356. {
  357. S2C_AcceptAllApplyForFriend response = null;
  358. response = (S2C_AcceptAllApplyForFriend)await MessageHelper.SendToServer(new C2S_AcceptAllApplyForFriend());
  359. if (response != null)
  360. {
  361. if (response.Error == ErrorCode.ERR_Success)
  362. {
  363. return true;
  364. }
  365. }
  366. return false;
  367. }
  368. //一键拒绝添加好友
  369. public static async ETTask<bool> ReqRefuseAllApplyForFriend()
  370. {
  371. S2C_RefuseAllApplyForFriend response = null;
  372. response = (S2C_RefuseAllApplyForFriend)await MessageHelper.SendToServer(new C2S_RefuseAllApplyForFriend());
  373. if (response != null)
  374. {
  375. if (response.Error == ErrorCode.ERR_Success)
  376. {
  377. FriendDataManager.Instance.ClearApplyDatas();
  378. EventAgent.DispatchEvent(ConstMessage.RED_CHANGE);
  379. EventAgent.DispatchEvent(ConstMessage.FRIEND_APPLY_CHANGE);
  380. return true;
  381. }
  382. }
  383. return false;
  384. }
  385. //请求删除好友
  386. public static async ETTask<bool> ReqDeleteFriend(long friendId)
  387. {
  388. S2C_RequestDeleteFriend response = null;
  389. response = (S2C_RequestDeleteFriend)await MessageHelper.SendToServer(new C2S_RequestDeleteFriend() { FriendId = friendId });
  390. if (response != null)
  391. {
  392. if (response.Error == ErrorCode.ERR_Success)
  393. {
  394. FriendDataManager.Instance.RemoveFriend(response.FriendId);
  395. PromptController.Instance.ShowFloatTextPrompt("好友已删除");
  396. EventAgent.DispatchEvent(ConstMessage.FRIEND_REMOVE);
  397. return true;
  398. }
  399. }
  400. return false;
  401. }
  402. }
  403. }