FriendSProxy.cs 18 KB

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