lvjincheng 4 anni fa
parent
commit
0d8264dd8f

+ 0 - 3
Assets/BowArrow/Scenes/GameChallengeScene/HunterGameSettleView.cs

@@ -66,9 +66,6 @@ public class HunterGameSettleView : MonoBehaviour
     public void TryAgain() {
         AudioMgr.ins.PlayBtn();
         if (GameAssistUI.ins) GameAssistUI.ins.recordPlayerRecordsWhenGameTryAgain();
-        if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
-            SocketPlayer.ins.TryAgain("GameChallenge");
-        }
         SceneManager.LoadScene("GameChallenge", LoadSceneMode.Single);
     }
 

+ 74 - 0
Assets/BowArrow/Scripts/Network/SocketComp/PKComp.cs

@@ -0,0 +1,74 @@
+using System.Collections.Generic;
+
+
+public class PKComp : Singleton<PKComp>
+{
+    public void randomMatch() {
+        MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
+        UserPlayer.ins.call("pkComp.randomMatch", playerInfo, GlobalData.matchGameType);
+    }
+
+    public void cancelRandomMatch() {
+        UserPlayer.ins.call("pkComp.cancelRandomMatch", LoginMgr.myUserInfo.id);
+    }
+
+    public void inviteFriendGamePK(int targetID) {
+        MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
+        UserPlayer.ins.call("pkComp.inviteFriendGamePK", playerInfo, GlobalData.matchGameType, targetID);
+    }
+
+    public void acceptFriendGamePK(string roomKey) {
+        MatchPlayerInfo playerInfo = CreateMyMatchPlayerInfo();
+        UserPlayer.ins.call("pkComp.acceptFriendGamePK", playerInfo, roomKey);
+    }
+
+    private MatchPlayerInfo CreateMyMatchPlayerInfo() {
+        UserInfo u = LoginMgr.myUserInfo;
+        MatchPlayerInfo playerInfo = new MatchPlayerInfo(u.id, u.avatarID, u.nickname);
+        return playerInfo;
+    }
+
+    //被服务端调用的接口
+    public void onGamePKMatchSuccess(List<MatchPlayerInfo> playerInfoList, int playerIndexInRoom, string roomKey) {
+        GlobalData.roomKey = roomKey;
+        GlobalData.matchPlayerInfos = playerInfoList;
+        GlobalData.playerIndexInRoom = playerIndexInRoom;
+        if (PKMatchingView.ins) {
+            PKMatchingView.ins.EnterGameSceneOnMatchSuccess();
+        }
+    }
+    public void onInviteFriendGamePK(MatchPlayerInfo matchPlayerInfo, int gameType, string roomKey) {
+        GlobalData.roomKey = roomKey;
+        string pkTypeName = null;
+        switch (gameType) {
+            case 9:
+                pkTypeName = "静止靶";
+                break;
+            case 10:
+                pkTypeName = "野兔闯关";
+                break;
+            case 11:
+                pkTypeName = "野鸡闯关";
+                break;
+            case 12:
+                pkTypeName = "野狼闯关";
+                break;
+        }
+        if (pkTypeName == null) return;
+        string tip = $"好友邀请你参加{pkTypeName}PK";
+        System.Action cb = delegate() {
+            if (!PKMatchingView.ins && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Home") {
+                PKMatchingView view = PKMatchingView.Create();
+                view.isFriendPKInvitee = true;
+                view.targetJoinRoomKey = roomKey;
+                GlobalData.pkMatchType = PKMatchType.OnlinePK;
+                GlobalData.matchGameType = gameType;
+            } else if (PKMatchingView.ins) {
+                PopupMgr.ins.ShowTip("当前正处于匹配状态,无法接受好友PK邀请!");
+            }
+        };
+        if (!PKMatchingView.ins && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "Home") {
+            PopupMgr.ins.ShowPKInviteNotice(matchPlayerInfo.avatarID, matchPlayerInfo.nickname, tip, cb);
+        }
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Network/SocketComp/PKComp.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 670674f30818c9b44b54accd866c8d21
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 3
Assets/BowArrow/Scripts/View/PKGameSettleView.cs

@@ -56,9 +56,6 @@ public class PKGameSettleView : MonoBehaviour
     public void TryAgain() {
         AudioMgr.ins.PlayBtn();
         if (GameAssistUI.ins) GameAssistUI.ins.recordPlayerRecordsWhenGameTryAgain();
-        if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
-            SocketPlayer.ins.TryAgain("Game");
-        }
         SceneManager.LoadScene("Game", LoadSceneMode.Single);
     }
 }