Browse Source

解决出牌时,牌型大小bug

johnclot69 3 months ago
parent
commit
1e317c2554

+ 6 - 10
incubator-game/src/main/java/com/incubator/game/handler/jdgd/JDGDDisCardHandler.java

@@ -93,16 +93,12 @@ public class JDGDDisCardHandler extends NetHandler {
             return;
         }
 
-        //
-
-        if (room.data.curDisCardList != null && room.data.curDisCardType != null) {
-            // 是否大过桌上牌
-            if (!room.canDisCard(disCardList, disCardType, 2)) {
-                logger.info("出牌错误,无法大过当前牌...");
-                response.setCode(10);
-                response.setMessage("出牌错误,无法大过当前牌...");
-                return;
-            }
+        // 是否大过桌上牌
+        if (!room.canDisCard(disCardList, disCardType, room.data.curLevelPoint)) {
+            logger.info("出牌错误,无法大过当前牌...");
+            response.setCode(10);
+            response.setMessage("出牌错误,无法大过当前牌...");
+            return;
         }
 
         // 出牌

+ 10 - 0
incubator-game/src/main/java/com/incubator/game/room/JDGDRoom.java

@@ -336,6 +336,16 @@ public class JDGDRoom extends Room implements GRoomInterface {
      * @return 是否可以出牌
      */
     public boolean canDisCard(int[] disCardsList, JDGDUtils.CardType disCardsType, int currentLevel) {
+        // 0.桌上无牌直接出
+        if (this.data.curDisCardList == null || this.data.curDisCardType == null) {
+            return true;
+        }
+
+        // 1.牌型不一样,判断手牌是否是炸弹
+        if (disCardsType != this.data.curDisCardType && !JDGDUtils.isBomb(disCardsType)) {
+            return false;
+        }
+
         // 获取权重值
         int previousWeight = JDGDUtils.getCardTypeWeight(this.data.curDisCardType);
         int currentWeight = JDGDUtils.getCardTypeWeight(disCardsType);

+ 17 - 0
incubator-game/src/main/java/com/incubator/game/util/JDGDUtils.java

@@ -51,6 +51,23 @@ public final class JDGDUtils {
         INVALID              // 无效牌型
     }
 
+    /**
+     * 是否是炸弹
+     *
+     * @param type
+     * @return
+     */
+    public static boolean isBomb(CardType type) {
+        return type == CardType.BOMB
+                || type == CardType.FOUR_BOMB
+                || type == CardType.FIVE_BOMB
+                || type == CardType.SIX_BOMB
+                || type == CardType.SEVEN_BOMB
+                || type == CardType.EIGHT_BOMB
+                || type == CardType.FOUR_KINGS
+                || type == CardType.ROYAL_FLUSH;
+    }
+
     /**
      * 比较两组牌的大小(仅在牌型相同时调用)
      *