Browse Source

优化掼蛋转蛋房间参数根据选择的局数和时间判断

johnclot69 2 months ago
parent
commit
5ae0e0c504

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

@@ -26,6 +26,18 @@ public class RoomPO {
 	public int maxNum;
 	/** 最大局数 **/
 	public int maxRound;
+	/** 结束时间 **/
+	public long maxTime;
+
+	/** 玩法1 1:连续打,2:按局数,3:按时间 **/
+	public int mode;
+	/**
+	 * 玩法具体值
+	 * 14:A必打 2:J必打 3:8必打 4:5必打
+	 * 4:4局 6:6局 8:8局 10:10局
+	 * 20:20分钟 30:30分钟 40:40分钟 60:60分钟
+	 */
+	public int modev;
 
 	//**************************配置相关***************************
 
@@ -33,6 +45,8 @@ public class RoomPO {
 	public Player[] playerMap = new Player[maxNum];
 	/** 当前局数 **/
 	public int curRound;
+	/** 当前时间 **/
+	public long curTime;
 	/** 庄家位置 **/
 	public int zhuangPos;
 	/** 当前级牌点数 **/

+ 0 - 4
incubator-game/src/main/java/com/incubator/game/handler/room/CreatRoomHandler.java

@@ -81,14 +81,10 @@ public class CreatRoomHandler extends NetHandler {
 			case 1:
 				// 掼蛋
 				jsonData = RoomUtil.gdRoomRule(type, mode, modev, lv, vic, jing, lp);
-				// 房间最大局数
-				jsonData.put("maxRound", 8);
 				break;
 			case 2:
 				// 转蛋
 				jsonData = RoomUtil.zdRoomRule(type, mode, modev, lv, team);
-				// 房间最大局数
-				jsonData.put("maxRound", 4);
 				break;
 			case 3:
 				// 复式掼蛋

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

@@ -29,9 +29,30 @@ public class GDRoom extends Room {
         this.data.type = jsonData.getInteger("type");
         this.data.gameType = jsonData.getInteger("gameType");
         this.data.ownerId = player != null? player.getId() : "";
-        this.data.maxNum = jsonData.getInteger("playerNum");
-        this.data.maxRound = jsonData.getInteger("maxRound");
-        this.data.playerMap = new Player[4];
+        this.data.maxNum = 4;
+
+        this.data.mode = jsonData.getInteger("mode");
+        this.data.modev = jsonData.getInteger("modev");
+
+        // 连续打
+        if (this.data.mode == 1) {
+            this.data.maxRound = 9999;
+        }
+
+        // 按局数
+        if (this.data.mode == 2) {
+            this.data.maxRound = jsonData.getInteger("modev");
+        }
+
+        // 按时间
+        if (this.data.mode == 3) {
+            this.data.curTime = System.currentTimeMillis();
+            long time = jsonData.getInteger("modev") * 60L * 1000L;
+            this.data.maxTime = this.data.curTime + time;
+            this.data.maxRound = 9999;
+        }
+
+        this.data.playerMap = new Player[this.data.maxNum];
         // 是否有进还贡规则
         this.data.isTribute = jsonData.getInteger("advanceType") == 0;
 
@@ -1231,8 +1252,13 @@ public class GDRoom extends Room {
         data.put("state", this.state);
         data.put("time", this.time);
 
+        data.put("mode", this.data.mode);
+        data.put("modev", this.data.modev);
         data.put("maxRound", this.data.maxRound);
+        data.put("maxTime", this.data.maxTime);
+
         data.put("curRound", this.data.curRound);
+        data.put("curTime", this.data.curTime);
         data.put("zhuangPos", this.data.zhuangPos);
         // 当前级牌点数
         data.put("curLevelPoint", this.data.curLevelPoint);

+ 85 - 20
incubator-game/src/main/java/com/incubator/game/room/ZDRoom.java

@@ -32,9 +32,30 @@ public class ZDRoom extends Room {
         this.data.type = jsonData.getInteger("type");
         this.data.gameType = jsonData.getInteger("gameType");
         this.data.ownerId = player != null? player.getId() : "";
-        this.data.maxNum = jsonData.getInteger("playerNum");
-        this.data.maxRound = jsonData.getInteger("maxRound");
-        this.data.playerMap = new Player[4];
+        this.data.maxNum = 4;
+
+        this.data.mode = jsonData.getInteger("mode");
+        this.data.modev = jsonData.getInteger("modev");
+
+        // 连续打
+        if (this.data.mode == 1) {
+            this.data.maxRound = 9999;
+        }
+
+        // 按局数
+        if (this.data.mode == 2) {
+            this.data.maxRound = jsonData.getInteger("modev");
+        }
+
+        // 按时间
+        if (this.data.mode == 3) {
+            this.data.curTime = System.currentTimeMillis();
+            long time = jsonData.getInteger("modev") * 60L * 1000L;
+            this.data.maxTime = this.data.curTime + time;
+            this.data.maxRound = 9999;
+        }
+
+        this.data.playerMap = new Player[this.data.maxNum];
         // 是否有进还贡规则
         this.data.isTribute = false;
         // 初始化级牌点数
@@ -218,23 +239,62 @@ public class ZDRoom extends Room {
                         this.time = 0;
                         Log.debug("游戏结束: 房间号 : {}, 房间人数 : {}, 当前局数 : {}", this.data.roomId, this.actors.size(), this.data.curRound);
                     } else {
-                        // 小于最大局数,切等待状态
-                        if (this.data.curRound < this.data.maxRound) {
-                            this.resetNextRoom();
-                            this.state = 0;
-                            this.flag = false;
-                            this.time = 0;
-                        } else {
-                            // 120秒未开始直接解散
-//                            if (this.time >= 120 && this.type != 1) {
-//                                // 广播
-//                                for (Player tmPlayer : this.actors.values()) {
-//                                    if (tmPlayer != null) {
-//                                        tmPlayer.receive(CommonProto.Cmd.DisbandRoom_VALUE, new HashMap<>());
-//                                    }
-//                                }
-//                                this.destroy();
-//                            }
+                        // 根据类型判断结束走向
+                        switch (this.data.mode) {
+                            case 1:
+                                // 连续打
+                                this.resetNextRoom();
+                                this.state = 0;
+                                this.flag = false;
+                                this.time = 0;
+                                break;
+                            case 2:
+                                // 按局数
+                                // 小于最大局数,切等待状态
+                                if (this.data.curRound < this.data.maxRound) {
+                                    this.resetNextRoom();
+                                    this.state = 0;
+                                    this.flag = false;
+                                    this.time = 0;
+                                } else {
+                                    // 广播
+                                    for (Player tmPlayer : this.actors.values()) {
+                                        if (tmPlayer != null) {
+                                            tmPlayer.receive(CommonProto.Cmd.DisbandRoom_VALUE, new HashMap<>());
+                                        }
+                                    }
+                                    this.destroy();
+                                }
+                                break;
+                            case 3:
+                                // 按时间
+                                // 小于最大时间,切等待状态
+                                if (System.currentTimeMillis() < this.data.maxTime) {
+                                    this.resetNextRoom();
+                                    this.state = 0;
+                                    this.flag = false;
+                                    this.time = 0;
+                                } else {
+                                    // 广播
+                                    for (Player tmPlayer : this.actors.values()) {
+                                        if (tmPlayer != null) {
+                                            tmPlayer.receive(CommonProto.Cmd.DisbandRoom_VALUE, new HashMap<>());
+                                        }
+                                    }
+                                    this.destroy();
+                                }
+                                break;
+                        }
+
+                        // 120秒未开始直接解散
+                        if (this.time >= 120) {
+                            // 广播
+                            for (Player tmPlayer : this.actors.values()) {
+                                if (tmPlayer != null) {
+                                    tmPlayer.receive(CommonProto.Cmd.DisbandRoom_VALUE, new HashMap<>());
+                                }
+                            }
+                            this.destroy();
                         }
                     }
                     break;
@@ -1230,8 +1290,13 @@ public class ZDRoom extends Room {
         data.put("state", this.state);
         data.put("time", this.time);
 
+        data.put("mode", this.data.mode);
+        data.put("modev", this.data.modev);
         data.put("maxRound", this.data.maxRound);
+        data.put("maxTime", this.data.maxTime);
+
         data.put("curRound", this.data.curRound);
+        data.put("curTime", this.data.curTime);
         data.put("zhuangPos", this.data.zhuangPos);
         // 当前级牌点数
         data.put("curLevelPoint", this.data.curLevelPoint);

+ 32 - 12
incubator-game/src/main/java/com/incubator/game/util/RoomUtil.java

@@ -27,17 +27,37 @@ public final class RoomUtil {
         // 1掼蛋 2转蛋 3复式掼蛋
         jsonData.put("gameType", type);
         // 玩法1 1:连续打,2:按局数,3:按时间
-        jsonData.put("playingTypeOne", mode);
-        // 玩法2 14:A必打 2:J必打 3:8必打 4:5必打
-        jsonData.put("playingTypeTwo", modev);
-
+        jsonData.put("mode", mode);
+
+        switch (mode) {
+            case 1: // 连续打
+                // 玩法2 14:A必打 2:J必打 3:8必打 4:5必打
+                jsonData.put("modev", modev);
+                // 胜利规则 1:有头游无末游过A结束,2:有头游过A结束,3:3局不过A判负结束,4:3局不过A从2开始
+                jsonData.put("flippingType", vic);
+                break;
+            case 2: // 按局数
+                // 玩法2 4:4局 6:6局 8:8局 10:10局
+                jsonData.put("modev", modev);
+                // 套圈规则 1:套圈,2:不套圈
+                jsonData.put("upgradeType", lp);
+                // 胜利规则 1:头游,2:有头游过A结束,3:3局不过A判负结束,4:3局不过A从2开始
+                jsonData.put("flippingType", vic);
+                break;
+            case 3: // 按时间
+                // 玩法2 20:20分钟 30:30分钟 40:40分钟 60:60分钟
+                jsonData.put("modev", modev);
+                // 套圈规则 1:套圈,2:不套圈
+                jsonData.put("upgradeType", lp);
+                // 胜利规则 1:头游,2:有头游过A结束,3:3局不过A判负结束,4:3局不过A从2开始
+                jsonData.put("flippingType", vic);
+                break;
+        }
 
-        // 升级规则 1:123级,2:124级,3:135级,4:246级
-        jsonData.put("upgradeType", lv);
-        // 翻山规则 1:有头游无末游过A结束,2:有头游过A结束,3:3局不过A判负结束,4:3局不过A从2开始
-        jsonData.put("flippingType", vic);
         // 进贡规则 0:进贡,1:不进贡(头游先出)
         jsonData.put("advanceType", jing);
+        // 升级规则 1:123级,2:124级,3:135级,4:246级
+        jsonData.put("upgradeType", lv);
 
 
         return jsonData;
@@ -58,10 +78,10 @@ public final class RoomUtil {
 
         // 1掼蛋 2转蛋 3复式掼蛋
         jsonData.put("gameType", type);
-        // 玩法1 1:连续打,2:按局数,3:按时间
-        jsonData.put("playingTypeOne", mode);
+        // 玩法1 2:按局数,3:按时间
+        jsonData.put("mode", mode);
         // 玩法2 4:4局 6:6局 8:8局 10:10局
-        jsonData.put("playingTypeTwo", 4);
+        jsonData.put("modev", modev);
 
 
         // 队友 0固定队友 1随机搭档 2均匀分配
@@ -87,7 +107,7 @@ public final class RoomUtil {
         // 1掼蛋 2转蛋 3复式掼蛋
         jsonData.put("gameType", type);
         // 玩法1 1:连续打,2:按局数,3:按时间
-        jsonData.put("playingTypeOne", mode);
+        jsonData.put("mode", mode);
         // 玩法2 14:A必打 2:J必打 3:8必打 4:5必打
         jsonData.put("playingTypeTwo", modev);