浏览代码

Merge remote-tracking branch 'origin/master'

Administrator 5 月之前
父节点
当前提交
d9a240b5a2

+ 4 - 0
incubator-game/src/main/java/com/incubator/game/data/po/RoomPO.java

@@ -84,6 +84,9 @@ public class RoomPO {
 	public List<Integer> cardList = new ArrayList<>();
 	/** 当前赖子 红星级牌 **/
 	public int wildCard;
+	/** 随机队友-亮牌 **/
+	public int showCard;
+
 	/** 比赛Id */
 	public long contestId;
 	public String roomIp;
@@ -123,5 +126,6 @@ public class RoomPO {
 		this.towKingList.clear();
 		this.cardList.clear();
 		this.wildCard = 0;
+		this.showCard = 0;
 	}
 }

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

@@ -1318,7 +1318,7 @@ public class GDRoom extends Room {
         for (Player tmPlayer : this.actors.values()) {
             if (tmPlayer != null) {
                 // 结算信息
-                Map<String, Object> data = this.roomToMessage(tmPlayer, this.data.currentPlayer);
+                Map<String, Object> data = this.roomToMessage(tmPlayer, null);
                 data.put("state", 3);
                 tmPlayer.receive(CommonProto.Cmd.GameStateChange_VALUE, data);
             }

+ 1 - 1
incubator-game/src/main/java/com/incubator/game/room/RoomService.java

@@ -123,7 +123,7 @@ public class RoomService {
         // 房主加入房间
         room.joinRoom(player);
         //绑定服务器ip
-        bindServerIp(room);
+//        bindServerIp(room);
         // 加入管理映射
         this.roomMap.put(room.data.roomId, room);
         //RedisUtil.saveRoomMapToRedis(RedisKeyConstant.WK_ROOM_MAP ,roomMap);

+ 75 - 49
incubator-game/src/main/java/com/incubator/game/room/ZDRoom.java

@@ -57,8 +57,8 @@ public class ZDRoom extends Room {
         this.data.isTribute = false;
         // 初始化牌库
         this.initCardList();
-        //初始化比赛
-        this.data.contestId= jsonData.getLong("contestId");
+        // 初始化比赛
+        this.data.contestId = this.data.type == 1? jsonData.getLong("contestId") : 0;
     }
 
     /**
@@ -328,6 +328,7 @@ public class ZDRoom extends Room {
      */
     @Override
     public synchronized void doSendCard() {
+        List<String> teammate = new ArrayList<>();
         for (Player player : this.actors.values()) {
             if (player != null) {
                 // 设置用户状态
@@ -350,6 +351,12 @@ public class ZDRoom extends Room {
                     player.data.remainCards = CardUtils.add(player.data.remainCards, card);
                     this.data.cardList.remove(0);
                 }
+                // 设置翻牌队友
+                if (CardUtils.contains(player.data.remainCards, this.data.showCard) && teammate.size() < 2) {
+                    if (!teammate.contains(player.getId())) {
+                        teammate.add(player.getId());
+                    }
+                }
                 // todo 测试代码
 //                if (this.data.wildCard != 0) {
 //                    player.data.remainCards = CardUtils.add(player.data.remainCards, this.data.wildCard);
@@ -358,6 +365,60 @@ public class ZDRoom extends Room {
 //                }
             }
         }
+
+        // 随机搭档
+        if (this.jsonData.getInteger("team") == 1) {
+            if (teammate.size() == 2) {
+                List<String> other = new ArrayList<>();
+                for (Player tmPlayer : this.actors.values()) {
+                    if (tmPlayer != null && !teammate.contains(tmPlayer.getId())) {
+                        other.add(tmPlayer.getId());
+                    }
+                }
+
+                if (other.size() == 2) {
+                    Player p1 = this.actors.getOrDefault(teammate.get(0), null);
+                    Player p2 = this.actors.getOrDefault(teammate.get(1), null);
+                    if (p1 != null && p2 != null) {
+                        p1.data.pos = 0;
+                        p2.data.pos = 2;
+                        p1.data.teammateId = p2.getId();
+                        p2.data.teammateId = p1.getId();
+                        // 设置座位
+                        this.data.playerMap[0] = p1;
+                        this.data.playerMap[2] = p2;
+                    }
+                    Player p3 = this.actors.getOrDefault(other.get(0), null);
+                    Player p4 = this.actors.getOrDefault(other.get(1), null);
+                    if (p3 != null && p4 != null) {
+                        p3.data.pos = 1;
+                        p4.data.pos = 3;
+                        p3.data.teammateId = p4.getId();
+                        p4.data.teammateId = p3.getId();
+                        // 设置座位
+                        this.data.playerMap[1] = p3;
+                        this.data.playerMap[3] = p4;
+                    }
+                    this.data.zhuangPos = 0;
+                }
+            }
+        }
+
+        // 均匀分配
+        if (this.jsonData.getInteger("team") == 2) {
+            // 按局数 并且 局数必须是3的倍数
+            if (this.data.mode != 2 || this.data.maxRound % 3 != 0) {
+                return;
+            }
+            // 保存最后一个玩家
+            Player lastPlayer = this.data.playerMap[this.data.playerMap.length - 1];
+            // 从后向前移动位置
+            for (int i = this.data.playerMap.length - 1; i > 0; i--) {
+                this.data.playerMap[i] = this.data.playerMap[i - 1];
+            }
+            // 将最后一个玩家移动到第一个位置
+            this.data.playerMap[0] = lastPlayer;
+        }
     }
 
     /**
@@ -372,13 +433,19 @@ public class ZDRoom extends Room {
             this.data.zhuangPos = RandomUtil.getIndex(this.data.maxNum);
             // 随机打几
             if (this.jsonData.getInteger("tc") == 0) {
-                this.data.curLevelIndex = RandomUtil.getIndex(GDUtils.levelPoint.length);
+                this.data.curLevelIndex = RandomUtil.getIndex(GDUtils.randomTeam.length);
+                // 随机队友-系统翻牌
+                this.data.showCard = GDUtils.randomTeam[this.data.curLevelIndex];
             }
             // 固定打2
             if (this.jsonData.getInteger("tc") == 1) {
-                this.data.curLevelIndex = 0;
+                this.data.curLevelIndex = 12;
+                // 随机队友-系统翻牌
+                this.data.showCard = GDUtils.randomTeam[this.data.curLevelIndex];
             }
-            this.data.curLevelPoint = GDUtils.levelPoint[this.data.curLevelIndex];
+            // 级牌下标
+            int index = (this.data.curLevelIndex + 1) % GDUtils.randomTeam.length;
+            this.data.curLevelPoint = (GDUtils.randomTeam[index] & 0xF);
             // 发牌
             this.doSendCard();
             // 进还贡数据
@@ -1310,7 +1377,7 @@ public class ZDRoom extends Room {
         for (Player tmPlayer : this.actors.values()) {
             if (tmPlayer != null) {
                 // 结算信息
-                Map<String, Object> data = this.roomToMessage(tmPlayer, this.data.currentPlayer);
+                Map<String, Object> data = this.roomToMessage(tmPlayer, null);
                 data.put("state", 3);
                 tmPlayer.receive(CommonProto.Cmd.GameStateChange_VALUE, data);
             }
@@ -1322,47 +1389,6 @@ public class ZDRoom extends Room {
         Log.debug("牌局结束...roomId : {}", this.data.roomId);
     }
 
-    /**
-     * 变更队友 0固定队友 1随机搭档 2均匀分配
-     */
-    private synchronized void changeTeam() {
-        // 随机搭档
-        if (this.jsonData.getInteger("team") == 1) {
-            boolean isTransPosition = ((int)(10 * Math.random())) % 2 == 1;
-            if (isTransPosition) {
-                List<String> keyList = new ArrayList<>(this.actors.keySet());
-                Collections.shuffle(keyList);
-                int pos = 0;
-                for (String id : keyList) {
-                    if (!StringUtils.isEmpty(id)) {
-                        Player tmPlayer = this.actors.getOrDefault(id, null);
-                        if (tmPlayer != null) {
-                            tmPlayer.data.pos = pos;
-                            this.data.playerMap[pos] = tmPlayer;
-                            pos += 1;
-                        }
-                    }
-                }
-            }
-        }
-
-        // 均匀分配
-        if (this.jsonData.getInteger("team") == 2) {
-            // 按局数 并且 局数必须是3的倍数
-            if (this.data.mode != 2 || this.data.maxRound % 3 != 0) {
-                return;
-            }
-            // 保存最后一个玩家
-            Player lastPlayer = this.data.playerMap[this.data.playerMap.length - 1];
-            // 从后向前移动位置
-            for (int i = this.data.playerMap.length - 1; i > 0; i--) {
-                this.data.playerMap[i] = this.data.playerMap[i - 1];
-            }
-            // 将最后一个玩家移动到第一个位置
-            this.data.playerMap[0] = lastPlayer;
-        }
-    }
-
     /**
      * 下一局重置房间数据
      */
@@ -1402,8 +1428,6 @@ public class ZDRoom extends Room {
 
         // 初始化牌桌
         this.initCardList();
-        // 变更队友
-        this.changeTeam();
     }
 
     /**
@@ -1440,6 +1464,7 @@ public class ZDRoom extends Room {
         data.put("curRound", this.data.curRound);
         data.put("curTime", this.data.curTime);
         data.put("zhuangPos", this.data.zhuangPos);
+        data.put("showCard", this.data.showCard);
         // 当前级牌点数
         data.put("curLevelPoint", this.data.curLevelPoint);
         // 是否有进还贡
@@ -1492,6 +1517,7 @@ public class ZDRoom extends Room {
         data.put("maxRound", this.data.maxRound);
         data.put("curRound", this.data.curRound);
         data.put("zhuangPos", this.data.zhuangPos);
+        data.put("showCard", this.data.showCard);
         // 当前级牌点数
         data.put("curLevelPoint", this.data.curLevelPoint);
         // 是否有进还贡

+ 17 - 1
incubator-game/src/main/java/com/incubator/game/util/GDUtils.java

@@ -27,7 +27,12 @@ public final class GDUtils {
     };
 
     /** 大王数值 **/
-    public static Integer BIGKING = 0xff;
+    public static int BIGKING = 0xff;
+
+    /** 随机队友-系统翻牌 2、3、4、5、6、7、8、9、10、J、Q、K、A **/
+    public static Integer[] randomTeam = {
+            0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e
+    };
 
     /** 级数配置 2、3、4、5、6、7、8、9、10、J、Q、K、A **/
     public static int[] levelPoint = {
@@ -111,6 +116,17 @@ public final class GDUtils {
         return maxCards;
     }
 
+    /**
+     * 随机队友-亮牌
+     *
+     * @return
+     */
+    public static int randomTeamShowCards() {
+        List<Integer> randomTeam = new ArrayList<>(Arrays.asList(GDUtils.randomTeam));
+        Collections.shuffle(randomTeam);
+        return randomTeam.get(0);
+    }
+
     /**
      * 是否为赖子 红星级牌
      *