From 9d38ac2c618eecdc2c8c04c816b41556fcb18d06 Mon Sep 17 00:00:00 2001 From: fy <> Date: Fri, 30 Jan 2026 16:04:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game_web/web_group/pom.xml | 62 +- libs/robot_common/pom.xml | 84 +- .../src/main/java/hunan/HuNanChangSha.java | 387 +++--- .../src/main/java/hunan/JiQiRens.java | 8 +- .../java/taurus/newRobot/AddRoomRobot.java | 1105 +---------------- .../main/java/taurus/newRobot/jiqiren.java | 609 +++++++++ .../java/taurus/newRobot/lianjiejiqiren.java | 852 +++++++++++++ libs/robot_common/src/test/java/Test.java | 8 +- 8 files changed, 1858 insertions(+), 1257 deletions(-) create mode 100644 libs/robot_common/src/main/java/taurus/newRobot/jiqiren.java create mode 100644 libs/robot_common/src/main/java/taurus/newRobot/lianjiejiqiren.java diff --git a/game_web/web_group/pom.xml b/game_web/web_group/pom.xml index ac388db..5fccf04 100644 --- a/game_web/web_group/pom.xml +++ b/game_web/web_group/pom.xml @@ -11,7 +11,8 @@ 1.8 1.8 pro - + 1.5.10 + @@ -80,7 +81,7 @@ com.robot robot_common - 1.0.7 + 1.0.8 @@ -96,6 +97,17 @@ 2.2.3 compile + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + @@ -118,7 +130,51 @@ - + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + + compile + compile + + compile + + + + testCompile + test-compile + + testCompile + + + + + diff --git a/libs/robot_common/pom.xml b/libs/robot_common/pom.xml index d8c2e40..91561a0 100644 --- a/libs/robot_common/pom.xml +++ b/libs/robot_common/pom.xml @@ -2,12 +2,13 @@ 4.0.0 com.robot robot_common - 1.0.7 + 1.0.8 jar robot_common UTF-8 - + 1.5.10 + @@ -44,24 +45,75 @@ log4j 1.2.17 + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-test + ${kotlin.version} + test + - + - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.1 - - - 1.8 - 1.8 - UTF-8 - - - - + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 1.8 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + compile + compile + + compile + + + + testCompile + test-compile + + testCompile + + + + + + 1.8 + 1.8 + UTF-8 + + + + \ No newline at end of file diff --git a/libs/robot_common/src/main/java/hunan/HuNanChangSha.java b/libs/robot_common/src/main/java/hunan/HuNanChangSha.java index 5a02253..935c5c6 100644 --- a/libs/robot_common/src/main/java/hunan/HuNanChangSha.java +++ b/libs/robot_common/src/main/java/hunan/HuNanChangSha.java @@ -1,14 +1,15 @@ package hunan; -import com.game.Global; import com.game.Util; import com.taurus.core.entity.ITArray; import com.taurus.core.entity.ITObject; import com.taurus.core.entity.TArray; import com.taurus.core.entity.TObject; import com.taurus.core.plugin.database.DataBase; +import com.taurus.core.plugin.redis.Redis; import com.taurus.core.util.Logger; import com.taurus.core.util.StringUtil; +import redis.clients.jedis.Jedis; import taurus.client.Message; import taurus.client.TaurusClient; import taurus.util.*; @@ -19,15 +20,12 @@ import java.util.*; public class HuNanChangSha { - public static int changShaCard = 0; public static boolean isTinChi = false; public static boolean isTinPeng = false; - private static final Logger log = Logger.getLogger(DoTest.class); +// private static final Logger log = Logger.getLogger(DoTest.class); - //湖南长沙麻将手牌 - private List changShaCardInhand = new ArrayList<>(); private List changShaCardInhandgang = new ArrayList<>(); @@ -35,7 +33,9 @@ public class HuNanChangSha { //长沙麻将出过的牌 private List changShachuguopai = new ArrayList<>(); - private Map chuGuoPainum = new HashMap<>(); + private List changShaCardInhand = new ArrayList<>(); + + private Map chuGuoPainum = new HashMap<>(); //杠的牌 @@ -53,24 +53,16 @@ public class HuNanChangSha { // 玩家座位号 public static int seat = 0; - public static int playerId = 0; - - public static int cardToOut1 = 0; - // 会话标识 public static String session = ""; // 访问令牌 public static String token = ""; - //红中麻将算法 -// private static HongZhongSuanFa hongZhongSuanFa = new HongZhongSuanFa(); + private static ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest(); // 公共的getter和setter方法 - public List getChangShaCardInhand() { - return changShaCardInhand; - } public List getgangdepai() { return gangdepai; @@ -89,11 +81,15 @@ public class HuNanChangSha { return chowGroup; } + public List getChangShaCardInhand() { + return changShaCardInhand; + } + public List getChuGuoCardInhand() { return changShachuguopai; } - public Map getChuGuoPainum() { + public Map getChuGuoPainum() { return chuGuoPainum; } @@ -125,22 +121,33 @@ public class HuNanChangSha { * @param message 消息对象 * @return */ - public String getCard(String command, Message message) { - + public String getCard(String command, Message message, TaurusClient client, Map mapclient) { if (command.equalsIgnoreCase("819")) { ITObject param = message.param; if (param == null) { return null; } + Jedis jedis222 = Redis.use("group1_db2").getJedis(); + if (param.getInt("player") != null) { + Integer player = param.getInt("player"); int drawnCard = param.getInt("card"); changShaSuanFaTest.drawnCards = drawnCard;//存储摸到的牌 changShaCardInhand.add(drawnCard); - changShaSuanFaTest.analyzeHand(changShaCardInhand); - + if (jedis222.hget("{robortInfo}:" + player, "circleId") != null && jedis222.hget("{robortInfo}:" + player, "pid") != null) { + String circleId = jedis222.hget("{robortInfo}:" + player, "circleId"); + String pid = jedis222.hget("{robortInfo}:" + player, "pid"); + String getStart = "g{" + circleId + "}:play:" + pid; + if (!pid.equals("0")) { + jedis222.hset(getStart, String.valueOf(player), "2"); + } + } } + + + jedis222.close(); } return null; } @@ -157,7 +164,6 @@ public class HuNanChangSha { // 直接调用hongZhongSuanFaTest中的shouldPong方法,它已经包含了所有需要的规则 return changShaSuanFaTest.shouldPong(proposedCard, changShaCardInhand); -// return hongZhongSuanFaTest.shouldPong(proposedCard, Arrays.asList(305,304,303,207,207,204,204,208,208,201,201,412,412)); } @@ -182,13 +188,17 @@ public class HuNanChangSha { } // {bank_seat=1, laiziCard=0, laiziCard2=0, laiziCard2Before=0, jing=0, laiziCardBefore=0, card_list=[101, 103, 104, 201, 204, 207, 208, 209, 307, 309, 501, 502, 503]} ITArray cardList = param.getTArray("card_list"); + + List handCards = new ArrayList<>(); + for (int i = 0; i < cardList.size(); i++) { + handCards.add(cardList.getInt(i)); + } + for (int i = 0; i < cardList.size(); i++) { changShaCardInhand.add(cardList.getInt(i)); } -// if (changShaCardInhand.size() > 13) { -// outCard(client); -// } + System.out.println("changShaCardInhand" + changShaCardInhand); } return null; @@ -231,61 +241,60 @@ public class HuNanChangSha { /** * 处理 吃,碰,杠,补,胡 + * * @param param * @param client - * @return - 吃 - [TCP->814] data:{"tip_list":[{"type":1,"id":1,"opcard":[108,109],"weight":1,"card":107}]} - 吃 碰 - {"tip_list":[{"type":1,"id":1,"opcard":[206,205],"weight":1,"card":207},{"type":2,"id":2,"opcard":[207],"weight":2,"card":207}]} - 碰补 - {"tip_list":[{"type":2,"id":1,"opcard":[101],"weight":2,"card":101},{"type":3,"id":2,"opcard":[101],"weight":3,"card":101}]} - 补 - [TCP->814] data:{"tip_list":[{"type":5,"id":1,"opcard":[101],"weight":3,"card":101}]} - 吃,碰,补,杠, - {"tip_list":[{"type":1,"id":1,"opcard":[206,204],"weight":1,"card":205},{"type":1,"id":2,"opcard":[206,207],"weight":1,"card":205},{"type":2,"id":3,"opcard":[205],"weight":2,"card":205},{"type":3,"id":4,"opcard":[205],"weight":3,"card":205},{"type":3,"id":5,"opcard":[205],"weight":4,"card":205}]} - 碰 - {"tip_list":[{"type":2,"id":1,"opcard":[207],"weight":2,"card":207}]} - 补,杠 - {"tip_list":[{"type":5,"id":1,"opcard":[207],"weight":3,"card":207},{"type":5,"id":2,"opcard":[207],"weight":4,"card":207}]} - - //拟定: - 1、对应的提示事件遍历 实行假设做了处理之后的结果 对应结果的对象 - boolean isTing 是否听牌 - boolean canTing 能否听牌 - int tingNum 听多少张 - int isDaHu 是否大胡 - int guzhang 有多少孤章 - int lastHands 差多少手 - int id tiplist id - List opcard - int weight tiplist weight - int card tiplist card - int type tiplist type - 2、通过遍历后的结果进行打分 - 打分系统: - 已经听牌: ---> 40 - 操作后能听 ---> 20 - 操作之后散听 ---> -50 - 听多张,每一张:---> 3 - 孤章,每一张:----> -3 - 差手数:每一手 ----> -5 - 操作之前是否大胡 ----> 10 - 去掉大胡 -----> -10 - - 先碰107,后补: - {"tip_list":[{"type":5,"id":1,"opcard":[107],"weight":3,"card":107},{"type":5,"id":2,"opcard":[107],"weight":4,"card":107}]} - - 手上有3个摸一个204:开补 - {"tip_list":[{"type":4,"id":1,"opcard":[204],"weight":3,"card":204},{"type":4,"id":2,"opcard":[204],"weight":4,"card":204}]} - - 手上有3个,对家打一个206:开补 - {"tip_list":[{"type":3,"id":1,"opcard":[206],"weight":3,"card":206}]} - + * @return 吃 + * [TCP->814] data:{"tip_list":[{"type":1,"id":1,"opcard":[108,109],"weight":1,"card":107}]} + * 吃 碰 + * {"tip_list":[{"type":1,"id":1,"opcard":[206,205],"weight":1,"card":207},{"type":2,"id":2,"opcard":[207],"weight":2,"card":207}]} + * 碰补 + * {"tip_list":[{"type":2,"id":1,"opcard":[101],"weight":2,"card":101},{"type":3,"id":2,"opcard":[101],"weight":3,"card":101}]} + * 补 + * [TCP->814] data:{"tip_list":[{"type":5,"id":1,"opcard":[101],"weight":3,"card":101}]} + * 吃,碰,补,杠, + * {"tip_list":[{"type":1,"id":1,"opcard":[206,204],"weight":1,"card":205},{"type":1,"id":2,"opcard":[206,207],"weight":1,"card":205},{"type":2,"id":3,"opcard":[205],"weight":2,"card":205},{"type":3,"id":4,"opcard":[205],"weight":3,"card":205},{"type":3,"id":5,"opcard":[205],"weight":4,"card":205}]} + * 碰 + * {"tip_list":[{"type":2,"id":1,"opcard":[207],"weight":2,"card":207}]} + * 补,杠 + * {"tip_list":[{"type":5,"id":1,"opcard":[207],"weight":3,"card":207},{"type":5,"id":2,"opcard":[207],"weight":4,"card":207}]} + *

+ * //拟定: + * 1、对应的提示事件遍历 实行假设做了处理之后的结果 对应结果的对象 + * boolean isTing 是否听牌 + * boolean canTing 能否听牌 + * int tingNum 听多少张 + * int isDaHu 是否大胡 + * int guzhang 有多少孤章 + * int lastHands 差多少手 + * int id tiplist id + * List opcard + * int weight tiplist weight + * int card tiplist card + * int type tiplist type + * 2、通过遍历后的结果进行打分 + * 打分系统: + * 已经听牌: ---> 40 + * 操作后能听 ---> 20 + * 操作之后散听 ---> -50 + * 听多张,每一张:---> 3 + * 孤章,每一张:----> -3 + * 差手数:每一手 ----> -5 + * 操作之前是否大胡 ----> 10 + * 去掉大胡 -----> -10 + *

+ * 先碰107,后补: + * {"tip_list":[{"type":5,"id":1,"opcard":[107],"weight":3,"card":107},{"type":5,"id":2,"opcard":[107],"weight":4,"card":107}]} + *

+ * 手上有3个摸一个204:开补 + * {"tip_list":[{"type":4,"id":1,"opcard":[204],"weight":3,"card":204},{"type":4,"id":2,"opcard":[204],"weight":4,"card":204}]} + *

+ * 手上有3个,对家打一个206:开补 + * {"tip_list":[{"type":3,"id":1,"opcard":[206],"weight":3,"card":206}]} */ - public String actionCard(ITObject param, TaurusClient client){ + public String actionCard(ITObject param, TaurusClient client) { ITArray tipList = param.getTArray("tip_list"); - log.info("tipList" +tipList); +// log.info("tipList" +tipList); ITObject params = TObject.newInstance(); int card = 0; @@ -294,22 +303,22 @@ public class HuNanChangSha { yupanhandcard.addAll(changShaCardInhand); //进行操作之前能否下听 - List shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand,chowGroup,pongGroup,gangdepai); + List shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand, chowGroup, pongGroup, gangdepai); boolean beforelisten = false;//记录操作之前的下听状态 - System.out.println("shifoutingpai"+shifoutingpai); + System.out.println("shifoutingpai" + shifoutingpai); if (shifoutingpai.size() > 0) { beforelisten = true; } - System.out.println("beforelisten"+beforelisten); + System.out.println("beforelisten" + beforelisten); //如果杠了之后还能继续听牌则杠 //优先处理胡牌 - for(int i=0;i gangusecars = new ArrayList<>(); gangusecars.addAll(changShaCardInhand); if (type == 3) { - Util.removeCard(gangusecars,card,3); - List shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars,chowGroup,pongGroup,gangdepai); + Util.removeCard(gangusecars, card, 3); + List shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai); System.out.println(shifoutingpai3); if (shifoutingpai3.size() > 0) { @@ -346,24 +353,24 @@ public class HuNanChangSha { List allList = new ArrayList<>(); allList.addAll(changShaCardInhand); allList.addAll(changShachuguopai); - int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai3,allList); - if (jutingnum==0){ - params.putString("session", session + "," + token); - params.putInt("qi", 0); - params.putInt("id", 0); - client.send("612", params, response -> { - }); - return "不开杠"; - } + int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai3, allList); + if (jutingnum == 0) { + params.putString("session", session + "," + token); + params.putInt("qi", 0); + params.putInt("id", 0); + client.send("612", params, response -> { + }); + return "不开杠"; + } - Util.removeCard(changShaCardInhand,card,3); + Util.removeCard(changShaCardInhand, card, 3); params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", id); client.send("612", params, response -> { }); return "开杠"; - }else{ + } else { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", 0); @@ -376,10 +383,9 @@ public class HuNanChangSha { if (type == 4) { - - // Util.removeCard(changShaCardInhand,card,4); - Util.removeCard(gangusecars,card,4); - List shifoutingpai4 = changShaSuanFaTest.handscardshifoutingpai(gangusecars,chowGroup,pongGroup,gangdepai); + // Util.removeCard(changShaCardInhand,card,4); + Util.removeCard(gangusecars, card, 4); + List shifoutingpai4 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai); if (shifoutingpai4.size() > 0) { //开杠 @@ -387,8 +393,8 @@ public class HuNanChangSha { List allList = new ArrayList<>(); allList.addAll(changShaCardInhand); allList.addAll(changShachuguopai); - int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai4,allList); - if (jutingnum==0){ + int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai4, allList); + if (jutingnum == 0) { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", 0); @@ -397,14 +403,14 @@ public class HuNanChangSha { return "不开杠"; } - Util.removeCard(changShaCardInhand,card,4); + Util.removeCard(changShaCardInhand, card, 4); params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", id); client.send("612", params, response -> { }); return "开杠"; - }else{ + } else { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", 0); @@ -416,8 +422,8 @@ public class HuNanChangSha { if (type == 5) { //Util.removeCard(changShaCardInhand,card,1); - Util.removeCard(gangusecars,card,1); - List shifoutingpai5 = changShaSuanFaTest.handscardshifoutingpai(gangusecars,chowGroup,pongGroup,gangdepai); + Util.removeCard(gangusecars, card, 1); + List shifoutingpai5 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai); if (shifoutingpai5.size() > 0) { //开杠 @@ -425,8 +431,8 @@ public class HuNanChangSha { List allList = new ArrayList<>(); allList.addAll(changShaCardInhand); allList.addAll(changShachuguopai); - int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai5,allList); - if (jutingnum==0){ + int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai5, allList); + if (jutingnum == 0) { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", 0); @@ -435,14 +441,14 @@ public class HuNanChangSha { return "不开杠"; } - Util.removeCard(changShaCardInhand,card,1); + Util.removeCard(changShaCardInhand, card, 1); params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", id); client.send("612", params, response -> { }); return "开杠"; - }else{ + } else { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", 0); @@ -459,10 +465,10 @@ public class HuNanChangSha { //判断是否是大胡 int beforeIsDahu = 0; - beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard,chowGroup,pongGroup,gangdepai); - System.out.println("bef:"+beforeIsDahu); + beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai); + System.out.println("bef:" + beforeIsDahu); //5、门清 - if (yupanhandcard.size()==13&&beforelisten){ + if (yupanhandcard.size() == 13 && beforelisten) { beforeIsDahu = 5;//门清 } @@ -470,8 +476,8 @@ public class HuNanChangSha { List allSeeCard = new ArrayList<>(); - Map pingfenResult = new HashMap<>(); - Map idObject = new HashMap<>(); + Map pingfenResult = new HashMap<>(); + Map idObject = new HashMap<>(); //int bupaiid = 0;//补牌id for (int i = 0; i < tipList.size(); i++) { @@ -482,7 +488,7 @@ public class HuNanChangSha { card = firstTip.getInt("card"); ITArray opcard = TArray.newInstance(); opcard = firstTip.getTArray("opcard"); - if (type == 6){ + if (type == 6) { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", id); @@ -491,67 +497,67 @@ public class HuNanChangSha { return "胡牌"; } //if((type==4||type==5||type==6)&&weight==3){ - // bupaiid = id; - // } + // bupaiid = id; + // } //对应的数据 ITObject tmp = new TObject(); //处理听的结果 switch (type) { case 1: //吃 - tmp = changShaSuanFaTest.pingguChi( beforelisten,card,opcard,yupanhandcard,beforeIsDahu,allSeeCard,chowGroup,pongGroup,gangdepai,changShachuguopai); + tmp = changShaSuanFaTest.pingguChi(beforelisten, card, opcard, yupanhandcard, beforeIsDahu, allSeeCard, chowGroup, pongGroup, gangdepai, changShachuguopai); break; case 2: //碰 - tmp = changShaSuanFaTest.pingguPeng(beforelisten,card,opcard,yupanhandcard,beforeIsDahu,allSeeCard,chowGroup,pongGroup,gangdepai,changShachuguopai); + tmp = changShaSuanFaTest.pingguPeng(beforelisten, card, opcard, yupanhandcard, beforeIsDahu, allSeeCard, chowGroup, pongGroup, gangdepai, changShachuguopai); break; default: break; } //记录下来事件 - if(tmp.size()>0){ - pingfenResult.put(id,tmp); + if (tmp.size() > 0) { + pingfenResult.put(id, tmp); } ITObject sj = new TObject(); sj.putInt("weight", weight); sj.putInt("type", type); sj.putTArray("opcard", opcard); - idObject.put(id,sj); + idObject.put(id, sj); } //计算分数 System.out.println(pingfenResult); - if(pingfenResult.size()>0){ - int changeid=changShaSuanFaTest.suanfen(pingfenResult); - System.out.println("changeid:"+changeid); + if (pingfenResult.size() > 0) { + int changeid = changShaSuanFaTest.suanfen(pingfenResult); + System.out.println("changeid:" + changeid); //选择最优的分数 - if (changeid==0){ + if (changeid == 0) { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", 0); client.send("612", params, response -> { }); return null; - }else { + } else { //获取 - for(Map.Entry entry : idObject.entrySet()){ - if(entry.getKey()==changeid){ + for (Map.Entry entry : idObject.entrySet()) { + if (entry.getKey() == changeid) { ITObject tmp = entry.getValue(); System.out.println("tmp ++++++++++= " + tmp); - if (tmp.getInt("type")==2){ + if (tmp.getInt("type") == 2) { //碰 ITArray outcards = tmp.getTArray("opcard"); for (int i = 0; i < outcards.size(); i++) { - Util.removeCard(changShaCardInhand,outcards.getInt(0),2); + Util.removeCard(changShaCardInhand, outcards.getInt(0), 2); } pongGroup.add(outcards.getInt(0)); pongGroup.add(outcards.getInt(0)); pongGroup.add(outcards.getInt(0)); - }else if (tmp.getInt("type")==1){ + } else if (tmp.getInt("type") == 1) { //吃 ITArray outcards = tmp.getTArray("opcard"); for (int i = 0; i < outcards.size(); i++) { - Util.removeCard(changShaCardInhand,outcards.getInt(i),1); + Util.removeCard(changShaCardInhand, outcards.getInt(i), 1); } System.out.println("判断吃 +++++++++" + card); System.out.println("判断吃 ==========" + outcards); @@ -591,11 +597,11 @@ public class HuNanChangSha { List tmpChangSch2 = new ArrayList<>(); tmpChangSch2.addAll(yupanhandcard); if (type == 3) { - Util.removeCard(tmpChangSch2,card,3); - }else if(type==4){ - Util.removeCard(tmpChangSch2,card,3); - }else if(type==5){ - Util.removeCard(tmpChangSch2,card,4); + Util.removeCard(tmpChangSch2, card, 3); + } else if (type == 4) { + Util.removeCard(tmpChangSch2, card, 3); + } else if (type == 5) { + Util.removeCard(tmpChangSch2, card, 4); } ChangshaWinSplitCard.checkNormalHu(tmpChangSch2, map2); @@ -603,7 +609,7 @@ public class HuNanChangSha { System.out.println(yupanhandcard); //假设补牌 //如果下听不能不能补牌 - if(beforelisten){ + if (beforelisten) { System.out.println("b补"); params.putString("session", session + "," + token); params.putInt("qi", 0); @@ -613,9 +619,9 @@ public class HuNanChangSha { return null; } //去一张下听? - Map> afterDahuOpbg = changShaSuanFaTest.quyizhangDahuTingPai(yupanhandcard,chowGroup,pongGroup,gangdepai); - Map> afterOpbg = changShaSuanFaTest.quyizhangTingPai(yupanhandcard); - if(type==4) { + Map> afterDahuOpbg = changShaSuanFaTest.quyizhangDahuTingPai(yupanhandcard, chowGroup, pongGroup, gangdepai); + Map> afterOpbg = changShaSuanFaTest.quyizhangTingPai(yupanhandcard); + if (type == 4) { if (afterDahuOpbg.size() > 0 || afterOpbg.size() > 0) { System.out.println("bs补"); params.putString("session", session + "," + token); @@ -627,11 +633,11 @@ public class HuNanChangSha { } } - if (map.size() > 0 && weight==3) { + if (map.size() > 0 && weight == 3) { if (map2.size() > 0) { //判断补牌后 - if (Integer.parseInt(map2.get("remainingMelds").toString())>Integer.parseInt(map.get("remainingMelds").toString())&&Integer.parseInt(map.get("remainingMelds").toString())<=2){ + if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) && Integer.parseInt(map.get("remainingMelds").toString()) <= 2) { System.out.println("b补"); params.putString("session", session + "," + token); params.putInt("qi", 0); @@ -639,11 +645,11 @@ public class HuNanChangSha { client.send("612", params, response -> { }); return null; - }else{ + } else { //判断七对 - int dh = changShaSuanFaTest.checkDahu(yupanhandcard,chowGroup,pongGroup,gangdepai); - if (dh>0){ + int dh = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai); + if (dh > 0) { System.out.println("不补"); params.putString("session", session + "," + token); params.putInt("qi", 0); @@ -723,7 +729,7 @@ public class HuNanChangSha { } */ - }else{ + } else { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", id); @@ -765,11 +771,9 @@ public class HuNanChangSha { } - - public String actionCardBak2(ITObject param, TaurusClient client) { ITArray tipList = param.getTArray("tip_list"); - log.info("tipList" +tipList); +// log.info("tipList" +tipList); //tipList[{opcard=[207, 208], weight=1, id=1, type=1, card=206}] boolean chiflag = false;//吃 boolean pengflag = false; //碰 @@ -787,7 +791,7 @@ public class HuNanChangSha { int id = firstTip.getInt("id"); int weight = firstTip.getInt("weight"); card = firstTip.getInt("card"); - if (type == 6){ + if (type == 6) { params.putString("session", session + "," + token); params.putInt("qi", 0); params.putInt("id", id); @@ -795,21 +799,21 @@ public class HuNanChangSha { }); return "胡牌"; } - if (type == 1){ + if (type == 1) { chiflag = true; } - if (type == 2){ + if (type == 2) { pengflag = true; } - if (type == 3 && weight ==3){ + if (type == 3 && weight == 3) { //补 bupai = true; } - if (type == 3 && weight ==4){ + if (type == 3 && weight == 4) { //杠 minggang = true; } - if (type == 5){ + if (type == 5) { penggang = true; } } @@ -843,8 +847,6 @@ public class HuNanChangSha { } - - /** * 处理吃 问题 * @param tipList @@ -1016,10 +1018,11 @@ public class HuNanChangSha { client.send("612", params, response -> {}); } */ + /** * 处理杠碰胡操作 * - * @param param 消息参数 + * @param * @return */ /* @@ -1682,8 +1685,6 @@ public class HuNanChangSha { } */ - - public static List getOtherCards1(List integers, int card) { List result = new ArrayList<>(); for (Integer num : integers) { @@ -1762,7 +1763,6 @@ public class HuNanChangSha { resultList.addAll(zigang); } - // 长沙麻将出牌 String changShaOutCard = changShaSuanFaTest.outCardSuanFa(changShaCardInhand, pongGroup, chowGroup, gangdepai, resultList); // String changShaOutCard = changShaSuanFaTest.outCardSuanFa(list, changShaCard,pongGroup); @@ -1791,12 +1791,12 @@ public class HuNanChangSha { changShachuguopai.add(cardToOut); // 从手牌中移除 changShaCardInhand.remove(Integer.valueOf(cardToOut)); - - params.putString("session", session + "," + token); client.send("611", params, response -> { }); + + return null; } @@ -1844,7 +1844,7 @@ public class HuNanChangSha { public static void main(String[] args) { HuNanChangSha huNanChangSha = new HuNanChangSha(); ITObject params = TObject.newInstance(); - TaurusClient tc = new TaurusClient("127.0.0.1","10", TaurusClient.ConnectionProtocol.Tcp); + TaurusClient tc = new TaurusClient("127.0.0.1", "10", TaurusClient.ConnectionProtocol.Tcp); List hands1 = new ArrayList<>(); hands1.add(209); hands1.add(209); @@ -1860,64 +1860,63 @@ public class HuNanChangSha { hands1.add(104); hands1.add(104); - // hands1.add(105); + // hands1.add(105); //hands1.add(103); //hands1.add(102); - int card= 203; + int card = 203; huNanChangSha.changShaCardInhand.addAll(hands1); - TArray tiplist= new TArray(); + TArray tiplist = new TArray(); ITArray opcard = TArray.newInstance(); opcard.addInt(102); - // opcard.addInt(205); + // opcard.addInt(205); - // opcard.addInt(203); + // opcard.addInt(203); TObject tob = new TObject(); - tob.putInt("weight",3); - tob.putInt("id",1); - tob.putInt("type",4); - tob.putInt("card",card); + tob.putInt("weight", 3); + tob.putInt("id", 1); + tob.putInt("type", 4); + tob.putInt("card", card); tob.putTArray("opcard", opcard); //tiplist.addTObject(tob); ITArray opcard2 = TArray.newInstance(); - // opcard2.addInt(106); + // opcard2.addInt(106); opcard2.addInt(107); TObject tob2 = new TObject(); - tob2.putInt("weight",5); - tob2.putInt("id",2); - tob2.putInt("type",5); - tob2.putInt("card",card); + tob2.putInt("weight", 5); + tob2.putInt("id", 2); + tob2.putInt("type", 5); + tob2.putInt("card", card); tob2.putTArray("opcard", opcard2); - // tiplist.addTObject(tob2); + // tiplist.addTObject(tob2); ITArray opcard3 = TArray.newInstance(); opcard3.addInt(204); opcard3.addInt(205); TObject tob3 = new TObject(); - tob3.putInt("weight",1); - tob3.putInt("id",1); - tob3.putInt("type",1); - tob3.putInt("card",card); + tob3.putInt("weight", 1); + tob3.putInt("id", 1); + tob3.putInt("type", 1); + tob3.putInt("card", card); tob3.putTArray("opcard", opcard3); tiplist.addTObject(tob3); - - params.putTArray("tip_list",tiplist); + params.putTArray("tip_list", tiplist); System.out.println(params); //已经吃掉数据 - // huNanChangSha.chowGroup.add(205); + // huNanChangSha.chowGroup.add(205); //huNanChangSha.chowGroup.add(204); - // huNanChangSha.chowGroup.add(206); + // huNanChangSha.chowGroup.add(206); //huNanChangSha.chowGroup.add(201); - // huNanChangSha.chowGroup.add(202); - // huNanChangSha.chowGroup.add(203); - // huNanChangSha.chowGroup.add(206); + // huNanChangSha.chowGroup.add(202); + // huNanChangSha.chowGroup.add(203); + // huNanChangSha.chowGroup.add(206); //huNanChangSha.chowGroup.add(204); //huNanChangSha.chowGroup.add(205); - String res = huNanChangSha.actionCard(params,tc); + String res = huNanChangSha.actionCard(params, tc); System.out.println(res); } diff --git a/libs/robot_common/src/main/java/hunan/JiQiRens.java b/libs/robot_common/src/main/java/hunan/JiQiRens.java index 6447ed4..02fbf5a 100644 --- a/libs/robot_common/src/main/java/hunan/JiQiRens.java +++ b/libs/robot_common/src/main/java/hunan/JiQiRens.java @@ -957,7 +957,8 @@ public class JiQiRens { //[TCP->822] data:{"tip_list":[{"type":8,"id":1,"opcard":[],"weight":8,"card":0}],"types":[{"type":21,"value":1}]} //板胡Event [TCP->823] data:{"type":8,"seat":1,"data":[{"opcard":[204,204,204,108,108,108],"type":21,"value":1}]} if ("811".equalsIgnoreCase(command)) {//初始化收手牌 - huNanChangSha.cardInHead(command, message, client); + Map d = null; +// huNanChangSha.cardInHead(command, message, client); } else if ("812".equalsIgnoreCase(command)) {//出牌广播 //{"opzicards":[{"opzicards":[],"playerId":101555}],"opmingcards":[{"opmingcards":[],"playerId":101555}],"outcard_map":[{"outcards":[209,205],"playerId":101555},{"outcards":[],"playerId":112233}],"card":205,"opchicards":[{"opchicards":[105,103],"playerId":101555}],"oppengcards":[{"oppengcards":[],"playerId":101555}],"seat":1} ITArray outcard_map = param.getTArray("outcard_map"); @@ -1054,9 +1055,10 @@ public class JiQiRens { HuNanChangSha.drawCard(command, message); } else if ("819".equalsIgnoreCase(command)) { //摸牌 - huNanChangSha.getCard(command, message); +// huNanChangSha.getCard(command, message); } else if ("813".equalsIgnoreCase(command)) {//出牌提示 - huNanChangSha.outCard(client,playerOutcardsMap,playerchisMap,playerpengsMap,playermingsMap,playerzisMap); + +// huNanChangSha.outCard(client,playerOutcardsMap,playerchisMap,playerpengsMap,playermingsMap,playerzisMap,null); } else if ("814".equalsIgnoreCase(command)) { //放招提示 huNanChangSha.actionCard(param, client); diff --git a/libs/robot_common/src/main/java/taurus/newRobot/AddRoomRobot.java b/libs/robot_common/src/main/java/taurus/newRobot/AddRoomRobot.java index 1f9f8cc..1ed06f2 100644 --- a/libs/robot_common/src/main/java/taurus/newRobot/AddRoomRobot.java +++ b/libs/robot_common/src/main/java/taurus/newRobot/AddRoomRobot.java @@ -1,108 +1,58 @@ package taurus.newRobot; -import com.taurus.core.entity.ITArray; -import com.taurus.core.entity.ITObject; -import com.taurus.core.entity.TObject; -import com.taurus.core.events.Event; -import com.taurus.core.events.IEventListener; -import com.taurus.core.plugin.database.DataBase; import com.taurus.core.plugin.redis.Redis; -import com.taurus.core.util.ICallback; -import com.taurus.core.util.StringUtil; -import hunan.*; import redis.clients.jedis.*; -import taurus.client.Message; -import taurus.client.MessageResponse; -import taurus.client.SocketCode; -import taurus.client.TaurusClient; -import taurus.client.business.AccountBusiness; -import taurus.client.business.GroupRoomBusiness; -import taurus.util.ChangShaSuanFaTest; -import taurus.util.TinHuChi; -import java.sql.SQLException; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; +import taurus.client.TaurusClient; -import static hunan.JiQiRens.sleepTime; public class AddRoomRobot { - public String wanfaId = ""; - // 会话标识 - private String session = ""; - // 访问令牌 - public String token = ""; - // 客户端连接对象 - private static TaurusClient client = null; - - - private HuNanHongZhong huNanHongZhong = new HuNanHongZhong(); - - private HuNanZhuanZhuan huNanZhuanZhuan = new HuNanZhuanZhuan(); - - private HuNanFangPaoFa huNanFangPaoFa = new HuNanFangPaoFa(); - - private HuNanPaoDeKuai huNanPaoDeKuai = new HuNanPaoDeKuai(); - - private HuNanChangSha huNanChangSha = new HuNanChangSha(); - - - private Map> playerOutcardsMap = new HashMap<>(); - - - private Map> playerchisMap = new HashMap<>(); - - private Map> playerpengsMap = new HashMap<>(); - - private Map> playermingsMap = new HashMap<>(); - - private Map> playerzisMap = new HashMap<>(); - - private Map mapclient = new HashMap<>(); public void addRoom() { Jedis jedis2 = Redis.use("group1_db2").getJedis(); Jedis jedis11 = Redis.use("group1_db11").getJedis(); - Jedis jedis0 = Redis.use().getJedis(); + System.out.println("进入1111111111111111111111111"); + //给玩法分配机器人 + if (jedis11.keys("group:*") != null) { + Set groupIds = jedis11.keys("group:*"); + for (String group : groupIds) { + String groupId = group.substring(group.indexOf(":") + 1); + String groupKey = "g{" + groupId + "}:play:*"; + if (jedis11.keys(groupKey) != null) { + Set playIds = jedis11.keys(groupKey); + // 遍历圈子下面的玩法 + for (String pid : playIds) { + String playId = pid.substring(pid.indexOf("play:") + 5); + String playKey = "g{" + groupId + "}:play:" + playId; - //获取圈子id和玩法id - List gKeys = scanKeysByPattern(jedis2, "g{*}:play:*"); - - try { - - if (jedis11.keys("group:*") != null) { - Set groupIds = jedis11.keys("group:*"); - for (String group : groupIds) { - String groupId = group.substring(group.indexOf(":") + 1); - String groupKey = "g{" + groupId + "}:play:*"; - if (jedis11.keys(groupKey) != null) { - Set playIds = jedis11.keys(groupKey); - // 遍历圈子下面的玩法 - for (String pid : playIds) { - String playId = pid.substring(pid.indexOf("play:") + 5); - String playKey = "g{" + groupId + "}:play:" + playId; - - String leftover_robot = "0"; - if (jedis11.hget(playKey, "leftover_robot") != null) { - leftover_robot = jedis11.hget(playKey, "leftover_robot"); - if (Integer.parseInt(leftover_robot) > 0) { - //给圈子玩法分配机器人,创建到redis - addPlayRobot(groupId, playId, leftover_robot); - } + String leftover_robot = "0"; + if (jedis11.hget(playKey, "leftover_robot") != null) { + leftover_robot = jedis11.hget(playKey, "leftover_robot"); + if (Integer.parseInt(leftover_robot) > 0) { + //给圈子玩法分配机器人,创建到redis + addPlayRobot(groupId, playId, leftover_robot); } } } - } } + } + System.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); + //机器人主动找真人 + joinzhenrenRoom(); + System.out.println("进入22222222222222222222222"); + //机器人主动进入退出, 这里进入的是中括号机器人退出的房间 + zhongJoninRoom(); +// System.out.println("进入3333333333333333333"); + //机器人创建房间 进入房间 + List gKeys = scanKeysByPattern(jedis2, "g{*}:play:*"); + try { Map> stringListMap = analyzePlayStructure(gKeys); - //取出 圈子玩法里的 机器人使用所有的状态 Map>> playDetails = getPlayDetails(jedis2, stringListMap); System.out.println("result" + playDetails); @@ -110,37 +60,17 @@ public class AddRoomRobot { //统计 玩法里 等待中的次数 为1的有几个 ,然后需要建立几个房间 Map> stringMapMap = analyzeAndMarkRoomsWithCircle(playDetails); System.out.println("stringIntegerMap" + stringMapMap); - - - Map>> allCreatedRooms = new HashMap<>(); // 按圈子ID排序处理 List circleIds = new ArrayList<>(stringMapMap.keySet()); Collections.sort(circleIds); for (String circleId : circleIds) { Map playRoomMap = stringMapMap.get(circleId); - - System.out.println("\n=== 处理圈子 " + circleId + " ==="); - - // 为当前圈子创建房间 - Map> createdRooms = createRoomsForCircle(circleId, playRoomMap); - - - allCreatedRooms.put(circleId, createdRooms); + System.out.println("创建房间,进入房间"); + jiqiren jiqiren = new jiqiren(); + System.out.println("circleId +++" + circleId); + System.out.println("playRoomMap +++ " + playRoomMap); + jiqiren.createRoomsForCircle(circleId, playRoomMap); } - - -// Object room = GroupRoomBusiness.matchRoom(groupId, pid, session, "Android", false); -// try { -// String game = jedis0.hget(String.valueOf(room), "game"); -// wanfaId = String.valueOf(game); -// }catch (Exception e){ -// e.printStackTrace(); -// }finally { -// jedis0.close(); -// } -// System.out.println("chaungjianwanfa" + gKeys); - - } catch (Exception e) { e.printStackTrace(); } finally { @@ -150,921 +80,24 @@ public class AddRoomRobot { } - /** - * 为单个圈子创建房间 - */ - public Map> createRoomsForCircle(String circleId, Map playRoomMap) { - Map> createdRooms = new HashMap<>(); - Jedis jedis2 = Redis.use("group1_db2").getJedis(); - Jedis jedis11 = Redis.use("group1_db11").getJedis(); + //机器人进入中括号房间 + public void zhongJoninRoom() { Jedis jedis0 = Redis.use().getJedis(); - // 按玩法ID排序处理 - List> sortedPlays = playRoomMap.entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .collect(Collectors.toList()); - - for (Map.Entry entry : sortedPlays) { - String playId = entry.getKey(); - int requiredRooms = entry.getValue(); - - if (requiredRooms <= 0) { - System.out.println("玩法 " + playId + ": 跳过创建 (需求数=" + requiredRooms + ")"); - continue; + try { + //获取所有房间 + Set roomIds = jedis0.keys("room:*"); + for (String id : roomIds) { + jiqiren jiqiren = new jiqiren(); + jiqiren.tcp_jiqirezhongkouhao(id); } - - System.out.println("玩法 " + playId + ": 创建 " + requiredRooms + " 个房间"); - - List roomsForPlay = new ArrayList<>(); - - for (int i = 1; i <= requiredRooms; i++) { - try { - String keys = "g{" + circleId + "}:play:" + playId; - Map stringStringMap = jedis2.hgetAll(keys); - - - List zeroValueKeys = getKeysWithValueZero(stringStringMap); - System.out.println("值为0的机器人ID: " + zeroValueKeys); - String randomKeyFromList = getRandomKeyFromList(zeroValueKeys); - System.out.println("随机给的用户id----" + randomKeyFromList); - - jedis2.hset(keys, randomKeyFromList, "1"); - - ITObject object = null; - AccountBusiness accountBusiness = null; - accountBusiness = new AccountBusiness(); - - // 登录获取session跟token - if (jedis0.keys("{user}:" + randomKeyFromList + "_token").size() != 0) { - Set keys1 = jedis0.keys("{user}:" + randomKeyFromList + "_token"); - if (keys1 == null) { - object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); - ITObject validate = TObject.newInstance(); - validate.putString("token", object.getString("token")); - token = object.getString("token"); - session = accountBusiness.getSession(); - } else { - Set keys2 = jedis0.smembers("{user}:" + randomKeyFromList + "_token"); - List keyList = new ArrayList<>(keys2); - session = "{user}:" + randomKeyFromList; - token = keyList.get(0); - } - } else { - object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); - ITObject validate = TObject.newInstance(); - validate.putString("token", object.getString("token")); - token = object.getString("token"); - session = accountBusiness.getSession(); - } - - - // 调用原有的房间匹配逻辑 - Object room = GroupRoomBusiness.matchRoom(Integer.parseInt(circleId), Integer.parseInt(playId), session, "Android", false); - String game = jedis0.hget(String.valueOf(room), "game"); - wanfaId = String.valueOf(game); - String roomKey = String.valueOf(room); - System.out.println("roomkey--------" + roomKey); - - client = null; - - System.out.println("wanfaId" + wanfaId); - -// List circleIds = new ArrayList<>(); - - - if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将 - client = new TaurusClient("8.138.242.190:6421", "game", TaurusClient.ConnectionProtocol.Tcp); - } - - if ("10".equalsIgnoreCase(wanfaId)) { - client = new TaurusClient("8.138.242.190:6311", "game", TaurusClient.ConnectionProtocol.Tcp); - client.connect(); - mapclient.put(randomKeyFromList,client); - } -// - if ("66".equalsIgnoreCase(wanfaId)) { - client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp); - } - - - System.out.println("mapclient----"+mapclient); - ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(circleId), roomKey, this.session, null); - String roomId = roomInfos.getString("room_id"); - String robort = "{robortInfo}:" + randomKeyFromList; - jedis2.hset(robort, "room_id", roomId); - jedis2.hset(robort, "circleId", circleId); - jedis2.hset(robort, "pid", playId); - - joinRoom(Integer.parseInt(randomKeyFromList)); //进入房间 - - - ready(); //准备 - - - String playKey1 = "g{" + circleId + "}:play:" + playId; - - jedis11.hincrBy(playKey1, "leftover_robot", -1); - - - if (room != null) { - roomsForPlay.add(room); - System.out.println(" 第 " + i + " 个房间创建成功"); - } else { - System.out.println(" 第 " + i + " 个房间创建失败"); - } - -// // 控制创建间隔 -// if (i < requiredRooms) { -// Thread.sleep(100); -// } -// - // 添加事件监听器处理网络消息 - client.addEventListener(TaurusClient.NetClientEvent.OnEvent, new IEventListener() { - @Override - public void handleEvent(Event event) { - - // 获取 msg - Message message = (Message) event.getParameter("msg"); - if (message == null) { - return; - } - - ITObject param = message.param; - //回调协议号 - String command = message.command; - - //根据玩法id 调用不同的回调 - if (StringUtil.isNotEmpty(command)) { - if ("66".equalsIgnoreCase(wanfaId)) {//跑的快 -// if ("2011".equalsIgnoreCase(command)) { //跑的快 初始化手牌 -// huNanPaoDeKuai.paoDeKuaiCardInHead(param, client); -// } else if ("2021".equalsIgnoreCase(command)) { //出牌广播 -// huNanPaoDeKuai.paoDekuaiChupaiGuangBo(param); -// } else if ("2004".equalsIgnoreCase(command)) { //出牌提示事件,牌权 -// Integer player = param.getInt("player"); -// Integer seat1 = param.getInt("seat"); -// -// if (seat1 != null) { -// huNanPaoDeKuai.seat = seat1; -// } -// -// //出牌 -// huNanPaoDeKuai.outCard(client); -// } else if ("2007".equalsIgnoreCase(command)) { //结算准备 -// //type为1 为大结算 type为0为小结算 -// Integer type = param.getInt("type"); -// -// if (type == 0) { -// huNanPaoDeKuai.getSeatRemainHistory().clear(); -// huNanPaoDeKuai.getPaoDekuaiCardInhand().clear(); -// ITArray card_list = huNanPaoDeKuai.getCard_list().getTArray("card_list"); -// card_list.clear(); -// ready(); -// } -// -// if (type == 1) { -// Jedis jedis11s = Redis.use("group1_db11").getJedis(); -// try { -// String key = "g{" + groupId + "}:play:" + pid; -// jedis11s.hincrBy(key, "leftover_robot", 1); -// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); -// try { -// DataBase.use().executeUpdate(sql); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } finally { -// jedis11s.close(); -// } -// } -// -// } else if ("2009".equalsIgnoreCase(command)) { -// Jedis jedis21 = Redis.use().getJedis(); -// sleepTime(3000); -// -// ITObject params = TObject.newInstance(); -// String[] playerIds2 = null; -// -// -// Set roomIds = jedis21.keys("room:*"); -// String roomKey = ""; -// //拿到所有的机器人 -// List robotIdsList = new ArrayList<>(); -// String sql2 = "SELECT id FROM `account` WHERE jiqiren=9998"; -// ITArray robotId2 = null; -// try { -// robotId2 = DataBase.use().executeQueryByTArray(sql2); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// for (int j = 0; j < Objects.requireNonNull(robotId2).size(); j++) { -// robotIdsList.add(robotId2.getTObject(j).getInt("id")); -// } -// -// -// for (String roomId : roomIds) { -// String roomId1 = roomId.substring(roomId.indexOf(":") + 1); -// roomKey = "room:" + roomId1; -// -// if (jedis21.hget(roomKey, "players") != null) { -// String players = jedis21.hget(roomKey, "players"); -// if (!players.equals("[]")) { -// players = players.substring(1, players.length() - 1); -// playerIds2 = players.split(","); -// -// -// if (playerIds2.length == 1) { -// for (String s : playerIds2) { -// if (robotIdsList.contains(Integer.parseInt(s))) { //房间里的人是机器人 -// String gpid = jedis21.hget(roomKey, "gpid"); -// String gpId = jedis21.hget(roomKey, "group"); -// String key = "g{" + gpId + "}:play:" + gpid; -// if (!players.equals("[]") && pid == Integer.parseInt(gpid)) { -// -// -// if (JiQiRens.count != null && JiQiRens.count.containsKey(Integer.parseInt(gpid))) { -// Integer currentValue = JiQiRens.count.get(Integer.parseInt(gpid)); -// if (currentValue > 0) { -// JiQiRens.count.put(Integer.parseInt(gpid), currentValue - 1); -// } -// } -// -// -// Jedis jedis20 = Redis.use("group1_db11").getJedis(); -// -// jedis20.hincrBy(key, "leftover_robot", 1); -// jedis20.close(); -// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, Integer.parseInt(s)); -// -// try { -// DataBase.use().executeUpdate(sql); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// -// client.send("1005", params, response -> { -// -// }); -// -// } -// } -// } -// } -// } -// } -// } -// -// jedis21.close(); -// -// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 -// Set roomIds = scanRooms(jedis0, "room:*"); -// String[] playerIds = null; -// for (String roomId : roomIds) { -// String rid = roomId.substring(roomId.indexOf(":") + 1); -// String roomKey = "room:" + rid; -// if (jedis0.hget(roomKey, "players") != null) { -// String players = jedis0.hget(roomKey, "players"); -// if (!players.equals("[]")) { -// players = players.substring(1, players.length() - 1); -// playerIds = players.split(","); -// for (String pyids : playerIds) { -// if (Integer.parseInt(pyids) == playerId) { -// jedis0.del(roomId); -// } -// } -// } -// } -// } -// } else if ("2031".equalsIgnoreCase(command)) { -// ITObject params = TObject.newInstance(); -// params.putInt("id", 0); -// client.send("1015", params, response -> { -// -// }); -// -// } -// } else if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将 -// -// if ("812".equalsIgnoreCase(command)) { //出牌广播 -// HuNanHongZhong.drawCard(command, message); -// } else if ("811".equalsIgnoreCase(command)) {//初始化手牌 -// huNanHongZhong.cardInHead(command, message, client); -// } else if ("819".equalsIgnoreCase(command)) { //摸牌 -// huNanHongZhong.getCard(command, message); -// } else if ("813".equalsIgnoreCase(command)) { //出牌,牌权 -// huNanHongZhong.outCard(client); -// } else if ("817".equalsIgnoreCase(command)) {//结算 -// huNanHongZhong.getHongZhongCardInhand().clear(); -// huNanHongZhong.getChuGuoCardInhand().clear(); -// -// Integer type = param.getInt("type"); -// if (type == 1 || type == 2) { //为1为大结算 为2为解散 -// Jedis jedis11s = Redis.use("group1_db11").getJedis(); -// try { -// String key = "g{" + groupId + "}:play:" + pid; -// jedis11s.hincrBy(key, "leftover_robot", 1); -//// -// if (count != null && count.containsKey(pid)) { -// Integer currentValue = count.get(pid); -// if (currentValue > 0) { -// count.put(pid, currentValue - 1); -// } -// } -// -// -// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); -// try { -// DataBase.use().executeUpdate(sql); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } finally { -// jedis11s.close(); -// } -// -// if (count != null && count.containsKey(pid)) { -// Integer value = count.get(pid); -// -// // 如果找到了对应的 pid -// String shangxianRobot = jedis11.hget(playKey, "shangxian_robot"); -// String leftoverRobot = jedis11.hget(playKey, "leftover_robot"); -// -// if (shangxianRobot != null && leftoverRobot != null) { -// if (value == 0) { -// jedis11.hset(playKey, "leftover_robot", shangxianRobot); -// } -// } -// } -// } -//// playerState.pongGroups.clear();; -//// playerState.handCards.clear(); -//// playerState.chiGroups.clear(); -//// playerState.gangGroups.clear();; -// -// -// ready(); -// } else if ("2009".equalsIgnoreCase(command)) { -// Jedis jedis21 = Redis.use().getJedis(); -// sleepTime(3000); -// ITObject params = TObject.newInstance(); -// String[] playerIds2 = null; -// -// -// Set roomIds = jedis21.keys("room:*"); -// String roomKey = ""; -// //拿到所有的机器人 -// List robotIdsList = new ArrayList<>(); -// String sql2 = "SELECT id FROM `account` WHERE jiqiren=9998"; -// ITArray robotId2 = null; -// try { -// robotId2 = DataBase.use().executeQueryByTArray(sql2); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// for (int j = 0; j < Objects.requireNonNull(robotId2).size(); j++) { -// robotIdsList.add(robotId2.getTObject(j).getInt("id")); -// } -// -// -// for (String roomId : roomIds) { -// String roomId1 = roomId.substring(roomId.indexOf(":") + 1); -// roomKey = "room:" + roomId1; -// -// if (jedis21.hget(roomKey, "players") != null) { -// String players = jedis21.hget(roomKey, "players"); -// if (!players.equals("[]")) { -// players = players.substring(1, players.length() - 1); -// playerIds2 = players.split(","); -// -// -// if (playerIds2.length == 1) { -// for (String s : playerIds2) { -// if (robotIdsList.contains(Integer.parseInt(s))) { //房间里的人是机器人 -// String gpid = jedis21.hget(roomKey, "gpid"); -// String gpId = jedis21.hget(roomKey, "group"); -// String key = "g{" + gpId + "}:play:" + gpid; -// if (!players.equals("[]") && pid == Integer.parseInt(gpid)) { -// -// -// if (JiQiRens.count != null && JiQiRens.count.containsKey(Integer.parseInt(gpid))) { -// Integer currentValue = JiQiRens.count.get(Integer.parseInt(gpid)); -// if (currentValue > 0) { -// JiQiRens.count.put(Integer.parseInt(gpid), currentValue - 1); -// } -// } -// -// -// Jedis jedis20 = Redis.use("group1_db11").getJedis(); -// -// jedis20.hincrBy(key, "leftover_robot", 1); -// jedis20.close(); -// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, Integer.parseInt(s)); -// -// try { -// DataBase.use().executeUpdate(sql); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// -// client.send("1005", params, response -> { -// -// }); -// -// } -// } -// } -// } -// } -// } -// } -// -// jedis21.close(); -// -// } else if ("814".equalsIgnoreCase(command)) {//杠碰胡通知协议 -//// sleepTime(2000); -// huNanHongZhong.actionCard(param, client); -// } else if ("820".equalsIgnoreCase(command)) { -// HuNanHongZhong.changePlayer(command, message); -// } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作 -// huNanHongZhong.shanchuchuguopai(param); -// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 -//// Jedis jedis11s = Redis.use("group1_db11").getJedis(); -//// try { -//// String key = "g{" + groupId + "}:play:" + pid; -//// jedis11s.hincrBy(key, "leftover_robot", 1); -//// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); -//// DataBase.use().executeUpdate(sql); -// Set roomIds = scanRooms(jedis0, "room:*"); -// String[] playerIds = null; -// for (String roomId : roomIds) { -// String rid = roomId.substring(roomId.indexOf(":") + 1); -// String roomKey = "room:" + rid; -// if (jedis0.hget(roomKey, "players") != null) { -// String players = jedis0.hget(roomKey, "players"); -// if (!players.equals("[]")) { -// players = players.substring(1, players.length() - 1); -// playerIds = players.split(","); -// for (String pyids : playerIds) { -// if (Integer.parseInt(pyids) == playerId) { -// jedis0.del(roomId); -// } -// } -// } -// } -// } -// -// } - } else if ("17".equalsIgnoreCase(wanfaId)) { //字牌放炮罚 - -// if ("811".equalsIgnoreCase(command)) { //初始化手牌 -// huNanFangPaoFa.cardInHead(command, message, client); -// -// } else if ("819".equalsIgnoreCase(command)) { //摸牌 -// huNanFangPaoFa.getCard(command, message); -// } else if ("813".equalsIgnoreCase(command)) { //出牌 牌权 -// sleepTime(1500); -// huNanFangPaoFa.outCard(client); -// } else if ("812".equalsIgnoreCase(command)) { //出牌广播 -// HuNanFangPaoFa.drawCard(command, message); -// } else if ("814".equalsIgnoreCase(command)) { //可执行的 操作 吃碰 偎提胡 -// huNanFangPaoFa.actionCard(param, client); -// } else if ("817".equalsIgnoreCase(command)) { //结算 -// huNanFangPaoFa.getFangPaoFaCardInhand().clear(); -// ready(); -// } else if ("822".equalsIgnoreCase(command)) { //放跑提示 -// -// HuNanFangPaoFa.fangPaoTipEvent(message, client); -// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 -// try { -// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); -// DataBase.use().executeUpdate(sql); -// -// } catch (SQLException e) { -// -// } -// } - } else if ("108".equalsIgnoreCase(wanfaId)) {//转转麻将 -// if ("811".equalsIgnoreCase(command)) {//初始化收手牌 -// huNanZhuanZhuan.cardInHead(command, message, client); -// } else if ("812".equalsIgnoreCase(command)) {//出牌广播 -// HuNanZhuanZhuan.drawCard(command, message); -// } else if ("819".equalsIgnoreCase(command)) {//摸牌 -// -// huNanZhuanZhuan.getCard(command, message); -// } else if ("813".equalsIgnoreCase(command)) {//出牌提示 -//// sleepTime(1500); -// huNanZhuanZhuan.outCard(client); -// } else if ("814".equalsIgnoreCase(command)) {//放招提示 -// huNanZhuanZhuan.actionCard(param, client); -// } else if ("817".equalsIgnoreCase(command)) {//结算 -// huNanZhuanZhuan.getZhuanZhuanCardInhand().clear(); -// huNanZhuanZhuan.getZhuanZhuanchuguopai().clear(); -// ready(); -// } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作 -// huNanZhuanZhuan.shanchuchuguopai(param); -// } else if ("820".equalsIgnoreCase(command)) {//换牌提示 -// HuNanZhuanZhuan.changePlayer(command, message); -// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 -// try { -// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); -// DataBase.use().executeUpdate(sql); -// } catch (SQLException e) { -// -// } -// } - } else if ("10".equalsIgnoreCase(wanfaId)) { - //长沙麻将 机器人处理事件 - if ("811".equalsIgnoreCase(command)) {//初始化收手牌 - huNanChangSha.cardInHead(command, message, client); - } else if ("812".equalsIgnoreCase(command)) {//出牌广播 - //{"opzicards":[{"opzicards":[],"playerId":101555}],"opmingcards":[{"opmingcards":[],"playerId":101555}],"outcard_map":[{"outcards":[209,205],"playerId":101555},{"outcards":[],"playerId":112233}],"card":205,"opchicards":[{"opchicards":[105,103],"playerId":101555}],"oppengcards":[{"oppengcards":[],"playerId":101555}],"seat":1} - ITArray outcard_map = param.getTArray("outcard_map"); - ITArray opchicards = param.getTArray("opchicards"); - ITArray oppengcards = param.getTArray("oppengcards"); - ITArray opmingcards = param.getTArray("opmingcards"); - ITArray opzicards = param.getTArray("opzicards"); - - // 清空旧数据,用新数据完全覆盖 - playerOutcardsMap.clear(); - playerchisMap.clear(); - playerpengsMap.clear(); - playermingsMap.clear(); - playerzisMap.clear(); - //出过的牌 - if (outcard_map != null) { - for (int i = 0; i < outcard_map.size(); i++) { - ITObject playerData = outcard_map.getTObject(i); - int playerId = playerData.getInt("playerId"); - ITArray outcardsArray = playerData.getTArray("outcards"); - - // 转换为List - List outcardsList = new ArrayList<>(); - for (int j = 0; j < outcardsArray.size(); j++) { - outcardsList.add(outcardsArray.getInt(j)); - } - - // 存储到Map中(覆盖旧数据) - playerOutcardsMap.put(playerId, outcardsList); - - } - } - - //吃的牌 - if (opchicards != null) { - for (int i = 0; i < opchicards.size(); i++) { - ITObject playerData = opchicards.getTObject(i); - int playerId = playerData.getInt("playerId"); - ITArray outchiArray = playerData.getTArray("opchicards"); - - List outchiList = new ArrayList<>(); - for (int j = 0; j < outchiArray.size(); j++) { - outchiList.add(outchiArray.getInt(j)); - } - playerchisMap.put(playerId, outchiList); - } - } - - //碰的牌 - if (oppengcards != null) { - for (int i = 0; i < oppengcards.size(); i++) { - ITObject playerData = oppengcards.getTObject(i); - int playerId = playerData.getInt("playerId"); - ITArray outpengArray = playerData.getTArray("oppengcards"); - - List outpengList = new ArrayList<>(); - for (int j = 0; j < outpengArray.size(); j++) { - outpengList.add(outpengArray.getInt(j)); - } - playerpengsMap.put(playerId, outpengList); - } - } - - //明杠的牌 - if (opmingcards != null) { - for (int i = 0; i < opmingcards.size(); i++) { - ITObject playerData = opmingcards.getTObject(i); - int playerId = playerData.getInt("playerId"); - ITArray outmingArray = playerData.getTArray("opmingcards"); - - List outmingList = new ArrayList<>(); - for (int j = 0; j < outmingArray.size(); j++) { - outmingList.add(outmingArray.getInt(j)); - } - playermingsMap.put(playerId, outmingList); - } - } - - //暗杠的牌 - if (opzicards != null) { - for (int i = 0; i < opzicards.size(); i++) { - ITObject playerData = opzicards.getTObject(i); - int playerId = playerData.getInt("playerId"); - ITArray outziArray = playerData.getTArray("opzicards"); - - List outziList = new ArrayList<>(); - for (int j = 0; j < outziArray.size(); j++) { - outziList.add(outziArray.getInt(j)); - } - playerzisMap.put(playerId, outziList); - } - } - - HuNanChangSha.drawCard(command, message); - } else if ("819".equalsIgnoreCase(command)) { - //摸牌 - huNanChangSha.getCard(command, message); - } else if ("813".equalsIgnoreCase(command)) {//出牌提示 - huNanChangSha.outCard(client, playerOutcardsMap, playerchisMap, playerpengsMap, playermingsMap, playerzisMap); - } else if ("814".equalsIgnoreCase(command)) { - //放招提示 - huNanChangSha.actionCard(param, client); - - } else if ("2009".equalsIgnoreCase(command)) { - //db0 - Jedis jedis22 = Redis.use().getJedis(); - //db2 - Jedis jedis33 = Redis.use("group1_db2").getJedis(); - sleepTime(5000); - System.out.println("param ++++++++++++++++ " + param); - Integer aid = param.getInt("aid"); - - ITObject params = TObject.newInstance(); - - String getKey ="{robortInfo}:"+aid; - String circleId1 = jedis33.hget(getKey, "circleId"); - String pid = jedis33.hget(getKey, "pid"); - if (!pid.equals("0")){ - String key = "g{" + circleId1 + "}:play:" + pid; - Jedis jedis20 = Redis.use("group1_db11").getJedis(); - System.out.println("进入 -------------------------"); - jedis20.hincrBy(key, "leftover_robot", 1); - jedis20.close(); - System.out.println("client ++++= " + client); - - - for (Map.Entry entry : mapclient.entrySet()) { - String key1 = entry.getKey(); - if (Integer.parseInt(key1)==aid){ - Object value = entry.getValue(); - TaurusClient client1 = (TaurusClient) value; - client1.send("1005", params, response -> { - - }); - } - } - - - sleepTime(1000); - jedis33.hset(getKey, "circleId","0"); - jedis33.hset(getKey, "pid","0"); - jedis33.hset(getKey, "room_id","0"); - } - - jedis33.close(); - - - - - jedis22.close(); - } else if ("817".equalsIgnoreCase(command)) {//结算 -// huNanChangSha.getChangShaCardInhand().clear(); -// huNanChangSha.getChuGuoCardInhand().clear(); -// huNanChangSha.getpongGroup().clear(); -// huNanChangSha.getchowGroup().clear(); -// TinHuChi.lastTingCount = 0; -// TinHuChi.isMoreThanLast = false; -// ChangShaSuanFaTest.isTin = false; -// ChangShaSuanFaTest.isChi = false; -// ChangShaSuanFaTest.isPeng = false; -// ChangShaSuanFaTest.tinCards.clear(); -// Integer type = param.getInt("type"); -// if (type == 1 || type == 2) { //为1为大结算 为2为解散 -// Jedis jedis11s = Redis.use("group1_db11").getJedis(); -// try { -// String key = "g{" + groupId + "}:play:" + pid; -// jedis11s.hincrBy(key, "leftover_robot", 1); -//// -// if (count != null && count.containsKey(pid)) { -// Integer currentValue = count.get(pid); -// if (currentValue > 0) { -// count.put(pid, currentValue - 1); -// } -// } -// -// -// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); -// try { -// DataBase.use().executeUpdate(sql); -// } catch (SQLException e) { -// e.printStackTrace(); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } finally { -// jedis11s.close(); -// } -// -// if (count != null && count.containsKey(pid)) { -// Integer value = count.get(pid); -// -// // 如果找到了对应的 pid -// Jedis jedis12 = Redis.use("group1_db11").getJedis(); -// -// String shangxianRobot = jedis12.hget(playKey, "shangxian_robot"); -// String leftoverRobot = jedis12.hget(playKey, "leftover_robot"); -// -// if (shangxianRobot != null && leftoverRobot != null) { -// if (value == 0) { -// jedis12.hset(playKey, "leftover_robot", shangxianRobot); -// } -// } -// jedis12.close(); -// } -// } -//// playerState.pongGroups.clear();; -//// playerState.handCards.clear(); -//// playerState.chiGroups.clear(); -//// playerState.gangGroups.clear();; -// -// -// ready(); -// //写定时器 - - } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作 - //[TCP->815] data:{"playerid":101555,"card":104,"opcard":[105,103],"from_seat":2,"type":1,"opengang":false} - huNanChangSha.shanchuchuguopai(param); - } else if ("820".equalsIgnoreCase(command)) {//换牌提示 - huNanChangSha.changePlayer(command, message); - } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 -// Jedis jedis11s = Redis.use("group1_db11").getJedis(); -// String key = "g{" + groupId + "}:play:" + pid; -// -// jedis11s.hincrBy(key, "leftover_robot", 1); -// jedis11s.close(); -// try { -// -// Set roomIds = scanRooms(jedis0, "room:*"); -// String[] playerIds = null; -// for (String roomId : roomIds) { -// String rid = roomId.substring(roomId.indexOf(":") + 1); -// String roomKey = "room:" + rid; -// -// if (jedis0.hget(roomKey, "players") != null) { -// String players = jedis0.hget(roomKey, "players"); -// -// if (!players.equals("[]")) { -// players = players.substring(1, players.length() - 1); -// playerIds = players.split(","); -// -// for (String pyids : playerIds) { -// -// if (Integer.parseInt(pyids) == playerId) { -// jedis0.del(roomId); -// } -// } -// } -// } -// } - - - } else if ("825".equalsIgnoreCase(command)) { - ITObject params = TObject.newInstance(); - params.putInt("qi", 0); - params.putInt("id", 1); - client.send("612", params, response -> { - - }); - } else if ("822".equalsIgnoreCase(command)) { - ITObject params = TObject.newInstance(); - //params.putInt("qi", 0); - params.putInt("id", 1); - //[TCP->822] data:{"tip_list":[{"type":8,"id":1,"opcard":[],"weight":8,"card":0}],"types":[{"type":21,"value":1}]} - //板胡Event [TCP->823] data:{"type":8,"seat":1,"data":[{"opcard":[204,204,204,108,108,108],"type":21,"value":1}]} - - client.send("612", params, response -> { - - }); - } else if ("835".equalsIgnoreCase(command)) { //听牌天听 - ITObject params = TObject.newInstance(); - params.putInt("qi", 0); - params.putInt("id", 1); - client.send("612", params, response -> { - - }); - - } - - - //END 长沙麻将 - } - } - } - }); - // 添加连接状态监听器 - client.addEventListener(TaurusClient.NetClientEvent.Connect, new - - IEventListener() { - @Override - public void handleEvent(Event event) { - SocketCode code = (SocketCode) event.getParameter("code"); - if (code == SocketCode.Connect) { - - } else { - } - } - }); - - - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - System.err.println("创建过程被中断"); - break; - } catch (Exception e) { - System.err.println("创建房间时出错: " + e.getMessage()); - } - } - - createdRooms.put(playId, roomsForPlay); - jedis2.close(); - jedis11.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { jedis0.close(); } - return createdRooms; } - /** - * 线程休眠方法 - * - * @param time 休眠时间(毫秒) - */ - public static void sleepTime(int time) { - try { - // 添加延迟 - Thread.sleep(time); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - /** - * 加入房间方法 - * - * @return - */ - public String joinRoom(int playerId) { - try { - // 添加2秒延迟 - Thread.sleep(5000); - - ITObject params = TObject.newInstance(); - params.putString("session", session + "," + token); - - client.send("1002", params, response -> { - ITObject obj = response.messageData.param.getTObject("tableInfo"); - }); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return null; - } - - - - - /** - * 准备方法 - * - * @return - */ - public String ready() { - try { - // 添加1秒延迟 - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } -// cardInhand = new ArrayList(); -// HuNanHongZhong.hongZhongCardInhand(); -// HuNanFangPaoFa.fangPaoFaCardInhand(); - - ITObject params = TObject.newInstance(); - params.putString("session", session + "," + token); - - client.send("1003", params, new ICallback() { - - @Override - public void action(MessageResponse messageResponse) { - - - } - }); - return null; - } - //统计 玩法里 等待中的次数 // 方法1:返回 Map<圈子ID, Map<玩法ID, 房间需求>> public Map> analyzeAndMarkRoomsWithCircle( @@ -1106,29 +139,6 @@ public class AddRoomRobot { return circlePlayRoomMap; } - //获取为0的value - public static List getKeysWithValueZero(Map robotData) { - List result = new ArrayList<>(); - - for (Map.Entry entry : robotData.entrySet()) { - if ("0".equals(entry.getValue())) { - result.add(entry.getKey()); - } - } - - return result; - } - - //随机分配机器人 - public String getRandomKeyFromList(List zeroValueKeys) { - if (zeroValueKeys == null || zeroValueKeys.isEmpty()) { - return null; - } - - Random random = new Random(); - int randomIndex = random.nextInt(zeroValueKeys.size()); - return zeroValueKeys.get(randomIndex); - } // 统计每个玩法的机器人总数 public Map>> getPlayDetails(Jedis jedis, @@ -1285,4 +295,25 @@ public class AddRoomRobot { jedis2.close(); return availableRobots; } + + public void joinzhenrenRoom() { + Jedis jedis0 = Redis.use().getJedis(); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis2 = Redis.use("group1_db2").getJedis(); + try { + //获取所有房间 + Set roomIds = jedis0.keys("room:*"); + for (String id : roomIds) { + jiqiren jiqiren = new jiqiren(); + jiqiren.tcp_jiqirenzhenren(id); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + jedis0.close(); + jedis11.close(); + jedis2.close(); + } + + } } diff --git a/libs/robot_common/src/main/java/taurus/newRobot/jiqiren.java b/libs/robot_common/src/main/java/taurus/newRobot/jiqiren.java new file mode 100644 index 0000000..fab9b84 --- /dev/null +++ b/libs/robot_common/src/main/java/taurus/newRobot/jiqiren.java @@ -0,0 +1,609 @@ +package taurus.newRobot; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.events.Event; +import com.taurus.core.events.IEventListener; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.ICallback; +import com.taurus.core.util.StringUtil; +import hunan.HuNanChangSha; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Pipeline; +import redis.clients.jedis.Response; +import taurus.client.Message; +import taurus.client.MessageResponse; +import taurus.client.SocketCode; +import taurus.client.TaurusClient; +import taurus.client.business.AccountBusiness; +import taurus.client.business.GroupRoomBusiness; +import taurus.util.ChangShaSuanFaTest; +import taurus.util.TinHuChi; + +import java.util.*; +import java.util.stream.Collectors; + +public class jiqiren { + + public String wanfaId = ""; + // 会话标识 + private String session = ""; + // 访问令牌 + public String token = ""; + + // 客户端连接对象 + private TaurusClient client = null; + + + private Map mapclient = new HashMap<>(); + + public TaurusClient getClient() { + return client; + } + + public void setClient(TaurusClient client) { + this.client = client; + } + + //进入真人房间 + public void tcp_jiqirenzhenren(String id) { + Jedis jedis0 = Redis.use().getJedis(); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis2 = Redis.use("group1_db2").getJedis(); + + String roomKey = ""; + String roomId = id.substring(id.indexOf(":") + 1); + roomKey = "room:" + roomId; + //玩法id + String gpid = jedis0.hget(roomKey, "gpid"); + //圈子id + String group = jedis0.hget(roomKey, "group"); + //获取玩法对应的机器人 g{330800}:play:10 + String playKey = "g{" + group + "}:play:" + gpid; + + + String players1 = jedis0.hget(roomKey, "players"); + + if (jedis11.hget(playKey, "leftover_robot") != null) { + //玩法配置的机器人数量 + String leftover_robot = jedis11.hget(playKey, "leftover_robot"); + //机器人主动找真人 + if (players1 != null && !players1.equals("[]")) { + List availableRobots1 = getAvailableRobots1(); + + String players = jedis0.hget(roomKey, "players"); + players = players.substring(1, players.length() - 1); + + String[] playerIds1 = players.split(","); + + String maxPlayers = jedis0.hget(roomKey, "maxPlayers"); + if (Integer.parseInt(maxPlayers) == 2) { + if (playerIds1.length == 1) { + //循环playerIds + for (int i = 0; i < playerIds1.length; i++) { + String playeid = playerIds1[i]; + if (!availableRobots1.contains(playeid) && Integer.parseInt(leftover_robot) > 0) { + Map stringStringMap = jedis2.hgetAll(playKey); + List zeroValueKeys = getKeysWithValueZero(stringStringMap); + System.out.println("值为0的机器人ID: " + zeroValueKeys); + String randomKeyFromList = getRandomKeyFromList(zeroValueKeys); + System.out.println("随机给的用户id----" + randomKeyFromList); + + + wanfaId = jedis0.hget(roomKey, "game"); + + if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将 + //client = new TaurusClient("8.138.242.190:6421", "game", TaurusClient.ConnectionProtocol.Tcp); + } + + if ("10".equalsIgnoreCase(wanfaId)) { + client = new TaurusClient("127.0.0.1:6311", "game", TaurusClient.ConnectionProtocol.Tcp); + //TaurusClient client1=getClient(); + client.connect(); + mapclient.put(randomKeyFromList, client); + } + if ("66".equalsIgnoreCase(wanfaId)) { + // client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp); + } + + ITObject object = null; + AccountBusiness accountBusiness = null; + accountBusiness = new AccountBusiness(); + // 登录获取session跟token + + if (jedis0.keys("{user}:" + randomKeyFromList + "_token").size() != 0) { + + Set keys1 = jedis0.keys("{user}:" + randomKeyFromList + "_token"); + if (keys1 == null) { + try { + object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); + } catch (Exception e) { + e.printStackTrace(); + } + ITObject validate = TObject.newInstance(); + validate.putString("token", object.getString("token")); + token = object.getString("token"); + session = accountBusiness.getSession(); + } else { + Set keys = jedis0.smembers("{user}:" + randomKeyFromList + "_token"); + List keyList = new ArrayList<>(keys); + session = "{user}:" + randomKeyFromList; + token = keyList.get(0); + + } + } else { + + try { + object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); + } catch (Exception e) { + e.printStackTrace(); + } + ITObject validate = TObject.newInstance(); + validate.putString("token", object.getString("token")); + token = object.getString("token"); + session = accountBusiness.getSession(); + } + + + String roomKey1 = "room:" + roomId; + + try { + ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(group), roomKey1, session, null); + } catch (Exception e) { + e.printStackTrace(); + } + joinRoom(Integer.parseInt(randomKeyFromList)); //进入房间 + + + jedis2.hset(playKey, randomKeyFromList, "1"); + String robortInfoKey = "{robortInfo}:" + randomKeyFromList; + jedis2.hset(robortInfoKey, "circleId", group); + jedis2.hset(robortInfoKey, "pid", gpid); + jedis2.hset(robortInfoKey, "room_id", roomId); + ready(); //准备 + + jedis11.hincrBy(playKey, "leftover_robot", -1); + lianjiejiqiren lianjiejiqiren = new lianjiejiqiren(); + lianjiejiqiren.token = token; + lianjiejiqiren.session = session; + lianjiejiqiren.lianjie(client, wanfaId, mapclient); + } + } + } + } + } + } + + + System.out.println(roomKey); + } + + + //进入中括号的房间 + public void tcp_jiqirezhongkouhao(String id) { + Jedis jedis0 = Redis.use().getJedis(); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis2 = Redis.use("group1_db2").getJedis(); + String roomKey = ""; + String roomId = id.substring(id.indexOf(":") + 1); + roomKey = "room:" + roomId; + //玩法id + String gpid = jedis0.hget(roomKey, "gpid"); + //圈子id + String group = jedis0.hget(roomKey, "group"); + //获取玩法对应的机器人 g{330800}:play:10 + String playKey = "g{" + group + "}:play:" + gpid; + String players1 = jedis0.hget(roomKey, "players"); + + if (jedis11.hget(playKey, "leftover_robot") != null && players1 != null) { + //玩法配置的机器人数量 + String leftover_robot = jedis11.hget(playKey, "leftover_robot"); + //机器人进入退出的房间 + if (players1.equals("[]")) { + String maxPlayers = jedis0.hget(roomKey, "maxPlayers"); + if (Integer.parseInt(maxPlayers) == 2) { + + if (Integer.parseInt(leftover_robot) > 0) { + int count = countValuesEqualToOne(jedis2, playKey); + System.out.println("count 数量 +++++++++++++++++++++" + count); + if (count < 2) { + Map stringStringMap = jedis2.hgetAll(playKey); + List zeroValueKeys = getKeysWithValueZero(stringStringMap); + System.out.println("值为0的机器人ID: " + zeroValueKeys); + String randomKeyFromList = getRandomKeyFromList(zeroValueKeys); + System.out.println("随机给的用户id----" + randomKeyFromList); + + wanfaId = jedis0.hget(roomKey, "game"); + + if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将 +// client = new TaurusClient("8.138.242.190:6421", "game", TaurusClient.ConnectionProtocol.Tcp); + } + if ("10".equalsIgnoreCase(wanfaId)) { + client = new TaurusClient("127.0.0.1:6311", "game", TaurusClient.ConnectionProtocol.Tcp); + client.connect(); + mapclient.put(randomKeyFromList, client); + } + if ("66".equalsIgnoreCase(wanfaId)) { +// client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp); + } + + ITObject object = null; + AccountBusiness accountBusiness = null; + accountBusiness = new AccountBusiness(); + // 登录获取session跟token + + if (jedis0.keys("{user}:" + randomKeyFromList + "_token").size() != 0) { + + Set keys1 = jedis0.keys("{user}:" + randomKeyFromList + "_token"); + if (keys1 == null) { + try { + object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); + } catch (Exception e) { + e.printStackTrace(); + } + ITObject validate = TObject.newInstance(); + validate.putString("token", object.getString("token")); + token = object.getString("token"); + session = accountBusiness.getSession(); + } else { + Set keys = jedis0.smembers("{user}:" + randomKeyFromList + "_token"); + List keyList = new ArrayList<>(keys); + session = "{user}:" + randomKeyFromList; + token = keyList.get(0); + + } + } else { + + try { + object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); + } catch (Exception e) { + e.printStackTrace(); + } + ITObject validate = TObject.newInstance(); + validate.putString("token", object.getString("token")); + token = object.getString("token"); + session = accountBusiness.getSession(); + } + + + String roomKey1 = "room:" + roomId; + + try { + ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(group), roomKey1, session, null); + } catch (Exception e) { + e.printStackTrace(); + } + joinRoom(Integer.parseInt(randomKeyFromList)); //进入房间 + + + jedis2.hset(playKey, randomKeyFromList, "1"); + String robortInfoKey = "{robortInfo}:" + randomKeyFromList; + jedis2.hset(robortInfoKey, "circleId", group); + jedis2.hset(robortInfoKey, "pid", gpid); + jedis2.hset(robortInfoKey, "room_id", roomId); + ready(); //准备 + + jedis11.hincrBy(playKey, "leftover_robot", -1); + lianjiejiqiren lianjiejiqiren = new lianjiejiqiren(); + lianjiejiqiren.token = token; + lianjiejiqiren.session = session; + lianjiejiqiren.lianjie(client, wanfaId, mapclient); + } + + } + + + } + } + } + + jedis0.close(); + jedis2.close(); + jedis11.close(); + + } + + + //创建房间,进入房间 + public void createRoomsForCircle(String circleId, Map playRoomMap) { + Jedis jedis2 = Redis.use("group1_db2").getJedis(); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis0 = Redis.use().getJedis(); + // 按玩法ID排序处理 + List> sortedPlays = playRoomMap.entrySet().stream() + .sorted(Map.Entry.comparingByKey()) + .collect(Collectors.toList()); + + for (Map.Entry entry : sortedPlays) { + String playId = entry.getKey(); + int requiredRooms = entry.getValue(); + + if (requiredRooms <= 0) { + System.out.println("玩法 " + playId + ": 跳过创建 (需求数=" + requiredRooms + ")"); + continue; + } + + boolean isPlaying = true; + //获取所有房间 + Set roomIds = jedis0.keys("room:*"); + for (String id : roomIds) { + String roomId = id.substring(id.indexOf(":") + 1); + String roomKey = "room:" + roomId; + String players = jedis0.hget(roomKey, "players"); + if (players != null) { + if (players.equals("[]")) { + isPlaying = false; + } + } + } + + + System.out.println("玩法 " + playId + ": 创建 " + requiredRooms + " 个房间"); + + List roomsForPlay = new ArrayList<>(); + + for (int i = 1; i <= requiredRooms; i++) { + try { + String keys = "g{" + circleId + "}:play:" + playId; + if (jedis11.hget(keys, "leftover_robot") != null && isPlaying) { + String leftover_robot = jedis11.hget(keys, "leftover_robot"); + if (Integer.parseInt(leftover_robot) > 0) { + Map stringStringMap = jedis2.hgetAll(keys); + + + List zeroValueKeys = getKeysWithValueZero(stringStringMap); + System.out.println("值为0的机器人ID: " + zeroValueKeys); + String randomKeyFromList = getRandomKeyFromList(zeroValueKeys); + System.out.println("随机给的用户id----" + randomKeyFromList); + + jedis2.hset(keys, randomKeyFromList, "1"); + + ITObject object = null; + AccountBusiness accountBusiness = null; + accountBusiness = new AccountBusiness(); + + // 登录获取session跟token + if (jedis0.keys("{user}:" + randomKeyFromList + "_token").size() != 0) { + Set keys1 = jedis0.keys("{user}:" + randomKeyFromList + "_token"); + if (keys1 == null) { + object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); + ITObject validate = TObject.newInstance(); + validate.putString("token", object.getString("token")); + token = object.getString("token"); + session = accountBusiness.getSession(); + } else { + Set keys2 = jedis0.smembers("{user}:" + randomKeyFromList + "_token"); + List keyList = new ArrayList<>(keys2); + session = "{user}:" + randomKeyFromList; + token = keyList.get(0); + } + } else { + object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456"); + ITObject validate = TObject.newInstance(); + validate.putString("token", object.getString("token")); + token = object.getString("token"); + session = accountBusiness.getSession(); + } + + + // 调用原有的房间匹配逻辑 + Object room = GroupRoomBusiness.matchRoom(Integer.parseInt(circleId), Integer.parseInt(playId), session, "Android", false); + String game = jedis0.hget(String.valueOf(room), "game"); + wanfaId = String.valueOf(game); + String roomKey = String.valueOf(room); + System.out.println("roomkey--------" + roomKey); + + client = null; + + System.out.println("wanfaId" + wanfaId); + + + if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将 + client = new TaurusClient("8.138.242.190:6421", "game", TaurusClient.ConnectionProtocol.Tcp); + } + + if ("10".equalsIgnoreCase(wanfaId)) { + client = new TaurusClient("127.0.0.1:6311", "game", TaurusClient.ConnectionProtocol.Tcp); +// client.setSession(session); + client.connect(); + mapclient.put(randomKeyFromList, client); + } + System.out.println("clinet 111 " + client); + + if ("66".equalsIgnoreCase(wanfaId)) { + client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp); + } + + System.out.println("id ++++++" + mapclient); + System.out.println("mapclient----" + mapclient); + ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(circleId), roomKey, this.session, null); + String roomId = roomInfos.getString("room_id"); + String robort = "{robortInfo}:" + randomKeyFromList; + jedis2.hset(robort, "room_id", roomId); + jedis2.hset(robort, "circleId", circleId); + jedis2.hset(robort, "pid", playId); + + + joinRoom(Integer.parseInt(randomKeyFromList)); //进入房间 + + + String playKey1 = "g{" + circleId + "}:play:" + playId; + + jedis11.hincrBy(playKey1, "leftover_robot", -1); + + lianjiejiqiren lianjiejiqiren = new lianjiejiqiren(); + lianjiejiqiren.token = token; + lianjiejiqiren.session = session; + lianjiejiqiren.lianjie(client, wanfaId, mapclient); + ready(); //准备 + + if (room != null) { + roomsForPlay.add(room); + System.out.println(" 第 " + i + " 个房间创建成功"); + } else { + System.out.println(" 第 " + i + " 个房间创建失败"); + } + } + + } + + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + System.err.println("创建过程被中断"); + break; + } catch (Exception e) { + System.err.println("创建房间时出错: " + e.getMessage()); + } + } + jedis2.close(); + jedis11.close(); + jedis0.close(); + } + } + + + /** + * 统计Hash中值为"1"的字段数量 + */ + public static int countValuesEqualToOne(Jedis jedis, String key) { + int count = 0; + + Map hashData = jedis.hgetAll(key); + + for (Map.Entry entry : hashData.entrySet()) { + if ("1".equals(entry.getValue())) { + count++; + System.out.println("找到字段: " + entry.getKey() + " = " + entry.getValue()); + } + } + + return count; + } + + + //获取所有机器人 + public List getAvailableRobots1() { + Jedis jedis2 = Redis.use("group1_db2").getJedis(); + + Set allRobotKeys = jedis2.keys("{robot}:*"); + List availableRobots = new ArrayList<>(); + + // 使用Pipeline提高效率 + Pipeline pipeline = jedis2.pipelined(); + List> responses = new ArrayList<>(); + + for (String robotKey : allRobotKeys) { + responses.add(pipeline.hget(robotKey, "start")); + } + + pipeline.sync(); + + // 提取机器人ID并筛选 + int index = 0; + for (String robotKey : allRobotKeys) { + String startStatus = responses.get(index).get(); + + String robotId = robotKey.substring(robotKey.indexOf(":") + 1); + availableRobots.add(robotId); + index++; + } + jedis2.close(); + return availableRobots; + } + + + //获取状态为0的机器人 + public static List getKeysWithValueZero(Map robotData) { + List result = new ArrayList<>(); + + for (Map.Entry entry : robotData.entrySet()) { + if ("0".equals(entry.getValue())) { + result.add(entry.getKey()); + } + } + + return result; + } + + + //随机分配机器人 + public String getRandomKeyFromList(List zeroValueKeys) { + if (zeroValueKeys == null || zeroValueKeys.isEmpty()) { + return null; + } + + Random random = new Random(); + int randomIndex = random.nextInt(zeroValueKeys.size()); + return zeroValueKeys.get(randomIndex); + } + + //监听 + + + /** + * 加入房间方法 + * + * @return + */ + public String joinRoom(int playerId) { + try { + // 添加2秒延迟 + Thread.sleep(5000); + + ITObject params = TObject.newInstance(); + params.putString("session", session + "," + token); + + client.send("1002", params, response -> { + ITObject obj = response.messageData.param.getTObject("tableInfo"); + }); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 线程休眠方法 + * + * @param time 休眠时间(毫秒) + */ + public static void sleepTime(int time) { + try { + // 添加延迟 + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /** + * 准备方法 + * + * @return + */ + public String ready() { + try { + // 添加1秒延迟 + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + + ITObject params = TObject.newInstance(); + params.putString("session", session + "," + token); + + client.send("1003", params, new ICallback() { + + @Override + public void action(MessageResponse messageResponse) { + + + } + }); + return null; + } + + +} diff --git a/libs/robot_common/src/main/java/taurus/newRobot/lianjiejiqiren.java b/libs/robot_common/src/main/java/taurus/newRobot/lianjiejiqiren.java new file mode 100644 index 0000000..c02ef5b --- /dev/null +++ b/libs/robot_common/src/main/java/taurus/newRobot/lianjiejiqiren.java @@ -0,0 +1,852 @@ + +package taurus.newRobot; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.events.Event; +import com.taurus.core.events.IEventListener; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.ICallback; +import com.taurus.core.util.StringUtil; +import hunan.HuNanChangSha; +import redis.clients.jedis.Jedis; +import taurus.client.Message; +import taurus.client.MessageResponse; +import taurus.client.SocketCode; +import taurus.client.TaurusClient; +import taurus.util.ChangShaSuanFaTest; +import taurus.util.TinHuChi; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class lianjiejiqiren { + + // 会话标识 + public String session = ""; + // 访问令牌 + public String token = ""; + + private HuNanChangSha huNanChangSha = new HuNanChangSha(); + + private Map> playerOutcardsMap = new HashMap<>(); + + private Map> playerchisMap = new HashMap<>(); + + private Map> playerpengsMap = new HashMap<>(); + + private Map> playermingsMap = new HashMap<>(); + + private Map> playerzisMap = new HashMap<>(); + + + public void lianjie(TaurusClient client, String wanfaId, Map mapclient) { + // 添加事件监听器处理网络消息 + client.addEventListener(TaurusClient.NetClientEvent.OnEvent, new IEventListener() { + @Override + public void handleEvent(Event event) { + + // 获取 msg + Message message = (Message) event.getParameter("msg"); + if (message == null) { + return; + } + + ITObject param = message.param; + //回调协议号 + String command = message.command; + + //根据玩法id 调用不同的回调 + if (StringUtil.isNotEmpty(command)) { + if ("66".equalsIgnoreCase(wanfaId)) {//跑的快 +// if ("2011".equalsIgnoreCase(command)) { //跑的快 初始化手牌 +// huNanPaoDeKuai.paoDeKuaiCardInHead(param, client); +// } else if ("2021".equalsIgnoreCase(command)) { //出牌广播 +// huNanPaoDeKuai.paoDekuaiChupaiGuangBo(param); +// } else if ("2004".equalsIgnoreCase(command)) { //出牌提示事件,牌权 +// Integer player = param.getInt("player"); +// Integer seat1 = param.getInt("seat"); +// +// if (seat1 != null) { +// huNanPaoDeKuai.seat = seat1; +// } +// +// //出牌 +// huNanPaoDeKuai.outCard(client); +// } else if ("2007".equalsIgnoreCase(command)) { //结算准备 +// //type为1 为大结算 type为0为小结算 +// Integer type = param.getInt("type"); +// +// if (type == 0) { +// huNanPaoDeKuai.getSeatRemainHistory().clear(); +// huNanPaoDeKuai.getPaoDekuaiCardInhand().clear(); +// ITArray card_list = huNanPaoDeKuai.getCard_list().getTArray("card_list"); +// card_list.clear(); +// ready(); +// } +// +// if (type == 1) { +// Jedis jedis11s = Redis.use("group1_db11").getJedis(); +// try { +// String key = "g{" + groupId + "}:play:" + pid; +// jedis11s.hincrBy(key, "leftover_robot", 1); +// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); +// try { +// DataBase.use().executeUpdate(sql); +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// jedis11s.close(); +// } +// } +// +// } else if ("2009".equalsIgnoreCase(command)) { +// Jedis jedis21 = Redis.use().getJedis(); +// sleepTime(3000); +// +// ITObject params = TObject.newInstance(); +// String[] playerIds2 = null; +// +// +// Set roomIds = jedis21.keys("room:*"); +// String roomKey = ""; +// //拿到所有的机器人 +// List robotIdsList = new ArrayList<>(); +// String sql2 = "SELECT id FROM `account` WHERE jiqiren=9998"; +// ITArray robotId2 = null; +// try { +// robotId2 = DataBase.use().executeQueryByTArray(sql2); +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// for (int j = 0; j < Objects.requireNonNull(robotId2).size(); j++) { +// robotIdsList.add(robotId2.getTObject(j).getInt("id")); +// } +// +// +// for (String roomId : roomIds) { +// String roomId1 = roomId.substring(roomId.indexOf(":") + 1); +// roomKey = "room:" + roomId1; +// +// if (jedis21.hget(roomKey, "players") != null) { +// String players = jedis21.hget(roomKey, "players"); +// if (!players.equals("[]")) { +// players = players.substring(1, players.length() - 1); +// playerIds2 = players.split(","); +// +// +// if (playerIds2.length == 1) { +// for (String s : playerIds2) { +// if (robotIdsList.contains(Integer.parseInt(s))) { //房间里的人是机器人 +// String gpid = jedis21.hget(roomKey, "gpid"); +// String gpId = jedis21.hget(roomKey, "group"); +// String key = "g{" + gpId + "}:play:" + gpid; +// if (!players.equals("[]") && pid == Integer.parseInt(gpid)) { +// +// +// if (JiQiRens.count != null && JiQiRens.count.containsKey(Integer.parseInt(gpid))) { +// Integer currentValue = JiQiRens.count.get(Integer.parseInt(gpid)); +// if (currentValue > 0) { +// JiQiRens.count.put(Integer.parseInt(gpid), currentValue - 1); +// } +// } +// +// +// Jedis jedis20 = Redis.use("group1_db11").getJedis(); +// +// jedis20.hincrBy(key, "leftover_robot", 1); +// jedis20.close(); +// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, Integer.parseInt(s)); +// +// try { +// DataBase.use().executeUpdate(sql); +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// +// client.send("1005", params, response -> { +// +// }); +// +// } +// } +// } +// } +// } +// } +// } +// +// jedis21.close(); +// +// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 +// Set roomIds = scanRooms(jedis0, "room:*"); +// String[] playerIds = null; +// for (String roomId : roomIds) { +// String rid = roomId.substring(roomId.indexOf(":") + 1); +// String roomKey = "room:" + rid; +// if (jedis0.hget(roomKey, "players") != null) { +// String players = jedis0.hget(roomKey, "players"); +// if (!players.equals("[]")) { +// players = players.substring(1, players.length() - 1); +// playerIds = players.split(","); +// for (String pyids : playerIds) { +// if (Integer.parseInt(pyids) == playerId) { +// jedis0.del(roomId); +// } +// } +// } +// } +// } +// } else if ("2031".equalsIgnoreCase(command)) { +// ITObject params = TObject.newInstance(); +// params.putInt("id", 0); +// client.send("1015", params, response -> { +// +// }); +// +// } +// } else if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将 +// +// if ("812".equalsIgnoreCase(command)) { //出牌广播 +// HuNanHongZhong.drawCard(command, message); +// } else if ("811".equalsIgnoreCase(command)) {//初始化手牌 +// huNanHongZhong.cardInHead(command, message, client); +// } else if ("819".equalsIgnoreCase(command)) { //摸牌 +// huNanHongZhong.getCard(command, message); +// } else if ("813".equalsIgnoreCase(command)) { //出牌,牌权 +// huNanHongZhong.outCard(client); +// } else if ("817".equalsIgnoreCase(command)) {//结算 +// huNanHongZhong.getHongZhongCardInhand().clear(); +// huNanHongZhong.getChuGuoCardInhand().clear(); +// +// Integer type = param.getInt("type"); +// if (type == 1 || type == 2) { //为1为大结算 为2为解散 +// Jedis jedis11s = Redis.use("group1_db11").getJedis(); +// try { +// String key = "g{" + groupId + "}:play:" + pid; +// jedis11s.hincrBy(key, "leftover_robot", 1); +//// +// if (count != null && count.containsKey(pid)) { +// Integer currentValue = count.get(pid); +// if (currentValue > 0) { +// count.put(pid, currentValue - 1); +// } +// } +// +// +// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); +// try { +// DataBase.use().executeUpdate(sql); +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// jedis11s.close(); +// } +// +// if (count != null && count.containsKey(pid)) { +// Integer value = count.get(pid); +// +// // 如果找到了对应的 pid +// String shangxianRobot = jedis11.hget(playKey, "shangxian_robot"); +// String leftoverRobot = jedis11.hget(playKey, "leftover_robot"); +// +// if (shangxianRobot != null && leftoverRobot != null) { +// if (value == 0) { +// jedis11.hset(playKey, "leftover_robot", shangxianRobot); +// } +// } +// } +// } +//// playerState.pongGroups.clear();; +//// playerState.handCards.clear(); +//// playerState.chiGroups.clear(); +//// playerState.gangGroups.clear();; +// +// +// ready(); +// } else if ("2009".equalsIgnoreCase(command)) { +// Jedis jedis21 = Redis.use().getJedis(); +// sleepTime(3000); +// ITObject params = TObject.newInstance(); +// String[] playerIds2 = null; +// +// +// Set roomIds = jedis21.keys("room:*"); +// String roomKey = ""; +// //拿到所有的机器人 +// List robotIdsList = new ArrayList<>(); +// String sql2 = "SELECT id FROM `account` WHERE jiqiren=9998"; +// ITArray robotId2 = null; +// try { +// robotId2 = DataBase.use().executeQueryByTArray(sql2); +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// for (int j = 0; j < Objects.requireNonNull(robotId2).size(); j++) { +// robotIdsList.add(robotId2.getTObject(j).getInt("id")); +// } +// +// +// for (String roomId : roomIds) { +// String roomId1 = roomId.substring(roomId.indexOf(":") + 1); +// roomKey = "room:" + roomId1; +// +// if (jedis21.hget(roomKey, "players") != null) { +// String players = jedis21.hget(roomKey, "players"); +// if (!players.equals("[]")) { +// players = players.substring(1, players.length() - 1); +// playerIds2 = players.split(","); +// +// +// if (playerIds2.length == 1) { +// for (String s : playerIds2) { +// if (robotIdsList.contains(Integer.parseInt(s))) { //房间里的人是机器人 +// String gpid = jedis21.hget(roomKey, "gpid"); +// String gpId = jedis21.hget(roomKey, "group"); +// String key = "g{" + gpId + "}:play:" + gpid; +// if (!players.equals("[]") && pid == Integer.parseInt(gpid)) { +// +// +// if (JiQiRens.count != null && JiQiRens.count.containsKey(Integer.parseInt(gpid))) { +// Integer currentValue = JiQiRens.count.get(Integer.parseInt(gpid)); +// if (currentValue > 0) { +// JiQiRens.count.put(Integer.parseInt(gpid), currentValue - 1); +// } +// } +// +// +// Jedis jedis20 = Redis.use("group1_db11").getJedis(); +// +// jedis20.hincrBy(key, "leftover_robot", 1); +// jedis20.close(); +// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, Integer.parseInt(s)); +// +// try { +// DataBase.use().executeUpdate(sql); +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// +// client.send("1005", params, response -> { +// +// }); +// +// } +// } +// } +// } +// } +// } +// } +// +// jedis21.close(); +// +// } else if ("814".equalsIgnoreCase(command)) {//杠碰胡通知协议 +//// sleepTime(2000); +// huNanHongZhong.actionCard(param, client); +// } else if ("820".equalsIgnoreCase(command)) { +// HuNanHongZhong.changePlayer(command, message); +// } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作 +// huNanHongZhong.shanchuchuguopai(param); +// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 +//// Jedis jedis11s = Redis.use("group1_db11").getJedis(); +//// try { +//// String key = "g{" + groupId + "}:play:" + pid; +//// jedis11s.hincrBy(key, "leftover_robot", 1); +//// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); +//// DataBase.use().executeUpdate(sql); +// Set roomIds = scanRooms(jedis0, "room:*"); +// String[] playerIds = null; +// for (String roomId : roomIds) { +// String rid = roomId.substring(roomId.indexOf(":") + 1); +// String roomKey = "room:" + rid; +// if (jedis0.hget(roomKey, "players") != null) { +// String players = jedis0.hget(roomKey, "players"); +// if (!players.equals("[]")) { +// players = players.substring(1, players.length() - 1); +// playerIds = players.split(","); +// for (String pyids : playerIds) { +// if (Integer.parseInt(pyids) == playerId) { +// jedis0.del(roomId); +// } +// } +// } +// } +// } +// +// } + } else if ("17".equalsIgnoreCase(wanfaId)) { //字牌放炮罚 + +// if ("811".equalsIgnoreCase(command)) { //初始化手牌 +// huNanFangPaoFa.cardInHead(command, message, client); +// +// } else if ("819".equalsIgnoreCase(command)) { //摸牌 +// huNanFangPaoFa.getCard(command, message); +// } else if ("813".equalsIgnoreCase(command)) { //出牌 牌权 +// sleepTime(1500); +// huNanFangPaoFa.outCard(client); +// } else if ("812".equalsIgnoreCase(command)) { //出牌广播 +// HuNanFangPaoFa.drawCard(command, message); +// } else if ("814".equalsIgnoreCase(command)) { //可执行的 操作 吃碰 偎提胡 +// huNanFangPaoFa.actionCard(param, client); +// } else if ("817".equalsIgnoreCase(command)) { //结算 +// huNanFangPaoFa.getFangPaoFaCardInhand().clear(); +// ready(); +// } else if ("822".equalsIgnoreCase(command)) { //放跑提示 +// +// HuNanFangPaoFa.fangPaoTipEvent(message, client); +// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 +// try { +// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); +// DataBase.use().executeUpdate(sql); +// +// } catch (SQLException e) { +// +// } +// } + } else if ("108".equalsIgnoreCase(wanfaId)) {//转转麻将 +// if ("811".equalsIgnoreCase(command)) {//初始化收手牌 +// huNanZhuanZhuan.cardInHead(command, message, client); +// } else if ("812".equalsIgnoreCase(command)) {//出牌广播 +// HuNanZhuanZhuan.drawCard(command, message); +// } else if ("819".equalsIgnoreCase(command)) {//摸牌 +// +// huNanZhuanZhuan.getCard(command, message); +// } else if ("813".equalsIgnoreCase(command)) {//出牌提示 +//// sleepTime(1500); +// huNanZhuanZhuan.outCard(client); +// } else if ("814".equalsIgnoreCase(command)) {//放招提示 +// huNanZhuanZhuan.actionCard(param, client); +// } else if ("817".equalsIgnoreCase(command)) {//结算 +// huNanZhuanZhuan.getZhuanZhuanCardInhand().clear(); +// huNanZhuanZhuan.getZhuanZhuanchuguopai().clear(); +// ready(); +// } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作 +// huNanZhuanZhuan.shanchuchuguopai(param); +// } else if ("820".equalsIgnoreCase(command)) {//换牌提示 +// HuNanZhuanZhuan.changePlayer(command, message); +// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 +// try { +// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId); +// DataBase.use().executeUpdate(sql); +// } catch (SQLException e) { +// +// } +// } + } else if ("10".equalsIgnoreCase(wanfaId)) { + //长沙麻将 机器人处理事件 + if ("811".equalsIgnoreCase(command)) {//初始化收手牌 +// System.out.println("初始化手牌" + session); + Jedis jedis222 = Redis.use("group1_db2").getJedis(); + for (Map.Entry entry : mapclient.entrySet()) { + System.out.println("mapclient++++++++++++++++++++++++++++++++"+mapclient); + System.out.println("client++++++++++++++++++++++++++++++++++"+client); + TaurusClient taurusClient = (TaurusClient) entry.getValue(); + if (client.getId() == taurusClient.getId()) { + String key = entry.getKey(); + System.out.println("key+++++++++++++++++++++++++++++++++++" + key); + if (jedis222.hget("{robortInfo}:" + key, "circleId") != null && jedis222.hget("{robortInfo}:" + key, "pid") != null) { + String circleId = jedis222.hget("{robortInfo}:" + key, "circleId"); + System.out.println("circleId +++++++++++++++++++++++++"+circleId); + String pid = jedis222.hget("{robortInfo}:" + key, "pid"); + System.out.println("pid +++++++++++++++++++++++++"+pid); + String getStart = "g{" + circleId + "}:play:" + pid; + if (!pid.equals("0")){ + jedis222.hset(getStart, key, "2"); + } + } + } + } + jedis222.close(); + huNanChangSha.cardInHead(command, message, client); + System.out.println("client " + client); + } else if ("812".equalsIgnoreCase(command)) {//出牌广播 + //{"opzicards":[{"opzicards":[],"playerId":101555}],"opmingcards":[{"opmingcards":[],"playerId":101555}],"outcard_map":[{"outcards":[209,205],"playerId":101555},{"outcards":[],"playerId":112233}],"card":205,"opchicards":[{"opchicards":[105,103],"playerId":101555}],"oppengcards":[{"oppengcards":[],"playerId":101555}],"seat":1} + ITArray outcard_map = param.getTArray("outcard_map"); + ITArray opchicards = param.getTArray("opchicards"); + ITArray oppengcards = param.getTArray("oppengcards"); + ITArray opmingcards = param.getTArray("opmingcards"); + ITArray opzicards = param.getTArray("opzicards"); + + // 清空旧数据,用新数据完全覆盖 + playerOutcardsMap.clear(); + playerchisMap.clear(); + playerpengsMap.clear(); + playermingsMap.clear(); + playerzisMap.clear(); + //出过的牌 + if (outcard_map != null) { + for (int i = 0; i < outcard_map.size(); i++) { + ITObject playerData = outcard_map.getTObject(i); + int playerId = playerData.getInt("playerId"); + ITArray outcardsArray = playerData.getTArray("outcards"); + + // 转换为List + List outcardsList = new ArrayList<>(); + for (int j = 0; j < outcardsArray.size(); j++) { + outcardsList.add(outcardsArray.getInt(j)); + } + + // 存储到Map中(覆盖旧数据) + playerOutcardsMap.put(playerId, outcardsList); + + } + } + + //吃的牌 + if (opchicards != null) { + for (int i = 0; i < opchicards.size(); i++) { + ITObject playerData = opchicards.getTObject(i); + int playerId = playerData.getInt("playerId"); + ITArray outchiArray = playerData.getTArray("opchicards"); + + List outchiList = new ArrayList<>(); + for (int j = 0; j < outchiArray.size(); j++) { + outchiList.add(outchiArray.getInt(j)); + } + playerchisMap.put(playerId, outchiList); + } + } + + //碰的牌 + if (oppengcards != null) { + for (int i = 0; i < oppengcards.size(); i++) { + ITObject playerData = oppengcards.getTObject(i); + int playerId = playerData.getInt("playerId"); + ITArray outpengArray = playerData.getTArray("oppengcards"); + + List outpengList = new ArrayList<>(); + for (int j = 0; j < outpengArray.size(); j++) { + outpengList.add(outpengArray.getInt(j)); + } + playerpengsMap.put(playerId, outpengList); + } + } + + //明杠的牌 + if (opmingcards != null) { + for (int i = 0; i < opmingcards.size(); i++) { + ITObject playerData = opmingcards.getTObject(i); + int playerId = playerData.getInt("playerId"); + ITArray outmingArray = playerData.getTArray("opmingcards"); + + List outmingList = new ArrayList<>(); + for (int j = 0; j < outmingArray.size(); j++) { + outmingList.add(outmingArray.getInt(j)); + } + playermingsMap.put(playerId, outmingList); + } + } + + //暗杠的牌 + if (opzicards != null) { + for (int i = 0; i < opzicards.size(); i++) { + ITObject playerData = opzicards.getTObject(i); + int playerId = playerData.getInt("playerId"); + ITArray outziArray = playerData.getTArray("opzicards"); + + List outziList = new ArrayList<>(); + for (int j = 0; j < outziArray.size(); j++) { + outziList.add(outziArray.getInt(j)); + } + playerzisMap.put(playerId, outziList); + } + } + + HuNanChangSha.drawCard(command, message); + } else if ("819".equalsIgnoreCase(command)) { + for (Map.Entry entry : mapclient.entrySet()) { + TaurusClient taurusClient = (TaurusClient) entry.getValue(); + if (client == taurusClient) { + //摸牌 + huNanChangSha.getCard(command, message, taurusClient,mapclient); + } + } + + } else if ("813".equalsIgnoreCase(command)) {//出牌提示 + System.out.println("出牌提示 ++++++++++++++++++++++++++++++++"); + System.out.println("mapclient ++++++++++++++++" + mapclient); + + System.out.println("进入出牌11111111111111112222222"); + System.out.println("client4444444444444444" + client); + huNanChangSha.outCard(client, playerOutcardsMap, playerchisMap, playerpengsMap, playermingsMap, playerzisMap); + + + } else if ("814".equalsIgnoreCase(command)) { + //吃碰杠 + huNanChangSha.actionCard(param, client); + + } else if ("2009".equalsIgnoreCase(command)) { + //db0 + Jedis jedis22 = Redis.use().getJedis(); + //db2 + Jedis jedis33 = Redis.use("group1_db2").getJedis(); + + Jedis jedis = Redis.use("group1_db0").getJedis(); + Integer aid = param.getInt("aid"); + String getKey = "{robortInfo}:" + aid; + + + System.out.println("param ++++++++++++++++ " + param); + + ITObject params = TObject.newInstance(); + + String[] playerIds2 = null; + + if (jedis33.hget(getKey, "pid") != null) { + String circleId1 = jedis33.hget(getKey, "circleId"); + String pid = jedis33.hget(getKey, "pid"); + + String key = "g{" + circleId1 + "}:play:" + pid; + if (jedis33.hget(getKey, "room_id") != null) { + String roomid = jedis33.hget(getKey, "room_id"); + + String roomKey = "room:" + roomid; + + if (jedis22.hget(roomKey, "players") != null) { + String players = jedis22.hget(roomKey, "players"); + if (!players.equals("[]")) { + players = players.substring(1, players.length() - 1); + playerIds2 = players.split(","); + if (playerIds2.length == 1) { + if (!pid.equals("0")) { + Jedis jedis20 = Redis.use("group1_db11").getJedis(); + System.out.println("进入 -------------------------"); + jedis20.hincrBy(key, "leftover_robot", 1); + jedis20.close(); + System.out.println("mapclient--------------" + mapclient); + + String room_id = jedis33.hget(getKey, "room_id"); + + for (Map.Entry entry : mapclient.entrySet()) { + String key1 = entry.getKey(); + if (Integer.parseInt(key1) == aid) { + // 获取指定field的值 + String value = jedis33.hget(key, String.valueOf(aid)); + if (!value.equals("2")) { + sleepTime(4000); + jedis33.hset(getKey, "circleId", "0"); + jedis33.hset(getKey, "pid", "0"); + jedis33.hset(getKey, "room_id", "0"); + //退出修改机器人状态 + jedis33.hset(key, String.valueOf(aid), "0"); + TaurusClient taurusClient = (TaurusClient) entry.getValue(); + taurusClient.send("1005", params, response -> { + }); + } + } + } + + } + } + } + + } + } + + jedis33.close(); + jedis22.close(); + jedis.close(); + } + } else if ("817".equalsIgnoreCase(command)) {//结算 + huNanChangSha.getChangShaCardInhand().clear(); + huNanChangSha.getChuGuoCardInhand().clear(); + huNanChangSha.getpongGroup().clear(); + huNanChangSha.getchowGroup().clear(); + TinHuChi.lastTingCount = 0; + TinHuChi.isMoreThanLast = false; + ChangShaSuanFaTest.isTin = false; + ChangShaSuanFaTest.isChi = false; + ChangShaSuanFaTest.isPeng = false; + ChangShaSuanFaTest.tinCards.clear(); + Integer type = param.getInt("type"); + if (type == 1 || type == 2) { //为1为大结算 为2为解散 + Jedis jedis11s = Redis.use("group1_db11").getJedis(); + try { + + //db2 + Jedis jedis21 = Redis.use("group1_db2").getJedis(); + try { + for (Map.Entry entry : mapclient.entrySet()) { + + TaurusClient taurusClient = (TaurusClient) entry.getValue(); + if (client == taurusClient) { + String key = entry.getKey(); + if (jedis21.hget("{robortInfo}:" + key, "circleId") != null && jedis21.hget("{robortInfo}:" + key, "pid") != null) { + String circleId = jedis21.hget("{robortInfo}:" + key, "circleId"); + String pid = jedis21.hget("{robortInfo}:" + key, "pid"); + String getStart = "g{" + circleId + "}:play:" + pid; + jedis21.hset(getStart, key, "0"); + + jedis11s.hincrBy(getStart, "leftover_robot", 1); + + jedis21.hset("{robortInfo}:" + key, "circleId", "0"); + jedis21.hset("{robortInfo}:" + key, "pid", "0"); + jedis21.hset("{robortInfo}:" + key, "room_id", "0"); + } + + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + jedis21.close(); + } + + + } catch (Exception e) { + e.printStackTrace(); + } finally { + jedis11s.close(); + } + +// if (count != null && count.containsKey(pid)) { +// Integer value = count.get(pid); +// +// // 如果找到了对应的 pid +// Jedis jedis12 = Redis.use("group1_db11").getJedis(); +// +// String shangxianRobot = jedis12.hget(playKey, "shangxian_robot"); +// String leftoverRobot = jedis12.hget(playKey, "leftover_robot"); +// +// if (shangxianRobot != null && leftoverRobot != null) { +// if (value == 0) { +// jedis12.hset(playKey, "leftover_robot", shangxianRobot); +// } +// } +// jedis12.close(); +// } + } + + ready(client); + //写定时器 + + } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作 + //[TCP->815] data:{"playerid":101555,"card":104,"opcard":[105,103],"from_seat":2,"type":1,"opengang":false} + huNanChangSha.shanchuchuguopai(param); + + } else if ("820".equalsIgnoreCase(command)) {//换牌提示 + huNanChangSha.changePlayer(command, message); + } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用 + +// Set roomIds = scanRooms(jedis0, "room:*"); +// String[] playerIds = null; +// for (String roomId : roomIds) { +// String rid = roomId.substring(roomId.indexOf(":") + 1); +// String roomKey = "room:" + rid; +// +// if (jedis0.hget(roomKey, "players") != null) { +// String players = jedis0.hget(roomKey, "players"); +// +// if (!players.equals("[]")) { +// players = players.substring(1, players.length() - 1); +// playerIds = players.split(","); +// +// for (String pyids : playerIds) { +// +// if (Integer.parseInt(pyids) == playerId) { +// jedis0.del(roomId); +// } +// } +// } +// } +// } + + } else if ("825".equalsIgnoreCase(command)) { + ITObject params = TObject.newInstance(); + params.putInt("qi", 0); + params.putInt("id", 1); + client.send("612", params, response -> { + + }); + } else if ("822".equalsIgnoreCase(command)) { + ITObject params = TObject.newInstance(); + //params.putInt("qi", 0); + params.putInt("id", 1); + //[TCP->822] data:{"tip_list":[{"type":8,"id":1,"opcard":[],"weight":8,"card":0}],"types":[{"type":21,"value":1}]} + //板胡Event [TCP->823] data:{"type":8,"seat":1,"data":[{"opcard":[204,204,204,108,108,108],"type":21,"value":1}]} + + client.send("612", params, response -> { + + }); + } else if ("835".equalsIgnoreCase(command)) { //听牌天听 + ITObject params = TObject.newInstance(); + params.putInt("qi", 0); + params.putInt("id", 1); + client.send("612", params, response -> { + + }); + + } + + + //END 长沙麻将 + } + } + } + }); + // 添加连接状态监听器 + client.addEventListener(TaurusClient.NetClientEvent.Connect, new + + IEventListener() { + @Override + public void handleEvent(Event event) { + SocketCode code = (SocketCode) event.getParameter("code"); + if (code == SocketCode.Connect) { + + } else { + } + } + }); + } + + + /** + * 准备方法 + * + * @return + */ + public String ready(TaurusClient client) { + try { + // 添加1秒延迟 + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } +// cardInhand = new ArrayList(); +// HuNanHongZhong.hongZhongCardInhand(); +// HuNanFangPaoFa.fangPaoFaCardInhand(); + + ITObject params = TObject.newInstance(); + params.putString("session", session + "," + token); + + client.send("1003", params, new ICallback() { + + @Override + public void action(MessageResponse messageResponse) { + + + } + }); + return null; + } + + + public static void sleepTime(int time) { + try { + // 添加延迟 + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/libs/robot_common/src/test/java/Test.java b/libs/robot_common/src/test/java/Test.java index c38bbb0..39bfb73 100644 --- a/libs/robot_common/src/test/java/Test.java +++ b/libs/robot_common/src/test/java/Test.java @@ -1,8 +1,8 @@ import com.taurus.core.plugin.PluginService; -import hunan.DoTest; +//import hunan.DoTest; import hunan.HuNanChangSha; import hunan.HuNanHongZhong; -import hunan.JiQiRens; +//import hunan.JiQiRens; import taurus.client.NetManager; import taurus.newRobot.AddRedisRobot; import taurus.newRobot.AddRoomRobot; @@ -59,8 +59,8 @@ public class Test { // AddRedisRobot addRedisRobot = new AddRedisRobot(); // addRedisRobot.getData(); - AddRoomRobot addRoomRobot = new AddRoomRobot(); - addRoomRobot.addRoom(); + AddRoomRobot addRoomRobot =new AddRoomRobot(); + addRoomRobot.addRoom(); while (true) { NetManager.processEvents();