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) {
- ITArray tipList = param.getTArray("tip_list");
-// log.info("tipList" +tipList);
- ITObject params = TObject.newInstance();
- int card = 0;
-
- //循环
- List yupanhandcard = new ArrayList<>();
- yupanhandcard.addAll(changShaCardInhand);
- //进行操作之前能否下听
-
- List shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand, chowGroup, pongGroup, gangdepai);
- boolean beforelisten = false;//记录操作之前的下听状态
- System.out.println("shifoutingpai" + shifoutingpai);
- if (shifoutingpai.size() > 0) {
- beforelisten = true;
- }
-
- System.out.println("beforelisten" + beforelisten);
- //如果杠了之后还能继续听牌则杠
-
- //优先处理胡牌
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip1 = (TObject) tipList.get(i).getObject();
- int type = firstTip1.getInt("type");
- int id = firstTip1.getInt("id");
- if (type == 6) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
- client.send("612", params, response -> {
- });
- return "胡牌";
- }
- }
-
- //如果下听了,可以杠
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- int type = firstTip.getInt("type");
- int id = firstTip.getInt("id");
- int weight = firstTip.getInt("weight");
- card = firstTip.getInt("card");
-
-
- if ((type == 5 || type == 3 || type == 4) && weight == 4) {
- //判断开杠后是否能下听
- List gangusecars = new ArrayList<>();
- gangusecars.addAll(changShaCardInhand);
-
- if (type == 3) {
- Util.removeCard(gangusecars, card, 3);
- List shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
- System.out.println(shifoutingpai3);
-
- if (shifoutingpai3.size() > 0) {
- //开杠
- //判断是否杠了之后没有牌可以听
- 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 "不开杠";
- }
-
- 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 {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return "不开杠";
- }
- }
-
- if (type == 4) {
-
-
- // Util.removeCard(changShaCardInhand,card,4);
- Util.removeCard(gangusecars, card, 4);
- List shifoutingpai4 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
- if (shifoutingpai4.size() > 0) {
- //开杠
-
- //判断是否杠了之后没有牌可以听
- List allList = new ArrayList<>();
- allList.addAll(changShaCardInhand);
- allList.addAll(changShachuguopai);
- int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai4, 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, 4);
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
- client.send("612", params, response -> {
- });
- return "开杠";
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return "不开杠";
- }
- }
- if (type == 5) {
- //Util.removeCard(changShaCardInhand,card,1);
-
- Util.removeCard(gangusecars, card, 1);
- List shifoutingpai5 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
- if (shifoutingpai5.size() > 0) {
- //开杠
-
- //判断是否杠了之后没有牌可以听
- List allList = new ArrayList<>();
- allList.addAll(changShaCardInhand);
- allList.addAll(changShachuguopai);
- int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai5, 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, 1);
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
- client.send("612", params, response -> {
- });
- return "开杠";
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return "不开杠";
- }
- }
-
-
- }
- }
-
- //判断是否是大胡
- int beforeIsDahu = 0;
-
- beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
- System.out.println("bef:" + beforeIsDahu);
- //5、门清
- if (yupanhandcard.size() == 13 && beforelisten) {
- beforeIsDahu = 5;//门清
- }
-
- //操作之前出现的牌
- List allSeeCard = new ArrayList<>();
-
-
- Map pingfenResult = new HashMap<>();
- Map idObject = new HashMap<>();
-
- //int bupaiid = 0;//补牌id
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- int type = firstTip.getInt("type");
- int id = firstTip.getInt("id");
- int weight = firstTip.getInt("weight");
- card = firstTip.getInt("card");
- ITArray opcard = TArray.newInstance();
- opcard = firstTip.getTArray("opcard");
- if (type == 6) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
- client.send("612", params, response -> {
- });
- return "胡牌";
- }
- //if((type==4||type==5||type==6)&&weight==3){
- // bupaiid = id;
- // }
- //对应的数据
- ITObject tmp = new TObject();
- //处理听的结果
- switch (type) {
- case 1:
- //吃
- 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);
- break;
- default:
- break;
- }
- //记录下来事件
- 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);
- }
- //计算分数
- System.out.println(pingfenResult);
- if (pingfenResult.size() > 0) {
- int changeid = changShaSuanFaTest.suanfen(pingfenResult);
- System.out.println("changeid:" + changeid);
- //选择最优的分数
- if (changeid == 0) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return null;
- } else {
- //获取
- for (Map.Entry entry : idObject.entrySet()) {
- if (entry.getKey() == changeid) {
- ITObject tmp = entry.getValue();
- System.out.println("tmp ++++++++++= " + tmp);
- 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);
- }
- pongGroup.add(outcards.getInt(0));
- pongGroup.add(outcards.getInt(0));
- pongGroup.add(outcards.getInt(0));
-
- } 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);
- }
- System.out.println("判断吃 +++++++++" + card);
- System.out.println("判断吃 ==========" + outcards);
- chowGroup.add(card);
- chowGroup.add(outcards.getInt(0));
- chowGroup.add(outcards.getInt(1));
- }
- }
- }
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", changeid);
- client.send("612", params, response -> {
- });
- return null;
- }
- }
-
- //计算牌数
-
- //如果 不吃,不碰,而且差三手牌情况,则补
- //if (bupaiid>0) {
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- int type = firstTip.getInt("type");
- int id = firstTip.getInt("id");
- int weight = firstTip.getInt("weight");
- card = firstTip.getInt("card");
-
- Map map = new HashMap<>();
- List tmpChangSch = new ArrayList<>();
- tmpChangSch.addAll(yupanhandcard);
- ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
- System.out.println("要不要补map:" + map);
-
- Map map2 = new HashMap<>();
- 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);
- }
-
- ChangshaWinSplitCard.checkNormalHu(tmpChangSch2, map2);
- System.out.println("要不要补map2:" + map2);
- System.out.println(yupanhandcard);
- //假设补牌
- //如果下听不能不能补牌
- if (beforelisten) {
- System.out.println("b补");
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return null;
- }
- //去一张下听?
- 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);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return null;
- }
- }
-
- 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) {
- System.out.println("b补");
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return null;
- } else {
-
- //判断七对
- int dh = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
- if (dh > 0) {
- System.out.println("不补");
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return null;
- }
-
- System.out.println("补");
-
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
-
- if (type == 3) {
- Util.removeCard(changShaCardInhand, card, 3);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- if (type == 4) {
- Util.removeCard(changShaCardInhand, card, 4);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- if (type == 5) {
- Util.removeCard(changShaCardInhand, card, 1);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- client.send("612", params, response -> {
- });
- return null;
- }
- /*if (Integer.parseInt(map.get("remainingMelds").toString()) > 2) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
-
- if (type == 3) {
- Util.removeCard(changShaCardInhand, card, 3);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- if (type == 4) {
- Util.removeCard(changShaCardInhand, card, 4);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- if (type == 5) {
- Util.removeCard(changShaCardInhand, card, 1);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- client.send("612", params, response -> {
- });
- return null;
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
- return null;
- }
- */
-
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
-
- if (type == 3) {
- Util.removeCard(changShaCardInhand, card, 3);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- if (type == 4) {
- Util.removeCard(changShaCardInhand, card, 4);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- if (type == 5) {
- Util.removeCard(changShaCardInhand, card, 1);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- gangdepai.add(card);
- }
- client.send("612", params, response -> {
- });
- return null;
- }
- }
- }
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
- });
-
- return null;
- }
-
-
- public String actionCardBak2(ITObject param, TaurusClient client) {
- ITArray tipList = param.getTArray("tip_list");
-// log.info("tipList" +tipList);
- //tipList[{opcard=[207, 208], weight=1, id=1, type=1, card=206}]
- boolean chiflag = false;//吃
- boolean pengflag = false; //碰
- boolean bupai = false; //补
- boolean minggang = false; //杠
- boolean angang = false; //暗杠
- boolean penggang = false; //开杠
-
- int card = 0;//当前 消息的牌
- ITObject params = TObject.newInstance();
-
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- int type = firstTip.getInt("type");
- int id = firstTip.getInt("id");
- int weight = firstTip.getInt("weight");
- card = firstTip.getInt("card");
- if (type == 6) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
- client.send("612", params, response -> {
- });
- return "胡牌";
- }
- if (type == 1) {
- chiflag = true;
- }
- if (type == 2) {
- pengflag = true;
- }
- if (type == 3 && weight == 3) {
- //补
- bupai = true;
- }
- if (type == 3 && weight == 4) {
- //杠
- minggang = true;
- }
- if (type == 5) {
- penggang = true;
- }
- }
-
- /*
- //如果吃,没有碰
- if (chiflag&&!pengflag){
- chiNoPeng(tipList,card,client);
- }
-
- //如果有吃有碰
- if (chiflag&&pengflag&&!minggang&&!penggang){
- chiOrPeng(tipList,card,client);
- }
-
- //没有吃,有碰
- if (!chiflag&&penggang&&!minggang&&!angang){
- pengNoChi(tipList,card,client);
- }
-
- if (bupai&&!penggang&&!angang){
- //补
-
- }
-
- //杠
- if (minggang||bupai||penggang){
- gangNoChiPeng(tipList,card,client);
- }*/
- return null;
- }
-
-
- /**
- * 处理吃 问题
- * @param tipList
- * @param client
- */
- /*
- public int chiNoPeng(ITArray tipList,int card,TaurusClient client){
- ITObject params = TObject.newInstance();
- params.putString("session", session + "," + token);
- //判断是否能吃
- //1、吃之后能否下听
- List shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
- if (shifoutingpai.size() == 0) {
- //没下听
- //如果吃了可以立马下听,则吃
- int chitingpaiid = changShaSuanFaTest.checkChiTingAction(card,changShaCardInhand);
- if (chitingpaiid>0){
- //处理吃后的数据
- params.putInt("qi", 0);
- params.putInt("id", chitingpaiid-1);
-
- //记录吃掉的牌
- List> lists = new ArrayList<>();
- lists.addAll(TinHuChi.checkChi(changShaCardInhand, card));
-
- List integers = lists.get(chitingpaiid-1);
- List result1 = getOtherCards1(integers, card);
-
- chowGroup.add(card);
- chowGroup.add(result1.get(0));
- chowGroup.add(result1.get(1));
- changShaCardInhand.add(card);
- Util.removeCard(changShaCardInhand,result1.get(0),1);
- Util.removeCard(changShaCardInhand,result1.get(1),1);
- Util.removeCard(changShaCardInhand,card,1);
-
- client.send("612", params, response -> {});
- return chitingpaiid;
- }
- //2、吃之后是否没了大胡
- //判断是否满足7对
- int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
- if (pisCardsCount>=4){
- params.putInt("qi", 0);
- params.putInt("id", 0);
- }else{
- //判断是否可以执行 清一色操作
- boolean isChow = changShaSuanFaTest.checkAllSameSuitAll(card,changShaCardInhand,pongGroup,chowGroup,gangdepai);
- if (isChow){
- //判断是否可以吃
- //判断吃之后是否会破坏下听
- //3、吃之后是否破坏牌型
- int canchiId = changShaSuanFaTest.checkCanChiAction(card,changShaCardInhand);
-
- if (canchiId>0){
-
- params.putInt("qi", 0);
- params.putInt("id", canchiId-1);
-
- //记录吃掉的牌
- List> lists = new ArrayList<>();
- lists.addAll(TinHuChi.checkChi(changShaCardInhand, card));
-
- List integers2 = lists.get(canchiId-1);
- List result2 = getOtherCards1(integers2, card);
-
- chowGroup.add(card);
- chowGroup.add(result2.get(0));
- chowGroup.add(result2.get(1));
- changShaCardInhand.add(card);
- Util.removeCard(changShaCardInhand,result2.get(0),1);
- Util.removeCard(changShaCardInhand,result2.get(1),1);
- Util.removeCard(changShaCardInhand,card,1);
-
- client.send("612", params, response -> {});
- return chitingpaiid;
-
-
- }else{
- params.putInt("qi", 0);
- params.putInt("id", 0);
- }
-
- }else{
- //不可以吃
- params.putInt("qi", 0);
- params.putInt("id", 0);
- }
- }
- }else{
- //不吃
-
- //吃之后没有下听
- params.putInt("qi", 0);
- params.putInt("id", 0);
- }
-
-
-
-
-
-
- client.send("612", params, response -> {});
- return 0;
- }
- */
- /**
- * 同时有吃有碰
- * @param tipList
- * @param client
- */
- /*
- public void chiOrPeng(ITArray tipList,int card,TaurusClient client){
- ITObject params = TObject.newInstance();
- //判断碰和吃
- //判断牌型是否下听
- params.putString("session", session + "," + token);
- List shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
- if (shifoutingpai.size() == 0) {
-
- //1、先判断是否碰之后破坏听牌
-
-
- //2、如果能碰,则进入判断吃逻辑,对比吃、碰那个会更优
-
-
- //3、判断吃或者碰之后都会破坏听牌,不能吃和碰
-
- }else{
- //有下听 先不做操作,后续判断换牌
- params.putInt("qi", 0);
- params.putInt("id", 0);
- }
-
-
-
-
-
-
-
-
- client.send("612", params, response -> {});
- }
-
- /**
- * 没吃,有碰
- * @param tipList
- * @param client
- */
-
- /*
- public void pengNoChi(ITArray tipList,int card,TaurusClient client){
- ITObject params = TObject.newInstance();
-
- client.send("612", params, response -> {});
- }*/
-
- /**
- * 杠没有吃,没有碰
- * @param tipList
- * @param client
- */
- /*
- public void gangNoChiPeng(ITArray tipList,int card,TaurusClient client){
- ITObject params = TObject.newInstance();
-
-
-
- client.send("612", params, response -> {});
- }
- */
-
- /**
- * 处理杠碰胡操作
- *
- * @param
- * @return
- */
- /*
- public String actionCardbak(ITObject param, TaurusClient client) {
- TinHuPeng tinHuPeng = new TinHuPeng();
-
- //获取碰杠胡参数 type 和id 后续算法接入,是否能让碰和杠
- ITArray tipList = param.getTArray("tip_list");
-
- int id = 0;
- int type = 0;
- int opcard = 0;
- int opcard1 = 0;
- int card = 0;
-
- //胡牌
- ITObject params = TObject.newInstance();
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- id = firstTip.getInt("id");
- type = firstTip.getInt("type");
-
-
- ITArray opcard2 = firstTip.getTArray("opcard");
-
- if (type == 6) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id);
- client.send("612", params, response -> {
-
- });
-
- return "胡牌";
- }
- }
-
- //吃杠
- int type2 = 0;
- int opcard3 = 0;
- int id3 = 0;
-
- List gangCardInhand = new ArrayList<>();
- gangCardInhand.addAll(changShaCardInhand);
- gangCardInhand.addAll(chowGroup);
- gangCardInhand.addAll(pongGroup);
- TingPaiChecker.TingResult tingResult = TingPaiChecker.checkTingPai(gangCardInhand);
- if (tingResult.isTingPai()) { //听牌状态
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- type2 = firstTip.getInt("type");
- opcard3 = firstTip.getTArray("opcard").getInt(0);
- id3 = firstTip.getInt("id");
-
-
- boolean b = TinHuGang.canGang(gangCardInhand, opcard3, true); //杠牌后是否还能听牌
-
- if (type2 == 3) {
-// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
-// boolean gang = isAllSameSuitgang(changShaCardInhand, opcard3);
- if (b) {
- System.out.println("听牌 +++进入吃杠===============================------------------------------------------------");
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id3);
- Util.removeCard(changShaCardInhand, opcard3, 3);
-
- client.send("612", params, response -> {
-
- });
- return "吃杠";
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
-
- });
-
- }
- }
- }
-
- } else {
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- type2 = firstTip.getInt("type");
- opcard3 = firstTip.getTArray("opcard").getInt(0);
- id3 = firstTip.getInt("id");
-
- if (type2 == 3) {
-// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
-// boolean gang = isAllSameSuitgang(changShaCardInhand, opcard3);
-// if (pisCardsCount < 5 && gang) { //不是七小对和清一色的情况下 才允许杠
-// System.out.println("没有 +++ 听牌 +++进入吃杠===============================------------------------------------------------");
-//
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", id3);
-// Util.removeCard(changShaCardInhand, opcard3, 3);
-//
-// client.send("612", params, response -> {
-//
-// });
-// return "吃杠";
-// } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
-
- });
-
- }
- }
- }
-
- TingPaiChecker.TingResult tingResult1 = TingPaiChecker.checkTingPai(gangCardInhand);
- if (tingResult1.isTingPai()) {
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- type2 = firstTip.getInt("type");
- opcard3 = firstTip.getTArray("opcard").getInt(0);
- id3 = firstTip.getInt("id");
-
- boolean c = TinHuGang.canGang(gangCardInhand, opcard3, false); //杠牌后是否还能听牌
- if (type2 == 4) {
- System.out.println("最新自杠 还没进入下面,但是类型为4自杠了===========================");
- if (c) {
- System.out.println("听牌 +++进入自杠===============================------------------------------------------------");
- System.out.println("opcard3 ++++++++++++++++++ ++++++++++888 " + opcard3);
- System.out.println("id3 ++++++++++++++++++ ++++++++++7777 " + id3);
-
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id3);
- Util.removeCard(changShaCardInhand, opcard3, 4);
- client.send("612", params, response -> {
-
- });
- return "自杠";
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
-
- });
- }
- }
- }
- } else {
- for (int i = 0; i < tipList.size(); i++) {
- TObject firstTip = (TObject) tipList.get(i).getObject();
- type2 = firstTip.getInt("type");
-
-
- if (type2 == 4) {
- System.out.println("放弃自杠111=======================================");
-
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
- client.send("612", params, response -> {
-
- });
-
- }
- }
- }
-
-
-// for (int i = 0; i < tipList.size(); i++) {
-// TObject firstTip = (TObject) tipList.get(i).getObject();
-// type2 = firstTip.getInt("type");
-// opcard3 = firstTip.getTArray("opcard").getInt(0);
-// id3 = firstTip.getInt("id");
-//
-// if (type2 == 3) {
-// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
-// boolean gang = isAllSameSuitgang(changShaCardInhand, opcard3);
-// if (pisCardsCount < 5 && gang) { //不是七小对和清一色的情况下 才允许杠
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", id3);
-// Util.removeCard(changShaCardInhand, opcard3, 3);
-//
-// client.send("612", params, response -> {
-//
-// });
-// return "吃杠";
-// } else {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", 0);
-// client.send("612", params, response -> {
-//
-// });
-//
-// }
-// }
-// }
-
-
- int id1 = 0;
- int type1 = 0;
- //吃牌判断
- boolean b = false;
- //碰牌判断
- boolean a = false;
- if (tipList.size() > 0) {
- TObject firstTip = (TObject) tipList.get(0).getObject();
- id1 = firstTip.getInt("id");
- type1 = firstTip.getInt("type");
-
-
- ITArray opcard2 = firstTip.getTArray("opcard");
-
- card = firstTip.getInt("card");
-
- b = TinHuChi.canChi(changShaCardInhand, card);
-
-
- List> lists = TinHuChi.checkChi(changShaCardInhand, card);
-
-
- opcard = firstTip.getTArray("opcard").getInt(0);
-
-
- if (type1 == 1) {
- opcard1 = firstTip.getTArray("opcard").getInt(1);
- }
- }
-
- System.out.println("进入吃type:" + type1);
-
- if (type1 == 2) {
-
- boolean isChow = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
- if (isChow) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
- } else {
- List shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
- //目前手牌没有听牌
- if (shifoutingpai.size() == 0) {
-
- //判断是否满足7对
- int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
- if (pisCardsCount >= 5) {
-
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
- } else {
- List temphand = new ArrayList<>();
- temphand.addAll(changShaCardInhand);
- temphand.add(opcard);
- Util.removeCard(temphand, opcard, 3);
- List checktingpai1 = TinHuChi.checktingpai(temphand);
- System.out.println("checktingpai1 碰牌" + checktingpai1);
- //碰完牌后打牌后可以听牌
- if (checktingpai1.size() > 0) {
- System.out.println("===============进入听胡碰牌================== ++++ ");
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id1);
-
- pongGroup.add(opcard);
- pongGroup.add(opcard);
- pongGroup.add(opcard);
- Util.removeCard(changShaCardInhand, opcard, 2);
- } else {
- //碰之前的map
- Map map = new HashMap<>();
- //碰之后的map
- Map map2 = new HashMap<>();
-
- //先判断碰之前还需要几手牌,以及孤章
-// int jiangnum = checkduijiang(changShaCardInhand);
- List tmpChangSch = new ArrayList<>();
- tmpChangSch.addAll(changShaCardInhand);
- tmpChangSch.add(opcard);
- ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
-
-
- //碰之后
- List pengtemphand = new ArrayList<>();
- pengtemphand.addAll(tmpChangSch);
- Util.removeCard(pengtemphand, opcard, 3);
-
- ChangshaWinSplitCard.checkNormalHu(pengtemphand, map2);
- //判断两个map是否找到更优
- System.out.println("碰之前 map1:" + Integer.parseInt(map.get("remainingMelds").toString()));
- System.out.println("碰之后 map2:" + Integer.parseInt(map2.get("remainingMelds").toString()));
- //碰之后的手数小于碰之前的手数,可以碰
- if (Integer.parseInt(map2.get("remainingMelds").toString()) < Integer.parseInt(map.get("remainingMelds").toString())) {
- System.out.println("===============碰之后的手数小于碰之前的手数,可以碰 决定碰牌================== ++++ ");
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id1);
-
- pongGroup.add(opcard);
- pongGroup.add(opcard);
- pongGroup.add(opcard);
- Util.removeCard(changShaCardInhand, opcard, 2);
- } else if (Integer.parseInt(map2.get("remainingMelds").toString()) == Integer.parseInt(map.get("remainingMelds").toString())) { //碰完后和碰之前手数相等,需要判断孤章数量
- //碰之后的数量
- int size2 = ((List) map2.get("cardResiue")).size();
- System.out.println("碰之后的孤章数量 size" + size2);
-
- int size1 = ((List) map.get("cardResiue")).size();
- System.out.println("碰之前的孤章数量 size" + size1);
- if (size2 < size1) {
- System.out.println("===============碰之后的孤章数量 小于 碰之前的孤章数量可以碰 ================== ++++ ");
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id1);
-
- pongGroup.add(opcard);
- pongGroup.add(opcard);
- pongGroup.add(opcard);
- Util.removeCard(changShaCardInhand, opcard, 2);
- }
- //碰之后的手数大于碰之前的手数,或者碰之后的孤章数量大于碰之前的孤章数量不能碰
- } else if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) || ((List) map2.get("cardResiue")).size() > ((List) map.get("cardResiue")).size()) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
- }
- }
- }
- }
-
- //听牌的时候先不碰
- if (shifoutingpai.size() > 0) {
- System.out.println("听牌的时候先不碰++++++++++++++++++++++++++++++++");
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
- }
- }
-
-
-// a = tinHuPeng.canPeng(changShaCardInhand, opcard);
-// ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest();
-// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
-// boolean peng = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
-// if (a && !ChangShaSuanFaTest.isTin) {
-// System.out.println("===============进入听胡碰牌===============================");
-//
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", id1);
-// pongGroup.add(opcard);
-// pongGroup.add(opcard);
-// pongGroup.add(opcard);
-// Util.removeCard(changShaCardInhand, opcard, 2);
-//
-// } else {
-// // 根据规则判断是否应该碰牌
-// if (shouldPong(opcard) && pisCardsCount < 5 && !peng && !isTinPeng) {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", id1);
-// pongGroup.add(opcard);
-// pongGroup.add(opcard);
-// pongGroup.add(opcard);
-// Util.removeCard(changShaCardInhand, opcard, 2);
-// } else {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 1); // 放弃碰牌
-// params.putInt("id", 0);
-//
-// }
-// }
-
- } else if (type1 == 3) {
-
- int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
- boolean gang = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
- if (pisCardsCount < 5 && !gang) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", id1);
- Util.removeCard(changShaCardInhand, opcard, 3);
-
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
-
- }
-
- } else if (type1 == 1) {
-
-// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
- boolean isChow = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
- if (isChow) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
- } else {
-
- //判断当前手牌是否已经听牌 已经听牌了就不要再吃牌了
- List shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
-
- //目前手牌没有听牌
- if (shifoutingpai.size() == 0) {
-
- //判断是否满足7对
- int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
- if (pisCardsCount >= 5) {
-
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
-
- } else {
-
- List> lists = new ArrayList<>();
- lists.addAll(TinHuChi.checkChi(changShaCardInhand, card));
- int index = 0;
- int flag = 0;
- for (List list : lists) {
- List temphand = new ArrayList<>();
- temphand.addAll(changShaCardInhand);
- temphand.add(card);
- Util.removeCard(temphand, list.get(0), 1);
- Util.removeCard(temphand, list.get(1), 1);
- Util.removeCard(temphand, list.get(2), 1);
- List checktingpai1 = TinHuChi.checktingpai(temphand);
- if (checktingpai1.size() > 0) {
- flag = index + 1;
- }
- index++;
- System.out.println("checktingpai1 吃牌 " + checktingpai1);
- }
-
-
- // TODO: 2026/1/1
- // 1.需要补充 没听牌也可以吃 但是吃之后要比吃之前的手牌强 也就是可听数量变多
- // 2.听牌后也能吃牌,要比吃之前的牌强
- // 3.碰也一样要加
- if (flag > 0) {
- System.out.println("===============进入听胡吃牌================== ++++ " + flag);
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", flag);
-
- int index1 = flag - 1;
- List integers = lists.get(index1);
- List result1 = getOtherCards1(integers, card);
-
- chowGroup.add(card);
- chowGroup.add(result1.get(0));
- chowGroup.add(result1.get(1));
- changShaCardInhand.add(card);
-
- Util.removeCard(changShaCardInhand, integers.get(0), 1);
- Util.removeCard(changShaCardInhand, integers.get(1), 1);
- Util.removeCard(changShaCardInhand, integers.get(2), 1);
- } else {
- Map map = new HashMap<>();
- Map map2 = new HashMap<>();
-
- //吃之前的逻辑
- List> lists1 = TinHuChi.checkChi(changShaCardInhand, card);
- int jiangnum = checkduijiang(changShaCardInhand);
- List tmpChangSch = new ArrayList<>();
- tmpChangSch.addAll(changShaCardInhand);
- tmpChangSch.add(card);
- ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
-
- System.out.println("checkNormalHu" + map.get("cardResiue"));
-
-
- System.out.println("checktingpai1" + lists1);
- int index1 = 0;
- int flag1 = 0;
- for (List list : lists1) {
- List temphand = new ArrayList<>();
- temphand.addAll(tmpChangSch);
- Util.removeCard(temphand, list.get(0), 1);
- Util.removeCard(temphand, list.get(1), 1);
- Util.removeCard(temphand, list.get(2), 1);
- ChangshaWinSplitCard.checkNormalHu(temphand, map2);
- //判断两个map是否找到更优
- System.out.println("map1:" + Integer.parseInt(map.get("remainingMelds").toString()));
- System.out.println("map2:" + Integer.parseInt(map2.get("remainingMelds").toString()));
- if (Integer.parseInt(map2.get("remainingMelds").toString()) < Integer.parseInt(map.get("remainingMelds").toString())) {
- flag1 = index1 + 1;
- } else if (Integer.parseInt(map2.get("remainingMelds").toString()) == Integer.parseInt(map.get("remainingMelds").toString())) {
- int size2 = ((List) map2.get("cardResiue")).size();
- System.out.println("size2" + size2);
- int size1 = ((List) map.get("cardResiue")).size();
- System.out.println("size1" + size1);
- if (size2 < size1) {
- flag1 = index1 + 1;
- }
-
- //如果手里没有将,则可以吃
- if (jiangnum > 0) {
- int chihoujiangnum = checkduijiang(temphand);
- if (chihoujiangnum > 0) {
- //吃之后还有将
- flag1 = index1 + 1;
- }
- } else {
- System.out.println("没队将");
- //孤章1张 差一手 不是将 而且card不是将
- if (Integer.parseInt(map.get("remainingMelds").toString()) == 1 && size1 == 1 && !isJiangPai(((List) map.get("cardResiue")).get(0)) && !isJiangPai(card)) {
- //吃
- break;
- }
- flag1 = index1 + 1;
- // break;
- }
- }
- index1++;
- }
-
- if (flag1 > 0) {
- System.out.println("flag1:" + flag1);
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", flag1);
-
- int index2 = flag1 - 1;
-
- if (index2 >= lists.size()) {
- index2 = 0;
- }
- System.out.println("index2:" + index2);
- System.out.println("lists:" + lists);
- List integers = new ArrayList<>();
- integers.addAll(lists.get(index2));
- List result2 = getOtherCards1(integers, card);
-
- chowGroup.add(card);
- chowGroup.add(result2.get(0));
- chowGroup.add(result2.get(1));
- changShaCardInhand.add(card);
-
- Util.removeCard(changShaCardInhand, integers.get(0), 1);
- Util.removeCard(changShaCardInhand, integers.get(1), 1);
- Util.removeCard(changShaCardInhand, integers.get(2), 1);
-
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
- }
- }
- }
- }
-
-
- //听牌的时候先不吃
- if (shifoutingpai.size() > 0) {
- System.out.println("听牌的时候先不吃++++++++++++++++++++++++++++++++");
- params.putString("session", session + "," + token);
- params.putInt("qi", 1);
- params.putInt("id", 0);
- }
-
-
-// if (b && TinHuChi.isMoreThanLast() && !ChangShaSuanFaTest.isTin) {
-//
-// System.out.println("===============进入听胡吃牌==================");
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", 1);
-//
-// chowGroup.add(card);
-// chowGroup.add(opcard);
-// chowGroup.add(opcard1);
-//// changShachuguopai.add(card);
-// Util.removeCard(changShaCardInhand, opcard, 1);
-// Util.removeCard(changShaCardInhand, opcard1, 1);
-//// }else {
-//// params.putString("session", session + "," + token);
-//// params.putInt("qi", 1);
-//// params.putInt("id", 0);
-//// }
-// } else {
-// System.out.println("isTin ++++++++++++++++++++++++++++++++++++" + isTinChi);
-// if (shouldChow(card) && pisCardsCount < 5 && !isChow && !isTinChi) {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", 1);
-// chowGroup.add(card);
-// chowGroup.add(opcard);
-// chowGroup.add(opcard1);
-//
-// Util.removeCard(changShaCardInhand, opcard, 1);
-// Util.removeCard(changShaCardInhand, opcard1, 1);
-// } else {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 1);
-// params.putInt("id", 0);
-// }
-// }
-
-
- //自杠
-// } else if (type1 == 4) {
-//// TingPaiChecker.TingResult tingResult1 = TingPaiChecker.checkTingPai(gangCardInhand);
-//
-// if (tingResult1.isTingPai()) {
-// boolean c = TinHuGang.canGang(gangCardInhand, opcard, false); //杠牌后是否还能听牌
-// if (c) {
-// System.out.println("听牌 +++进入自杠===============================------------------------------------------------");
-//
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", 1);
-// Util.removeCard(changShaCardInhand, opcard, 4);
-//
-// } else {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", 0);
-// }
-// } else {
-//// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
-//// boolean gang = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
-//// if (pisCardsCount < 5 && !gang) {
-// System.out.println("没有 +++ 听牌 +++进入自杠===============================------------------------------------------------");
-////
-//// params.putString("session", session + "," + token);
-//// params.putInt("qi", 0);
-//// params.putInt("id", 1);
-//// Util.removeCard(changShaCardInhand, opcard, 4);
-//// } else {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", 0);
-//// }
-//
-// }
-//
-//
-// // 碰后补杠
-// }
- }
- } else if (type1 == 5) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 0);
-// Util.removeCard(changShaCardInhand, opcard, 1);
-// }
- }
-
- client.send("612", params, response -> {
-
- });
- return null;
- }
-
- */
- public static List getOtherCards1(List integers, int card) {
- List result = new ArrayList<>();
- for (Integer num : integers) {
- if (num != card) {
- result.add(num);
- }
- }
- return result;
- }
-
- public static boolean isAllSameSuitgang(List handCards, int opcard3) {
- // 统计各花色的牌数量
- Map suitCountMap = new HashMap<>();
-
- for (Integer card : handCards) {
- int suit = card / 100; // 获取花色,100=万,200=筒,300=条
- suitCountMap.put(suit, suitCountMap.getOrDefault(suit, 0) + 1);
- }
-
- // 检查是否有花色的牌数量超过8张
- for (Map.Entry entry : suitCountMap.entrySet()) {
- int suit = entry.getKey();
- int count = entry.getValue();
- if (count >= 9) {
- // 检查杠牌的花色是否与当前花色一致
- int gangSuit = opcard3 / 100;
- if (suit == gangSuit) {
- return true;
- } else {
- return false;
- }
- }
- }
- return true;
- }
-
- public static String changePlayer(String command, Message message) {
- if (command.equalsIgnoreCase("820")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-
- }
- return null;
- }
-
-
- /**
- * 出牌方法
- */
-// public String outCard(TaurusClient client, List list) {
- public String outCard(TaurusClient client, Map> playerOutcardsMap, Map> playerchisMap, Map> playerpengsMap, Map> playermingsMap, Map> playerzisMap) {
- // playerOutcardsMap + playerchisMap 传到 outCardSuanFa
- //对出牌进行整合
-
- List resultList = new ArrayList<>();
- for (List cards : playerOutcardsMap.values()) {
- resultList.addAll(cards);
- }
-
- for (List chis : playerchisMap.values()) {
- resultList.addAll(chis);
- }
-
- for (List pengs : playerpengsMap.values()) {
- resultList.addAll(pengs);
- }
-
- for (List minggangs : playermingsMap.values()) {
- resultList.addAll(minggangs);
- }
-
- for (List zigang : playerzisMap.values()) {
- resultList.addAll(zigang);
- }
-
- // 长沙麻将出牌
- String changShaOutCard = changShaSuanFaTest.outCardSuanFa(changShaCardInhand, pongGroup, chowGroup, gangdepai, resultList);
-// String changShaOutCard = changShaSuanFaTest.outCardSuanFa(list, changShaCard,pongGroup);
- ITObject params = TObject.newInstance();
- int cardToOut;
- if (StringUtil.isNotEmpty(changShaOutCard)) {
- cardToOut = Integer.parseInt(changShaOutCard);
- } else {
- cardToOut = changShaCardInhand.get(0);
- }
-
- params.putInt("card", cardToOut);
-
-
- int outCountBefore = changShachuguopai.size(); // 当前历史出牌数量
-
- // 第n次出牌时,发送前n-1张出牌
- if (outCountBefore >= 1) {
- // 发送前n-1张(所有历史出牌)
- List cardsToSend = changShachuguopai.subList(0, outCountBefore);
- params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
- }
- params.putTArray("card_list", CardUtil.maJiangToTArray(changShaCardInhand));
-
- // 将当前出的牌添加到历史出牌列表
- changShachuguopai.add(cardToOut);
- // 从手牌中移除
- changShaCardInhand.remove(Integer.valueOf(cardToOut));
- params.putString("session", session + "," + token);
- client.send("611", params, response -> {
-
- });
-
-
- return null;
- }
-
- /**
- * 删除出过的牌组
- *
- * @param param
- * @return
- */
- public String shanchuchuguopai(ITObject param) {
- if (param == null) {
- return null;
- }
-
- Integer card = param.getInt("card"); // 操作牌值
- Integer type = param.getInt("type"); // 操作类型
- Integer from_seat = param.getInt("from_seat"); // 牌来源座位
-
-
- Integer playerid = param.getInt("playerid");
-
-
- String sql2 = String.format("SELECT id FROM `account` WHERE jiqiren=9998");
- try {
- ITArray robotId2 = DataBase.use().executeQueryByTArray(sql2);
- List robotIdsList = new ArrayList<>();
-
- for (int j = 0; j < robotId2.size(); j++) {
- robotIdsList.add(robotId2.getTObject(j).getInt("id"));
- }
-
- if (!robotIdsList.contains(playerid)) {
- if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
- getChuGuoCardInhand().remove(Integer.valueOf(card));
- }
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- return null;
- }
-
- public static void main(String[] args) {
- HuNanChangSha huNanChangSha = new HuNanChangSha();
- ITObject params = TObject.newInstance();
- TaurusClient tc = new TaurusClient("8.138.242.190", "10", TaurusClient.ConnectionProtocol.Tcp);
- List hands1 = new ArrayList<>();
- hands1.add(209);
- hands1.add(209);
- hands1.add(209);
- hands1.add(208);
-
- hands1.add(208);
- hands1.add(207);
- hands1.add(207);
-
- hands1.add(206);
- hands1.add(205);
- hands1.add(104);
-
- hands1.add(104);
- // hands1.add(105);
- //hands1.add(103);
- //hands1.add(102);
-
- int card = 203;
- huNanChangSha.changShaCardInhand.addAll(hands1);
- TArray tiplist = new TArray();
- ITArray opcard = TArray.newInstance();
- opcard.addInt(102);
- // opcard.addInt(205);
-
- // opcard.addInt(203);
- TObject tob = new TObject();
- 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(107);
- TObject tob2 = new TObject();
- tob2.putInt("weight", 5);
- tob2.putInt("id", 2);
- tob2.putInt("type", 5);
- tob2.putInt("card", card);
- tob2.putTArray("opcard", opcard2);
- // 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.putTArray("opcard", opcard3);
- tiplist.addTObject(tob3);
-
-
- params.putTArray("tip_list", tiplist);
- System.out.println(params);
- //已经吃掉数据
- // huNanChangSha.chowGroup.add(205);
- //huNanChangSha.chowGroup.add(204);
- // huNanChangSha.chowGroup.add(206);
-
- //huNanChangSha.chowGroup.add(201);
- // 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);
- System.out.println(res);
- }
-
-
-}
diff --git a/libs/robot_common/src/main/java/hunan/HuNanFangPaoFa.java b/libs/robot_common/src/main/java/hunan/HuNanFangPaoFa.java
deleted file mode 100644
index c29048f..0000000
--- a/libs/robot_common/src/main/java/hunan/HuNanFangPaoFa.java
+++ /dev/null
@@ -1,214 +0,0 @@
-package hunan;
-
-import com.game.Util;
-import com.taurus.core.entity.ITArray;
-import com.taurus.core.entity.ITObject;
-import com.taurus.core.entity.TObject;
-import taurus.client.Message;
-import taurus.client.TaurusClient;
-import taurus.util.CardUtil;
-import taurus.util.HongZhongSuanFaTest;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class HuNanFangPaoFa {
-
- public static int fangPaoFaCardCard = 0;
-
- //湖南字牌放炮罚 手牌
- private List fangPaoFaCardInhand = new ArrayList();
-
- // 玩家座位号
- public static int seat = 0;
-
- // 会话标识
- public static String session = "";
- // 访问令牌
- public static String token = "";
-
- public void fangPaoFaCardInhand() {
- fangPaoFaCardInhand = new ArrayList();
- }
-
-
- public List getFangPaoFaCardInhand() {
- return fangPaoFaCardInhand;
- }
-
- /**
- * 初始化手牌协议 811
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public String cardInHead(String command, Message message, TaurusClient client) {
- if (command.equalsIgnoreCase("811")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-// {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");
- for (int i = 0; i < cardList.size(); i++) {
- fangPaoFaCardInhand.add(cardList.getInt(i));
- }
- if (fangPaoFaCardInhand.size() > 19) {
- outCard(client);
- System.out.println("机器人:" + param.getInt("seat") + "为庄家,需要出牌" + ",牌为:" + fangPaoFaCardInhand.get(0));
- }
- System.out.println("机器人:" + param.getInt("seat") + "放炮罚初始化手牌" + ",牌为:" + fangPaoFaCardInhand.toString());
-
- }
- return null;
- }
-
- /**
- * 摸牌协议 819
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public String getCard(String command, Message message) {
- if (command.equalsIgnoreCase("819")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
- System.out.println("轮到座位号:" + param.getInt("seat") + "的用户摸牌" + ",牌为:" + param.getInt("card"));
- if (param.getInt("seat") != null && seat == param.getInt("seat")) {
- fangPaoFaCardInhand.add(param.getInt("card"));
- System.out.println("摸牌后放炮罚 手牌" + fangPaoFaCardInhand);
- }
- }
- return null;
- }
-
- /**
- * 出牌方法
- */
- public String outCard(TaurusClient client) {
- ITObject params = TObject.newInstance();
- params.putString("session", session + "," + token);
- params.putInt("card", fangPaoFaCardInhand.get(0));
- System.out.println("放炮罚出牌 " + fangPaoFaCardInhand.get(0));
- fangPaoFaCardInhand.remove(0);
- System.out.println("目前机器人剩余手牌:" + fangPaoFaCardInhand.toString());
- client.send("611", params, response -> {
- System.out.println("出牌成功: " + response.returnCode);
- });
- return null;
- }
-
- /**
- * 出牌广播协议 812
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public static String drawCard(String command, Message message) {
- if (command.equalsIgnoreCase("812")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
- fangPaoFaCardCard = param.getInt("card");
- System.out.println("出牌广播" + fangPaoFaCardCard);
- System.out.println("座位号:" + param.getInt("seat") + "的用户出牌:" + param.getInt("card"));
- }
- return null;
- }
-
- /**
- * 处理 吃碰 偎提胡
- *
- * @param param 消息参数
- * @return
- */
- public String actionCard(ITObject param, TaurusClient client) {
- //获取碰杠胡参数 type 和id 后续算法接入,是否能让碰和杠
- ITArray tipList = param.getTArray("tip_list");
- int id = 0;
- int type = 0;
- int opcard = 0;
- int opcard1 = 0;
- int card = 0;
- ITArray bi_list = null;
- ITObject params = TObject.newInstance();
- if (tipList != null && tipList.size() > 0) {
- TObject firstTip = (TObject) tipList.get(0).getObject();
- id = firstTip.getInt("id");
- type = firstTip.getInt("type");
- card = firstTip.getInt("card");
- // 获取吃牌组合中的第一张牌
- opcard = firstTip.getTArray("opcard").getInt(0);
- // 获取吃牌组合中的第二张牌
- opcard1 = firstTip.getTArray("opcard").getInt(1);
- bi_list = firstTip.getTArray("bi_list");
- System.out.println("id ++ " + id);
- System.out.println("type ++ " + type);
- System.out.println("opcard ++ " + opcard);
- System.out.println("card ++ " + card);
- System.out.println("bi_list ++ " + bi_list);
- }
-
- //执行吃
- if (type == 1) {
- params.putString("session", session + "," + token);
- params.putInt("id", id);
- CardUtil.removeCard1(fangPaoFaCardInhand, opcard, 1);
- CardUtil.removeCard1(fangPaoFaCardInhand, opcard1, 1);
- if (bi_list != null ){
- CardUtil.removeCard1(fangPaoFaCardInhand, card, 1);
- }
- System.out.println("删除吃的牌");
- //执行碰
- } else if (type == 2) {
- params.putString("session", session + "," + token);
- params.putInt("id", id);
- CardUtil.removeCard1(fangPaoFaCardInhand, card, 1);
- System.out.println("删除碰的牌");
- //执行吃杠
- } else if (type == 3) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
-// Util.removeCard(hongZhongCardInhand, opcard, 3);
- System.out.println("执行吃杠");
- } else if (type == 4) {
- params.putString("session", session + "," + token);
- params.putInt("id", id);
- CardUtil.removeCard1(fangPaoFaCardInhand, card, 2);
- System.out.println("执行偎----");
- // 碰后补杠
- } else if (type == 5) {
-// params.putString("session", session + "," + token);
-// params.putInt("qi", 0);
-// params.putInt("id", 1);
-// Util.removeCard(hongZhongCardInhand, opcard, 1);
-// System.out.println("执行碰后补杠");
- } else if (type == 8) {
- params.putInt("id", id);
- }
-
- System.out.println("调用612");
-
- client.send("612", params, response -> {
- System.out.println("操作成功: " + response.returnCode);
- });
- return null;
- }
-
- public static void fangPaoTipEvent(Message message,TaurusClient client) {
- ITObject param = message.param;
- Integer card = param.getInt("card");
- ITObject params = TObject.newInstance();
- params.putInt("card", card);
- client.send("823", params, response -> {
- System.out.println("操作成功: " + response.returnCode);
- });
- }
-}
diff --git a/libs/robot_common/src/main/java/hunan/HuNanHongZhong.java b/libs/robot_common/src/main/java/hunan/HuNanHongZhong.java
deleted file mode 100644
index 51b0ed2..0000000
--- a/libs/robot_common/src/main/java/hunan/HuNanHongZhong.java
+++ /dev/null
@@ -1,319 +0,0 @@
-package hunan;
-
-import com.game.Util;
-import com.taurus.core.entity.ITArray;
-import com.taurus.core.entity.ITObject;
-import com.taurus.core.entity.TObject;
-import com.taurus.core.util.StringUtil;
-import taurus.client.Message;
-import taurus.client.TaurusClient;
-import taurus.util.CardUtil;
-import taurus.util.HongZhongSuanFaTest;
-
-import java.util.*;
-
-public class HuNanHongZhong {
-
-
- public static int hongZhongCard = 0;
-
- //湖南红中麻将手牌
- private List hongZhongCardInhand = new ArrayList<>();
-
- //红中麻将出过的牌
- private List hongZhongchuguopai = new ArrayList<>();
-
-
- // 玩家座位号
- public static int seat = 0;
-
- public static int playerId = 0;
-
-
- // 会话标识
- public static String session = "";
- // 访问令牌
- public static String token = "";
- //红中麻将算法
-// private static HongZhongSuanFa hongZhongSuanFa = new HongZhongSuanFa();
-
- private static HongZhongSuanFaTest hongZhongSuanFaTest = new HongZhongSuanFaTest();
-
-
-
- // 公共的getter和setter方法
- public List getHongZhongCardInhand() {
- return hongZhongCardInhand;
- }
-
- public List getChuGuoCardInhand() {
- return hongZhongchuguopai;
- }
-
-
- /**
- * 出牌广播协议 812
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public static String drawCard(String command, Message message) {
- if (command.equalsIgnoreCase("812")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
- hongZhongCard = param.getInt("card");
-
- }
- return null;
- }
-
-
- /**
- * 摸牌协议 819
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public String getCard(String command, Message message) {
- if (command.equalsIgnoreCase("819")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106}
-
- if (param.getInt("player") != null) {
- int drawnCard = param.getInt("card");
-
- hongZhongSuanFaTest.drawnCards = drawnCard;
- hongZhongCardInhand.add(drawnCard);
-
- // 创建包含摸牌后的完整手牌
- List newHand = new ArrayList<>(hongZhongCardInhand);
-
- // 调用分离分析方法,将刻子、顺子、红中单独拎出后分析剩余牌
- hongZhongSuanFaTest.separateAndAnalyzeHand(newHand);
-
- // 直接调用hongZhongSuanFaTest中的analyzeDrawCard方法分析摸牌后是否可听牌
- hongZhongSuanFaTest.analyzeDrawCard(hongZhongCardInhand, drawnCard);
-
-
- // 调用新添加的findDiscardToTing方法,分析打出哪张牌可以听牌
- Map> discardOptions = hongZhongSuanFaTest.findDiscardToTing(newHand);
-
- // 如果有可打出后听牌的选项,记录信息
- if (!discardOptions.isEmpty()) {
- // 这些信息将在出牌决策时被考虑
- } else {
- }
- }
- }
- return null;
- }
-
- /**
- * 判断是否应该碰牌
- *
- * @param proposedCard 提议碰的牌
- * @return 是否应该碰牌
- */
- public boolean shouldPong(int proposedCard) {
-
- // 直接调用hongZhongSuanFaTest中的shouldPong方法,它已经包含了所有需要的规则
- return hongZhongSuanFaTest.shouldPong(proposedCard, hongZhongCardInhand);
-
-// return hongZhongSuanFaTest.shouldPong(proposedCard, Arrays.asList(305,304,303,207,207,204,204,208,208,201,201,412,412));
- }
-
-
- /**
- * 初始化手牌协议 811
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public String cardInHead(String command, Message message, TaurusClient client) {
- if (command.equalsIgnoreCase("811")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-// {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");
- for (int i = 0; i < cardList.size(); i++) {
- hongZhongCardInhand.add(cardList.getInt(i));
- }
- if (hongZhongCardInhand.size() > 13) {
- outCard(client);
- }
-
- }
- return null;
- }
-
- /**
- * 处理杠碰胡操作
- *
- * @param param 消息参数
- * @return
- */
- public String actionCard(ITObject param, TaurusClient client) {
- //获取碰杠胡参数 type 和id 后续算法接入,是否能让碰和杠
- ITArray tipList = param.getTArray("tip_list");
- int id = 0;
- int type = 0;
- int opcard = 0;
- ITObject params = TObject.newInstance();
- if (tipList != null && tipList.size() > 0) {
- TObject firstTip = (TObject) tipList.get(0).getObject();
- id = firstTip.getInt("id");
- type = firstTip.getInt("type");
- opcard = firstTip.getTArray("opcard").getInt(0);
-
-
- }
- //弃 是根据算法选择是否要弃掉 不进行碰杠胡
- //params.putInt("qi", 0);
- //params.putInt("id", 0);
-
- //执行碰牌
- if (type == 2) {
- // 根据规则判断是否应该碰牌
- if (shouldPong(opcard)) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(hongZhongCardInhand, opcard, 2);
-
- } else {
- params.putString("session", session + "," + token);
- params.putInt("qi", 1); // 放弃碰牌
- params.putInt("id", 0);
-
- }
-// Global.logger.info("删除碰的牌");
- //执行胡牌
- } else if (type == 6) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
-
- //执行吃杠
- } else if (type == 3) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(hongZhongCardInhand, opcard, 3);
-
- //执行自杠
- } else if (type == 4) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(hongZhongCardInhand, opcard, 4);
-
- // 碰后补杠
- } else if (type == 5) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(hongZhongCardInhand, opcard, 1);
-
- }
-
-// cardInhand.remove(0);
-// cardInhand.remove(1);
-
-
- client.send("612", params, response -> {
-
- });
- return null;
- }
-
-
- public static String changePlayer(String command, Message message) {
- if (command.equalsIgnoreCase("820")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-
- }
- return null;
- }
-
-
- /**
- * 出牌方法
- */
-// public String outCard(TaurusClient client, List< Integer> list) {
- public String outCard(TaurusClient client) {
- // 调用分离分析方法,将刻子、顺子、红中单独拎出后分析剩余牌
-
- hongZhongSuanFaTest.separateAndAnalyzeHand(hongZhongCardInhand);
-
- // 红中麻将出牌
- String hongzhongOutCard = hongZhongSuanFaTest.outCardSuanFa(hongZhongCardInhand, hongZhongCard);
-// String hongzhongOutCard = hongZhongSuanFaTest.outCardSuanFa(list, hongZhongCard);
- ITObject params = TObject.newInstance();
- int cardToOut;
- if (StringUtil.isNotEmpty(hongzhongOutCard)) {
- cardToOut = Integer.parseInt(hongzhongOutCard);
- } else {
- cardToOut = hongZhongCardInhand.get(0);
- }
- params.putInt("card", cardToOut);
-
- int outCountBefore = hongZhongchuguopai.size(); // 当前历史出牌数量
-
- // 第n次出牌时,发送前n-1张出牌
- if (outCountBefore >= 1) {
- // 发送前n-1张(所有历史出牌)
- List cardsToSend = hongZhongchuguopai.subList(0, outCountBefore);
- params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
- }
- params.putTArray("card_list", CardUtil.maJiangToTArray(hongZhongCardInhand));
-
- // 将当前出的牌添加到历史出牌列表
- hongZhongchuguopai.add(cardToOut);
- // 从手牌中移除
- hongZhongCardInhand.remove(Integer.valueOf(cardToOut));
-
-
- params.putString("session", session + "," + token);
- client.send("611", params, response -> {
-
- });
- return null;
- }
-
- /**
- * 删除出过的牌组
- *
- * @param param
- * @return
- */
- public String shanchuchuguopai(ITObject param) {
- if (param == null) {
- return null;
- }
- Integer card = param.getInt("card"); // 操作牌值
- Integer type = param.getInt("type"); // 操作类型
- Integer from_seat = param.getInt("from_seat"); // 牌来源座位
-
-
-
-
- if (type == 2 || type == 3 || type == 5) { // 碰,杠
- getChuGuoCardInhand().remove(Integer.valueOf(card));
-
- }
- return null;
- }
-}
diff --git a/libs/robot_common/src/main/java/hunan/HuNanPaoDeKuai.java b/libs/robot_common/src/main/java/hunan/HuNanPaoDeKuai.java
deleted file mode 100644
index b32a2dd..0000000
--- a/libs/robot_common/src/main/java/hunan/HuNanPaoDeKuai.java
+++ /dev/null
@@ -1,116 +0,0 @@
-package hunan;
-
-import com.taurus.core.entity.ITArray;
-import com.taurus.core.entity.ITObject;
-import com.taurus.core.entity.TObject;
-import taurus.client.TaurusClient;
-import taurus.util.*;
-
-import java.util.*;
-
-public class HuNanPaoDeKuai {
-
- public static int seat = 0;
-
- //座位号 剩余牌数量
- private Map> seatRemainHistory = new HashMap<>();
-
- // 跑的快玩家手牌
- private List paoDekuaiCardInhand = new ArrayList<>();
-
- // 会话标识
- public static String session = "";
- // 访问令牌
- public static String token = "";
-
- //跑的快别人出的牌
- private ITObject card_list = TObject.newInstance();
-
- public static int guangboseat = 0;
-
- public static int remain = 0;
-
- public Map> getSeatRemainHistory() {
- return seatRemainHistory;
- }
-
- public List getPaoDekuaiCardInhand() {
- return paoDekuaiCardInhand;
- }
-
- public ITObject getCard_list() {
- return card_list;
- }
-
- /**
- * 出牌方法
- */
- public String outCard(TaurusClient client) {
- ITArray itArray = null;
- itArray = test.intelligentPaoDeKuaiOutCard(paoDekuaiCardInhand, card_list, seatRemainHistory);
-
- if (remain == 1 && itArray == null) { //如果玩家的下家只有一张牌,玩家出单张必须是最大的
- CardObj maxSingleCard = CardUtil.findMaxSingleCard(paoDekuaiCardInhand);
-
- itArray = CardUtil.toTArray1(maxSingleCard);
- }
-
- //跑得快出牌
-
- ITObject params = TObject.newInstance();
- params.putString("session", session + "," + token);
- params.putTArray("card", itArray);
- params.putTArray("all_card", CardUtil.toTArray(paoDekuaiCardInhand));
- CardUtil.removeCard(paoDekuaiCardInhand, CardUtil.toList(itArray)); //删除手牌里打过的牌
-
- client.send("1013", params, response ->
-
- {
-
- });
- return null;
- }
-
- /**
- * 跑得快初始化手牌
- *
- * @param param 消息参数
- * @return
- */
- public String paoDeKuaiCardInHead(ITObject param, TaurusClient client) {
- ITArray cardList = param.getTArray("cards");
- List cardObjs = new ArrayList<>();
- if (cardList.size() != 0) {
- cardObjs = CardUtil.toList(cardList);
- }
- paoDekuaiCardInhand.addAll(cardObjs);
-
- return null;
- }
-
- /**
- * 跑的快出牌广播
- *
- * @param param 消息参数
- * @return
- */
- public String paoDekuaiChupaiGuangBo(ITObject param) {
- card_list = param.getTObject("card_obj");
- guangboseat = param.getInt("player");
- remain = param.getInt("remain"); //剩余牌数量
- saveRemainHistory(guangboseat, remain);
-
-
-
- return null;
- }
-
- public void saveRemainHistory(int guangboseat, int remain) {
- if (!seatRemainHistory.containsKey(guangboseat)) {
- seatRemainHistory.put(guangboseat, new ArrayList<>());
- }
- seatRemainHistory.get(guangboseat).add(remain);
- }
-
-
-}
diff --git a/libs/robot_common/src/main/java/hunan/HuNanZhuanZhuan.java b/libs/robot_common/src/main/java/hunan/HuNanZhuanZhuan.java
deleted file mode 100644
index eb5687d..0000000
--- a/libs/robot_common/src/main/java/hunan/HuNanZhuanZhuan.java
+++ /dev/null
@@ -1,338 +0,0 @@
-package hunan;
-
-import com.game.Util;
-import com.taurus.core.entity.ITArray;
-import com.taurus.core.entity.ITObject;
-import com.taurus.core.entity.TObject;
-import com.taurus.core.util.StringUtil;
-import taurus.client.Message;
-import taurus.client.TaurusClient;
-import taurus.util.CardUtil;
-import taurus.util.ZhuanZhuanSuanFaTest;
-
-import java.util.*;
-
-public class HuNanZhuanZhuan {
-
- public static int zhuanZhuanCard = 0;
-
- //湖南转转麻将手牌
- private List zhuanZhuanCardInhand = new ArrayList();
-
-
- //打出的牌
- private List zhuanZhuanchuguopai = new ArrayList<>();
-
-
- private static ZhuanZhuanSuanFaTest zhuanZhuanFaTest = new ZhuanZhuanSuanFaTest();
-
-
-
- // 玩家座位号
- public static int seat = 0;
-
- // 会话标识
- public static String session = "";
- // 访问令牌
- public static String token = "";
-
- public List getZhuanZhuanCardInhand() {
- return zhuanZhuanCardInhand;
- }
-
- public List getZhuanZhuanchuguopai() {
- return zhuanZhuanchuguopai;
- }
-
- /**
- * 初始化手牌协议 811
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public String cardInHead(String command, Message message, TaurusClient client ) {
- if (command.equalsIgnoreCase("811")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-// {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");
- for (int i = 0; i < cardList.size(); i++) {
- zhuanZhuanCardInhand.add(cardList.getInt(i));
- }
- if (zhuanZhuanCardInhand.size() > 13) {
- outCard(client);
- if (!zhuanZhuanCardInhand.isEmpty()) {
- System.out.println("机器人:" + param.getInt("seat") + "为庄家,需要出牌1111" + ",牌为:" + zhuanZhuanCardInhand.get(0));
- } else {
- System.out.println("机器人:" + param.getInt("seat") + "为庄家,需要出牌1111,但手牌为空");
- }
- }
- System.out.println("机器人:" + param.getInt("bank_seat") + "初始化手牌" + ",牌为:" + zhuanZhuanCardInhand.toString());
-
- }
- return null;
- }
-
-
- // ... existing code ...
- /**
- * 出牌方法
- *
- */
- public void outCard(TaurusClient client) {
- //麻将出牌
- String zhuanzhaunOutCard = zhuanZhuanFaTest.outCardSuanFa(zhuanZhuanCardInhand, zhuanZhuanCard);
-
- ITObject params = TObject.newInstance();
- int cardToOut;
- if (StringUtil.isNotEmpty(zhuanzhaunOutCard)) {
- cardToOut = Integer.parseInt(zhuanzhaunOutCard);
- }else {
- cardToOut = zhuanZhuanCardInhand.get(0);
- }
- params.putString("session", session + "," + token);
-
- params.putInt("card", cardToOut);
- int outCountBefore = zhuanZhuanchuguopai.size();
-
- if (outCountBefore >=1){
- List cardsToSend = zhuanZhuanchuguopai.subList(0, outCountBefore);
- params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
- }
- params.putTArray("card_list", CardUtil.maJiangToTArray(zhuanZhuanCardInhand));
- zhuanZhuanchuguopai.add(cardToOut);
- System.out.println("机器人出牌: " + cardToOut);
- zhuanZhuanCardInhand.remove(Integer.valueOf(cardToOut));
- System.out.println("目前机器人剩余手牌:" + zhuanZhuanCardInhand.toString());
-
- client.send("611", params, response -> {
- System.out.println("出牌成功: " + response.returnCode);
- });
-
- }
-// ... existing code ...
-
-
-
-
-
- /**
- * 出牌广播协议 812
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public static String drawCard(String command, Message message) {
- if (command.equalsIgnoreCase("812")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
- zhuanZhuanCard = param.getInt("card");
- System.out.println("出牌广播" + zhuanZhuanCard);
- System.out.println("座位号:" + param.getInt("seat") + "的用户出牌:" + param.getInt("card"));
- }
- return null;
- }
-
-
- /**
- * 摸牌协议 819
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public String getCard(String command, Message message) {
- if (command.equalsIgnoreCase("819")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106}
- int card = param.getInt("card");
- System.out.println("轮到座位号:" + param.getInt("seat") + "的用户摸牌" + ",牌为:" + card);
- if (param.getInt("player") != null) {
- zhuanZhuanCardInhand.add(card);
-
- // 添加摸牌分析逻辑
- System.out.println("\n===== 摸牌分析开始 =====");
-
- // 创建包含摸牌后的手牌副本
- List tempHand = new ArrayList<>(zhuanZhuanCardInhand);
- tempHand.sort(Integer::compareTo);
-
- // 调用算法类进行摸牌分析
- if (zhuanZhuanFaTest != null) {
- boolean isTing = zhuanZhuanFaTest.analyzeDrawCard(zhuanZhuanCardInhand, card);
-
- // 如果摸牌后可以听牌,记录信息
- if (isTing) {
- System.out.println("\n摸牌后已进入听牌状态!");
- }
-
- // 分析打出哪张牌可以听牌
- Map> discardToTingMap = zhuanZhuanFaTest.findDiscardToTing(tempHand);
- if (discardToTingMap != null && !discardToTingMap.isEmpty()) {
- System.out.println("可打出后听牌的牌数量: " + discardToTingMap.size());
- }
- }
-
- System.out.println("===== 摸牌分析结束 =====");
-// cardInhand.add(104);
- }
- }
- return null;
- }
-
- public static String changePlayer(String command, Message message) {
- if (command.equalsIgnoreCase("820")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
- System.out.println("出牌权转移到座位号:" + param.getInt("seat") + "的用户");
- }
- return null;
- }
-
-
- /**
- * 处理杠碰胡操作
- *
- * @param param 消息参数
- * @return
- */
- public String actionCard(ITObject param,TaurusClient client) {
- //获取碰杠胡参数 type 和id 后续算法接入,是否能让碰和杠
- ITArray tipList = param.getTArray("tip_list");
- int id = 0;
- int type = 0;
- int opcard = 0;
- ITObject params = TObject.newInstance();
- if (tipList != null && tipList.size() > 0) {
- TObject firstTip = (TObject) tipList.get(0).getObject();
- id = firstTip.getInt("id");
- type = firstTip.getInt("type");
- opcard = firstTip.getTArray("opcard").getInt(0);
- System.out.println("id ++ " + id);
- System.out.println("type ++ " + type);
- System.out.println("机器人收到牌:" + opcard + ",当前手牌:" + zhuanZhuanCardInhand);
- }
- //弃 是根据算法选择是否要弃掉 不进行碰杠胡
- //params.putInt("qi", 0);
- //params.putInt("id", 0);
-
- // 如果是碰操作,使用算法判断是否应该碰
- if (type == 2 && zhuanZhuanFaTest != null) {
- // 复制当前手牌进行分析
- List tempHands = new ArrayList<>(zhuanZhuanCardInhand);
- // 使用算法判断是否应该碰牌
- boolean shouldPong = zhuanZhuanFaTest.shouldPong(opcard, tempHands);
- if (!shouldPong) {
- // 如果算法判断不应该碰,设置放弃操作
- params.putInt("qi", 1);
- params.putInt("id", 0);
- System.out.println("智能决策:不碰该牌,保持手牌灵活性");
-
- client.send("612", params, response -> {
- System.out.println("操作成功: " + response.returnCode);
- });
- return null;
- }
- }
-
- // 如果是杠操作,使用算法判断是否应该杠
- if (type == 3 || type == 4 || type == 5) {
- if (zhuanZhuanFaTest != null) {
- List tempHands = new ArrayList<>(zhuanZhuanCardInhand);
- boolean shouldGang = zhuanZhuanFaTest.shouldGang(opcard, tempHands, type);
- if (!shouldGang) {
- params.putInt("qi", 1);
- params.putInt("id", 0);
- System.out.println("智能决策:不杠该牌,保持手牌灵活性");
-
- client.send("612", params, response -> {
- System.out.println("操作成功: " + response.returnCode);
- });
- return null;
- }
- }
- }
-
- //执行碰牌
- if (type == 2) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(zhuanZhuanCardInhand, opcard, 2);
- System.out.println("执行碰牌:" + opcard);
-// Global.logger.info("删除碰的牌");
- //执行胡牌
- } else if (type == 6) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- System.out.println("执行胡牌:" + opcard);
- //执行吃杠
- } else if (type == 3) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(zhuanZhuanCardInhand, opcard, 3);
- System.out.println("执行吃杠:" + opcard);
- //执行自杠
- } else if (type == 4) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(zhuanZhuanCardInhand, opcard, 4);
- System.out.println("执行自杠:" + opcard);
- // 碰后补杠
- } else if (type == 5) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(zhuanZhuanCardInhand, opcard, 1);
- System.out.println("执行碰后补杠:" + opcard);
- }
-
-// cardInhand.remove(0);
-// cardInhand.remove(1);
- System.out.println("执行id为:" + 0 + "的操作");
-
- client.send("612", params, response -> {
- System.out.println("操作成功: " + response.returnCode);
- });
- return null;
- }
-
- /**
- * 删除出过的牌组
- *
- * @param param
- * @return
- */
- public String shanchuchuguopai(ITObject param) {
- if (param == null) {
- return null;
- }
- Integer card = param.getInt("card"); // 操作牌值
- Integer type = param.getInt("type"); // 操作类型
- Integer from_seat = param.getInt("from_seat"); // 牌来源座位
- System.out.println("删除出过的牌组 card " + card);
- System.out.println("删除出过的牌组 type " + type);
- System.out.println("删除出过的牌组 from_seat " + from_seat);
- System.out.println("机器人 seat " + seat);
-
- if (type == 2 || type == 3 || type == 5) { // 碰,杠
- zhuanZhuanchuguopai.remove(Integer.valueOf(card));
- System.out.println("删除出过的牌组 成功");
- }
- return null;
- }
-}
diff --git a/libs/robot_common/src/main/java/hunan/JiQiRens.java b/libs/robot_common/src/main/java/hunan/JiQiRens.java
deleted file mode 100644
index 638c5a9..0000000
--- a/libs/robot_common/src/main/java/hunan/JiQiRens.java
+++ /dev/null
@@ -1,1725 +0,0 @@
-package hunan;
-
-
-import com.game.Util;
-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.Logger;
-import com.taurus.core.util.StringUtil;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.ScanParams;
-import redis.clients.jedis.ScanResult;
-import taurus.client.*;
-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.stream.Collectors;
-
-public class JiQiRens {
-
-
- private final static Logger log;
-
- static {
- log = Logger.getLogger(JiQiRens.class);
- }
-
-
- // 扣点点玩家手牌
- public static List cardInhand = new ArrayList();
-
- //使用数量
- public static Map count = new HashMap();
-
- //扣点点别人打的牌
- private String card = "";
-
- // 玩家座位号
- public static int seat = 0;
- // 玩家ID
- // 登录密码
- public static String password = "123456";
- // 会话标识
- private String session = "";
- // 访问令牌
- public String token = "";
- // 玩法ID
- public String wanfaId = "";
-
- public int tuichutime = 0;
-
- // 客户端连接对象
- private 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 HuNanChangShaNew huNanChangShaNew = new HuNanChangShaNew();//新的机器人处理对象
-
-
- private TinHuChi tinHuChi = new TinHuChi();
-
-
- 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<>();
-
-
-
- //圈子id
-// public static int groupId = 0;
-
- //房间id
-// public static String roomId = "";
-
-
- /**
- * TCP测试方法,用于建立客户端连接并处理游戏事件
- *
- * @throws Exception
- */
- public void tcp_test(int playerId, Integer pid, int groupId) throws Exception {
- Jedis jedis11 = Redis.use("group1_db11").getJedis();
- Jedis jedis0 = Redis.use().getJedis();
- String playKey = "g{" + groupId + "}:play:" + pid;
-
-
- try {
- Set roomIds = jedis0.keys("room:*");
-// Set roomIds = scanRooms(jedis0, "room:*");
- String roomKey = "";
- if (jedis11.hget(playKey, "leftover_robot") != null) {
- if (wanfaId.equals("")) {
- Boolean is_match = false;
- //查询有房间的时候。房间里的玩法 和 传递过来需要建的玩法是否相等,不相等代表没有这个玩法,需要建立
- for (String id : roomIds) {
- String roomId = id.substring(id.indexOf(":") + 1);
- roomKey = "room:" + roomId;
- String gpid = jedis0.hget(roomKey, "gpid");
-
- if (gpid != null) {
- if (Integer.parseInt(gpid) == pid) {
- is_match = true;
- }
-
- }
- }
-
- //没有房间,或者房间内的玩法还没有现在传递需要建立的玩法的时候 需要建立房间
- if (roomIds.size() == 0 || !is_match) {
- ITObject object = null;
- AccountBusiness accountBusiness = null;
- accountBusiness = new AccountBusiness();
- // 登录获取session跟token
-
- if (jedis0.keys("{user}:" + playerId + "_token").size() != 0) {
-
-
- Set keys1 = jedis0.keys("{user}:" + playerId + "_token");
- if (keys1 == null) {
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- } else {
- Set keys = jedis0.smembers("{user}:" + playerId + "_token");
- List keyList = new ArrayList<>(keys);
- session = "{user}:" + playerId;
- token = keyList.get(0);
-
- }
- } else {
-
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- }
-
- Object room = GroupRoomBusiness.matchRoom(groupId, pid, session, "Android", false);
- String game = jedis0.hget(String.valueOf(room), "game");
- wanfaId = String.valueOf(game);
-
- }
- }
- //满人房间玩法
- List manrenwanfa = new ArrayList<>();
-
- String[] playerIds2 = null;
- for (String id : roomIds) {
- String roomId = id.substring(id.indexOf(":") + 1);
- String roomKeys = "room:" + roomId;
- if (jedis0.hget(roomKeys, "players") != null) {
- String players = jedis0.hget(roomKeys, "players");
- String players1 = players.substring(1, players.length() - 1);
- playerIds2 = players1.split(",");
- if (playerIds2.length == 2) {
- manrenwanfa.add(jedis0.hget(roomKeys, "gpid"));
- }
- }
- }
-
-
- List> xuyaojianlifangjian = new ArrayList<>();
- for (String id : roomIds) {
- String roomId = id.substring(id.indexOf(":") + 1);
- String roomKeys = "room:" + roomId;
- if (jedis0.hget(roomKeys, "players") != null && jedis0.hget(roomKeys, "gpid") != null) {
- String gpid = jedis0.hget(roomKeys, "gpid");
- String players = jedis0.hget(roomKeys, "players");
- if (players.equals("[]")) {
- xuyaojianlifangjian.add(Arrays.asList(gpid, players));
- } else {
- String players1 = players.substring(1, players.length() - 1);
- String[] playerIds9 = players1.split(",");
- xuyaojianlifangjian.add(Arrays.asList(gpid, String.valueOf(playerIds9.length)));
- }
- }
-
- if ( jedis0.hget(roomKeys, "gpid") != null){
- String gpid = jedis0.hget(roomKeys, "gpid");
- if (jedis0.hget(roomKeys, "players") == null) {
- xuyaojianlifangjian.add(Arrays.asList(gpid, "5"));
-
- }
- }
-
- }
-
- Set excludedKeys = xuyaojianlifangjian.stream()
- .filter(list -> {
- String value = list.get(1);
- return value.equals("[]") || value.equals("1") || value.equals("5");
- })
- .map(list -> list.get(0))
- .collect(Collectors.toSet());
-
-
- List> filteredResult = xuyaojianlifangjian.stream()
- .filter(list -> manrenwanfa.contains(list.get(0)))
- .filter(list -> !excludedKeys.contains(list.get(0)))
- .collect(Collectors.toList());
-
-
- List keys10 = filteredResult.stream()
- .map(list -> list.get(0)) // 获取每个list的第一个元素(key)
- .collect(Collectors.toList());
-
-
-
- List robotIdsList1 = new ArrayList<>();
-
- String sql3 = String.format("SELECT id FROM `account` WHERE jiqiren=9998 and start = 0");
- ITArray robotId3 = DataBase.use().executeQueryByTArray(sql3);
-
- for (int j = 0; j < robotId3.size(); j++) {
- robotIdsList1.add(robotId3.getTObject(j).getInt("id"));
- }
-
-
- int userIndex = 0;
- for (String s : keys10) {
-
- String groupKeys = "g{" + groupId + "}:play:" + s;
- if (jedis11.hget(groupKeys, "leftover_robot") != null) {
- String shengyu = jedis11.hget(groupKeys, "leftover_robot");
- if (Integer.parseInt(shengyu) > 0 && userIndex < robotIdsList1.size()) {
- Integer playerid = robotIdsList1.get(userIndex);
- userIndex++;
-
- ITObject object = null;
- AccountBusiness accountBusiness = null;
- accountBusiness = new AccountBusiness();
-
- // 登录获取session跟token
- if (jedis0.keys("{user}:" + playerid + "_token").size() != 0) {
- Set keys1 = jedis0.keys("{user}:" + playerid + "_token");
- if (keys1 == null) {
- object = accountBusiness.idPasswordLogin(playerid, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- } else {
- Set keys = jedis0.smembers("{user}:" + playerid + "_token");
- List keyList = new ArrayList<>(keys);
- session = "{user}:" + playerid;
- token = keyList.get(0);
- }
- } else {
- object = accountBusiness.idPasswordLogin(playerid, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- }
-
-
- Object roomkey = GroupRoomBusiness.matchRoom(groupId, Integer.parseInt(s), session, "Android", false);
- String game = jedis0.hget(String.valueOf(roomkey), "game");
- wanfaId = String.valueOf(game);
- }
- }
- }
-
- String[] playerIds = null;
- String leftover_robot = jedis11.hget(playKey, "leftover_robot");
- if (Integer.parseInt(leftover_robot) > 0) {
- //真人等机器人游戏id赋值
- for (String id : roomIds) {
- String roomId = id.substring(id.indexOf(":") + 1);
- roomKey = "room:" + roomId;
-
- String players = jedis0.hget(roomKey, "players");
- String gpid = jedis0.hget(roomKey, "gpid");
-
- String roKey = "g{" + groupId + "}:play:" + gpid;
- String leftover_robot1 = jedis11.hget(roKey, "leftover_robot");
-
- if (players != null && !players.equals("[]")) {
- players = players.substring(1, players.length() - 1);
- playerIds = players.split(",");
- List robotIdsList = new ArrayList<>();
- //拿到所有的机器人
- String sql2 = String.format("SELECT id FROM `account` WHERE jiqiren=9998");
- ITArray robotId2 = DataBase.use().executeQueryByTArray(sql2);
-
- for (int j = 0; j < robotId2.size(); j++) {
- robotIdsList.add(robotId2.getTObject(j).getInt("id"));
- }
- for (String s : playerIds) {
-
- if (leftover_robot1 != null) {
- if (playerIds.length == 1 && !robotIdsList.contains(Integer.parseInt(s)) && Integer.parseInt(leftover_robot1) > 0) {
-
- wanfaId = jedis0.hget(roomKey, "game");
-
- }
- }
- }
- }
- }
-
-
- if (wanfaId.equals("")) {
- for (String id : roomIds) {
- String roomId = id.substring(id.indexOf(":") + 1);
- String roomKeys1 = "room:" + roomId;
- if (jedis0.hget(roomKeys1, "gpid") != null) {
- String gpid = jedis0.hget(roomKeys1, "gpid");
-
- if (pid == Integer.parseInt(gpid)) {
- wanfaId = jedis0.hget(roomKeys1, "game");
- }
- }
- }
- }
-
- System.out.println(wanfaId);
- 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);
- }
-//
- if ("66".equalsIgnoreCase(wanfaId)) {
- client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp);
- }
- client.connect();
-// }
-
- //连接根据不同的玩法id 配置不同的连接
-
-
- //这里是机器人主动进入空房间
- Set roomIds1 = jedis0.keys("room:*");
-
-
- for (String id : roomIds1) {
- String roomId = id.substring(id.indexOf(":") + 1);
- roomKey = "room:" + roomId;
- if (jedis0.hget(roomKey, "gpid") != null) {
- String gpid = jedis0.hget(roomKey, "gpid");
- String playKey2 = "g{" + groupId + "}:play:" + gpid;
-
- String roomPidKey = null;
- boolean flag = false;
- if (jedis0.hget(roomKey, "players") == null) {
-
-
- roomKey = "room:" + roomId;
- roomPidKey = jedis0.hget(roomKey, "gpid");
-
- if (jedis0.hget(roomKey, "game") != null) {
- String gameId = jedis0.hget(roomKey, "game");
-
- if (wanfaId.equals(gameId)) {
-
- flag = true;
- }
- }
- }
-
- String players = jedis0.hget(roomKey, "players");
-
-
- if (jedis11.hget(playKey2, "leftover_robot") != null) {
- String leftover_robot1 = jedis11.hget(playKey2, "leftover_robot");
- if (players == null && Integer.parseInt(roomPidKey) == pid && Integer.parseInt(leftover_robot1) > 0 && flag) {
-
-
- ITObject object = null;
- AccountBusiness accountBusiness = null;
- accountBusiness = new AccountBusiness();
- // 登录获取session跟token
- if (jedis0.keys("{user}:" + playerId + "_token").size() != 0) {
- Set keys1 = jedis0.keys("{user}:" + playerId + "_token");
- if (keys1 == null) {
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- } else {
- Set keys = jedis0.smembers("{user}:" + playerId + "_token");
- List keyList = new ArrayList<>(keys);
- session = "{user}:" + playerId;
- token = keyList.get(0);
- }
- } else {
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- }
-
- String group = jedis0.hget(roomKey, "group");
- ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(group), roomKey, session, null);
- joinRoom(playerId); //进入房间
- ready(); //准备
- String playKey1 = "g{" + groupId + "}:play:" + roomPidKey;
-
-
-// //增加使用数量
- Integer key = Integer.valueOf(roomPidKey);
-
- count.put(key, count.getOrDefault(key, 0) + 1);
-
-
- jedis11.hincrBy(playKey1, "leftover_robot", -1);
- String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 1, playerId);
- DataBase.use().executeUpdate(sql);
-
-
- }
- }
- }
-
-
- roomKey = "room:" + roomId;
- if (jedis0.hget(roomKey, "gpid") != null) {
- String gpid = jedis0.hget(roomKey, "gpid");
- String playKey2 = "g{" + groupId + "}:play:" + gpid;
-
- String roomPidKey = null;
- boolean flag = false;
- if (jedis0.hget(roomKey, "players") != null) {
- if (jedis0.hget(roomKey, "players").equals("[]")) {
-
- roomKey = "room:" + roomId;
- roomPidKey = jedis0.hget(roomKey, "gpid");
- if (jedis0.hget(roomKey, "game") != null) {
-
- String gameId = jedis0.hget(roomKey, "game");
- if (wanfaId.equals(gameId)) {
- flag = true;
- }
- }
- }
- String players = jedis0.hget(roomKey, "players");
-
-
- if (jedis11.hget(playKey2, "leftover_robot") != null) {
- String leftover_robot1 = jedis11.hget(playKey2, "leftover_robot");
- if (players.equals("[]") && Integer.parseInt(roomPidKey) == pid && Integer.parseInt(leftover_robot1) > 0 && flag) {
-
- ITObject object = null;
- AccountBusiness accountBusiness = null;
- accountBusiness = new AccountBusiness();
- // 登录获取session跟token
- if (jedis0.keys("{user}:" + playerId + "_token").size() != 0) {
- Set keys1 = jedis0.keys("{user}:" + playerId + "_token");
- if (keys1 == null) {
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- } else {
- Set keys = jedis0.smembers("{user}:" + playerId + "_token");
- List keyList = new ArrayList<>(keys);
- session = "{user}:" + playerId;
- token = keyList.get(0);
-
- }
- } else {
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- }
-
- String group = jedis0.hget(roomKey, "group");
- ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(group), roomKey, session, null);
- joinRoom(playerId); //进入房间
- ready(); //准备
- String playKey1 = "g{" + groupId + "}:play:" + roomPidKey;
-
-
-// //增加使用数量
- Integer key = Integer.valueOf(roomPidKey);
-
- count.put(key, count.getOrDefault(key, 0) + 1);
-
-
- jedis11.hincrBy(playKey1, "leftover_robot", -1);
- String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 1, playerId);
- DataBase.use().executeUpdate(sql);
-
-
- }
- }
-
- }
-
- }
-
-
- }
-
- // 添加事件监听器处理网络消息
- 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 ("93".equalsIgnoreCase(wanfaId)) { //扣点点
- if ("812".equalsIgnoreCase(command)) { //出牌广播
- sleepTime(1000);
- drawCard(command, message);
- } else if ("820".equalsIgnoreCase(command)) {
- changePlayer(command, message);
- } else if ("819".equalsIgnoreCase(command)) { //摸牌
- getCard(command, message);
- } else if ("811".equalsIgnoreCase(command)) { //初始化手牌
- cardInHead(command, message, wanfaId);
- } else if ("813".equalsIgnoreCase(command)) { //出牌,牌权
- sleepTime(2000);
- outCard(command, message, wanfaId);
- } else if ("817".equalsIgnoreCase(command)) {
- ready();
- //杠碰胡通知协议
- } else if ("814".equalsIgnoreCase(command)) {
- sleepTime(2000);
- actionCard(param);
- //doGang杠后补牌 补杠事件
- } else if ("838".equalsIgnoreCase(command)) {
- sleepTime(2000);
- buGang(param);
- }
- } else 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)) {
- //长沙麻将 机器人处理事件
-
- //[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);
- } 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,null,null);
- } 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)) {
- Jedis jedis22 = Redis.use().getJedis();
- sleepTime(3000);
-
- ITObject params = TObject.newInstance();
- String[] playerIds2 = null;
-
-
- Set roomIds = jedis22.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 (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) {
- for (String s : playerIds2) {
- if (robotIdsList.contains(Integer.parseInt(s))) { //房间里的人是机器人
- String gpid = jedis22.hget(roomKey, "gpid");
- String gpId = jedis22.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 -> {
-
- });
-
- }
- }
- }
-
- }
- }
- }
- }
-
- 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 {
- }
- }
- });
-
-
- //这里是机器人主动找真人房间进入
- for (String id : roomIds) {
- String roomId = id.substring(id.indexOf(":") + 1);
- roomKey = "room:" + roomId;
- if (jedis0.hget(roomKey, "gpid") != null) {
- String gpid = jedis0.hget(roomKey, "gpid");
- String players1 = jedis0.hget(roomKey, "players");
-
- if (players1 != null && !players1.equals("[]")) {
-
- String players = jedis0.hget(roomKey, "players");
- players = players.substring(1, players.length() - 1);
-
- String[] playerIds1 = players.split(",");
-
- String sql2 = "SELECT id FROM `account` WHERE jiqiren=9998";
- ITArray robotId2 = DataBase.use().executeQueryByTArray(sql2);
-
- 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];
- List robotIdsList = new ArrayList<>();
-
- for (int j = 0; j < robotId2.size(); j++) {
- robotIdsList.add(robotId2.getTObject(j).getInt("id"));
- }
-
- roomKey = "room:" + roomId;
- String gpid2 = jedis0.hget(roomKey, "gpid");
- String playKey2 = "g{" + groupId + "}:play:" + gpid2;
- String leftover_robot1 = jedis11.hget(playKey2, "leftover_robot");
-
- if (!robotIdsList.contains(Integer.parseInt(playeid)) && Integer.parseInt(gpid2) == pid && Integer.parseInt(leftover_robot1) > 0) {
- ITObject object = null;
- AccountBusiness accountBusiness = null;
- accountBusiness = new AccountBusiness();
- // 登录获取session跟token
-
- if (jedis0.keys("{user}:" + playerId + "_token").size() != 0) {
-
- Set keys1 = jedis0.keys("{user}:" + playerId + "_token");
- if (keys1 == null) {
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- } else {
- Set keys = jedis0.smembers("{user}:" + playerId + "_token");
- List keyList = new ArrayList<>(keys);
- session = "{user}:" + playerId;
- token = keyList.get(0);
-
- }
- } else {
-
- object = accountBusiness.idPasswordLogin(playerId, password);
- ITObject validate = TObject.newInstance();
- validate.putString("token", object.getString("token"));
- token = object.getString("token");
- session = accountBusiness.getSession();
- }
-
-
- String readyTime = jedis0.hget(roomKey, "readyTime");
-// long readyTime1 = Long.parseLong(readyTime);
- //判断如果readyTime已经过去七秒
-
- //判断准备时间,只是要取出准备时间超过七秒的房间
-// if (System.currentTimeMillis() - readyTime1 > 1000) {
- String roomKey1 = "room:" + roomId;
- String group = jedis0.hget(roomKey1, "group");
- ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(group), roomKey1, session, null);
- joinRoom(playerId); //进入房间
- ready(); //准备
- String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 1, playerId);
- DataBase.use().executeUpdate(sql);
- String playKey1 = "g{" + groupId + "}:play:" + pid;
-
- //增加使用数量
- Integer key = Integer.valueOf(pid);
-
- count.put(key, count.getOrDefault(key, 0) + 1);
-
- jedis11.hincrBy(playKey1, "leftover_robot", -1);
-// }
- }
-
- }
- }
- }
- }
- }
-
- }
-
-
-// ready(); //准备
- }
- }
-
-
- } catch (Exception e) {
-
- e.printStackTrace();
- } finally {
-
- jedis11.close();
- jedis0.close();
- }
-
- }
-
-
- /**
- * 出牌广播协议 812
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public String drawCard(String command, Message message) {
- if (command.equalsIgnoreCase("812")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
- card = param.getString("card");
-
- }
- return null;
- }
-
- /**
- * 位置转换协议 820
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public static String changePlayer(String command, Message message) {
- if (command.equalsIgnoreCase("820")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-
-// {seat=2}
-
- }
- return null;
- }
-
- /**
- * 摸牌协议 819
- *
- * @param command 协议号
- * @param message 消息对象
- * @return
- */
- public static String getCard(String command, Message message) {
- if (command.equalsIgnoreCase("819")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106}
-
- if (param.getInt("seat") != null && seat == param.getInt("seat")) {
- cardInhand.add(param.getInt("card"));
-// cardInhand.add(104);
- }
- }
- return null;
- }
-
- /**
- * 扣点点 初始化手牌协议 811
- *
- * @param command 协议号
- * @param message 消息对象
- * @param wanfaId 玩法ID
- * @return
- */
- public String cardInHead(String command, Message message, String wanfaId) {
- if (command.equalsIgnoreCase("811")) {
- ITObject param = message.param;
- if (param == null) {
- return null;
- }
-// {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");
- for (int i = 0; i < cardList.size(); i++) {
- cardInhand.add(cardList.getInt(i));
- }
- if (cardInhand.size() > 13) {
- outCard(command, message, wanfaId);
-
-
- }
-
-
- }
- return null;
- }
-
- /**
- * 出牌方法
- *
- * @param command 协议号
- * @param message 消息对象
- * @param wanfaId 玩法ID
- * @return
- */
- public String outCard(String command, Message message, String wanfaId) {
-
-
-
-
- ITObject params = TObject.newInstance();
- params.putString("session", session + "," + token);
- params.putInt("card1", 0);
- params.putInt("card", cardInhand.get(0));
- cardInhand.remove(0);
-
- client.send("611", params, response -> {
-
- });
- return null;
- }
-
- /**
- * 处理杠碰胡操作
- *
- * @param param 消息参数
- * @return
- */
- public String actionCard(ITObject param) {
- //获取碰杠胡参数 type 和id 后续算法接入,是否能让碰和杠
- ITArray tipList = param.getTArray("tip_list");
- int id = 0;
- int type = 0;
- int opcard = 0;
- ITObject params = TObject.newInstance();
- if (tipList != null && tipList.size() > 0) {
- TObject firstTip = (TObject) tipList.get(0).getObject();
- id = firstTip.getInt("id");
- type = firstTip.getInt("type");
- opcard = firstTip.getTArray("opcard").getInt(0);
-
-
- }
- //弃 是根据算法选择是否要弃掉 不进行碰杠胡
- //params.putInt("qi", 0);
- //params.putInt("id", 0);
-
- //执行碰牌
- if (type == 2) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(cardInhand, opcard, 2);
-
-// Global.logger.info("删除碰的牌");
- //执行胡牌
- } else if (type == 6) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
-
- //执行吃杠
- } else if (type == 3) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(cardInhand, opcard, 3);
-
- //执行自杠
- } else if (type == 4) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(cardInhand, opcard, 4);
-
- // 碰后补杠
- } else if (type == 5) {
- params.putString("session", session + "," + token);
- params.putInt("qi", 0);
- params.putInt("id", 1);
- Util.removeCard(cardInhand, opcard, 1);
-
- }
-
-// cardInhand.remove(0);
-// cardInhand.remove(1);
-
-
- client.send("612", params, response -> {
-
- });
- return null;
- }
-
- // 优化方案:使用 scan 替代 keys
- public Set scanRooms(Jedis jedis, String pattern) {
- Set keys = new HashSet<>();
- String cursor = "0";
- ScanParams scanParams = new ScanParams().match(pattern).count(100);
-
- do {
- ScanResult scanResult = jedis.scan(cursor, scanParams);
- keys.addAll(scanResult.getResult());
- cursor = String.valueOf(scanResult.getCursor());
- } while (!cursor.equals("0"));
-
- return keys;
- }
-
- /**
- * 处理补杠操作
- *
- * @param param 消息参数
- */
- public void buGang(ITObject param) {
- Integer card = param.getInt("card");
- ITObject params = TObject.newInstance();
- params.putInt("card", card);
- client.send("839", params, response -> {
-
- });
- }
-
-
- /**
- * 准备方法
- *
- * @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;
- }
-
-
- /**
- * 加入房间方法
- *
- * @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();
- }
- }
-
- /**
- * 程序入口点
- *
- * @param args
- * @throws Exception
- */
-// public static void main(String[] args) throws Exception {
-// try {
-// PluginService.me().loadConfig();
-// } catch (Exception e1) {
-// e1.printStackTrace();
-// }
-//
-//// NetManager.debug_print = false;
-//// NetManager.TIMEOUT_TIME = 10;
-//// NetManager.VERSION = 10;
-//
-// tcp_test();
-//
-//
-// while (true) {
-// NetManager.processEvents();
-// try {
-// Thread.sleep(8);
-// } catch (InterruptedException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// }
-// }
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/HttpClient.java b/libs/robot_common/src/main/java/taurus/client/HttpClient.java
deleted file mode 100644
index f7ec741..0000000
--- a/libs/robot_common/src/main/java/taurus/client/HttpClient.java
+++ /dev/null
@@ -1,226 +0,0 @@
-package taurus.client;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.ConnectException;
-import java.net.HttpURLConnection;
-import java.net.SocketTimeoutException;
-import java.net.URL;
-import java.util.LinkedList;
-import java.util.Queue;
-
-import com.taurus.core.entity.ITObject;
-import com.taurus.core.entity.TObject;
-import com.taurus.core.util.ICallback;
-import com.taurus.core.util.ByteArray;
-import com.taurus.core.util.Logger;
-import com.taurus.core.util.StringUtil;
-import com.taurus.core.util.Utils;
-
-import taurus.client.TaurusClient.ConnectionProtocol;
-
-
-
-/**
- * Http缃戠粶璇锋眰澶勭悊绫?
- * @author daixiwei daixiwei15@126.com
- *
- */
-public class HttpClient implements ISocketLayer {
- private static final Logger logger = Logger.getLogger(HttpClient.class);
- private static final byte[] NULL_BYTES = new byte[0];
- private static final String _Method = "POST";
- private static final String _ContentTypeName = "Content-Type";
- private static final String _ContentType = "application/octet-stream";
- private static final String _Result = "$r";
- private static final String _Param = "$p";
- private static final String _Session = "$s";
- private static final String _Version = "$v";
- String _url;
- String _session_id = "";
-
- final Queue _actionQueue = new LinkedList();
-
-
- public HttpClient(String url) {
- _url = url;
- }
-
- private void __sendMsg(Message msg) {
- byte[] bytes = NULL_BYTES;
- ITObject _data = TObject.newInstance();
- _data.putString(_Session, _session_id);
- _data.putInt(_Version, NetManager.VERSION);
- if (msg.useText && msg.param == null) {
- if (StringUtil.isEmpty(msg.textParam)) {
- msg.param = TObject.newInstance();
- } else {
- try {
- msg.param = TObject.newFromJsonData(msg.textParam);
- } catch (Exception e) {
- msg.param = TObject.newInstance();
- }
- }
- }
- _data.putTObject(_Param, msg.param);
- ByteArray buff = new ByteArray(_data.toBinary());
- try {
- buff.compress();
- } catch (Exception e) {
- logger.error(e);
- }
- bytes = buff.bytes();
-
- __requestAsync(msg, bytes);
- }
-
- private void __requestAsync(final Message msg,byte[] bytes) {
- OutputStream out = null;
- InputStream in = null;
- int code = 500;
- HttpURLConnection conn = null;
- try {
-
- URL realUrl = new URL(_url + msg.command);
- conn = (HttpURLConnection) realUrl.openConnection();
- conn.setDoOutput(true);
- conn.setDoInput(true);
- conn.setRequestProperty(_ContentTypeName, _ContentType);
- conn.setUseCaches(false);// Post 璇锋眰涓嶈兘浣跨敤缂撳瓨
- conn.setRequestMethod(_Method);
- conn.setConnectTimeout(NetManager.TIMEOUT_TIME * 1000);
- conn.setReadTimeout(NetManager.TIMEOUT_TIME * 1000);
- conn.connect();
-
-
- out = conn.getOutputStream();
- out.write(bytes);
- if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
- in = conn.getInputStream();
- bytes = Utils.uncompress(in);
- if (bytes!=null) {
-
- ITObject tem = TObject.newFromBinaryData(bytes);
- int result = tem.getInt(_Result);
-
- if (result == 0) {
- ITObject _param = tem.getTObject(_Param);
- msg.param = _param;
- if(msg.useText) {
- msg.textParam = _param.toJson();
- }
- }
- code = result;
-
- }
- }
- } catch (SocketTimeoutException e) {
- logger.error(e);
- code = 102;
- } catch (ConnectException ex1) {
- logger.error(ex1);
- code = 101;
- } catch (Exception ex2) {
- logger.error(ex2);
- code = 500;
- }finally {
- try {
- if (out != null) {
- out.close();
- }
- } catch (IOException ex) {
- logger.error(ex);
- }
- try {
- if (in != null) {
- in.close();
- }
- }catch (IOException ex) {
- logger.error(ex);
- }
- if(conn!=null) {
- conn.disconnect();
- }
- }
- if (msg.callback != null) {
- final MessageResponse response = new MessageResponse();
- response.messageData = msg;
- response.returnCode = code;
- enqueueActionForDispatch(new Runnable() {
- @Override
- public void run() {
- msg.callback.action(response);
- }
- });
- }
-
- }
-
- @Override
- public void connect(String ip, String game) {
-
- }
-
- @Override
- public void disconnect() {
-
- }
-
- private void enqueueActionForDispatch(Runnable action) {
- synchronized (_actionQueue) {
- _actionQueue.offer(action);
- }
- }
-
- @Override
- public void processEvent() {
- while (true) {
- Runnable myAction;
- synchronized (_actionQueue) {
- if (_actionQueue.size() <= 0) {
- break;
- }
- myAction = _actionQueue.poll();
- }
- myAction.run();
- }
- }
-
- public void write(final Message msg) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- __sendMsg(msg);
- }
- }).start();
- }
-
- public int getAveragePingTime() {
- return 1000;
- }
-
- public void setSession(String session) {
- _session_id = session == null ? StringUtil.Empty : session;
- }
-
- public String getSession() {
- return _session_id;
-
- }
-
- @Override
- public void setOnConnect(ICallback onConnect) {
-
- }
-
- @Override
- public void setOnEvent(ICallback onEvent) {
-
- }
-
- @Override
- public ConnectionProtocol getProtocol() {
- return ConnectionProtocol.Web;
- }
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/ISocketLayer.java b/libs/robot_common/src/main/java/taurus/client/ISocketLayer.java
deleted file mode 100644
index 03a2d23..0000000
--- a/libs/robot_common/src/main/java/taurus/client/ISocketLayer.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package taurus.client;
-
-import com.taurus.core.util.ICallback;
-
-import taurus.client.TaurusClient.ConnectionProtocol;
-
-/**
- * 网络协议处理通用接口
- * @author daixiwei daixiwei15@126.com
- *
- */
-public interface ISocketLayer {
- /**
- * 连接服务器
- * @param ip
- * @param game
- */
- public void connect(String ip, String game);
-
- /**
- * 断开连接
- */
- public void disconnect();
-
- /**
- * 处理事件
- */
- public void processEvent();
-
- /**
- * 发送消息
- * @param msg
- */
- public void write(Message msg);
-
- /**
- * get Protocol type
- * @return
- */
- public ConnectionProtocol getProtocol();
-
- /**
- * 设置连接状态回调
- */
- public void setOnConnect(ICallback onConnect);
-
-
- /**
- * 设置事件消息回调E
- */
- public void setOnEvent(ICallback onEvent);
-
- /**
- * 网络延时
- */
- public int getAveragePingTime();
-
- /**
- * 获取服务器Session字符
- */
- public String getSession();
-
- /**
- * 设置服务器Session字符
- * @param session
- */
- public void setSession(String session);
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/Message.java b/libs/robot_common/src/main/java/taurus/client/Message.java
deleted file mode 100644
index d7867e9..0000000
--- a/libs/robot_common/src/main/java/taurus/client/Message.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package taurus.client;
-
-import com.taurus.core.entity.ITObject;
-import com.taurus.core.util.ICallback;
-
-/**
- * 网络协议消息包
- * @author daixiwei daixiwei15@126.com
- *
- */
-public class Message {
- /**
- * 使用文本,不转换ITObject
- */
- public boolean useText;
- /**
- * 网络协议指令Key
- */
- public String command;
-
- /**
- * 参数
- */
- public ITObject param;
- /**
- * 文本数据
- */
- public String textParam;
-
- /**
- * 网络消息回调
- */
- public ICallback callback;
- /**
- * 自定义参数
- */
- public Object data;
- /**
- * 网络包最后写入时间
- */
- public long lastTime;
- /**
- * 网络包返回匹配的GID
- */
- public int gid;
-
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/MessageResponse.java b/libs/robot_common/src/main/java/taurus/client/MessageResponse.java
deleted file mode 100644
index 73beb43..0000000
--- a/libs/robot_common/src/main/java/taurus/client/MessageResponse.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package taurus.client;
-
-/**
- * 缃戠粶娑堟伅鍥炶皟鏁版嵁瀵硅薄
- * @author daixiwei daixiwei15@126.com
- *
- */
-public class MessageResponse {
- /**
- * 娑堟伅鏁版嵁
- */
- public Message messageData;
- /**
- * 杩斿洖缁撴瀯鍊?
- */
- public int returnCode;
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/NetManager.java b/libs/robot_common/src/main/java/taurus/client/NetManager.java
deleted file mode 100644
index eb586c2..0000000
--- a/libs/robot_common/src/main/java/taurus/client/NetManager.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package taurus.client;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 网络管理对象
- * @author daixiwei daixiwei15@126.com
- *
- */
-public class NetManager {
-
- private static List _clientList = new ArrayList();
- private static Map _clientMap = new HashMap();
-
- /**
- * 网络超时时间
- */
- public static int TIMEOUT_TIME = 10;
- /**
- * 网络版本号
- */
- public static int VERSION = 10;
- public static boolean debug_print = false;
-
- static void addNetClient(TaurusClient net) {
- if (net == null) {
- throw new RuntimeException("TaurusClient is null, it can't be added.");
- }
- if (_clientMap.containsKey(net.getId())) {
- throw new RuntimeException("A client with id: " + net.getId() + " already exists! Controller can't be added: " + net);
- }
- synchronized (_clientList) {
- _clientMap.put(net.getId(), net);
- _clientList.add(net);
- }
-
- }
-
- /**
- * The process events
- */
- public static void processEvents() {
- for (int i = 0; i < _clientList.size(); ++i) {
- TaurusClient nc = _clientList.get(i);
- if (nc._kill){
- synchronized (_clientList) {
- _clientMap.remove(nc.getId());
- _clientList.remove(nc);
- }
- i--;
- continue;
- }else{
- nc.processEvent();
- }
- }
-
- }
-
- /**
- * 返回指定的NetClient
- * @param id
- * @return
- */
- public static TaurusClient getNetClient(int id) {
- for (int i = 0; i < _clientList.size(); ++i) {
- TaurusClient nc = _clientList.get(i);
- if (nc.getId() == id)
- return nc;
- }
- return null;
- }
-
- /**
- * 断开指定连接
- * @param id
- */
- public static void killConnection(int id) {
- for (int i = 0; i < _clientList.size(); ++i) {
- TaurusClient nc = _clientList.get(i);
- if (nc.getId() == id) {
- nc.killConnection();
- synchronized (_clientList) {
- _clientMap.remove(id);
- _clientList.remove(nc);
- }
- break;
- }
- }
- }
-
- /**
- * 断开所有连接
- */
- public static void killAllConnection() {
- synchronized (_clientList) {
- for (TaurusClient nc : _clientList) {
- nc.killConnection();
- }
- _clientList.clear();
- _clientMap.clear();
- }
-
- }
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/SocketCode.java b/libs/robot_common/src/main/java/taurus/client/SocketCode.java
deleted file mode 100644
index f49a0fa..0000000
--- a/libs/robot_common/src/main/java/taurus/client/SocketCode.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package taurus.client;
-
-/**
- * Socket code
- * @author daixiwei daixiwei15@126.com
- *
- */
-public enum SocketCode{
- /**
- * 杩炴帴鎴愬姛
- */
- Connect,
- Disconnect,
- /**
- * 鏈煡寮傚父
- */
- Exception,
- /**
- * 杩炴帴鏈嶅姟寮傚父
- */
- ExceptionOnConnect,
- /**
- * 鍙戦€佹暟鎹祦閿欒
- */
- SendError,
- /**
- * 鎺ユ敹鏈嶅姟鍣ㄦ暟鎹祦寮傚父
- */
- ExceptionOnReceive,
- /**
- * 鏈嶅姟鍣ㄨ繛鎺ヨ秴鏃?
- */
- TimeoutDisconnect,
- /**
- * 鏈嶅姟鍣ㄦ柇寮€杩炴帴
- */
- DisconnectByServer,
- /**
- * 瀹㈡埛绔綉缁滃紓甯?
- */
- NetworkException,
- /**
- * 杩炴帴瀹夊叏寮傚父锛屼竴鑸负闃茬伀澧欓樆姝?
- */
- SecurityExceptionOnConnect
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/TaurusClient.java b/libs/robot_common/src/main/java/taurus/client/TaurusClient.java
deleted file mode 100644
index 574cbd5..0000000
--- a/libs/robot_common/src/main/java/taurus/client/TaurusClient.java
+++ /dev/null
@@ -1,354 +0,0 @@
-package taurus.client;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.taurus.core.entity.ITObject;
-import com.taurus.core.events.Event;
-import com.taurus.core.events.EventDispatcher;
-import com.taurus.core.events.IEventListener;
-import com.taurus.core.util.*;
-
-import taurus.client.io.SocketEngine;
-
-
-/**
- * 缃戠粶鏍稿績鍔熻兘澶勭悊绫?
- * @author daixiwei daixiwei15@126.com
- *
- */
-public class TaurusClient {
- private static final Logger logger = Logger.getLogger(TaurusClient.class);
- private int _id;
- private boolean _connect;
- private String _gameId;
- private String _currentIp;
-
- private ISocketLayer _scoket;
- private ThreadManager _threadManager;
-
- private EventDispatcher _dispatcher;
- private Map> _responseMap;
- volatile boolean _kill = false;
- private static int _tempID;
- private int _protocolCompression=100;
-
- private static int _getValidID() {
- return ++_tempID;
- }
-
- /**
- *
- * @param host
- * @param game
- * @param protocol
- */
- public TaurusClient(String host, String game, ConnectionProtocol protocol) {
- ISocketLayer socket = null;
- switch (protocol) {
- case Tcp:
- socket = new SocketEngine(this);
- break;
- case Web:
- socket = new HttpClient(host);
- _connect = true;
- break;
- default:
- socket = new SocketEngine(this);
- break;
- }
- __initialize(host, game, socket);
- }
-
- /**
- *
- * @param host
- * @param game
- * @param socket
- * @param protocol
- */
- public TaurusClient(String host, String game, ISocketLayer socket) {
- __initialize(host, game, socket);
-
- }
-
- /**
- * 娣诲姞浜嬩欢
- * @param eventType
- * @param listener
- */
- public void addEventListener(String eventType, IEventListener listener) {
- _dispatcher.addEventListener(eventType, listener);
- }
-
- /**
- * 绉婚櫎鎵€鏈変簨浠?
- */
- public void removeAllListener() {
- _dispatcher.removeAllListener();
- }
-
- /**
- * 绉婚櫎鎸囧畾浜嬩欢
- * @param eventType
- * @param listener
- */
- public void removeEventListener(String eventType, IEventListener listener) {
- _dispatcher.removeEventListener(eventType, listener);
- }
-
- private void __initialize(String host, String game, ISocketLayer socket) {
- _dispatcher = new EventDispatcher();
- _responseMap = new HashMap>();
- _id = _getValidID();
- NetManager.addNetClient(this);
- _currentIp = host;
- _gameId = game;
- _threadManager = new ThreadManager();
- _threadManager.start();
- _scoket = socket;
- _scoket.setOnConnect(new ICallback() {
- @Override
- public void action(SocketCode code) {
- if (code == SocketCode.Connect)
- _connect = true;
- else
- _connect = false;
- Event evt = new Event(NetClientEvent.Connect);
- evt.setParameter("code", code);
- _dispatcher.dispatchEvent(evt);
- }
- });
- _scoket.setOnEvent(new ICallback() {
- @Override
- public void action(Message msg) {
- if (_connect) {
- Event evt = new Event(NetClientEvent.OnEvent);
- evt.setParameter("msg", msg);
- _dispatcher.dispatchEvent(evt);
- if (NetManager.debug_print){
- String str = getProtocol() == ConnectionProtocol.Web ? "WEB" : "TCP";
- String data_str = msg.useText ? msg.textParam : (msg.param != null ? msg.param.toJson() : "null");
- logger.debug("Event [" + str + "->" + msg.command + "] data:" + data_str);
- }
- }
- }
- });
- }
-
- /**
- * 杩炴帴鏈嶅姟鍣?
- */
- public void connect() {
- _scoket.connect(_currentIp, _gameId);
- }
-
- /**
- * Kill net connection.
- */
- public void killConnection() {
- removeAllListener();
- _responseMap.clear();
- _threadManager.stop();
- _scoket.disconnect();
- _connect = false;
- _kill = true;
- }
-
- /**
- * 鍙戦€佺綉缁滄秷鎭寘
- * @param msg 娑堟伅鏁版嵁瀵硅薄
- */
- protected void send(Message msg) {
- if (msg == null)
- return;
- if (NetManager.debug_print) {
- String str = getProtocol() == ConnectionProtocol.Web ? "WEB" : "TCP";
- String data_str = msg.useText ? msg.textParam : (msg.param != null ? msg.param.toJson() : "null");
- str = "Requst [" + str + "->" + msg.command + "] ->data:" + data_str;
- logger.debug(str);
- }
- if (msg.callback != null) {
- _responseMap.put(msg, msg.callback);
- msg.callback = new ICallback() {
-
- @Override
- public void action(MessageResponse response) {
- ICallback callback = _responseMap.get(response.messageData);
- if (callback == null) {
- return;
- }
- if (NetManager.debug_print){
- String str = getProtocol() == ConnectionProtocol.Web ? "WEB" : "TCP";
- String data_str = msg.useText ? msg.textParam : (msg.param != null ? msg.param.toJson() : "null");
- str = "Response [" + str + "->" + msg.command + "] ->result:"+ response.returnCode + " param:" + data_str;
- logger.debug(str);
- }
- _responseMap.remove(response.messageData);
- callback.action(response);
- }
-
- };
- }
-
- _threadManager.enqueueSend(new ICallback() {
- @Override
- public void action(Message msg) {
- sendData(msg);
- }
- }, msg);
- }
-
-
- /**
- * 鍙戦€佺綉缁滄秷鎭寘
- * @param cmd 缃戠粶鍗忚鎸囦护Key
- * @param param 鍙傛暟
- * @param callback 缃戠粶娑堟伅鍥炶皟
- * @return
- */
- public Message send(String cmd, ITObject param, ICallback callback) {
- Message msg = new Message();
- msg.useText = false;
- msg.command = cmd;
- msg.param = param;
- msg.callback = callback;
- this.send(msg);
- return msg;
- }
-
- /**
- * 鍙戦€佺綉缁滄秷鎭寘
- * @param cmd 缃戠粶鍗忚鎸囦护Key
- * @param text JSON 鏂囨湰
- * @param callback 缃戠粶娑堟伅鍥炶皟
- * @return
- */
- public Message sendText(String cmd, String text, ICallback callback) {
- Message msg = new Message();
- msg.command = cmd;
- msg.textParam = text;
- msg.callback = callback;
- msg.useText = true;
- this.send(msg);
- return msg;
- }
-
- /**
- * 鍙戦€佹暟鎹嚎绋嬫柟娉?
- * @param message
- */
- private void sendData(Message msg) {
- _scoket.write(msg);
- }
-
- /**
- * 澶勭悊浜嬩欢
- */
- void processEvent() {
- if(_scoket!=null) {
- _scoket.processEvent();
- }
- }
-
- /**
- * 娓呯悊鍝嶅簲鍥炶皟
- */
- public void clearResponse() {
- _responseMap.clear();
- }
-
- /**
- * The net client id
- * @return
- */
- public int getId() {
-
- return _id;
-
- }
-
- /**
- * The curren ip
- * @return
- */
- public String getCurrentIp() {
- return _currentIp;
- }
-
- /**
- * The curren Game ID
- * @return
- */
- public String getGameID() {
- return _gameId;
- }
-
- /**
- * 缃戠粶鏄惁宸茶繛鎺?
- * @return
- */
- public boolean isConnected() {
- return _connect;
- }
-
- /**
- * 褰撳墠缃戠粶绫诲瀷
- * @return
- */
- public ConnectionProtocol getProtocol() {
- return _scoket.getProtocol();
- }
-
- /**
- * 缃戠粶寤舵椂
- * @return
- */
- public int getAveragePingTime() {
- return _scoket.getAveragePingTime();
- }
-
- /**
- * 鑾峰彇鏈嶅姟鍣⊿ession瀛楃
- * @return
- */
- public String getSession() {
- return _scoket.getSession();
- }
-
- /**
- * 璁剧疆鏈嶅姟鍣⊿ession瀛楃
- * @param session
- */
- public void setSession(String session) {
- _scoket.setSession(session);
- }
-
- /**
- * 璁剧疆鍘嬬缉闃€鍊?
- * @param protocolCompression
- */
- public void setProtocolCompression(int protocolCompression) {
- _protocolCompression = protocolCompression;
- }
-
- /**
- * 鑾峰彇鍘嬬缉闃€鍊?
- *
- * @return
- */
- public int getProtocolCompression() {
- return _protocolCompression;
- }
-
-
- public static enum ConnectionProtocol {
- Tcp, Web,
- }
-
- public static class NetClientEvent {
- public static final String Connect = "connect";
-
- public static final String OnEvent = "onevent";
- }
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/ThreadManager.java b/libs/robot_common/src/main/java/taurus/client/ThreadManager.java
deleted file mode 100644
index 9b38ce6..0000000
--- a/libs/robot_common/src/main/java/taurus/client/ThreadManager.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package taurus.client;
-
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.Stack;
-
-import com.taurus.core.util.ICallback;
-
-
-
-/**
- * 网络(读/写) 线程管理
- * @author daixiwei daixiwei15@126.com
- *
- */
-public class ThreadManager {
- class MessgaeThread {
- public ICallback _dataDelegate;
-
- public Message _message;
- }
-
- private boolean _running = false;
- private Thread _outThread;
- private boolean _outHasQueuedItems = false;
- private Queue _outThreadQueue = new LinkedList();
- private Object _outQueueLocker = new Object();
- private Stack pool = new Stack();
-
- private MessgaeThread MessgaeThreadGet() {
- if (pool.size() > 0) {
- MessgaeThread msg = pool.pop();
- return msg;
- } else
- return new MessgaeThread();
- }
-
- private void MessgaeThreadReturn(MessgaeThread value) {
- pool.push(value);
- value._dataDelegate = null;
- value._message = null;
- }
-
- private static void sleep(int ms) {
- try {
- Thread.sleep(ms);
- } catch (InterruptedException e) {
-
- }
- }
-
- private void outThread() {
- while (_running) {
- sleep(5);
- if (_outHasQueuedItems) {
- Object obj = _outQueueLocker;
- synchronized (obj) {
- while (_outThreadQueue.size() > 0) {
- MessgaeThread item = _outThreadQueue.poll();
- processOutItem(item);
- }
- _outHasQueuedItems = false;
- }
- }
- }
- }
-
- private void processOutItem(MessgaeThread item) {
- ICallback _dataDelegate = item._dataDelegate;
- Message message = item._message;
- MessgaeThreadReturn(item);
- if (_dataDelegate != null) {
- _dataDelegate.action(message);
- }
- }
-
- public void start() {
- if (_running) {
- return;
- }
- _running = true;
- if (_outThread == null) {
- _outThread = new Thread(new Runnable() {
- @Override
- public void run() {
- outThread();
- }
- });
- _outThread.start();
- _outThread.setName("WriteMessage");
- }
- }
-
- public void stop() {
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- stopThread();
- }
- });
- thread.start();
- }
-
- private void stopThread() {
- _running = false;
-
- if (_outThread != null) {
- _outThread.interrupt();
- }
- _outThread = null;
- }
-
- public void enqueueSend(ICallback callback, Message message) {
- MessgaeThread hashtable = MessgaeThreadGet();
- hashtable._dataDelegate = callback;
- hashtable._message = message;
- Object obj = _outQueueLocker;
- synchronized (obj) {
- _outThreadQueue.offer(hashtable);
- _outHasQueuedItems = true;
- }
- }
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/business/AccountBusiness.java b/libs/robot_common/src/main/java/taurus/client/business/AccountBusiness.java
deleted file mode 100644
index 7bfa172..0000000
--- a/libs/robot_common/src/main/java/taurus/client/business/AccountBusiness.java
+++ /dev/null
@@ -1,344 +0,0 @@
-package taurus.client.business;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import com.data.bean.AccountBean;
-import com.data.bean.GameBean;
-import com.data.cache.AccountCache;
-import com.data.cache.BaseCache;
-import com.data.cache.GameCache;
-import com.data.util.ErrorCode;
-import com.data.util.Utility;
-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.plugin.redis.RedisLock;
-import com.taurus.core.util.Logger;
-import com.taurus.core.util.StringUtil;
-import com.taurus.core.util.Utils;
-import com.taurus.web.Controller;
-import com.taurus.web.WebException;
-
-import redis.clients.jedis.Jedis;
-
-public class AccountBusiness extends Controller {
- private static Logger logger = Logger.getLogger(AccountBusiness.class);
-
- public static String request(String httpUrl, String httpArg) {
- BufferedReader reader = null;
- String result = null;
- StringBuffer sbf = new StringBuffer();
- httpUrl = httpUrl + "?" + httpArg;
-
- try {
- URL url = new URL(httpUrl);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.connect();
- InputStream is = connection.getInputStream();
- reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- String strRead = reader.readLine();
- if (strRead != null) {
- sbf.append(strRead);
- while ((strRead = reader.readLine()) != null) {
- sbf.append("\n");
- sbf.append(strRead);
- }
- }
- reader.close();
- result = sbf.toString();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
-
- public static String md5(String plainText) {
- StringBuffer buf = null;
- try {
- MessageDigest md = MessageDigest.getInstance("MD5");
- md.update(plainText.getBytes());
- byte b[] = md.digest();
- int i;
- buf = new StringBuffer("");
- for (int offset = 0; offset < b.length; offset++) {
- i = b[offset];
- if (i < 0)
- i += 256;
- if (i < 16)
- buf.append("0");
- buf.append(Integer.toHexString(i));
- }
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- return buf.toString();
- }
-
- public static String encodeUrlString(String str, String charset) {
- String strret = null;
- if (str == null)
- return str;
- try {
- strret = java.net.URLEncoder.encode(str, charset);
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- return strret;
- }
-
- private final ITObject fillLoginData(String session, int accountid) {
- ITObject resData = TObject.newInstance();
- ITObject userData = TObject.newInstance();
- resData.putTObject("account", userData);
- resData.putUtfString("session_id", session);
- resData.putTArray("games", getOnlineGames());
- Jedis jedis0 = Redis.use("group1_db0").getJedis();
- try {
- Map map = jedis0.hgetAll(session);
- userData.putInt("id", accountid);
- userData.putInt("diamo", Integer.parseInt(map.get("diamo")));
- userData.putUtfString("nick", map.get("nick"));
- userData.putUtfString("portrait", map.get("portrait"));
- userData.putInt("sex", Integer.parseInt(map.get("sex")));
- userData.putInt("type", Integer.parseInt(map.get("type")));
- int mng = Integer.parseInt(map.get("mng"));
- userData.putInt("mng", mng);
-
- String phone = map.get("phone");
- if (StringUtil.isNotEmpty(phone)) {
- userData.putUtfString("phone", phone);
- }
-
- String address = map.get("address");
- if (StringUtil.isNotEmpty(address)) {
- userData.putUtfString("address", address);
- }
-
- String real_info = map.get("real_info");
- if (StringUtil.isNotEmpty(real_info)) {
- userData.putTObject("real_info", TObject.newFromJsonData(real_info));
- }
- String oldRoom = Utility.getOldRoomV2(jedis0, 0, session, accountid);
- if (StringUtil.isNotEmpty(oldRoom)) {
- String roomid = oldRoom.replace("room:", "");
- String group = jedis0.hget(oldRoom, "group");
- int groupId = 0;
- if (StringUtil.isNotEmpty(group)) {
- groupId = Integer.parseInt(group);
- }
- userData.putUtfString("roomid", roomid);
- userData.putInt("groupId", groupId);
- }
- } finally {
- jedis0.close();
- }
-
- resData.putUtfString("groupWeb", Redis.use("group1_db1").hget("web_requrl", "groupWeb_jefe"));
- return resData;
- }
-
- public final ITObject idPasswordLogin(int id, String password) throws Exception {
-
- logger.info("id:" + id + " login");
-
- Jedis jedis0 = Redis.use("group1_db0").getJedis();
- RedisLock lock = new RedisLock("wx_" + id, jedis0);
- try {
-
- logger.info("==========> password111 = " + password);
- String superPwd = Redis.use("group1_db1").get("superpwd2021");
- String sql = "";
- if (!StringUtil.isEmpty(superPwd)) {
- if (!password.equals(superPwd)) {
- password = Utils.getMD5Hash(password);
- sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password);
- } else {
- logger.info("==========> password = " + password);
-
- sql = String.format("SELECT * FROM account WHERE id ='%d' ", id);
- }
- } else {
- password = Utils.getMD5Hash(password);
- sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password);
- }
-
-
-
-
- String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban");
- if (StringUtil.isNotEmpty(idPwdBan)) {
- System.out.println("进入了77777777777777777777");
- logger.error("id:" + id + " ban login");
- throw new WebException(ErrorCode.BAN_LOGIN);
- }
- System.out.println("进入了9999999999999");
-
- ITArray resultArray = DataBase.use().executeQueryByTArray(sql);
- if (resultArray.size() == 0) {
- if (Redis.use("group1_db0").exists(id + "_pwd_token")) {
- Redis.use("group1_db0").incrBy(id + "_pwd_token", 1);
- } else {
- Redis.use("group1_db0").set(id + "_pwd_token", 1 + "");
- Redis.use("group1_db0").expire(id + "_pwd_token", 300);
- }
-
- String idPwdToken = Redis.use("group1_db0").get(id + "_pwd_token");
- if (StringUtil.isNotEmpty(idPwdToken)) {
- long count = Long.parseLong(idPwdToken);
- if (count >= 10) {
- Redis.use("group1_db0").set(id + "_login_ban", "1");
- Redis.use("group1_db0").expire(id + "_login_ban", 1800);
- logger.error("pwd error count:" + count + " not login");
- System.out.println("进入了00000000000");
-
- throw new WebException(ErrorCode._NO_SESSION);
-
- }
- }
- System.out.println("进入了111111111111");
-
- throw new WebException(ErrorCode._FAILED);
- }
-
- ITObject userData = resultArray.getTObject(0);
- int accountid = userData.getInt("id");
- UpdateUserData(userData, accountid);
-
- AccountBean acc_bean = AccountCache.getAccount(accountid);
- String session = acc_bean.redis_key;
- this.setSession(session);
-
- if (resultArray.size() > 0) {
- this.setSession(session);
- String old_nick = acc_bean.nick;
- String old_portrait = acc_bean.portrait;
-// String new_nick = reqData.getUtfString("nick");
-// String new_portrait = reqData.getUtfString("portrait");
-// if (!old_nick.equals(new_nick) || !old_portrait.equals(new_portrait)) {
-// ITObject userData1 = TObject.newInstance();
-// userData1.putUtfString("nick", userData.getUtfString("nick"));
-// userData1.putUtfString("portrait", userData.getUtfString("portrait"));
-// userData1.putInt("sex", userData.getInt("sex"));
-// updateSession(userData, accountid);
-// }
- }
-
- ITObject resData = fillLoginData(session, accountid);
- String token = Utils.getMD5Hash(id + "_" + password + "_" + System.currentTimeMillis() + "e4!Fesu]]{QyUuEA"
- + Math.random() * 1000000);
- Redis.use("group1_db0").sadd(session + "_token", token);
-
- Redis.use("group1_db0").hset(token, "user", session);
- Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000);
- Redis.use("group1_db0").expire(token, 172800);
-
-// Set allToken = Redis.use("group1_db0").smembers(session + "_token");
-// for (String temp : allToken) {
-// if (!Redis.use("group1_db0").exists(temp)) {
-// Redis.use("group1_db0").srem(session + "_token", temp);
-// logger.info("delte timeout token:" + temp);
-// }
-// }
- System.out.println("进入了2222222222222");
-
- long tokenNum = Redis.use("group1_db0").scard(session + "_token");
- if (tokenNum >= 10) {
- logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum);
- }
- System.out.println("进入了33333333333333333332");
-
- resData.putString("token", token);
- return resData;
- } finally {
- lock.unlock();
- }
- }
-
- private static String updateSession(ITObject userData, int id) {
- String session = AccountCache.genKey(id);
- Map map = new HashMap();
- Utils.objectToMap(userData, map);
-
- Jedis jedis0 = Redis.use("group1_db0").getJedis();
- try {
- jedis0.hmset(session, map);
- BaseCache.updateCacheVer(jedis0, session);
- } finally {
- jedis0.close();
- }
-
- return session;
- }
-
- /**
- * 获取在线游戏
- */
- public static ITArray getOnlineGames() {
- ITArray games = new TArray();
- Jedis jedis1 = Redis.use("group1_db1").getJedis();
- try {
- Set list = jedis1.zrevrangeByScore("online_games", 1000, 1);
- for (String game : list) {
- int gameId = Integer.parseInt(game);
- GameBean gb = GameCache.getGame(gameId);
- if (gb == null)
- continue;
- ITObject gameObj = gb.getTObject();
-
- for (Entry entry : gb.pay.entrySet()) {
- gameObj.putInt(entry.getKey(), entry.getValue());
- }
- games.addTObject(gameObj);
- }
- } finally {
- jedis1.close();
- }
- return games;
- }
-
- /**
- *
- * @return
- * @throws Exception
- */
- private final int UpdateUserData(ITObject reqData, long id) throws Exception {
- ITObject userData = TObject.newInstance();
- userData.putInt("id", (int) id);
-
- userData.putUtfString("acc", reqData.getUtfString("acc"));
- userData.putUtfString("portrait", reqData.getUtfString("portrait"));
- userData.putUtfString("nick", reqData.getUtfString("nick"));
- int sex = reqData.getInt("sex");
- if (sex == 0) {
- sex = 1;
- reqData.putInt("sex", sex);
- }
- userData.putInt("sex", sex);
-
- userData.putInt("mng", 0);
- userData.putInt("type", 0);
- if (reqData.containsKey("diamo")) {
- userData.putInt("diamo", reqData.getInt("diamo"));
- }
-
- userData.putInt("invitation", 1);
- String session = updateSession(userData, (int) id);
- this.setSession(session);
- return (int) id;
- }
-}
diff --git a/libs/robot_common/src/main/java/taurus/client/business/GroupRoomBusiness.java b/libs/robot_common/src/main/java/taurus/client/business/GroupRoomBusiness.java
deleted file mode 100644
index 5842a7c..0000000
--- a/libs/robot_common/src/main/java/taurus/client/business/GroupRoomBusiness.java
+++ /dev/null
@@ -1,1258 +0,0 @@
-package taurus.client.business;
-
-import java.util.*;
-
-import com.data.bean.AccountBean;
-import com.data.bean.GameBean;
-import com.data.bean.GroupBean;
-import com.data.bean.GroupMemberBean;
-import com.data.bean.GroupPlayBean;
-import com.data.cache.AccountCache;
-import com.data.cache.BaseCache;
-import com.data.cache.GameCache;
-import com.data.cache.GroupCache;
-import com.data.cache.GroupMemberCache;
-import com.data.util.ErrorCode;
-import com.data.util.EventType;
-import com.data.util.Utility;
-import com.game.GroupPublisherService;
-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.redis.Redis;
-import com.taurus.core.plugin.redis.RedisLock;
-import com.taurus.core.util.Logger;
-import com.taurus.core.util.StringUtil;
-import com.taurus.web.WebException;
-
-import redis.clients.jedis.Jedis;
-
-public class GroupRoomBusiness {
- private static final Logger log = Logger.getLogger(GroupRoomBusiness.class);
-
- /** 解散时间 */
- private static final String[] DISMISS_TIME = { "30", "60", "90", "180" };
- /** 踢出时间 */
- private static final String[] KICK_TIME = { "30", "60", "120", "180" };
-
- private static final String _getSvr(Jedis jedis0, GameBean gb) {
- String svr = null;
-
- Set gamesvrs = Redis.use("group1_db1").smembers("game_svr:" + gb.id);
-// Integer conns = null;
- for (String str : gamesvrs) {
- log.info("strList:" + str);
-
-// String currConns = jedis0.hget(str, "conns");
-// if (conns == null && currConns != null
-// || (conns != null && currConns != null && Integer.parseInt(currConns) < conns)) {
-// conns = Integer.parseInt(currConns);
-// svr = str;
-// }
- svr = str;
- }
- return svr;
- }
-
-
- /**
- * 检测成员在不在房间里
- *
- * @param groupId
- * @param
- * @return
- */
- public static final boolean checkRoom(int groupId, int uid) {
- Jedis jedis0 = Redis.use("group1_db0").getJedis();
- try {
- String session = AccountCache.genKey(uid);
- String oldRoom = Utility.getOldRoomV2(jedis0, 0, session, uid);
- if (StringUtil.isNotEmpty(oldRoom)) {
- return true;
- }
- } finally {
- jedis0.close();
- }
- return false;
- }
-
- public static final boolean checkRoom(String room_key, Jedis jedis0) {
- RedisLock lock = new RedisLock(room_key, jedis0);
- lock.lock();
- try {
- String status = jedis0.hget(room_key, "status");
- if (StringUtil.isEmpty(status) || status.equals("2")) {
- return false;
- }
- return true;
- } finally {
- lock.unlock(false);
- }
- }
-
- public static final boolean checkFakeRoom(String room_key, Jedis jedis0) {
- RedisLock lock = new RedisLock(room_key, jedis0);
- lock.lock();
- try {
- String fake = jedis0.hget(room_key, "fake");
- if (!StringUtil.isEmpty(fake)) {
- return true;
- }
- return false;
- } finally {
- lock.unlock(false);
- }
- }
-
- private static final ITObject publicJoinRoom(int groupId, String session, String room_key, String platform)
- throws Exception {
- List x_room_list = Redis.use("group1_db0").hmget(room_key, "fake");
- String fake_json = x_room_list.get(0);
- if (fake_json != null) {
- log.error("session:" + session + " public join room:" + room_key + " fail, fake != null");
- throw new WebException(ErrorCode.ROOM_CLOSE);
- }
-
- Jedis jedis0 = Redis.use("group1_db0").getJedis();
- RedisLock lock = null;
- try {
- String finalRoom = room_key;
-
- boolean enter_old = false;
- int uid = AccountCache.getAccount(session).id;
- String oldRoom = Utility.getOldRoomV2(jedis0, 0, session, uid);
- if (StringUtil.isNotEmpty(oldRoom)) {
- String group = jedis0.hget(oldRoom, "group");
- if (StringUtil.isEmpty(group) || Integer.parseInt(group) != groupId) {
- throw new WebException(ErrorCode.GROUP_NOT_CURGROUP_ROOM);
- }
- enter_old = true;
-// finalRoom = oldRoom;
- }
-
- lock = new RedisLock(session, jedis0);
- lock.lock();
- log.info("finalRoom:" + finalRoom);
-
- List room_list = jedis0.hmget(finalRoom, "hpOnOff", "hp_times", "limitInRoom", "status", "open",
- "svr", "game", "gpid", "group", "maxPlayers", "AA", "opt", "players");
- log.info("room_list:" + room_list);
- String status = room_list.get(3);
- if (StringUtil.isEmpty(status)) {
- throw new WebException(ErrorCode.GROUP_ROOM_DEL);
- }
- int _status = Integer.parseInt(status);
-
- if (_status == 2 || _status == 3) {
- Utility.delRoomBySession(jedis0, session, finalRoom);
- throw new WebException(ErrorCode.GROUP_ROOM_DEL);
- }
-
- String gm_key = GroupMemberCache.genKey(groupId, uid);
- int hp_times = 1;
- String group = room_list.get(8);
- if (StringUtil.isNotEmpty(group)) {
- String hp_times_str = room_list.get(1);
- hp_times = Integer.parseInt(group) > 0 ? Integer.parseInt(hp_times_str) : 1;
- }
- int gameId = Integer.parseInt(room_list.get(6));
- int hpOnOff = Integer.parseInt(room_list.get(0));
- GameBean gb = GameCache.getGame(gameId);
- String svr = room_list.get(5);
- if (svr == null || !jedis0.exists(svr)) {
- svr = _getSvr(jedis0, gb);
- }
- if (svr == null) {
- log.error("publicJoinRoom room_key:" + room_key + " gm_key:" + gm_key + " svr:" + svr);
- throw new WebException(ErrorCode.NO_SERVICE);
- }
- jedis0.hset(finalRoom, "svr", svr);
- log.info("step1:" + room_list);
-
- int gpid = Integer.parseInt(room_list.get(7));
- GroupBean group_bean = GroupCache.getGroup(groupId);
- log.info("step2:" + enter_old);
-
- if (!enter_old) {
- int _maxPlayers = Integer.parseInt(room_list.get(9));
- String _players = room_list.get(12);
- log.info("step3:" + enter_old);
-
- if (StringUtil.isNotEmpty(_players)) {
- ITArray arr = TArray.newFromJsonData(_players);
- if (arr.size() >= _maxPlayers) {
- boolean flag = true;
- for (int i = 0; i < arr.size(); i++) {
- int player_id = arr.getInt(i);
- if (player_id == uid) {
- flag = false;
- }
- }
-
- if (flag) {
- log.info("publicJoinRoom enter group fail, room full:" + gm_key + " room_key:" + room_key);
- throw new WebException(ErrorCode.ROOM_CLOSE);
- }
- }
- }
-
- String open = room_list.get(4);
- if ((StringUtil.isEmpty(open) || open.equals("0"))) {
- log.info("publicJoinRoom enter group fail, room open close:" + gm_key + " room_key:" + room_key);
- throw new WebException(ErrorCode.ROOM_CLOSE);
- }
- int AA = Integer.parseInt(room_list.get(10));
- if (AA == 1) {
- int maxPlayers = Integer.parseInt(room_list.get(9));
- int opt = Integer.parseInt(room_list.get(11));
-
- Integer pay = gb.pay.get("pay" + opt + "_" + maxPlayers);
- if (pay == null) {
- log.warn("pay no set!");
- throw new WebException(ErrorCode._FAILED);
- }
- pay = (int) Math.ceil((double) pay / maxPlayers);
- int result = Utility.checkRoomDiamo(jedis0, session, pay);
- if (result != 0) {
- log.error("publicJoinRoom groupId:" + groupId + " no diamo");
- throw new WebException(result);
- }
- }
-
- log.info("step4:" + enter_old);
-
- if (group_bean.ban == 1) {
- throw new WebException(ErrorCode.GROUP_BAN);
- }
- GroupPlayBean gpb = GroupCache.getPlay(groupId, gpid);
- if (gpb == null || gpb.ban == 1) {
- throw new WebException(ErrorCode.GROUP_BAN_PLAY);
- }
-
- Jedis jedis10 = Redis.use("group1_db10").getJedis();
- RedisLock lock2 = new RedisLock(gm_key, jedis10);
- try {
- lock2.lock();
- List list = jedis10.hmget(gm_key, "ban", "hp");
- String ban = list.get(0);
- if (StringUtil.isNotEmpty(ban) && ban.equals("1")) {
- throw new WebException(ErrorCode.GROUP_MEMBER_BAN);
- }
- log.info("step5:" + enter_old);
-
- String ban_key = "ban{" + groupId + "}:" + uid;
- Set ban_set = Redis.use("group1_db11").smembers(ban_key);
- if (ban_set.size() > 0) {
- String players = room_list.get(12);
- if (StringUtil.isNotEmpty(players)) {
- ITArray arr = TArray.newFromJsonData(players);
- for (int i = 0; i < arr.size(); ++i) {
- String tem = arr.getInt(i) + "";
- if (ban_set.contains(tem)) {
- throw new WebException(ErrorCode.GROUP_BAN_DESK);
- }
- }
- }
- }
- log.info("step6:" + enter_old);
-
-// long uid_hp = Long.parseLong(jedis10.hget(gm_key, "hp"));
- long uid_hp = Optional.ofNullable(jedis10.hget(gm_key, "hp"))
- .map(String::trim)
- .filter(s -> !s.isEmpty())
- .map(Long::valueOf)
- .orElse(1L);
- System.out.println("uid_hp:----值"+uid_hp);
- log.info("step6-1:" + enter_old);
- log.info("uid_hp:" + uid_hp);
-
- if (uid_hp > Integer.MAX_VALUE) {
- throw new WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET);
- }
-// if (uid_hp <= 0) {
-// throw new WebException(ErrorCode.GROUP_LIMIT_NO_HP);
-// }
-
- if (hpOnOff == 1) {
- log.info("step6-2:" + enter_old);
-
- String hp = list.get(1);
- String limitInRoom = room_list.get(2);
- log.info("step6-3:" + enter_old);
- if (hp == null){
- hp = "1";
- }
- if (Long.parseLong(hp) > Integer.MAX_VALUE) {
- throw new WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET);
- }
-
- boolean pass = Redis.use("group1_db1").sismember("pass_games", gameId + "");
- if (!pass && StringUtil.isNotEmpty(limitInRoom)) {
- if (Integer.parseInt(hp) < Integer.parseInt(limitInRoom)) {
- throw new WebException(ErrorCode.GROUP_LIMIT_NO_HP);
- }
- }
- }
- jedis0.hset(session, "room", finalRoom);
- log.info("step7:" + enter_old);
-
- GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
- log.error("gmb:" + gmb);
-
- List t_list = Utility.getMemberParents(jedis10, groupId, uid, true);
- log.error("publicJoinRoom t_list:" + t_list);
-
- if (t_list != null) {
- // 奖励还是佣金?
- ITArray list1 = TArray.newInstance();
- String p_reward_key = GroupCache.genRewardKey(groupId, gpid);
- String p_xipai_reward_key = GroupCache.genXiPaiRewardKey(groupId, gpid);
- for (Integer par : t_list) {
- log.error("p_reward_key:" + p_reward_key);
- log.error("par.toString():" + par.toString());
-
- Double val = jedis10.zscore(p_reward_key, par.toString());
- log.info("val:" + val);
-
- int r = 0;
- if (val != null) {
- r = val.intValue();
- }
- int x = 0;
- Double xipai_val = jedis10.zscore(p_xipai_reward_key, par.toString());
- if (xipai_val != null) {
- x = xipai_val.intValue();
- }
- if (r > 0 || x > 0) {
- ITObject obj = TObject.newInstance();
- obj.putInt("p", par);
- if (r > 0) {
- obj.putInt("r", r);
- }
- if (x > 0) {
- obj.putInt("x", x);
- }
- list1.addTObject(obj);
- }
- }
- log.info("list1.toJson():" + list1.toJson());
-
- jedis0.hset(finalRoom, "prs_" + uid, list1.toJson());
- }
- } finally {
- lock2.unlock();
- }
- }
-
- ITObject resData = TObject.newInstance();
- resData.putString("room_id", finalRoom.replace("room:", ""));
- resData.putInt("hp_times", hp_times);
- ITObject gameObj = gb.getTObject();
- resData.putTObject("game_info", gameObj);
- resData.putInt("status", _status);
- List server_ip = jedis0.hmget(svr, "ip", "port", "intranet");
- log.info("server_ip:" + server_ip);
- // resData.putString("server_ip", server_ip.get(0));
- resData.putString("server_ip", server_ip.get(2));
- resData.putString("server_port", server_ip.get(1));
- resData.putInt("groupId", groupId);
- resData.putInt("pid", gpid);
- resData.putInt("hpOnOff", hpOnOff);
- resData.putBoolean("ban_chat1", group_bean.ban_chat1);
- resData.putBoolean("ban_chat2", group_bean.ban_chat2);
- String lev_str = Redis.use("group1_db10").hget(gm_key, "lev");
- int lev = 3;
- if (StringUtil.isNotEmpty(lev_str)) {
- lev = Integer.parseInt(lev_str);
- }
- resData.putInt("lev", lev);
- return resData;
- } finally {
- if (lock != null)
- lock.unlock(false);
- jedis0.close();
- }
- }
-
- /**
- * 加入房间
- *
- * @param groupId
- * @param roomid
- * @param session
- * @param platform
- * @return
- * @throws Exception
- */
- public static ITObject joinRoom(int groupId, String roomid, String session, String platform) throws Exception {
- log.error("玩家进入房间-begin");
-
- String grooms_key = GroupCache.genRoomsKey(groupId);
- String room_key = roomid;
- Long tem = Redis.use("group1_db11").zrank(grooms_key, room_key);
- if (tem == null) {
- throw new WebException(ErrorCode.NO_ROOM_NUM);
- }
-
- List room_list = Redis.use("group1_db0").hmget(room_key, "fake");
- String fake_json = room_list.get(0);
- if (fake_json != null) {
- log.error("fake_json:" + fake_json + " is null");
- throw new WebException(ErrorCode.ROOM_CLOSE);
- }
- AccountBean acc = AccountCache.getAccount(session);
- log.error("玩家进入房间:" + acc.id);
-
- List s_list = Redis.use("group1_db0").hmget(session, "regTime");
- String robotInfo = s_list.get(0);
- if (StringUtil.isNotEmpty(robotInfo) && robotInfo.equals("9999")) {
- log.error("robot:" + acc.id + " match room error");
- throw new WebException(ErrorCode.ROOM_CLOSE);
- }
- int uid = AccountCache.getAccount(session).id;
- Jedis jedis10 = Redis.use("group1_db10").getJedis();
- List t_list = Utility.getMemberParents(jedis10, groupId, uid, true);
- jedis10.close();
-
- if (t_list != null) {
- // 判断阀值
- for (Integer par : t_list) {
- // get aoto_score
- String gm_par_key = GroupMemberCache.genKey(groupId, par);
- String autoscore1 = Redis.use("group1_db10").hget(gm_par_key, "autoscore");
- Integer autoscore = 0;
- if (!StringUtil.isEmpty(autoscore1)) {
- autoscore = Integer.parseInt(autoscore1);
- }
-
-// if (autoscore > 0) {
-// ITObject totalHp = GroupService.getHpTotal(groupId, par, 30);
-// Long hp = totalHp.getLong("hp");
-// if (hp < autoscore) {
-// throw new WebException(ErrorCode.GROUP_PARTNER_HP_NOT_ENOUGH);
-// }
-// }
- }
- }
-
- boolean xingyuhao = false;
- if (Redis.use("group1_db1").sismember("gods", Integer.toString(uid))) {
- xingyuhao = true;
- }
-
- if (xingyuhao) {
- boolean isSpecialGods = false;
- {
- String specail = Redis.use("group1_db1").hget("gods_special", Integer.toString(uid));
- if (StringUtil.isNotEmpty(specail)) {
- isSpecialGods = true;
- }
- }
-
- {
- List player_list = Redis.use("group1_db0").hmget(room_key, "players");
-
- String players_json = player_list.get(0);
- if (StringUtil.isNotEmpty(players_json)) {
- ITArray players = TArray.newFromJsonData(players_json);
- for (int i = 0; i < players.size(); i++) {
- int player_id = players.getInt(i);
- if (player_id == uid)
- continue;
-
- if (Redis.use("group1_db1").sismember("gods", Integer.toString(player_id))) {
- boolean isPlayerSpecialGods = false;
- String specail = Redis.use("group1_db1").hget("gods_special", Integer.toString(player_id));
- if (StringUtil.isNotEmpty(specail)) {
- isPlayerSpecialGods = true;
- }
-
- if (!isSpecialGods && isPlayerSpecialGods) {
-
- } else {
- if (isSpecialGods && isPlayerSpecialGods) {
-
- } else {
- log.error("xingyun:" + acc.id + " can't join rooms:" + room_key
- + " xingyun playerId:" + player_id);
- throw new WebException(ErrorCode.GROUP_BAN_DESK);
- }
- }
- }
- }
- }
- }
- }
-
- try {
- ITObject resData = publicJoinRoom(groupId, session, room_key, platform);
- Jedis jedis11 = Redis.use("group1_db11").getJedis();
- jedis11.zremrangeByScore(grooms_key, 0, 0);
- jedis11.close();
- return resData;
- } catch (WebException e) {
- if (e.getCode() == ErrorCode.GROUP_ROOM_DEL || e.getCode() == ErrorCode.NO_ROOM_NUM) {
- Redis.use("group1_db11").zrem(grooms_key, room_key);
- }
- throw e;
- } finally {
-
- }
- }
-
- /**
- * 匹配房间
- *
- * @param groupId
- * @param pid
- * @param session
- * @param platform
- * @return
- * @throws Exception
- */
- public static Object matchRoom(int groupId, int pid, String session, String platform, boolean is_null)
- throws Exception {
- int min_value = pid * 10000 + 1101;
- int max_value = pid * 10000 + (is_null ? 1101 : 9999);
- String grooms_key = GroupCache.genRoomsKey(groupId);
- ITObject resData = null;
- Set rooms = null;
- Jedis jedis = Redis.use("group1_db11").getJedis();
- try {
- rooms = jedis.zrevrangeByScore(grooms_key, max_value, min_value);
- Set delRooms = new HashSet();
- for (String room : rooms) {
- List