PKComp.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Collections.Generic;
  2. public class PKComp : Singleton<PKComp>
  3. {
  4. public void randomMatch() {
  5. MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
  6. UserPlayer.ins.call("pkComp.randomMatch", playerInfo, GlobalData.matchGameType);
  7. }
  8. public void cancelRandomMatch() {
  9. UserPlayer.ins.call("pkComp.cancelRandomMatch", LoginMgr.myUserInfo.id);
  10. }
  11. public void inviteFriendGamePK(int targetID) {
  12. MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
  13. UserPlayer.ins.call("pkComp.inviteFriendGamePK", playerInfo, GlobalData.matchGameType, targetID);
  14. }
  15. public void acceptFriendGamePK(string roomKey) {
  16. MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
  17. UserPlayer.ins.call("pkComp.acceptFriendGamePK", playerInfo, roomKey);
  18. }
  19. private MatchPlayerInfo CreateMyMatchPlayerInfo() {
  20. UserInfo u = LoginMgr.myUserInfo;
  21. MatchPlayerInfo playerInfo = new MatchPlayerInfo(u.id, u.avatarID, u.nickname);
  22. return playerInfo;
  23. }
  24. //被服务端调用的接口
  25. public void onGamePKMatchSuccess(List<MatchPlayerInfo> playerInfoList, int playerIndexInRoom, string roomKey) {
  26. GlobalData.roomKey = roomKey;
  27. GlobalData.matchPlayerInfos = playerInfoList;
  28. GlobalData.playerIndexInRoom = playerIndexInRoom;
  29. if (PKMatchingView.ins) {
  30. PKMatchingView.ins.EnterGameSceneOnMatchSuccess();
  31. }
  32. }
  33. public void onInviteFriendGamePK(MatchPlayerInfo matchPlayerInfo, int gameType, string roomKey) {
  34. GlobalData.roomKey = roomKey;
  35. string pkTypeName = null;
  36. switch (gameType) {
  37. case 9:
  38. pkTypeName = "静止靶";
  39. break;
  40. case 10:
  41. pkTypeName = "野兔闯关";
  42. break;
  43. case 11:
  44. pkTypeName = "野鸡闯关";
  45. break;
  46. case 12:
  47. pkTypeName = "野狼闯关";
  48. break;
  49. }
  50. if (pkTypeName == null) return;
  51. string tip = $"好友邀请你参加{pkTypeName}PK";
  52. System.Action cb = delegate() {
  53. if (!PKMatchingView.ins && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Home") {
  54. PKMatchingView view = PKMatchingView.Create();
  55. view.isFriendPKInvitee = true;
  56. view.targetJoinRoomKey = roomKey;
  57. GlobalData.pkMatchType = PKMatchType.OnlinePK;
  58. GlobalData.matchGameType = gameType;
  59. } else if (PKMatchingView.ins) {
  60. PopupMgr.ins.ShowTip("当前正处于匹配状态,无法接受好友PK邀请!");
  61. }
  62. };
  63. if (!PKMatchingView.ins && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Home") {
  64. PopupMgr.ins.ShowPKInviteNotice(matchPlayerInfo.avatarID, matchPlayerInfo.nickname, tip, cb);
  65. }
  66. }
  67. }