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("47.109.55.7", "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/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanFangPaoFa.java b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanFangPaoFa.java
new file mode 100644
index 0000000..741e99a
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanFangPaoFa.java
@@ -0,0 +1,212 @@
+package com.robotcm.hunan;
+
+import com.taurus.core.entity.ITArray;
+import com.taurus.core.entity.ITObject;
+import com.taurus.core.entity.TObject;
+import com.robotcm.taurus.client.Message;
+import com.robotcm.taurus.client.TaurusClient;
+import com.robotcm.taurus.util.CardUtil;
+
+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/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanHongZhong.java b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanHongZhong.java
new file mode 100644
index 0000000..2df1b65
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanHongZhong.java
@@ -0,0 +1,322 @@
+package com.robotcm.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 com.robotcm.taurus.client.Message;
+import com.robotcm.taurus.client.TaurusClient;
+import com.robotcm.taurus.util.CardUtil;
+import com.robotcm.taurus.util.HongZhongSuanFaTest;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+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/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanPaoDeKuai.java b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanPaoDeKuai.java
new file mode 100644
index 0000000..c5b0420
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanPaoDeKuai.java
@@ -0,0 +1,121 @@
+package com.robotcm.hunan;
+
+import com.robotcm.taurus.util.CardObj;
+import com.robotcm.taurus.util.CardUtil;
+import com.robotcm.taurus.util.test;
+import com.taurus.core.entity.ITArray;
+import com.taurus.core.entity.ITObject;
+import com.taurus.core.entity.TObject;
+import com.robotcm.taurus.client.TaurusClient;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanZhuanZhuan.java b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanZhuanZhuan.java
new file mode 100644
index 0000000..20bc150
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/hunan/HuNanZhuanZhuan.java
@@ -0,0 +1,341 @@
+package com.robotcm.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 com.robotcm.taurus.client.Message;
+import com.robotcm.taurus.client.TaurusClient;
+import com.robotcm.taurus.util.CardUtil;
+import com.robotcm.taurus.util.ZhuanZhuanSuanFaTest;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+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/robots/robotchangma/src/main/java/com/robotcm/hunan/JiQiRens.java b/robots/robotchangma/src/main/java/com/robotcm/hunan/JiQiRens.java
new file mode 100644
index 0000000..70a6a3f
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/hunan/JiQiRens.java
@@ -0,0 +1,1727 @@
+package com.robotcm.hunan;
+
+
+import com.game.Util;
+import com.robotcm.taurus.client.Message;
+import com.robotcm.taurus.client.MessageResponse;
+import com.robotcm.taurus.client.SocketCode;
+import com.robotcm.taurus.client.TaurusClient;
+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 com.robotcm.taurus.client.business.AccountBusiness;
+import com.robotcm.taurus.client.business.GroupRoomBusiness;
+import com.robotcm.taurus.util.ChangShaSuanFaTest;
+import com.robotcm.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 = "blm523";
+ // 会话标识
+ 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("47.109.55.7:6421", "game", TaurusClient.ConnectionProtocol.Tcp);
+ }
+
+ if ("10".equalsIgnoreCase(wanfaId)) {
+ client = new TaurusClient("47.109.55.7:6311", "game", TaurusClient.ConnectionProtocol.Tcp);
+ }
+//
+ if ("66".equalsIgnoreCase(wanfaId)) {
+ client = new TaurusClient("47.109.55.7: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/robots/robotchangma/src/main/java/com/robotcm/service/GroupLogService.java b/robots/robotchangma/src/main/java/com/robotcm/service/GroupLogService.java
new file mode 100644
index 0000000..d4dc9c2
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/service/GroupLogService.java
@@ -0,0 +1,2173 @@
+package com.robotcm.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.data.bean.AccountBean;
+import com.data.bean.GroupMemberBean;
+import com.data.cache.AccountCache;
+import com.data.cache.GroupCache;
+import com.data.cache.GroupMemberCache;
+import com.data.util.ConsumeCode;
+import com.data.util.CountUtil;
+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.DateUtils;
+import com.taurus.core.util.Logger;
+import com.taurus.core.util.StringUtil;
+import com.taurus.web.WebException;
+
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.Pipeline;
+
+
+public class GroupLogService {
+
+ private static final Logger log = Logger.getLogger(GroupLogService.class);
+ //体力值变化
+ private static final int CHOOSE_CHAGE = 1;
+ //操作上分
+ private static final int CHOOSE_UPPER = 2;
+ //操作下分
+ private static final int CHOOSE_SUB = 4;
+ //抽水
+ private static final int CHOOSE_PUMP = 8;
+ //奖励
+ private static final int CHOOSE_RWARD = 16;
+ //转账
+ private static final int CHOOSE_TRADE = 32;
+ //提取
+ private static final int CHOOSE_TAKE_REWARD = 64;
+ //洗牌
+ private static final int CHOOSE_XIPAI = 128;
+
+ //暗抽
+ private static final int CHOOSE_ANCHOU = 256;
+
+ /**
+ * 上下分记录类型
+ */
+ private static final int[] MGRLOG_TYPE = {ConsumeCode.HP_MGR_UPPER,ConsumeCode.HP_MGR_SUB,ConsumeCode.HP_PARTNER_UPPER,ConsumeCode.HP_PARTNER_SUB};
+ /**
+ * 获取成员排行
+ * @param groupId
+ * @param pid
+ * @param limit
+ * @param num
+ * @param beginTime
+ * @param endTime
+ * @return
+ * @throws Exception
+ */
+ public static final ITObject getMemberRank(int groupId, int uid, int pid, int type, int limit,int num,int beginTime,int endTime) throws Exception{
+ ITObject obj1 = TObject.newInstance();
+ GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid);
+ if (mng_bean == null) {
+ throw new WebException(ErrorCode.GROUP_NOT_MEMBER);
+ }
+
+ int mgn_partner = mng_bean.partnerLev;
+ int mgn_lev = mng_bean.lev;
+
+ String strGodsList = null;
+ Set godsList = Redis.use("group1_db1").smembers("gods");
+ boolean findok = false;
+ if(!godsList.isEmpty()) {
+ for (String mem : godsList) {
+ if (strGodsList == null) {
+ strGodsList = mem;
+ } else {
+ strGodsList += "," + mem;
+ }
+ }
+ strGodsList = "("+strGodsList+")";
+ findok = true;
+ }
+
+ //log.info("getMemberRank strGodsList:"+strGodsList+" mgn_partner:"+mgn_partner + " mgn_lev:"+mgn_lev);
+
+
+ //if (mgn_lev == 1 && mgn_partner == 0) {
+ String sql = String.format("SELECT uid,SUM(win) AS win,SUM(round) as round,SUM(score) as score FROM group_member_log WHERE groupId = %s ",groupId);
+ if(pid > 0) {
+ sql = sql + " AND pid =" + pid;
+ }
+ if (findok){
+ sql = sql+ " AND uid not in "+strGodsList;
+ }
+ if (type == 0)
+ {
+ sql = sql + String.format(" AND time >=%s AND time <%s GROUP BY uid ORDER BY round DESC limit %s,%s",beginTime,endTime,limit,num);
+ }
+ else if (type == 1)
+ {
+ sql = sql + String.format(" AND time >=%s AND time <%s GROUP BY uid ORDER BY score DESC limit %s,%s",beginTime,endTime,limit,num);
+ }
+
+ //log.info("getMemberRank sql:"+sql);
+ ITArray arr =DataBase.use().executeQueryByTArray(sql);
+ for(int i=0;i 0 and time >=%s AND time <%s ", groupId, beginTime, endTime);
+ if (findok){
+ sql2 = sql2+ " and uid not in "+strGodsList;
+ }
+ //log.info("getMemberRank sql2:"+sql2);
+ int allActiveNum = 0;
+ ITArray arr2 =DataBase.use().executeQueryByTArray(sql2);
+ if(arr2.size()>0) {
+ ITObject obj = arr2.getTObject(0);
+ allActiveNum = obj.getLong("num").intValue();
+ }
+ obj1.putInt("allActiveNum", allActiveNum);
+ //}
+
+ obj1.putInt("limit", limit);
+ return obj1;
+ }
+
+ /**
+ * 获取战绩列表
+ * @param platform
+ * @param groupId
+ * @param limit
+ * @param num
+ * @return
+ */
+ public static ITObject getPersonRecords(String platform,int groupId,int timeType,int beginTime,int endTime,int limit,int num,int qid,int uid) throws Exception{
+ String qid_sql = StringUtil.Empty;
+ qid_sql = "and uid="+qid;
+
+ ITArray militaryList = TArray.newInstance();
+
+ ITObject obj1 = TObject.newInstance();
+ if(timeType == 0) {
+
+ beginTime = DateUtils.getBeginDay() ;
+ endTime = DateUtils.getBeginDay() + 3600 * 24;
+ }else if(timeType == 1) {
+
+ beginTime = DateUtils.getBeginDay() - 3600 * 24 ;
+ endTime = DateUtils.getBeginDay();
+ }
+ else if(timeType == 2) {
+
+ beginTime = DateUtils.getBeginDay() - 3600 * 48 ;
+ endTime = DateUtils.getBeginDay() - 3600 * 24;
+ }
+
+ int total = 0;
+ int consume = 0;
+
+ String where = String.format("gid=%s and time>=%s and time<=%s",groupId,beginTime,endTime);
+ if(limit==0) {
+
+ String count_sql = String.format("SELECT count(*) AS total FROM room_rec_log where %s %s",where,qid_sql);
+ ITArray arr =DataBase.use().executeQueryByTArray(count_sql);
+ if(arr.size()>0) {
+ ITObject obj = arr.getTObject(0);
+ total = obj.getLong("total").intValue();
+ }
+
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ try {
+
+ String key = String.format("g%s:m%s:consume_hp", groupId,uid);
+ if(timeType >= 0 && timeType <=2) {
+
+ String hp_key = String.format("%s:d%s",key,beginTime);
+ String r_str = jedis9.get(hp_key);
+ int r_num = 0;
+ if(StringUtil.isNotEmpty(r_str)) {
+ r_num = Integer.parseInt(r_str);
+ }
+ consume = r_num;
+ }
+ else{
+ int timeBegin = beginTime;
+ while(timeBegin <= endTime) {
+
+ String hp_key = String.format("%s:d%s",key,timeBegin);
+ String r_str = jedis9.get(hp_key);
+ int r_num = 0;
+ if(StringUtil.isNotEmpty(r_str)) {
+ r_num = Integer.parseInt(r_str);
+ }
+ consume += r_num;
+ timeBegin += 86400;
+ }
+ }
+
+ getMemberData(jedis9,uid,obj1,groupId, 0,beginTime,endTime,false,false);
+ }finally {
+ jedis9.close();
+ }
+ }
+
+ String sql = String.format("select rec_key from room_rec_log where %s %s GROUP BY roomid ORDER BY time desc limit %s,%s",
+ where,qid_sql,limit,num);
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+
+ if(list.size()>0) {
+ Jedis jedis5 = Redis.use("group1_db5").getJedis();
+ try {
+ for(int i=0;i pids = Redis.use("group1_db11").zrangeByScore(gp_key, 10, 11);
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ ITArray arr = TArray.newInstance();
+ try {
+ for(String pid:pids) {
+
+ ITObject objp = TObject.newInstance();
+
+ objp.putInt("pid", Integer.parseInt(pid));
+
+ if(timeType == 0) {
+
+ String key = String.format("g{%s}:m%s:valid_round:p%s", groupId,uid,pid);
+ int round = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("round", round);
+
+ key = String.format("g%s:hp_cost:m%s:p%s",groupId,uid,pid);
+ int pump = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("pump", pump);
+
+ key = String.format("g{%s}:m%s:p%s:reward_log", groupId,uid,pid);
+ int award = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("award", award);
+ }
+ else if(timeType == 1) {
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+
+ String key = String.format("g{%s}:m%s:valid_round:p%s%s", groupId,uid,pid,curMonth);
+ int round = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("round", round);
+
+ key = String.format("g%s:hp_cost:m%s:p%s%s",groupId,uid,pid,curMonth);
+ int pump = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("pump", pump);
+
+ key = String.format("g{%s}:m%s:p%s:reward_log%s", groupId,uid,pid,curMonth);
+ int award = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("award", award);
+ }
+ else if(timeType == 2) {
+
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+
+ String key = String.format("g{%s}:m%s:valid_round:p%s%s", groupId,uid,pid,curMonth);
+ int round = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("round", round);
+
+ key = String.format("g%s:hp_cost:m%s:p%s%s",groupId,uid,pid,curMonth);
+ int pump = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("pump", pump);
+
+ key = String.format("g{%s}:m%s:p%s:reward_log%s", groupId,uid,pid,curMonth);
+ int award = _getCountValue(jedis9,key,beginTime,endTime);
+ objp.putInt("award", award);
+ }
+ arr.addTObject(objp);
+ }
+ }finally {
+ jedis9.close();
+ }
+
+ obj.putTArray("members", arr);
+ obj.putInt("limit", limit);
+
+
+ return obj;
+ }
+
+
+ public static ITObject getDirectStatMember(int groupId,int uid,int rootUid,int limit, int num,int timeType,int beginTime, int endTime) throws Exception{
+
+ ITObject obj = TObject.newInstance();
+
+ String limitSql = String.format("limit %s,%s",limit, num);
+ String sql = String.format("SELECT uid, partnerLev"
+ + " FROM group_member"
+ + " WHERE groupId = %s and ((parentId=%s and partnerLev = 0) or uid = %s) GROUP BY uid %s",
+ groupId, uid, uid, limitSql);
+
+
+ ITArray temp = TArray.newInstance();
+
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ try {
+
+ for (int i = 0; i < list.size(); ++i) {
+
+ ITObject objLine = list.getTObject(i);
+ if(objLine.containsKey("uid")) {
+
+ int tagUid = objLine.getInt("uid");
+
+ AccountBean acc = AccountCache.getAccount(tagUid);
+ objLine.putString("nick", acc.nick);
+
+ //int newBeginTime = beginTime - 86400*30;
+ getMemberData(jedis9,tagUid,objLine,groupId,timeType, beginTime,endTime,false,false);
+
+ if(timeType == 0) {
+ {
+ String tmpKey = String.format("g{%s}:m%s:", groupId,tagUid);
+ int reward_hp = _getCountValue(jedis9,tmpKey + "reward_log",beginTime,endTime);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp = _getCountValue(jedis9,key,beginTime,endTime);
+ objLine.putInt("reward_hp", (int)reward_hp);
+ }
+ else if(timeType == 1){
+ {
+ String key = String.format("g{%s}:m%s:", groupId,tagUid);
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ int reward_hp = _getValue(jedis9,key + "reward_log" + curMonth);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp =_getValue(jedis9,key+ curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ else if(timeType == 2){
+ {
+ String key = String.format("g{%s}:m%s:", groupId,tagUid);
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ int reward_hp = _getValue(jedis9,key + "reward_log" + curMonth);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp =_getValue(jedis9,key+ curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ temp.addTObject(objLine);
+ }
+ }
+ }
+ finally {
+ jedis9.close();
+ }
+
+ obj.putTArray("members", temp);
+ obj.putInt("limit", limit);
+
+
+ return obj;
+ }
+
+ public static ITObject getXingYunHaoMember(int groupId, int limit, int num,int timeType,int beginTime, int endTime) throws Exception{
+ ITObject obj = TObject.newInstance();
+
+ String limitSql = String.format("limit %s,%s",limit, num);
+
+ String strGodsList = null;
+ Set godsList = Redis.use("group1_db1").smembers("gods");
+ Map mapString = Redis.use("group1_db1").hgetAll("gods_special");
+ for (Map.Entry entry : mapString.entrySet()) {
+ String strPlayerId = entry.getKey();
+ godsList.remove(strPlayerId);
+ }
+
+ List allList = new ArrayList();
+ allList.addAll(godsList);
+ for(String mem : godsList)
+ {
+ if (strGodsList == null)
+ {
+ strGodsList = mem;
+ }
+ else {
+ strGodsList += "," + mem;
+ }
+ }
+
+ String sql = String.format("SELECT uid, partnerLev"
+ + " FROM group_member"
+ + " WHERE groupId = %s and uid in (%s) GROUP BY uid %s",
+ groupId, strGodsList, limitSql);
+
+
+
+ ITArray temp = TArray.newInstance();
+ int allTotalWin = 0;
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ try {
+
+ for (int i = 0; i < list.size(); ++i) {
+
+ ITObject objLine = list.getTObject(i);
+ if(objLine.containsKey("uid")) {
+
+ int tagUid = objLine.getInt("uid");
+
+ AccountBean acc = AccountCache.getAccount(tagUid);
+ objLine.putString("nick", acc.nick);
+
+ getMemberData(jedis9,tagUid,objLine,groupId,timeType, beginTime,endTime,false,false);
+
+ temp.addTObject(objLine);
+ }
+ }
+
+ for (String user : allList) {
+ String key = String.format("g{%s}:m%s:", groupId,user);
+ int total_win = _getCountValue(jedis9,key + "total_win_self",beginTime,endTime);
+ allTotalWin += total_win;
+ }
+ }
+ finally {
+ jedis9.close();
+ }
+
+ obj.putTArray("members", temp);
+ obj.putInt("limit", limit);
+ obj.putLong("all_total_win", allTotalWin);
+
+
+ return obj;
+ }
+
+ public static ITObject getPartnerStatMember(int groupId,int uid,int rootUid,int limit, int num,int timeType,int beginTime, int endTime) throws Exception{
+
+ ITObject obj = TObject.newInstance();
+
+ String limitSql = String.format("limit %s,%s",limit, num);
+
+ String sql = String.format("SELECT uid, partnerLev"
+ + " FROM group_member"
+ + " WHERE groupId = %s and (parentId=%s or uid = %s) and partnerLev > 0 GROUP BY uid %s",
+ groupId, uid, uid, limitSql);
+
+
+
+ ITArray temp = TArray.newInstance();
+
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ try {
+
+ for (int i = 0; i < list.size(); ++i) {
+
+ ITObject objLine = list.getTObject(i);
+ if(objLine.containsKey("uid")) {
+
+ int tagUid = objLine.getInt("uid");
+
+ AccountBean acc = AccountCache.getAccount(tagUid);
+ objLine.putString("nick", acc.nick);
+
+ if(tagUid != uid) {
+ //int newBeginTime = beginTime - 86400 * 30;
+ getMemberData(jedis9,tagUid,objLine,groupId,timeType, beginTime,endTime,false,true);
+ }
+ else {
+ //int newBeginTime = beginTime - 86400 * 30;
+ //getMemberData(jedis9,tagUid,objLine,groupId,timeType, beginTime,endTime,false,true);
+ getDirectMemberData(jedis9,tagUid,objLine,groupId,timeType,beginTime,endTime);
+ }
+
+
+ if(tagUid == uid) {
+
+ if(timeType == 0) {
+ {
+ String tmpKey = String.format("g{%s}:m%s:", groupId,tagUid);
+ int reward_hp = _getCountValue(jedis9,tmpKey + "reward_log",beginTime,endTime);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String key = String.format("g{%s}:m%s:d_reward", groupId,tagUid);
+ int reward_hp = _getCountValue(jedis9,key,beginTime,endTime);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ else if(timeType == 1){
+ {
+ String key = String.format("g{%s}:m%s:", groupId,tagUid);
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ int reward_hp = _getValue(jedis9,key + "reward_log" + curMonth);
+
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ String key = String.format("g{%s}:m%s:d_reward", groupId,tagUid);
+ int reward_hp =_getValue(jedis9,key + curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ else if(timeType == 2){
+ {
+ String key = String.format("g{%s}:m%s:", groupId, tagUid);
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ String key = String.format("g{%s}:m%s:d_reward", groupId,tagUid);
+ int reward_hp =_getValue(jedis9, key+curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ }
+ else {
+ if(timeType == 0) {
+ {
+ long reward_hp_total = 0;
+ List listParent = Utility.getChildParentList(groupId, tagUid, true);
+ for (Integer parId : listParent) {
+ String tmpKey = String.format("g{%s}:m%s:", groupId, parId);
+ int reward_hp = _getCountValue(jedis9, tmpKey + "reward_log", beginTime, endTime);
+ reward_hp_total += reward_hp;
+ }
+ objLine.putInt("reward_tongji", (int) reward_hp_total);
+ }
+
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp = _getCountValue(jedis9,key,beginTime,endTime);
+ objLine.putInt("reward_hp", (int)reward_hp);
+ }
+ else if(timeType == 1){
+ {
+ String key = String.format("g{%s}:m%s:", groupId, tagUid);
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp =_getValue(jedis9,key + curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ else if(timeType == 2){
+ {
+ String key = String.format("g{%s}:m%s:", groupId, tagUid);
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth);
+
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp =_getValue(jedis9, key+curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ }
+
+ temp.addTObject(objLine);
+ }
+ }
+ }
+ finally {
+ jedis9.close();
+ }
+
+ obj.putTArray("members", temp);
+ obj.putInt("limit", limit);
+
+
+ return obj;
+ }
+
+ public static ITObject findPartnerStatMember(int groupId,int uid,int rootUid,int tagId, int limit, int num,int timeType,int beginTime, int endTime) throws Exception{
+
+ ITObject obj = TObject.newInstance();
+
+ String limitSql = String.format("limit %s,%s",limit, num);
+
+ String sql = String.format("SELECT uid, partnerLev"
+ + " FROM group_member"
+ + " WHERE groupId = %s and (parentId=%s or uid = %s) and partnerLev > 0 and uid=%s GROUP BY uid %s",
+ groupId, uid, uid, tagId, limitSql);
+
+
+
+ ITArray temp = TArray.newInstance();
+
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ try {
+
+ for (int i = 0; i < list.size(); ++i) {
+
+ ITObject objLine = list.getTObject(i);
+ if(objLine.containsKey("uid")) {
+
+ int tagUid = objLine.getInt("uid");
+
+ AccountBean acc = AccountCache.getAccount(tagUid);
+ objLine.putString("nick", acc.nick);
+
+ if(tagUid != uid) {
+ //int newBeginTime = beginTime - 86400 * 30;
+ getMemberData(jedis9,tagUid,objLine,groupId,timeType, beginTime,endTime,false,true);
+ }
+ else {
+ //int newBeginTime = beginTime - 86400 * 30;
+ //getMemberData(jedis9,tagUid,objLine,groupId,timeType, beginTime,endTime,false,true);
+ getDirectMemberData(jedis9,tagUid,objLine,groupId,timeType,beginTime,endTime);
+ }
+
+
+ if(tagUid == uid) {
+
+ if(timeType == 0) {
+ {
+ String tmpKey = String.format("g{%s}:m%s:", groupId,tagUid);
+ int reward_hp = _getCountValue(jedis9,tmpKey + "reward_log",beginTime,endTime);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String key = String.format("g{%s}:m%s:d_reward", groupId,tagUid);
+ int reward_hp = _getCountValue(jedis9,key,beginTime,endTime);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ else if(timeType == 1){
+ {
+ String key = String.format("g{%s}:m%s:", groupId,tagUid);
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ int reward_hp = _getValue(jedis9,key + "reward_log" + curMonth);
+
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ String key = String.format("g{%s}:m%s:d_reward", groupId,tagUid);
+ int reward_hp =_getValue(jedis9,key + curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ else if(timeType == 2){
+ {
+ String key = String.format("g{%s}:m%s:", groupId, tagUid);
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ String key = String.format("g{%s}:m%s:d_reward", groupId,tagUid);
+ int reward_hp =_getValue(jedis9, key+curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ }
+ else {
+ if(timeType == 0) {
+ {
+ long reward_hp_total = 0;
+ List listParent = Utility.getChildParentList(groupId, tagUid, true);
+ for (Integer parId : listParent) {
+ String tmpKey = String.format("g{%s}:m%s:", groupId, parId);
+ int reward_hp = _getCountValue(jedis9, tmpKey + "reward_log", beginTime, endTime);
+ reward_hp_total += reward_hp;
+ }
+ objLine.putInt("reward_tongji", (int) reward_hp_total);
+ }
+
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp = _getCountValue(jedis9,key,beginTime,endTime);
+ objLine.putInt("reward_hp", (int)reward_hp);
+ }
+ else if(timeType == 1){
+ {
+ String key = String.format("g{%s}:m%s:", groupId, tagUid);
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth);
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp =_getValue(jedis9,key + curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ else if(timeType == 2){
+ {
+ String key = String.format("g{%s}:m%s:", groupId, tagUid);
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth);
+
+ objLine.putInt("reward_tongji", reward_hp);
+ }
+
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+ String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,tagUid,uid);
+ int reward_hp =_getValue(jedis9, key+curMonth);
+ objLine.putInt("reward_hp", reward_hp);
+ }
+ }
+
+ temp.addTObject(objLine);
+ }
+ }
+ }
+ finally {
+ jedis9.close();
+ }
+
+ obj.putTArray("members", temp);
+ obj.putInt("limit", limit);
+
+
+ return obj;
+ }
+
+
+ public static ITObject getPartnerStat(int groupId,int uid,int limit, int num,int timeType,int beginTime, int endTime) throws Exception{
+
+ ITObject obj = TObject.newInstance();
+ GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
+ int lev = gmb.lev;
+ boolean mgr = lev < 3;
+ ITArray list = null;
+ String limitSql = String.format("limit %s,%s",limit, num);
+ if (mgr) {
+
+ String sql = String.format("SELECT A.uid,A.partnerLev, A.autoscore,"
+ + "(SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total "
+ + "FROM group_member AS A"
+ + " where A.groupId= %s and A.partnerLev=1 %s",
+ groupId,groupId, limitSql);
+
+ list = DataBase.use().executeQueryByTArray(sql);
+ } else {
+
+ String sql = String.format(
+ "SELECT A.uid,A.partnerLev, A.autoscore, (SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total "
+ + "FROM group_member AS A"
+ + " where A.groupId= %s and (A.parentId=%s or A.uid=%s) AND A.partnerLev >0 %s",
+ groupId,groupId, uid, uid, limitSql);
+
+ list = DataBase.use().executeQueryByTArray(sql);
+ }
+
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+
+ try {
+
+ for (int i = 0; i < list.size(); ++i) {
+
+ ITObject objLine = list.getTObject(i);
+ int tagUid = objLine.getInt("uid");
+ AccountBean acc = AccountCache.getAccount(tagUid);
+ objLine.putString("nick", acc.nick);
+
+ getMemberData(jedis9,tagUid,objLine,groupId,timeType,beginTime,endTime,true,true);
+ }
+ }
+ finally {
+ jedis9.close();
+ jedis10.close();
+ }
+
+ obj.putTArray("members", list);
+ obj.putInt("limit", limit);
+
+ return obj;
+ }
+
+ public static ITObject findPartnerStat(int groupId,int uid, int tagId, int limit, int num,int timeType,int beginTime, int endTime) throws Exception{
+
+ ITObject obj = TObject.newInstance();
+ GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
+ int lev = gmb.lev;
+ boolean mgr = lev < 3;
+ ITArray list = null;
+ String limitSql = String.format("limit %s,%s",limit, num);
+ if (mgr) {
+
+ String sql = String.format("SELECT A.uid,A.partnerLev, A.autoscore,"
+ + "(SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total "
+ + "FROM group_member AS A"
+ + " where A.groupId= %s and A.uid=%s %s",
+ groupId,groupId, tagId, limitSql);
+
+ list = DataBase.use().executeQueryByTArray(sql);
+ } else {
+ if (uid != tagId)
+ {
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+ try {
+ List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true);
+ if (par_list == null || !par_list.contains(uid)) {
+ throw new WebException(ErrorCode.GROUP_NOT_PERMISSION);
+ }
+ }
+ finally {
+ jedis10.close();
+ }
+
+ }
+
+ String sql = String.format(
+ "SELECT A.uid,A.partnerLev, A.autoscore, (SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total "
+ + "FROM group_member AS A"
+ + " where A.groupId= %s AND A.uid=%s %s",
+ groupId,groupId, tagId, limitSql);
+
+ list = DataBase.use().executeQueryByTArray(sql);
+ }
+
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+
+ try {
+
+ for (int i = 0; i < list.size(); ++i) {
+
+ ITObject objLine = list.getTObject(i);
+ int tagUid = objLine.getInt("uid");
+ AccountBean acc = AccountCache.getAccount(tagUid);
+ objLine.putString("nick", acc.nick);
+
+ getMemberData(jedis9,tagUid,objLine,groupId,timeType,beginTime,endTime,true,true);
+ }
+ }
+ finally {
+ jedis9.close();
+ jedis10.close();
+ }
+
+ obj.putTArray("members", list);
+ obj.putInt("limit", limit);
+
+ return obj;
+ }
+
+ public static void getMemberData(Jedis jedis9,
+ int uid,
+ ITObject param,
+ int groupId,
+ int timeType,int beginTime, int endTime,
+ boolean rewardHP,boolean total) {
+
+ String key = String.format("g{%s}:m%s:", groupId,uid);
+ String self = total ? "" : "_self";
+ if(timeType == 0) {
+
+ if(rewardHP) {
+// int reward_hp = _getCountValue(jedis9,key + "reward_log",beginTime,endTime);
+// param.putInt("reward_hp", reward_hp);
+
+ // 包含下级合伙人
+ long reward_hp_total = 0;
+ List listParent = Utility.getChildParentList(groupId, uid, true);
+ for(Integer parId : listParent) {
+ String tmpKey = String.format("g{%s}:m%s:", groupId,parId);
+ int reward_hp = _getCountValue(jedis9,tmpKey + "reward_log",beginTime,endTime);
+ reward_hp_total += reward_hp;
+ }
+ param.putLong("reward_hp", reward_hp_total);
+ }
+
+ int valid_round = _getCountValue(jedis9,key + "valid_round"+ self,beginTime,endTime);
+ param.putInt("valid_round" , valid_round);
+
+ int total_round = _getCountValue(jedis9,key + "round_log"+ self,beginTime,endTime);
+ param.putInt("total_round" , total_round);
+
+ int total_win = _getCountValue(jedis9,key + "total_win"+ self,beginTime,endTime);
+ param.putInt("total_win" , total_win);
+
+ int xipai_reward_log = _getCountValue(jedis9,key + "xipai_reward_log"+ self,beginTime,endTime);
+ param.putInt("xipai_reward_log" , xipai_reward_log);
+ }
+ else if(timeType == 1){
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+
+ if(rewardHP) {
+ int reward_hp = _getValue(jedis9,key + "reward_log" + curMonth);
+ param.putInt("reward_hp", reward_hp);
+ }
+
+
+ int valid_round = _getValue(jedis9,key + "valid_round"+ self + curMonth);
+ param.putInt("valid_round" , valid_round);
+
+ int total_round = _getValue(jedis9,key + "round_log" + self + curMonth);
+ param.putInt("total_round", total_round);
+
+ int total_win = _getValue(jedis9,key + "total_win" + self + curMonth);
+ param.putInt("total_win", total_win);
+
+ int xipai_reward_log = _getValue(jedis9,key + "xipai_reward_log" + self + curMonth);
+ param.putInt("xipai_reward_log", xipai_reward_log);
+
+ }
+ else if(timeType == 2){
+
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+
+ if(rewardHP) {
+ int reward_hp = _getValue(jedis9,key + "reward_log" + curMonth);
+ param.putInt("reward_hp", reward_hp);
+ }
+
+ int valid_round = _getValue(jedis9,key + "valid_round" + self + curMonth);
+ param.putInt("valid_round", valid_round);
+
+ int total_round = _getValue(jedis9,key + "round_log" + self + curMonth);
+ param.putInt("total_round" , total_round);
+
+ int total_win = _getValue(jedis9,key + "total_win"+ self + curMonth);
+ param.putInt("total_win" , total_win);
+ int xipai_reward_log = _getValue(jedis9,key + "xipai_reward_log"+ self + curMonth);
+ param.putInt("xipai_reward_log" , xipai_reward_log);
+ }
+ }
+
+ private static void getDirectMemberData(Jedis jedis9,
+ int uid,
+ ITObject param,
+ int groupId,
+ int timeType,int beginTime, int endTime) {
+
+ String key = String.format("g{%s}:m%s:", groupId,uid);
+
+ if(timeType == 0) {
+
+ int valid_round = _getCountValue(jedis9,key + "d_valid_round",beginTime,endTime);
+ param.putInt("valid_round" , valid_round);
+
+ int total_round = _getCountValue(jedis9,key + "d_round_log",beginTime,endTime);
+ param.putInt("total_round" , total_round);
+
+ int total_win = _getCountValue(jedis9,key + "d_total_win",beginTime,endTime);
+ param.putInt("total_win" , total_win);
+
+ int xipai_reward_log = _getCountValue(jedis9,key + "xipai_reward_log_to",beginTime,endTime);
+ param.putInt("xipai_reward_log" , xipai_reward_log);
+ }
+ else if(timeType == 1){
+
+ String curMonth = ":m" + DateUtils.getBeginMonth();
+
+ int valid_round = _getValue(jedis9,key + "d_valid_round"+ curMonth);
+ param.putInt("valid_round" , valid_round);
+
+ int total_round = _getValue(jedis9,key + "d_round_log" + curMonth);
+ param.putInt("total_round", total_round);
+
+ int total_win = _getValue(jedis9,key + "d_total_win" + curMonth);
+ param.putInt("total_win", total_win);
+ int xipai_reward_log = _getValue(jedis9,key + "xipai_reward_log_to" + curMonth);
+ param.putInt("xipai_reward_log", xipai_reward_log);
+ }
+ else if(timeType == 2){
+
+ String curMonth = ":m" + DateUtils.getBeginLastMonth();
+
+ int valid_round = _getValue(jedis9,key + "d_valid_round" + curMonth);
+ param.putInt("valid_round", valid_round);
+
+ int total_round = _getValue(jedis9,key + "d_round_log" + curMonth);
+ param.putInt("total_round" , total_round);
+
+ int total_win = _getValue(jedis9,key + "d_total_win"+ curMonth);
+ param.putInt("total_win" , total_win);
+
+ int xipai_reward_log = _getValue(jedis9,key + "xipai_reward_log_to"+ curMonth);
+ param.putInt("xipai_reward_log" , xipai_reward_log);
+ }
+ }
+
+ /**
+ * 获取战绩列表
+ * @param platform
+ * @param groupId
+ * @param limit
+ * @param num
+ * @return
+ */
+ public static ITObject getMemberStat(int groupId, int uid, int qid,int partnerId,int limit,int num,int timeType,int beginTime,int endTime) throws Exception{
+
+ ITObject obj1 = TObject.newInstance();
+
+ String qid_sql = StringUtil.Empty;
+ if(qid > 0) {
+
+ GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid);
+ if (mng_bean == null) {
+ throw new WebException(ErrorCode.GROUP_NOT_MEMBER);
+ }
+
+ int mgn_partner = mng_bean.partnerLev;
+ int mgn_lev = mng_bean.lev;
+ if (mgn_lev == 3 && mgn_partner == 0) {
+ throw new WebException(ErrorCode.GROUP_NOT_PARTNER);
+ }
+
+ if (mgn_lev == 3) {
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+ try {
+ List par_list = Utility.getMemberParents(jedis10, groupId, qid, false);
+ if (par_list == null || !par_list.contains(uid)) {
+ throw new WebException(ErrorCode.GROUP_NOT_PERMISSION);
+ }
+ }
+ finally {
+ jedis10.close();
+ }
+
+ }
+
+ qid_sql = " AND A.uid="+qid;
+ }
+ else if(partnerId > 0) {
+
+ String ugm_key = GroupMemberCache.genKey(groupId, partnerId);
+ String lev = Redis.use("group1_db10").hget(ugm_key, "lev");
+ boolean mgr = StringUtil.isNotEmpty(lev) && Integer.parseInt(lev) < 3;
+
+ String p = Utility.getChildParentSql(groupId, partnerId, true);
+ if(mgr) {
+ p = p + ",0";
+ }
+
+ qid_sql = String.format(" AND (A.parentId in(%s) or A.uid = %s)", p, partnerId);
+ }
+
+ if(timeType == 0) {
+
+ beginTime = DateUtils.getBeginDay() ;
+ endTime =DateUtils.getEndDay();
+ }else if(timeType == 1) {
+
+ beginTime = DateUtils.getBeginDay() - 3600 * 24 ;
+ endTime = DateUtils.getBeginDay();
+ }
+ else if(timeType == 2) {
+
+ beginTime = DateUtils.getBeginDay() - 3600 * 48 ;
+ endTime = DateUtils.getBeginDay() - 3600 * 24;
+ }
+
+ String sql = String.format("SELECT IFNULL(SUM(B.win), 0) AS win,IFNULL(SUM(B.round), 0) AS round,IFNULL(SUM(B.score), 0) AS score,A.uid,A.hp,A.lev,A.partnerLev "
+ + "FROM group_member AS A "
+ + "LEFT JOIN group_member_log AS B ON A.groupId = B.groupId and A.uid = B.uid AND B.time >=%s AND B.time <%s "
+ + "WHERE A.groupId = %s %s "
+ + "GROUP BY A.uid "
+ + "ORDER BY round DESC "
+ + "limit %s,%s",
+ beginTime,endTime,groupId,qid_sql,limit,num);
+
+ ITArray arr = DataBase.use().executeQueryByTArray(sql);
+ if (arr.size() > 0) {
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ try {
+ for (int i = 0; i < arr.size(); ++i) {
+
+ ITObject obj = arr.getTObject(i);
+ AccountBean acc = AccountCache.getAccount(obj.getInt("uid"));
+ if (acc != null) {
+ obj.putString("nick", acc.nick);
+ } else {
+ obj.putString("nick", StringUtil.Empty);
+ }
+ }
+ } finally {
+ jedis9.close();
+ }
+ }
+ obj1.putTArray("members", arr);
+ obj1.putInt("limit", limit);
+
+ return obj1;
+ }
+
+ /**
+ * 获取战绩列表
+ * @param platform
+ * @param groupId
+ * @param limit
+ * @param num
+ * @return
+ */
+ public static ITObject getRecords(String platform,int groupId,
+ int limit,int num,
+ int qid,int uid,int includeMembers,
+ int timeType,int beginTime,int endTime) throws Exception{
+
+ boolean find = true;
+ boolean mgr = true;
+ boolean tagIsPartner = false;
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+ try {
+
+ GroupMemberBean mng = GroupCache.getMember(groupId, uid);
+ int _lev = mng.lev;
+ mgr = _lev < 3;
+
+ if(qid>0) {
+
+ GroupMemberBean tag = GroupCache.getMember(groupId, qid);
+ if (tag!=null) {
+
+ int parentId = tag.parentId;
+ if(!mgr) {
+
+ if(parentId==0) {
+
+ find = false;
+ }else {
+
+ if(tag.partnerLev > 0) {
+ tagIsPartner= true;
+ }
+ List par_list = Utility.getMemberParents(jedis10, groupId, includeMembers == 0 ? parentId : qid, true);
+ if(par_list==null || !par_list.contains(uid)) {
+
+ find = false;
+ }
+ }
+ }
+ }else {
+
+ find = false;
+ }
+ }
+ }finally {
+ jedis10.close();
+ }
+
+
+ ITArray militaryList = TArray.newInstance();
+ if(find) {
+
+ String where = StringUtil.Empty;
+ if(timeType == 0) {
+
+ where = String.format("gid=%s and time>=%s and time<=%s",groupId,beginTime,endTime);
+ }
+ else if(timeType == 1) {
+
+ beginTime = DateUtils.getBeginMonth();
+ where = String.format("gid=%s and time>=%s",groupId,beginTime);
+ }
+ else if(timeType == 2) {
+
+ beginTime = DateUtils.getBeginLastMonth();
+ endTime = DateUtils.getBeginMonth();
+ where = String.format("gid=%s and time>=%s and time<=%s",groupId,beginTime,endTime);
+ }
+ else {
+ beginTime = DateUtils.getBeginDay() - 259200;
+ endTime = DateUtils.getEndDay();
+ where = String.format("gid=%s and time>=%s and time<=%s",groupId,beginTime,endTime);
+ }
+
+ if(qid==0) {
+ if (!mgr)
+ {
+ String p = Utility.getChildParentSql(groupId, uid, true);
+ where += String.format(" and (parentId in(%s) or uid = %s)", p, uid);
+ }
+ }else {
+
+ if(includeMembers == 1) {
+
+ String p;
+ if(tagIsPartner) {
+ p = Utility.getChildParentSql(groupId, qid, true);
+ where += String.format(" and (parentId in(%s) or uid = %s)", p, qid);
+ }
+ else {
+ where += " and uid="+qid;
+ }
+ }
+ else {
+ where += " and uid="+qid;
+ }
+ }
+
+
+
+ String sql = String.format("select rec_key from room_rec_log where %s ORDER BY time desc limit %s,%s",
+ where,limit,num);
+
+
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+
+ if(list.size()>0) {
+ Jedis jedis5 = Redis.use("group1_db5").getJedis();
+ try {
+ for(int i=0;i=%s",
+ groupId,roomid,time3last);
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+ if(list.size()==0)return null;
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+ try {
+ GroupMemberBean mng = GroupCache.getMember(groupId, uid);
+ int _lev = mng.lev;
+ boolean mgr = _lev < 3;
+ if(!mgr) {
+ for(int i=0;i par_list = Utility.getMemberParents(jedis10,groupId, par, true);
+ if(par_list!=null&&par_list.contains(uid)) {
+ find = true;
+ break;
+ }
+ }
+ }else {
+ find = true;
+ }
+ }finally {
+ jedis10.close();
+ }
+ if(!find)return null;
+
+ ITArray militaryList = TArray.newInstance();
+ Jedis jedis5 = Redis.use("group1_db5").getJedis();
+ try {
+ for(int i = 0; i < list.size(); i++) {
+ String rec_key = list.getTObject(i).getString("rec_key");
+ ITObject data = Utility.getMilitaryList(jedis5,rec_key, platform);
+ boolean flag = true;
+ for(int j = 0; j < militaryList.size(); j++) {
+ ITObject temp = militaryList.getTObject(j);
+ String temp_create_time = temp.getString("create_time");
+ String create_time = data.getString("create_time");
+ String temp_rec_key = temp.getString("military_id");
+
+ if (temp_rec_key.equals(rec_key) && create_time.equals(temp_create_time))
+ {
+ flag = false;
+ break;
+ }
+ }
+
+ if (flag)
+ {
+ militaryList.addTObject(data);
+ }
+ }
+
+ return militaryList;
+ }finally {
+ jedis5.close();
+ }
+ }
+
+
+ /**
+ *
+ * @param groupId
+ * @param uid
+ * @param limit
+ * @param num
+ * @param type 1上分 2下分 3合伙人上分 4合伙人下分
+ * @return
+ * @throws Exception
+ */
+ public static final ITObject getHpLogMgr(int groupId,int uid,int limit,int num,int type,int qid,String tagName) throws Exception {
+ GroupMemberBean mng = GroupCache.getMember(groupId, uid);
+ int beginDay = DateUtils.getBeginDay();
+ int beginTime = beginDay - 9 * 24 *3600;
+ if (mng.lev >= 3)
+ {
+ beginTime = beginDay - 2 * 24 *3600;
+ }
+
+ long endTime = DateUtils.getEndDay();
+
+ int reason = MGRLOG_TYPE[type-1];
+ String mgr_sql = StringUtil.Empty;
+ String qid_sql = StringUtil.Empty;
+
+ ITArray arr = null;
+
+ if(type > 2) {
+
+ mgr_sql = "and A.mgr_id="+uid;
+
+ if(StringUtil.isNotEmpty(tagName) || qid > 0) {
+
+ if(qid > 0) {
+
+ qid_sql = "and A.uid="+qid;
+
+ String where_sql = String.format("WHERE A.gid = %s "
+ + "and A.reason = %s "
+ + "and A.time>=%s "
+ + "and A.time <=%s %s %s",groupId,reason,beginTime,endTime,mgr_sql,qid_sql);
+
+ String sql = String.format("SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ arr =DataBase.use().executeQueryByTArray(sql);
+ }
+
+ if(StringUtil.isNotEmpty(tagName)) {
+
+ String where_sql = String.format("WHERE A.gid = %s "
+ + "and A.reason = %s "
+ + "and A.time>=%s "
+ + "and A.time <=%s %s %s",groupId,reason,beginTime,endTime,mgr_sql,qid_sql);
+
+ String sql = String.format("SELECT A.uid,A.mgr_id,A.hp,A.cur_hp,A.time "
+ + "FROM group_hp_log as A "
+ + "RIGHT JOIN account as B "
+ + "ON A.uid = B.id and B.nick like '%%%s%%' "
+ + "%s ORDER BY time desc "
+ + "limit %s,%s",tagName,where_sql,limit,num);
+
+ ITArray temp = DataBase.use().executeQueryByTArray(sql);
+ if(temp.size() > 0) {
+ if(arr == null) {
+ arr = temp;
+ }
+ else {
+
+ for(int i = 0; i 0 && mo.getInt("uid") == qid) {
+ continue;
+ }
+ arr.addTObject(temp.getTObject(i));
+ }
+ }
+ }
+ }
+ }
+ else {
+ String where_sql = String.format("WHERE A.gid = %s "
+ + "and A.reason = %s "
+ + "and A.time>=%s "
+ + "and A.time <=%s %s %s",groupId,reason,beginTime,endTime,mgr_sql,qid_sql);
+
+ String sql = String.format("SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ arr =DataBase.use().executeQueryByTArray(sql);
+ }
+ }
+ else {
+
+ if(StringUtil.isNotEmpty(tagName) || qid > 0) {
+
+ if(qid > 0) {
+ qid_sql = "and (A.uid="+qid;
+ qid_sql +=" or A.mgr_id="+qid + ")";
+
+ String where_sql = String.format("WHERE A.gid = %s "
+ + "and A.reason = %s "
+ + "and A.time>=%s "
+ + "and A.time <=%s %s %s",groupId,reason,beginTime,endTime,mgr_sql,qid_sql);
+
+ String sql = String.format("SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ arr =DataBase.use().executeQueryByTArray(sql);
+ }
+
+ if(StringUtil.isNotEmpty(tagName)) {
+
+ String where_sql = String.format("WHERE A.gid = %s "
+ + "and A.reason = %s "
+ + "and A.time>=%s "
+ + "and A.time <=%s %s %s",groupId,reason,beginTime,endTime,mgr_sql,qid_sql);
+
+ String sql = String.format("SELECT A.uid,A.mgr_id,A.hp,A.cur_hp,A.time "
+ + "FROM group_hp_log as A "
+ + "RIGHT JOIN account as B "
+ + "ON (A.uid = B.id OR A.mgr_id = B.id) and B.nick like '%%%s%%' "
+ + "%s ORDER BY time desc "
+ + "limit %s,%s",tagName,where_sql,limit,num);
+
+ ITArray temp = DataBase.use().executeQueryByTArray(sql);
+ if(temp.size() > 0) {
+ if(arr == null) {
+ arr = temp;
+ }
+ else {
+
+ for(int i = 0; i 0 && mo.getInt("uid") == qid) {
+ continue;
+ }
+ arr.addTObject(temp.getTObject(i));
+ }
+ }
+ }
+
+ }
+ }else {
+
+ String where_sql = String.format("WHERE A.gid = %s "
+ + "and A.reason = %s "
+ + "and A.time>=%s "
+ + "and A.time <=%s %s %s",groupId,reason,beginTime,endTime,mgr_sql,qid_sql);
+
+ String sql = String.format("SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ arr =DataBase.use().executeQueryByTArray(sql);
+ }
+
+ }
+
+ ITObject resData = TObject.newInstance();
+ resData.putInt("limit", limit);
+
+ if(arr != null) {
+
+ for(int i=0;i=%s and time <=%s",groupId,ConsumeCode.HP_PUMP,beginTime,endTime);
+
+ String sql = String.format("SELECT uid,hp,roomid,pid,time FROM group_hp_log %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ ITArray arr =DataBase.use().executeQueryByTArray(sql);
+ for(int i=0;i %s",groupId,tagId,reason_sql,time);
+ String sql = String.format("SELECT mgr_id,hp,reason,cur_hp,time,info,roomid "
+ + "FROM group_hp_log %s "
+ + "ORDER BY time desc "
+ + "limit %s,%s",
+ where_sql,limit,num);
+ log.info("jefe sql:"+sql);
+ ITArray arr =DataBase.use().executeQueryByTArray(sql);
+ for(int i=0;i0) {
+ AccountBean acc = AccountCache.getAccount(obj.getInt("mgr_id"));
+ obj.putString("m_nick", acc.nick);
+ }
+ }
+ ITObject resData = TObject.newInstance();
+ resData.putInt("limit", limit);
+ resData.putTArray("hp_logs", arr);
+ return resData;
+ }
+
+ /**
+ * 体力值详情
+ * @param groupId
+ * @param tagId
+ * @param limit
+ * @param num
+ * @param choose
+ * @return
+ */
+ public static final ITObject getHpLogDetailInfo(int groupId,int tagId,String roomId,int time) throws Exception{
+ String reason_sql = StringUtil.Empty;
+ reason_sql += ConsumeCode.HP_CLEARING+ ",";
+ reason_sql += ConsumeCode.HP_PUMP+ ",";
+ reason_sql += ConsumeCode.HP_XIPAI_PUMP+ ",";
+ reason_sql += ConsumeCode.HP_ANCHOU_PUMP + ",";
+ if(StringUtil.isNotEmpty(reason_sql)) {
+ reason_sql = reason_sql.substring(0, reason_sql.length()-1);
+ }else {
+ reason_sql = "0";
+ }
+
+ String where_sql = String.format("WHERE gid = %s and uid =%s and reason in(%s) and roomId ='%s' and time >= %s and time <= %s",groupId,tagId,reason_sql,roomId,time - 7200,time + 3600);
+ String sql = String.format("SELECT mgr_id,hp,reason,cur_hp,time,info,roomid "
+ + "FROM group_hp_log %s "
+ + "ORDER BY time desc",
+ where_sql);
+ try {
+ ITArray arr =DataBase.use().executeQueryByTArray(sql);
+ for(int i=0;i0) {
+ AccountBean acc = AccountCache.getAccount(obj.getInt("mgr_id"));
+ obj.putString("m_nick", acc.nick);
+ }
+ }
+ ITObject resData = TObject.newInstance();
+ resData.putTArray("hp_logs", arr);
+ return resData;
+ }
+ catch (Exception e)
+ {
+ log.info("sql error:"+sql);
+ log.error(e);
+ }
+
+ ITObject resData = TObject.newInstance();
+ return resData;
+ }
+
+ private static final int _getCountValue(Jedis jedis9,String key,int beginTime,int endTime) {
+ String str = null;
+ int tem = beginTime;
+ int tem_day = (endTime - beginTime) /86400;
+ int count =0;
+ for(int k=0;k=%s and time <=%s and uid=%s and hp != 0",
+ groupId,ConsumeCode.HP_PARTNER_REWARD,ConsumeCode.HP_PARTNER_XIPAI_REWARD,ConsumeCode.HP_PARTNER_ANCHOU_REWARD,beginTime,endTime,tagId);
+ int total_num = 0;
+ int total_hp = 0;
+ if(limit==0) {
+ String count_sql = String.format("SELECT IFNULL(SUM(round),0) AS num,IFNULL(SUM(hp),0) AS total_hp FROM group_hp_log %s",where_sql);
+ ITArray arr =DataBase.use().executeQueryByTArray(count_sql);
+ if(arr.size()>0) {
+ ITObject obj = arr.getTObject(0);
+ total_num = obj.getDouble("num").intValue();
+ total_hp = obj.getDouble("total_hp").intValue();
+ }
+ }
+
+ String sql = String.format("SELECT hp,pid,roomid,time,round,reason,info FROM group_hp_log %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ ITArray arr =DataBase.use().executeQueryByTArray(sql);
+ ITObject resData = TObject.newInstance();
+ resData.putInt("limit", limit);
+ resData.putTArray("reward_logs", arr);
+ resData.putInt("total_num", total_num);
+ resData.putInt("total_hp", total_hp);
+ return resData;
+ }
+
+ /**
+ * 奖励统计
+ * @param groupId
+ * @param pid
+ * @param beginTime
+ * @param endTime
+ * @return
+ */
+ public static final ITObject getRewardLogCount(int groupId,int pid,int beginTime,int endTime) {
+ String p_key = pid>0?(":p"+pid):StringUtil.Empty;
+ String valid_key = String.format("g%s:valid_room%s",groupId,p_key);
+ String round_key = String.format("g%s:round%s",groupId,p_key);
+ String hp_cost_key = String.format("g%s:hp_cost%s",groupId,p_key);
+ String hp_reward_key = String.format("g%s:hp_reward%s",groupId,p_key);
+
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ try {
+ int v_round = _getCountValue(jedis9,valid_key,beginTime,endTime);
+ int round = _getCountValue(jedis9,round_key,beginTime,endTime);
+ int hp_cost = _getCountValue(jedis9,hp_cost_key,beginTime,endTime);
+ int hp_reward = _getCountValue(jedis9,hp_reward_key,beginTime,endTime);
+ ITObject resData = TObject.newInstance();
+ resData.putInt("v_round", v_round);
+ resData.putInt("round", round);
+ resData.putInt("hp_cost", hp_cost);
+ resData.putInt("gains", hp_cost-hp_reward);
+ return resData;
+ }finally {
+ jedis9.close();
+ }
+
+ }
+
+ /**
+ * 体力值提取记录
+ * @param groupId
+ * @param tagid
+ * @param limit
+ * @param num
+ * @param beginTime
+ * @param endTime
+ * @return
+ * @throws Exception
+ */
+ public static final ITObject getHpLogTakeInfo(int groupId,int uid, int tagId, int limit,int num,int beginTime,int endTime) throws Exception{
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+ try {
+ GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid);
+ if (uid_bean == null) {
+ throw new WebException(ErrorCode.GROUP_NOT_MEMBER);
+ }
+
+ if (uid_bean.lev >= 3)
+ {
+ List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true);
+ if (par_list == null || !par_list.contains(uid)) {
+ throw new WebException(ErrorCode.GROUP_NOT_PERMISSION);
+ }
+ }
+ }
+ finally {
+ jedis10.close();
+ }
+
+ String where_sql = String.format("WHERE gid = %s and uid=%s and reason = %s and time>=%s and time <=%s",groupId,tagId,ConsumeCode.HP_TAKE_REWARD,beginTime,endTime);
+
+ String sql = String.format("SELECT hp,time FROM group_hp_log %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ ITArray arr =DataBase.use().executeQueryByTArray(sql);
+ ITObject resData = TObject.newInstance();
+ resData.putInt("limit", limit);
+ resData.putTArray("hp_logs", arr);
+ return resData;
+ }
+
+ public static final ITObject getHpLogTakeBankInfo(int groupId,int uid, int tagId,int limit,int num,int beginTime,int endTime) throws Exception{
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+ try {
+ GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid);
+ if (uid_bean == null) {
+ throw new WebException(ErrorCode.GROUP_NOT_MEMBER);
+ }
+
+ if (uid_bean.lev >= 3 && uid != tagId)
+ {
+ List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true);
+ if (par_list == null || !par_list.contains(uid)) {
+ throw new WebException(ErrorCode.GROUP_NOT_PERMISSION);
+ }
+ }
+ }
+ finally {
+ jedis10.close();
+ }
+
+ String where_sql = String.format("WHERE gid = %s and uid=%s and (reason = %s or reason = %s) and time>=%s and time <=%s",groupId,tagId,ConsumeCode.HP_TAKE_BANK,ConsumeCode.HP_SAVE_BANK,beginTime,endTime);
+
+ String sql = String.format("SELECT hp,time FROM group_hp_log %s ORDER BY time desc limit %s,%s",where_sql,limit,num);
+ ITArray arr =DataBase.use().executeQueryByTArray(sql);
+ ITObject resData = TObject.newInstance();
+ resData.putInt("limit", limit);
+ resData.putTArray("hp_logs", arr);
+ return resData;
+ }
+
+
+
+ /**
+ * 获取消耗统计
+ * @param groupId
+ * @return
+ */
+ public static final ITArray getCostCount(int groupId, int uid, int beginTime,int endTime) {
+ String gp_key = GroupCache.genPidsKey(groupId);
+ Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 10, 11);
+ GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid);
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ ITArray arr = TArray.newInstance();
+ try {
+ if (uid_bean.lev < 3)
+ {
+ for(String pid:pids) {
+
+ ITObject obj = TObject.newInstance();
+
+ String round_key = String.format("g%s:round:p%s",groupId,pid);
+ obj.putInt("round", _getCountValue(jedis9,round_key,beginTime,endTime)*100);
+
+ String valid_key = String.format("g%s:valid_room:p%s",groupId,pid);
+ obj.putInt("valid", _getCountValue(jedis9,valid_key,beginTime,endTime)*100);
+
+ String no_valid_key = String.format("g%s:no_valid_room:p%s",groupId,pid);
+ obj.putInt("no_valid", _getCountValue(jedis9,no_valid_key,beginTime,endTime)*100);
+
+ String diamo_cost_key = String.format("g%s:diamo_cost:p%s",groupId,pid);
+ obj.putInt("diamo_cost", _getCountValue(jedis9,diamo_cost_key,beginTime,endTime)*100);
+
+ obj.putInt("pid", Integer.parseInt(pid));
+
+ arr.addTObject(obj);
+ }
+ }
+ else {
+ for(String pid:pids) {
+
+ ITObject obj = TObject.newInstance();
+ String round_key = String.format("g{%s}:m%s:all_count:p%s", groupId, uid,pid);
+ int all_round = _getCountValue(jedis9,round_key,beginTime,endTime);
+ obj.putInt("round", all_round);
+
+ String valid_key = String.format("g{%s}:m%s:valid_round2:p%s", groupId,uid,pid);
+ int valid = _getCountValue(jedis9,valid_key,beginTime,endTime);
+ obj.putInt("valid", valid);
+
+ int no_valid_key = all_round - valid;
+ obj.putInt("no_valid", no_valid_key);
+
+ String diamo_cost_key = String.format("g{%s}:m%s:valid_diamo:p%s", groupId,uid,pid);
+ obj.putInt("diamo_cost", _getCountValue(jedis9,diamo_cost_key,beginTime,endTime));
+
+ obj.putInt("pid", Integer.parseInt(pid));
+
+ arr.addTObject(obj);
+ }
+ }
+ }finally {
+ jedis9.close();
+ }
+ return arr;
+ }
+
+ /**
+ * 获取局数统计
+ * @param groupId
+ * @return
+ */
+ public static final ITArray getRoundCount(int groupId,int pid) {
+ int bengin = DateUtils.getBeginDay() - 29 *86400;
+
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ ITArray arr = TArray.newInstance();
+ try {
+ String p_key = pid>0?(":p"+pid):StringUtil.Empty;
+ for(int i=0;i<30;++i) {
+ String round_key = String.format("g%s:round%s:d%s",groupId,p_key,bengin);
+ String r_str = jedis9.get(round_key);
+ ITObject obj = TObject.newInstance();
+ obj.putInt("time", bengin);
+ int r_num = 0;
+ if(StringUtil.isNotEmpty(r_str)) {
+ r_num = Integer.parseInt(r_str);
+ }
+ obj.putInt("num", r_num);
+ arr.addTObject(obj);
+ bengin +=86400;
+ }
+ }finally {
+ jedis9.close();
+ }
+ return arr;
+ }
+
+ /**
+ * 获取体力值消耗统计
+ * @param groupId
+ * @return
+ */
+ public static final ITArray getHpConsumeCount(int groupId,int uid) {
+ int bengin = DateUtils.getBeginDay() - 2 *86400;
+
+ Jedis jedis9 = Redis.use("group1_db9").getJedis();
+ ITArray arr = TArray.newInstance();
+ try {
+ String key = String.format("g%s:m%s:consume_hp", groupId,uid);
+ for(int i=0;i<3;++i) {
+ String hp_key = String.format("%s:d%s",key,bengin);
+ String r_str = jedis9.get(hp_key);
+ ITObject obj = TObject.newInstance();
+ obj.putInt("time", bengin);
+ int r_num = 0;
+ if(StringUtil.isNotEmpty(r_str)) {
+ r_num = Integer.parseInt(r_str);
+ }
+ obj.putInt("num", r_num);
+ arr.addTObject(obj);
+ bengin +=86400;
+ }
+ }finally {
+ jedis9.close();
+ }
+ return arr;
+ }
+
+ /**
+ * 获取体力值统计信息
+ * @param groupId
+ * @return
+ * @throws Exception
+ */
+ public static final ITObject getHpCountInfo(int groupId) throws Exception {
+ String sql = String.format("SELECT uid FROM group_member WHERE groupId=%s"
+ + " AND partnerLev >0",groupId);
+ ITArray list = DataBase.use().executeQueryByTArray(sql);
+ Jedis jedis10 = Redis.use("group1_db10").getJedis();
+ int _t_hp = 0;
+ try {
+ for(int i=0;i0) t_hp1,"
+ + " (SELECT IFNULL(SUM(ABS(hp)),0) %s AND hp <0) t_hp2", where, where);
+ ITArray arr = DataBase.use().executeQueryByTArray(count_sql);
+ ITObject obj1 = TObject.newInstance();
+ if (arr.size() > 0) {
+ ITObject obj = arr.getTObject(0);
+ obj1.putLong("hp_num1", obj.getDouble("t_hp1").longValue());
+ obj1.putLong("hp_num2", obj.getDouble("t_hp2").longValue());
+ } else {
+ obj1.putLong("hp_num1", 0);
+ obj1.putLong("hp_num2", 0);
+ }
+ obj1.putLong("hp_num3", _t_hp);
+ return obj1;
+ }
+}
diff --git a/robots/robotchangma/src/main/java/com/robotcm/service/GroupPublisherService.java b/robots/robotchangma/src/main/java/com/robotcm/service/GroupPublisherService.java
new file mode 100644
index 0000000..3e07414
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/service/GroupPublisherService.java
@@ -0,0 +1,117 @@
+package com.robotcm.service;
+
+import com.taurus.core.entity.ITObject;
+import com.taurus.core.entity.TObject;
+import com.taurus.core.plugin.redis.Redis;
+
+public class GroupPublisherService {
+ public static final String CHANNEL_NAME = "mgr_group";
+
+ private static final String CMD_ADD_ROOM = "add_room";
+ private static final String CMD_DEL_ROOM = "del_room";
+ private static final String CMD_DEL_PLAY = "del_play";
+ private static final String CMD_ADD_PLAY = "add_play";
+ private static final String CMD_UPDATE_PLAY = "update_play";
+ private static final String CMD_DEL_GROUP = "del_group";
+ private static final String CMD_UPDATE_GROUP = "update_group";
+
+ private static final String CMD_UPDATE_JOINS = "update_joins";
+ private static final String CMD_UPDATE_MAIL_TIP = "update_mail_tip";
+// private static final String CMD_UPDATE_MEMBER = "update_member";
+
+ public static void addRoomEvt(int groupId, String roomid) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putString("roomid", roomid);
+ data.putString("cmd", CMD_ADD_ROOM);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void delRoomEvt(int groupId, String roomid) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putString("roomid", roomid);
+ data.putString("cmd", CMD_DEL_ROOM);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void delPlayEvt(int groupId, int pid) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putInt("pid", pid);
+ data.putString("cmd", CMD_DEL_PLAY);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void addPlayEvt(int groupId, int pid) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putInt("pid", pid);
+ data.putString("cmd", CMD_ADD_PLAY);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void updatePlayEvt(int groupId, int pid) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putInt("pid", pid);
+ data.putString("cmd", CMD_UPDATE_PLAY);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void delGroupEvt(int groupId) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putString("cmd", CMD_DEL_GROUP);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void updateGroupEvt(int groupId, String name, boolean ban,String notice,int option,int showNum) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putString("cmd", CMD_UPDATE_GROUP);
+ data.putString("name", name);
+ data.putBoolean("ban", ban);
+ data.putString("notice", notice);
+ data.putInt("option", option);
+ data.putInt("show_num", showNum);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void updateJoinsEvt(int groupId, int joins) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putInt("joins", joins);
+ data.putString("cmd", CMD_UPDATE_JOINS);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ public static void updateMailTipEvt(int groupId, int uid) {
+ ITObject data = TObject.newInstance();
+ data.putInt("gid", groupId);
+ data.putInt("uid", uid);
+ data.putString("cmd", CMD_UPDATE_MAIL_TIP);
+ Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+
+ /**
+ * 1 hp 2 等级 3 合伙人等级
+ *
+ * @param groupId
+ * @param uid
+ * @param type
+ * @param value
+ */
+ public static void updateMemberEvt(int groupId, int uid, int type, int value) {
+// if (type == 1) {
+// return;
+// }
+// ITObject data = TObject.newInstance();
+// data.putInt("gid", groupId);
+// data.putInt("uid", uid);
+// data.putInt("type", type);
+// data.putInt("value", value);
+// data.putString("cmd", CMD_UPDATE_MEMBER);
+// Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
+ }
+}
diff --git a/robots/robotchangma/src/main/java/com/robotcm/service/GroupRoomService.java b/robots/robotchangma/src/main/java/com/robotcm/service/GroupRoomService.java
new file mode 100644
index 0000000..1d27bc9
--- /dev/null
+++ b/robots/robotchangma/src/main/java/com/robotcm/service/GroupRoomService.java
@@ -0,0 +1,1121 @@
+package com.robotcm.service;
+
+import java.util.*;
+
+import com.data.bean.*;
+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.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 jdk.nashorn.internal.objects.Global;
+import redis.clients.jedis.Jedis;
+
+public class GroupRoomService {
+ private static final Logger log = Logger.getLogger(GroupRoomService.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 = gb.svr_list;
+ Integer conns = null;
+ for(String str : gamesvrs) {
+ 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;
+ }
+ }
+ return svr;
+ }
+
+
+
+ private final static String createGroupRoom(String session, int groupId, int pid) throws Exception {
+ Jedis jedis0 = Redis.use("group1_db0").getJedis();
+ try {
+ GroupPlayBean gpb = GroupCache.getPlay(groupId, pid);
+ if (gpb==null) {
+ throw new WebException(ErrorCode.GROUP_PLAY_EXIST);
+ }
+
+ int gameId = gpb.gameId;
+ GameBean gb = GameCache.getGame(gameId);
+ String svr = _getSvr(jedis0,gb);
+ if (svr == null) {
+ log.error("createGroupRoom gameId:" + gameId + " svr:"+svr);
+ throw new WebException(ErrorCode.NO_SERVICE);
+ }
+
+ String grooms_key = GroupCache.genRoomsKey(groupId);
+ GroupBean group = GroupCache.getGroup(groupId);
+ ITObject configData = TObject.newFromJsonData(gpb.config);
+ int maxPlayers = gpb.maxPlayers;
+
+ int opt = configData.getInt("opt");
+
+ String owner_session = AccountCache.genKey(group.owner);
+ Integer pay = gb.pay.get("pay"+opt+"_"+maxPlayers);
+ if(pay == null) {
+ log.warn("pay no set!");
+ throw new WebException(ErrorCode._FAILED);
+ }
+
+ if(pay > 0) {
+ ArrayList result_list = Utility.payDiamo(jedis0, owner_session,pay);
+ if(result_list==null) {
+ throw new WebException(ErrorCode._FAILED);
+ }
+ long result = result_list.get(0);
+ if(result !=0) {
+ log.error("createGroupRoom groupId:" + groupId + " pid:"+pid + " group.owner:"+group.owner+" no diamo");
+ throw new WebException(ErrorCode.NO_DIAMO);
+ }
+ long cur_diamo = result_list.get(1);
+ Utility.payDiamo(EventType.REDIS_EVENT_GROUP_ROOM, group.owner, gameId, pay,(int)cur_diamo, groupId,pid);
+ }
+
+ int dissolve_opt = group.dissolve_opt;
+ int kick_opt = group.kick_opt;
+
+ String newRoomId = Redis.use("group1_db1").rpop("free_room");
+ Redis.use("group1_db1").lpush("free_room", newRoomId);
+ String room_key = "room:" + newRoomId;
+
+ long time = System.currentTimeMillis() / 1000;
+ Map roomMap = new HashMap();
+ roomMap.put("id", newRoomId);
+ roomMap.put("owner", owner_session);
+ roomMap.put("svr", svr);
+ roomMap.put("AA", "0");
+ roomMap.put("pay", pay+"");
+ roomMap.put("agent", "1");
+ roomMap.put("group", groupId+"");
+ roomMap.put("gpid", pid+"");
+ roomMap.put("payer", group.owner+"");
+ roomMap.put("maxPlayers", maxPlayers + "");
+ roomMap.put("times", gb.opt.get(opt)+"");
+ roomMap.put("opt", opt + "");
+ roomMap.put("status", "0");
+ roomMap.put("hpOnOff", gpb.hpOnOff+"");
+ roomMap.put("rewardType", gpb.rewardType+"");
+ roomMap.put("rewardValueType", gpb.rewardValueType+"");
+ roomMap.put("xipai_rewardType", gpb.xipai_rewardType+"");
+ roomMap.put("xipai_rewardValueType", gpb.xipai_rewardValueType+"");
+ roomMap.put("dismiss_time", DISMISS_TIME[dissolve_opt-1]);
+ roomMap.put("kick_time", KICK_TIME[kick_opt-1]);
+ roomMap.put("hp_times",gpb.hp_times+"");
+ if(gpb.hpOnOff == 1) {
+ ITObject hpObj = TObject.newFromJsonData(gpb.hpConfig);
+ if (hpObj.getInt("limitInRoom") != null) {
+ roomMap.put("limitInRoom", hpObj.getInt("limitInRoom") + "");
+ }
+ configData.putTObject("hpData", hpObj);
+ }
+
+ configData.del("opt");
+ configData.del("AA");
+ roomMap.put("options", configData.toJson());
+ roomMap.put("game", gameId + "");
+ roomMap.put("open", "1");
+ roomMap.put("round", "0");
+ roomMap.put("create_time", time + "");
+ roomMap.put("cache_ver", "1");
+ jedis0.hmset(room_key, roomMap);
+
+ /**
+ * pid open status 剩余空位
+ * 11 1 1 00
+ */
+
+ String fake = jedis0.hget(room_key, "fake");
+ if (StringUtil.isNotEmpty(fake))
+ {
+ log.info("create room:"+newRoomId + " session:" + session + " fake:" + fake + " pay:"+ pay + " players:" + jedis0.hget(room_key, "players"));
+ Redis.use().hset(room_key, "status", 3 + "");
+ Redis.use().hincrBy(room_key, "cache_ver", 1);
+ Redis.use().expire(room_key, 20);
+ }
+ else {
+ Redis.use("group1_db11").zadd(grooms_key, pid*10000+1101, room_key);
+ GroupPublisherService.addRoomEvt(groupId, newRoomId);
+ }
+ return room_key;
+ } finally {
+ jedis0.close();
+ }
+
+ }
+
+ /**
+ * 检测成员在不在房间里
+ * @param groupId
+ * @param session
+ * @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();
+ List room_list = jedis0.hmget(finalRoom,"hpOnOff","hp_times","limitInRoom","status","open","svr","game","gpid","group","maxPlayers","AA","opt","players");
+ 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);
+
+ int gpid = Integer.parseInt(room_list.get(7));
+ GroupBean group_bean = GroupCache.getGroup(groupId);
+ if(!enter_old) {
+ int _maxPlayers = Integer.parseInt(room_list.get(9));
+ String _players = room_list.get(12);
+ 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);
+ }
+ }
+
+
+ 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);
+ }
+
+ 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 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) {
+ String hp = list.get(1);
+ String limitInRoom = room_list.get(2);
+ 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);
+
+ GroupMemberBean gmb = GroupCache.getMember(groupId, uid);
+
+
+ List t_list = Utility.getMemberParents(jedis10,groupId, uid,true);
+ 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);
+ String p_anchou_reward_key = GroupCache.genAnChouRewardKey(groupId,gpid);
+ for(Integer par : t_list) {
+ Double val = jedis10.zscore(p_reward_key, par.toString());
+ int r = 0;
+ if(val != null) {
+ r = val.intValue();
+ }
+ int x = 0;
+ int a = 0;
+ Double xipai_val = jedis10.zscore(p_xipai_reward_key, par.toString());
+ Double anchou_val = jedis10.zscore(p_anchou_reward_key,par.toString());
+ if(xipai_val != null) {
+ x = xipai_val.intValue();
+ }
+ if (anchou_val != null){
+ a = anchou_val.intValue();
+ }
+ if(r>0 || x>0 || a>0) {
+ ITObject obj = TObject.newInstance();
+ obj.putInt("p", par);
+ if (r > 0) {
+ obj.putInt("r", r);
+ }
+ if (x > 0) {
+ obj.putInt("x", x);
+ }
+ if (a > 0) {
+ obj.putInt("a", a);
+ }
+ list1.addTObject(obj);
+ }
+ }
+ 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");
+ //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{
+ String grooms_key = GroupCache.genRoomsKey(groupId);
+ String room_key = "room:"+roomid;
+ Long tem = Redis.use("group1_db11").zrank(grooms_key, room_key);
+ if(tem==null) {
+ throw new WebException(ErrorCode.NO_ROOM_NUM);
+ }
+
+ List