Browse Source

解决掼蛋房一次抗贡之后会一直抗贡

johnclot69 2 months ago
parent
commit
ea5e8a623c

+ 2 - 1
incubator-game/src/main/java/com/incubator/game/handler/room/TributeHandler.java

@@ -55,10 +55,11 @@ public class TributeHandler extends NetHandler {
 		}
 
 		// 是否是进还贡状态
-		if (room.data.tributeList.isEmpty() || !room.data.towKingList.isEmpty()) {
+		if (room.data.tributeList.isEmpty() || room.data.tributeState == 3) {
 			Log.info("没有进还贡或已抗贡,进还贡失败");
 			response.setCode(CommonProto.Code.ROOM_NOT_EXIST_ERR_VALUE);
 			response.setMessage("没有进还贡或已抗贡,进还贡失败...");
+			return;
 		}
 
 		// 判断参数

+ 25 - 8
incubator-game/src/main/java/com/incubator/game/room/GDRoom.java

@@ -69,8 +69,6 @@ public class GDRoom extends Room {
         this.data.curLevelPoint = GDUtils.levelPoint[this.data.curLevelIndex];
         // 初始化牌库
         this.initCardList();
-        //初始化状态
-        this.state = 0;
     }
 
     /**
@@ -459,7 +457,7 @@ public class GDRoom extends Room {
                     }
                     this.data.result.clear();
                 }
-                if (this.data.towKingList.size() >= 2) {
+                if (this.isTwoKing()) {
                     this.data.tributeState = 3;
                 } else {
                     if (!this.data.tributeList.isEmpty() && !this.isTwoKing() && this.data.tributeState == 0) {
@@ -503,6 +501,11 @@ public class GDRoom extends Room {
                 this.state = 2;
                 this.flag = true;
                 this.time = 0;
+                // 清理数据
+                this.data.tributeState = 0;
+                this.data.result.clear();
+                this.data.tributeList.clear();
+                this.data.towKingList.clear();
             }
         } catch (Exception e) {
             Log.error("===游戏开局出错...", e);
@@ -639,6 +642,7 @@ public class GDRoom extends Room {
         }
 
         // 抗贡
+        int num = 0;
         for (String[] tributeId : this.data.tributeList) {
             // 进贡者
             Player tributePlayer = this.actors.getOrDefault(tributeId[0], null);
@@ -646,7 +650,7 @@ public class GDRoom extends Room {
                 // 统计手牌数量
                 Map<Integer, Integer> cardMap = CardUtils.getCardMap(tributePlayer.data.remainCards);
                 if (!cardMap.isEmpty()) {
-                    int num = cardMap.getOrDefault(GDUtils.BIGKING, 0);
+                    num = cardMap.getOrDefault(GDUtils.BIGKING, 0);
                     if (num > 0 && !this.data.towKingList.contains(tributeId[0])) {
                         // 记录信息
                         this.data.towKingList.add(tributeId[0]);
@@ -655,9 +659,9 @@ public class GDRoom extends Room {
             }
         }
 
-        if (this.data.towKingList.size() < 2) {
-            this.data.towKingList.clear();
-        }
+//        if (this.data.towKingList.size() < 2) {
+//            this.data.towKingList.clear();
+//        }
     }
 
     /**
@@ -666,7 +670,19 @@ public class GDRoom extends Room {
      * @return
      */
     public boolean isTwoKing() {
-        return this.data.towKingList.size() >= 2;
+        int num = 0;
+        for (String[] tributeId : this.data.tributeList) {
+            // 进贡者
+            Player tributePlayer = this.actors.getOrDefault(tributeId[0], null);
+            if (tributePlayer != null) {
+                // 统计手牌数量
+                Map<Integer, Integer> cardMap = CardUtils.getCardMap(tributePlayer.data.remainCards);
+                if (!cardMap.isEmpty()) {
+                    num += cardMap.getOrDefault(GDUtils.BIGKING, 0);
+                }
+            }
+        }
+        return num > 0 && num % 2 == 0;
     }
 
     /**
@@ -820,6 +836,7 @@ public class GDRoom extends Room {
         this.data.tributeState = 0;
         this.data.result.clear();
         this.data.tributeList.clear();
+        this.data.towKingList.clear();
         // 进还贡数据
         Map<String, Object> tributeInfo = new HashMap<>();
         tributeInfo.put("tributeList", this.data.tributeList);