Browse Source

再来一次

lvjincheng 4 years ago
parent
commit
4c48780a50

+ 10 - 2
Assets/BowArrow/Scenes/GameChallengeScene/HunterGameSettleView.cs

@@ -38,13 +38,18 @@ public class HunterGameSettleView : MonoBehaviour
             } else if (counter.hitScores[myIndex] == counter.hitScores[otherIndex]) {
                 score = 15; //平分
             }
-            UserPlayer.ins.call("rankComp.uploadGameScore", GameMgr.gameType, score);
+            try { 
+                UserPlayer.ins.call("rankComp.uploadGameScore", GameMgr.gameType, score);
+            } catch (System.Exception e) { Debug.LogError(e.Message); }
         }
     }
 
     void CheckOpenNextLevelBtn(ChallengeGameMode gameMode, string gameRes) {
-        if (GlobalData.pkMatchType != PKMatchType.None) return;
         Transform btnT = this.transform.Find("Btns/Btn2");
+        if (GlobalData.pkMatchType != PKMatchType.None) {
+            btnT.gameObject.SetActive(false);
+            return;
+        }
         bool open = gameRes == "胜利" && gameMode.currentlevel < 5;
         btnT.gameObject.SetActive(open);
         if (open) {
@@ -58,6 +63,9 @@ 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);
     }
 

+ 1 - 0
Assets/BowArrow/Scripts/Manager/GameMode/OnlinePKTest.cs

@@ -7,6 +7,7 @@ public class OnlinePKTest : MonoBehaviour
     static bool canTest = false;
     public static void Init() {
         if (!canTest) return;
+        Debug.Log("联机PK测试初始化");
         #if UNITY_EDITOR
             GlobalData.pkMatchType = PKMatchType.OnlinePK;
             GlobalData.matchRoomType = 1;

+ 27 - 1
Assets/BowArrow/Scripts/Network/SocketPlayer.cs

@@ -20,6 +20,10 @@ public class SocketPlayer : JC.SocketIO.SocketIOClient
         base.OnDestroy();
     }
     void DestroySelf() {
+        if (willTryAgain) {
+            willTryAgain = false;
+            return;
+        }
         if (gameObject) Destroy(gameObject);
     }
     
@@ -98,10 +102,15 @@ public class SocketPlayer : JC.SocketIO.SocketIOClient
     //上传游戏数据
     public void UploadPKGameData(string key, object data) {
         if (!isValid) return;
-        call("UploadPKGameData", key, data);
+        call("UploadPKGameData", repeatID.ToString() + key, data);
     }
     public Action<string, string> onReceivePKGameData;  
     public void OnReceivePKGameData(string key, string data) {
+        if (key.StartsWith(repeatID_str)) {
+            key = key.Substring(repeatID_str.Length);
+        } else {
+            return;
+        }
         onReceivePKGameData?.Invoke(key, data);
     }
     //创建好友PK房间
@@ -116,4 +125,21 @@ public class SocketPlayer : JC.SocketIO.SocketIOClient
     public void JoinFriendPKRoom(int roomID) {
         call("JoinFriendPKRoom", roomID);
     }
+    //再来一次
+    bool willTryAgain = false;
+    int repeatID = 0;
+    string repeatID_str = "0";
+    public void TryAgain(string sceneName) {
+        willTryAgain = true;
+        repeatID++;
+        repeatID_str = repeatID.ToString();
+        call("TryAgain", repeatID_str, sceneName);
+    }
+    public void OnTryAgain(string repeatID_s, string sceneName) {
+        if (repeatID_str == repeatID_s) return;
+        repeatID = int.Parse(repeatID_s);
+        repeatID_str = repeatID_s;
+        willTryAgain = true;
+        SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
+    }
 }

+ 6 - 1
Assets/BowArrow/Scripts/View/PKGameSettleView.cs

@@ -46,7 +46,9 @@ public class PKGameSettleView : MonoBehaviour
             PKGameMode_OnlinePK gm = (PKGameMode_OnlinePK)gameMode;
             string res = results[gm.myPlayerIndex];
             int score = res == "胜利" ? 20 : 10;
-            UserPlayer.ins.call("rankComp.uploadGameScore", GameMgr.gameType, score);
+            try { 
+                UserPlayer.ins.call("rankComp.uploadGameScore", GameMgr.gameType, score);
+            } catch (System.Exception e) { Debug.LogError(e.Message); }
         }
     }
 
@@ -59,6 +61,9 @@ 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);
     }
 }