机器人优化
parent
254fd9ba86
commit
9d38ac2c61
|
|
@ -11,6 +11,7 @@
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<build.type>pro</build.type>
|
<build.type>pro</build.type>
|
||||||
|
<kotlin.version>1.5.10</kotlin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
@ -80,7 +81,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.robot</groupId>
|
<groupId>com.robot</groupId>
|
||||||
<artifactId>robot_common</artifactId>
|
<artifactId>robot_common</artifactId>
|
||||||
<version>1.0.7</version>
|
<version>1.0.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-webapp -->
|
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-webapp -->
|
||||||
|
|
@ -96,6 +97,17 @@
|
||||||
<version>2.2.3</version>
|
<version>2.2.3</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-test</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
@ -118,6 +130,50 @@
|
||||||
</webResources>
|
</webResources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test-compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<jvmTarget>1.8</jvmTarget>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>testCompile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>testCompile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.robot</groupId>
|
<groupId>com.robot</groupId>
|
||||||
<artifactId>robot_common</artifactId>
|
<artifactId>robot_common</artifactId>
|
||||||
<version>1.0.7</version>
|
<version>1.0.8</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>robot_common</name>
|
<name>robot_common</name>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<kotlin.version>1.5.10</kotlin.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!--依赖 taurus-core -->
|
<!--依赖 taurus-core -->
|
||||||
|
|
@ -44,16 +45,67 @@
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>1.2.17</version>
|
<version>1.2.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-test</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test-compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<jvmTarget>1.8</jvmTarget>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.6.1</version>
|
<version>3.6.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>testCompile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>testCompile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- <compilerArgument>-parameters</compilerArgument> -->
|
<!-- <compilerArgument>-parameters</compilerArgument> -->
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
package hunan;
|
package hunan;
|
||||||
|
|
||||||
import com.game.Global;
|
|
||||||
import com.game.Util;
|
import com.game.Util;
|
||||||
import com.taurus.core.entity.ITArray;
|
import com.taurus.core.entity.ITArray;
|
||||||
import com.taurus.core.entity.ITObject;
|
import com.taurus.core.entity.ITObject;
|
||||||
import com.taurus.core.entity.TArray;
|
import com.taurus.core.entity.TArray;
|
||||||
import com.taurus.core.entity.TObject;
|
import com.taurus.core.entity.TObject;
|
||||||
import com.taurus.core.plugin.database.DataBase;
|
import com.taurus.core.plugin.database.DataBase;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
import com.taurus.core.util.Logger;
|
import com.taurus.core.util.Logger;
|
||||||
import com.taurus.core.util.StringUtil;
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
import taurus.client.Message;
|
import taurus.client.Message;
|
||||||
import taurus.client.TaurusClient;
|
import taurus.client.TaurusClient;
|
||||||
import taurus.util.*;
|
import taurus.util.*;
|
||||||
|
|
@ -19,15 +20,12 @@ import java.util.*;
|
||||||
|
|
||||||
public class HuNanChangSha {
|
public class HuNanChangSha {
|
||||||
|
|
||||||
|
|
||||||
public static int changShaCard = 0;
|
public static int changShaCard = 0;
|
||||||
public static boolean isTinChi = false;
|
public static boolean isTinChi = false;
|
||||||
public static boolean isTinPeng = false;
|
public static boolean isTinPeng = false;
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(DoTest.class);
|
// private static final Logger log = Logger.getLogger(DoTest.class);
|
||||||
|
|
||||||
//湖南长沙麻将手牌
|
|
||||||
private List<Integer> changShaCardInhand = new ArrayList<>();
|
|
||||||
|
|
||||||
private List<Integer> changShaCardInhandgang = new ArrayList<>();
|
private List<Integer> changShaCardInhandgang = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -35,7 +33,9 @@ public class HuNanChangSha {
|
||||||
//长沙麻将出过的牌
|
//长沙麻将出过的牌
|
||||||
private List<Integer> changShachuguopai = new ArrayList<>();
|
private List<Integer> changShachuguopai = new ArrayList<>();
|
||||||
|
|
||||||
private Map<Integer,Integer> chuGuoPainum = new HashMap<>();
|
private List<Integer> changShaCardInhand = new ArrayList<>();
|
||||||
|
|
||||||
|
private Map<Integer, Integer> chuGuoPainum = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
//杠的牌
|
//杠的牌
|
||||||
|
|
@ -53,24 +53,16 @@ public class HuNanChangSha {
|
||||||
// 玩家座位号
|
// 玩家座位号
|
||||||
public static int seat = 0;
|
public static int seat = 0;
|
||||||
|
|
||||||
public static int playerId = 0;
|
|
||||||
|
|
||||||
public static int cardToOut1 = 0;
|
|
||||||
|
|
||||||
// 会话标识
|
// 会话标识
|
||||||
public static String session = "";
|
public static String session = "";
|
||||||
// 访问令牌
|
// 访问令牌
|
||||||
public static String token = "";
|
public static String token = "";
|
||||||
//红中麻将算法
|
|
||||||
// private static HongZhongSuanFa hongZhongSuanFa = new HongZhongSuanFa();
|
|
||||||
|
|
||||||
private static ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest();
|
private static ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest();
|
||||||
|
|
||||||
|
|
||||||
// 公共的getter和setter方法
|
// 公共的getter和setter方法
|
||||||
public List<Integer> getChangShaCardInhand() {
|
|
||||||
return changShaCardInhand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getgangdepai() {
|
public List<Integer> getgangdepai() {
|
||||||
return gangdepai;
|
return gangdepai;
|
||||||
|
|
@ -89,11 +81,15 @@ public class HuNanChangSha {
|
||||||
return chowGroup;
|
return chowGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> getChangShaCardInhand() {
|
||||||
|
return changShaCardInhand;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Integer> getChuGuoCardInhand() {
|
public List<Integer> getChuGuoCardInhand() {
|
||||||
return changShachuguopai;
|
return changShachuguopai;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer,Integer> getChuGuoPainum() {
|
public Map<Integer, Integer> getChuGuoPainum() {
|
||||||
return chuGuoPainum;
|
return chuGuoPainum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,23 +121,34 @@ public class HuNanChangSha {
|
||||||
* @param message 消息对象
|
* @param message 消息对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getCard(String command, Message message) {
|
public String getCard(String command, Message message, TaurusClient client, Map<String, Object> mapclient) {
|
||||||
|
|
||||||
if (command.equalsIgnoreCase("819")) {
|
if (command.equalsIgnoreCase("819")) {
|
||||||
ITObject param = message.param;
|
ITObject param = message.param;
|
||||||
if (param == null) {
|
if (param == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Jedis jedis222 = Redis.use("group1_db2").getJedis();
|
||||||
|
|
||||||
|
|
||||||
if (param.getInt("player") != null) {
|
if (param.getInt("player") != null) {
|
||||||
|
Integer player = param.getInt("player");
|
||||||
int drawnCard = param.getInt("card");
|
int drawnCard = param.getInt("card");
|
||||||
changShaSuanFaTest.drawnCards = drawnCard;//存储摸到的牌
|
changShaSuanFaTest.drawnCards = drawnCard;//存储摸到的牌
|
||||||
changShaCardInhand.add(drawnCard);
|
changShaCardInhand.add(drawnCard);
|
||||||
changShaSuanFaTest.analyzeHand(changShaCardInhand);
|
|
||||||
|
|
||||||
|
|
||||||
|
if (jedis222.hget("{robortInfo}:" + player, "circleId") != null && jedis222.hget("{robortInfo}:" + player, "pid") != null) {
|
||||||
|
String circleId = jedis222.hget("{robortInfo}:" + player, "circleId");
|
||||||
|
String pid = jedis222.hget("{robortInfo}:" + player, "pid");
|
||||||
|
String getStart = "g{" + circleId + "}:play:" + pid;
|
||||||
|
if (!pid.equals("0")) {
|
||||||
|
jedis222.hset(getStart, String.valueOf(player), "2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
jedis222.close();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +164,6 @@ public class HuNanChangSha {
|
||||||
// 直接调用hongZhongSuanFaTest中的shouldPong方法,它已经包含了所有需要的规则
|
// 直接调用hongZhongSuanFaTest中的shouldPong方法,它已经包含了所有需要的规则
|
||||||
return changShaSuanFaTest.shouldPong(proposedCard, changShaCardInhand);
|
return changShaSuanFaTest.shouldPong(proposedCard, changShaCardInhand);
|
||||||
|
|
||||||
// return hongZhongSuanFaTest.shouldPong(proposedCard, Arrays.asList(305,304,303,207,207,204,204,208,208,201,201,412,412));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -182,13 +188,17 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
// {bank_seat=1, laiziCard=0, laiziCard2=0, laiziCard2Before=0, jing=0, laiziCardBefore=0, card_list=[101, 103, 104, 201, 204, 207, 208, 209, 307, 309, 501, 502, 503]}
|
// {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");
|
ITArray cardList = param.getTArray("card_list");
|
||||||
|
|
||||||
|
List<Integer> handCards = new ArrayList<>();
|
||||||
|
for (int i = 0; i < cardList.size(); i++) {
|
||||||
|
handCards.add(cardList.getInt(i));
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < cardList.size(); i++) {
|
for (int i = 0; i < cardList.size(); i++) {
|
||||||
changShaCardInhand.add(cardList.getInt(i));
|
changShaCardInhand.add(cardList.getInt(i));
|
||||||
}
|
}
|
||||||
// if (changShaCardInhand.size() > 13) {
|
|
||||||
// outCard(client);
|
|
||||||
|
|
||||||
// }
|
System.out.println("changShaCardInhand" + changShaCardInhand);
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -231,61 +241,60 @@ public class HuNanChangSha {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理 吃,碰,杠,补,胡
|
* 处理 吃,碰,杠,补,胡
|
||||||
|
*
|
||||||
* @param param
|
* @param param
|
||||||
* @param client
|
* @param client
|
||||||
* @return
|
* @return 吃
|
||||||
吃
|
* [TCP->814] data:{"tip_list":[{"type":1,"id":1,"opcard":[108,109],"weight":1,"card":107}]}
|
||||||
[TCP->814] data:{"tip_list":[{"type":1,"id":1,"opcard":[108,109],"weight":1,"card":107}]}
|
* 吃 碰
|
||||||
吃 碰
|
* {"tip_list":[{"type":1,"id":1,"opcard":[206,205],"weight":1,"card":207},{"type":2,"id":2,"opcard":[207],"weight":2,"card":207}]}
|
||||||
{"tip_list":[{"type":1,"id":1,"opcard":[206,205],"weight":1,"card":207},{"type":2,"id":2,"opcard":[207],"weight":2,"card":207}]}
|
* 碰补
|
||||||
碰补
|
* {"tip_list":[{"type":2,"id":1,"opcard":[101],"weight":2,"card":101},{"type":3,"id":2,"opcard":[101],"weight":3,"card":101}]}
|
||||||
{"tip_list":[{"type":2,"id":1,"opcard":[101],"weight":2,"card":101},{"type":3,"id":2,"opcard":[101],"weight":3,"card":101}]}
|
* 补
|
||||||
补
|
* [TCP->814] data:{"tip_list":[{"type":5,"id":1,"opcard":[101],"weight":3,"card":101}]}
|
||||||
[TCP->814] data:{"tip_list":[{"type":5,"id":1,"opcard":[101],"weight":3,"card":101}]}
|
* 吃,碰,补,杠,
|
||||||
吃,碰,补,杠,
|
* {"tip_list":[{"type":1,"id":1,"opcard":[206,204],"weight":1,"card":205},{"type":1,"id":2,"opcard":[206,207],"weight":1,"card":205},{"type":2,"id":3,"opcard":[205],"weight":2,"card":205},{"type":3,"id":4,"opcard":[205],"weight":3,"card":205},{"type":3,"id":5,"opcard":[205],"weight":4,"card":205}]}
|
||||||
{"tip_list":[{"type":1,"id":1,"opcard":[206,204],"weight":1,"card":205},{"type":1,"id":2,"opcard":[206,207],"weight":1,"card":205},{"type":2,"id":3,"opcard":[205],"weight":2,"card":205},{"type":3,"id":4,"opcard":[205],"weight":3,"card":205},{"type":3,"id":5,"opcard":[205],"weight":4,"card":205}]}
|
* 碰
|
||||||
碰
|
* {"tip_list":[{"type":2,"id":1,"opcard":[207],"weight":2,"card":207}]}
|
||||||
{"tip_list":[{"type":2,"id":1,"opcard":[207],"weight":2,"card":207}]}
|
* 补,杠
|
||||||
补,杠
|
* {"tip_list":[{"type":5,"id":1,"opcard":[207],"weight":3,"card":207},{"type":5,"id":2,"opcard":[207],"weight":4,"card":207}]}
|
||||||
{"tip_list":[{"type":5,"id":1,"opcard":[207],"weight":3,"card":207},{"type":5,"id":2,"opcard":[207],"weight":4,"card":207}]}
|
* <p>
|
||||||
|
* //拟定:
|
||||||
//拟定:
|
* 1、对应的提示事件遍历 实行假设做了处理之后的结果 对应结果的对象
|
||||||
1、对应的提示事件遍历 实行假设做了处理之后的结果 对应结果的对象
|
* boolean isTing 是否听牌
|
||||||
boolean isTing 是否听牌
|
* boolean canTing 能否听牌
|
||||||
boolean canTing 能否听牌
|
* int tingNum 听多少张
|
||||||
int tingNum 听多少张
|
* int isDaHu 是否大胡
|
||||||
int isDaHu 是否大胡
|
* int guzhang 有多少孤章
|
||||||
int guzhang 有多少孤章
|
* int lastHands 差多少手
|
||||||
int lastHands 差多少手
|
* int id tiplist id
|
||||||
int id tiplist id
|
* List<Integer> opcard
|
||||||
List<Integer> opcard
|
* int weight tiplist weight
|
||||||
int weight tiplist weight
|
* int card tiplist card
|
||||||
int card tiplist card
|
* int type tiplist type
|
||||||
int type tiplist type
|
* 2、通过遍历后的结果进行打分
|
||||||
2、通过遍历后的结果进行打分
|
* 打分系统:
|
||||||
打分系统:
|
* 已经听牌: ---> 40
|
||||||
已经听牌: ---> 40
|
* 操作后能听 ---> 20
|
||||||
操作后能听 ---> 20
|
* 操作之后散听 ---> -50
|
||||||
操作之后散听 ---> -50
|
* 听多张,每一张:---> 3
|
||||||
听多张,每一张:---> 3
|
* 孤章,每一张:----> -3
|
||||||
孤章,每一张:----> -3
|
* 差手数:每一手 ----> -5
|
||||||
差手数:每一手 ----> -5
|
* 操作之前是否大胡 ----> 10
|
||||||
操作之前是否大胡 ----> 10
|
* 去掉大胡 -----> -10
|
||||||
去掉大胡 -----> -10
|
* <p>
|
||||||
|
* 先碰107,后补:
|
||||||
先碰107,后补:
|
* {"tip_list":[{"type":5,"id":1,"opcard":[107],"weight":3,"card":107},{"type":5,"id":2,"opcard":[107],"weight":4,"card":107}]}
|
||||||
{"tip_list":[{"type":5,"id":1,"opcard":[107],"weight":3,"card":107},{"type":5,"id":2,"opcard":[107],"weight":4,"card":107}]}
|
* <p>
|
||||||
|
* 手上有3个摸一个204:开补
|
||||||
手上有3个摸一个204:开补
|
* {"tip_list":[{"type":4,"id":1,"opcard":[204],"weight":3,"card":204},{"type":4,"id":2,"opcard":[204],"weight":4,"card":204}]}
|
||||||
{"tip_list":[{"type":4,"id":1,"opcard":[204],"weight":3,"card":204},{"type":4,"id":2,"opcard":[204],"weight":4,"card":204}]}
|
* <p>
|
||||||
|
* 手上有3个,对家打一个206:开补
|
||||||
手上有3个,对家打一个206:开补
|
* {"tip_list":[{"type":3,"id":1,"opcard":[206],"weight":3,"card":206}]}
|
||||||
{"tip_list":[{"type":3,"id":1,"opcard":[206],"weight":3,"card":206}]}
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public String actionCard(ITObject param, TaurusClient client){
|
public String actionCard(ITObject param, TaurusClient client) {
|
||||||
ITArray tipList = param.getTArray("tip_list");
|
ITArray tipList = param.getTArray("tip_list");
|
||||||
log.info("tipList" +tipList);
|
// log.info("tipList" +tipList);
|
||||||
ITObject params = TObject.newInstance();
|
ITObject params = TObject.newInstance();
|
||||||
int card = 0;
|
int card = 0;
|
||||||
|
|
||||||
|
|
@ -294,22 +303,22 @@ public class HuNanChangSha {
|
||||||
yupanhandcard.addAll(changShaCardInhand);
|
yupanhandcard.addAll(changShaCardInhand);
|
||||||
//进行操作之前能否下听
|
//进行操作之前能否下听
|
||||||
|
|
||||||
List<Integer> shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand,chowGroup,pongGroup,gangdepai);
|
List<Integer> shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand, chowGroup, pongGroup, gangdepai);
|
||||||
boolean beforelisten = false;//记录操作之前的下听状态
|
boolean beforelisten = false;//记录操作之前的下听状态
|
||||||
System.out.println("shifoutingpai"+shifoutingpai);
|
System.out.println("shifoutingpai" + shifoutingpai);
|
||||||
if (shifoutingpai.size() > 0) {
|
if (shifoutingpai.size() > 0) {
|
||||||
beforelisten = true;
|
beforelisten = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("beforelisten"+beforelisten);
|
System.out.println("beforelisten" + beforelisten);
|
||||||
//如果杠了之后还能继续听牌则杠
|
//如果杠了之后还能继续听牌则杠
|
||||||
|
|
||||||
//优先处理胡牌
|
//优先处理胡牌
|
||||||
for(int i=0;i<tipList.size();i++){
|
for (int i = 0; i < tipList.size(); i++) {
|
||||||
TObject firstTip1 = (TObject) tipList.get(i).getObject();
|
TObject firstTip1 = (TObject) tipList.get(i).getObject();
|
||||||
int type = firstTip1.getInt("type");
|
int type = firstTip1.getInt("type");
|
||||||
int id = firstTip1.getInt("id");
|
int id = firstTip1.getInt("id");
|
||||||
if (type == 6){
|
if (type == 6) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", id);
|
params.putInt("id", id);
|
||||||
|
|
@ -328,16 +337,14 @@ public class HuNanChangSha {
|
||||||
card = firstTip.getInt("card");
|
card = firstTip.getInt("card");
|
||||||
|
|
||||||
|
|
||||||
|
if ((type == 5 || type == 3 || type == 4) && weight == 4) {
|
||||||
|
|
||||||
if ((type == 5 || type == 3 || type==4)&&weight==4) {
|
|
||||||
//判断开杠后是否能下听
|
//判断开杠后是否能下听
|
||||||
List<Integer> gangusecars = new ArrayList<>();
|
List<Integer> gangusecars = new ArrayList<>();
|
||||||
gangusecars.addAll(changShaCardInhand);
|
gangusecars.addAll(changShaCardInhand);
|
||||||
|
|
||||||
if (type == 3) {
|
if (type == 3) {
|
||||||
Util.removeCard(gangusecars,card,3);
|
Util.removeCard(gangusecars, card, 3);
|
||||||
List<Integer> shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars,chowGroup,pongGroup,gangdepai);
|
List<Integer> shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
|
||||||
System.out.println(shifoutingpai3);
|
System.out.println(shifoutingpai3);
|
||||||
|
|
||||||
if (shifoutingpai3.size() > 0) {
|
if (shifoutingpai3.size() > 0) {
|
||||||
|
|
@ -346,8 +353,8 @@ public class HuNanChangSha {
|
||||||
List<Integer> allList = new ArrayList<>();
|
List<Integer> allList = new ArrayList<>();
|
||||||
allList.addAll(changShaCardInhand);
|
allList.addAll(changShaCardInhand);
|
||||||
allList.addAll(changShachuguopai);
|
allList.addAll(changShachuguopai);
|
||||||
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai3,allList);
|
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai3, allList);
|
||||||
if (jutingnum==0){
|
if (jutingnum == 0) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -356,14 +363,14 @@ public class HuNanChangSha {
|
||||||
return "不开杠";
|
return "不开杠";
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.removeCard(changShaCardInhand,card,3);
|
Util.removeCard(changShaCardInhand, card, 3);
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", id);
|
params.putInt("id", id);
|
||||||
client.send("612", params, response -> {
|
client.send("612", params, response -> {
|
||||||
});
|
});
|
||||||
return "开杠";
|
return "开杠";
|
||||||
}else{
|
} else {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -376,10 +383,9 @@ public class HuNanChangSha {
|
||||||
if (type == 4) {
|
if (type == 4) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Util.removeCard(changShaCardInhand,card,4);
|
// Util.removeCard(changShaCardInhand,card,4);
|
||||||
Util.removeCard(gangusecars,card,4);
|
Util.removeCard(gangusecars, card, 4);
|
||||||
List<Integer> shifoutingpai4 = changShaSuanFaTest.handscardshifoutingpai(gangusecars,chowGroup,pongGroup,gangdepai);
|
List<Integer> shifoutingpai4 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
|
||||||
if (shifoutingpai4.size() > 0) {
|
if (shifoutingpai4.size() > 0) {
|
||||||
//开杠
|
//开杠
|
||||||
|
|
||||||
|
|
@ -387,8 +393,8 @@ public class HuNanChangSha {
|
||||||
List<Integer> allList = new ArrayList<>();
|
List<Integer> allList = new ArrayList<>();
|
||||||
allList.addAll(changShaCardInhand);
|
allList.addAll(changShaCardInhand);
|
||||||
allList.addAll(changShachuguopai);
|
allList.addAll(changShachuguopai);
|
||||||
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai4,allList);
|
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai4, allList);
|
||||||
if (jutingnum==0){
|
if (jutingnum == 0) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -397,14 +403,14 @@ public class HuNanChangSha {
|
||||||
return "不开杠";
|
return "不开杠";
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.removeCard(changShaCardInhand,card,4);
|
Util.removeCard(changShaCardInhand, card, 4);
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", id);
|
params.putInt("id", id);
|
||||||
client.send("612", params, response -> {
|
client.send("612", params, response -> {
|
||||||
});
|
});
|
||||||
return "开杠";
|
return "开杠";
|
||||||
}else{
|
} else {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -416,8 +422,8 @@ public class HuNanChangSha {
|
||||||
if (type == 5) {
|
if (type == 5) {
|
||||||
//Util.removeCard(changShaCardInhand,card,1);
|
//Util.removeCard(changShaCardInhand,card,1);
|
||||||
|
|
||||||
Util.removeCard(gangusecars,card,1);
|
Util.removeCard(gangusecars, card, 1);
|
||||||
List<Integer> shifoutingpai5 = changShaSuanFaTest.handscardshifoutingpai(gangusecars,chowGroup,pongGroup,gangdepai);
|
List<Integer> shifoutingpai5 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
|
||||||
if (shifoutingpai5.size() > 0) {
|
if (shifoutingpai5.size() > 0) {
|
||||||
//开杠
|
//开杠
|
||||||
|
|
||||||
|
|
@ -425,8 +431,8 @@ public class HuNanChangSha {
|
||||||
List<Integer> allList = new ArrayList<>();
|
List<Integer> allList = new ArrayList<>();
|
||||||
allList.addAll(changShaCardInhand);
|
allList.addAll(changShaCardInhand);
|
||||||
allList.addAll(changShachuguopai);
|
allList.addAll(changShachuguopai);
|
||||||
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai5,allList);
|
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai5, allList);
|
||||||
if (jutingnum==0){
|
if (jutingnum == 0) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -435,14 +441,14 @@ public class HuNanChangSha {
|
||||||
return "不开杠";
|
return "不开杠";
|
||||||
}
|
}
|
||||||
|
|
||||||
Util.removeCard(changShaCardInhand,card,1);
|
Util.removeCard(changShaCardInhand, card, 1);
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", id);
|
params.putInt("id", id);
|
||||||
client.send("612", params, response -> {
|
client.send("612", params, response -> {
|
||||||
});
|
});
|
||||||
return "开杠";
|
return "开杠";
|
||||||
}else{
|
} else {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -459,10 +465,10 @@ public class HuNanChangSha {
|
||||||
//判断是否是大胡
|
//判断是否是大胡
|
||||||
int beforeIsDahu = 0;
|
int beforeIsDahu = 0;
|
||||||
|
|
||||||
beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard,chowGroup,pongGroup,gangdepai);
|
beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
|
||||||
System.out.println("bef:"+beforeIsDahu);
|
System.out.println("bef:" + beforeIsDahu);
|
||||||
//5、门清
|
//5、门清
|
||||||
if (yupanhandcard.size()==13&&beforelisten){
|
if (yupanhandcard.size() == 13 && beforelisten) {
|
||||||
beforeIsDahu = 5;//门清
|
beforeIsDahu = 5;//门清
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,8 +476,8 @@ public class HuNanChangSha {
|
||||||
List<Integer> allSeeCard = new ArrayList<>();
|
List<Integer> allSeeCard = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
Map<Integer,ITObject> pingfenResult = new HashMap<>();
|
Map<Integer, ITObject> pingfenResult = new HashMap<>();
|
||||||
Map<Integer,ITObject> idObject = new HashMap<>();
|
Map<Integer, ITObject> idObject = new HashMap<>();
|
||||||
|
|
||||||
//int bupaiid = 0;//补牌id
|
//int bupaiid = 0;//补牌id
|
||||||
for (int i = 0; i < tipList.size(); i++) {
|
for (int i = 0; i < tipList.size(); i++) {
|
||||||
|
|
@ -482,7 +488,7 @@ public class HuNanChangSha {
|
||||||
card = firstTip.getInt("card");
|
card = firstTip.getInt("card");
|
||||||
ITArray opcard = TArray.newInstance();
|
ITArray opcard = TArray.newInstance();
|
||||||
opcard = firstTip.getTArray("opcard");
|
opcard = firstTip.getTArray("opcard");
|
||||||
if (type == 6){
|
if (type == 6) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", id);
|
params.putInt("id", id);
|
||||||
|
|
@ -499,59 +505,59 @@ public class HuNanChangSha {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 1:
|
case 1:
|
||||||
//吃
|
//吃
|
||||||
tmp = changShaSuanFaTest.pingguChi( beforelisten,card,opcard,yupanhandcard,beforeIsDahu,allSeeCard,chowGroup,pongGroup,gangdepai,changShachuguopai);
|
tmp = changShaSuanFaTest.pingguChi(beforelisten, card, opcard, yupanhandcard, beforeIsDahu, allSeeCard, chowGroup, pongGroup, gangdepai, changShachuguopai);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//碰
|
//碰
|
||||||
tmp = changShaSuanFaTest.pingguPeng(beforelisten,card,opcard,yupanhandcard,beforeIsDahu,allSeeCard,chowGroup,pongGroup,gangdepai,changShachuguopai);
|
tmp = changShaSuanFaTest.pingguPeng(beforelisten, card, opcard, yupanhandcard, beforeIsDahu, allSeeCard, chowGroup, pongGroup, gangdepai, changShachuguopai);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//记录下来事件
|
//记录下来事件
|
||||||
if(tmp.size()>0){
|
if (tmp.size() > 0) {
|
||||||
pingfenResult.put(id,tmp);
|
pingfenResult.put(id, tmp);
|
||||||
}
|
}
|
||||||
ITObject sj = new TObject();
|
ITObject sj = new TObject();
|
||||||
sj.putInt("weight", weight);
|
sj.putInt("weight", weight);
|
||||||
sj.putInt("type", type);
|
sj.putInt("type", type);
|
||||||
sj.putTArray("opcard", opcard);
|
sj.putTArray("opcard", opcard);
|
||||||
idObject.put(id,sj);
|
idObject.put(id, sj);
|
||||||
}
|
}
|
||||||
//计算分数
|
//计算分数
|
||||||
System.out.println(pingfenResult);
|
System.out.println(pingfenResult);
|
||||||
if(pingfenResult.size()>0){
|
if (pingfenResult.size() > 0) {
|
||||||
int changeid=changShaSuanFaTest.suanfen(pingfenResult);
|
int changeid = changShaSuanFaTest.suanfen(pingfenResult);
|
||||||
System.out.println("changeid:"+changeid);
|
System.out.println("changeid:" + changeid);
|
||||||
//选择最优的分数
|
//选择最优的分数
|
||||||
if (changeid==0){
|
if (changeid == 0) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
client.send("612", params, response -> {
|
client.send("612", params, response -> {
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}else {
|
} else {
|
||||||
//获取
|
//获取
|
||||||
for(Map.Entry<Integer,ITObject> entry : idObject.entrySet()){
|
for (Map.Entry<Integer, ITObject> entry : idObject.entrySet()) {
|
||||||
if(entry.getKey()==changeid){
|
if (entry.getKey() == changeid) {
|
||||||
ITObject tmp = entry.getValue();
|
ITObject tmp = entry.getValue();
|
||||||
System.out.println("tmp ++++++++++= " + tmp);
|
System.out.println("tmp ++++++++++= " + tmp);
|
||||||
if (tmp.getInt("type")==2){
|
if (tmp.getInt("type") == 2) {
|
||||||
//碰
|
//碰
|
||||||
ITArray outcards = tmp.getTArray("opcard");
|
ITArray outcards = tmp.getTArray("opcard");
|
||||||
for (int i = 0; i < outcards.size(); i++) {
|
for (int i = 0; i < outcards.size(); i++) {
|
||||||
Util.removeCard(changShaCardInhand,outcards.getInt(0),2);
|
Util.removeCard(changShaCardInhand, outcards.getInt(0), 2);
|
||||||
}
|
}
|
||||||
pongGroup.add(outcards.getInt(0));
|
pongGroup.add(outcards.getInt(0));
|
||||||
pongGroup.add(outcards.getInt(0));
|
pongGroup.add(outcards.getInt(0));
|
||||||
pongGroup.add(outcards.getInt(0));
|
pongGroup.add(outcards.getInt(0));
|
||||||
|
|
||||||
}else if (tmp.getInt("type")==1){
|
} else if (tmp.getInt("type") == 1) {
|
||||||
//吃
|
//吃
|
||||||
ITArray outcards = tmp.getTArray("opcard");
|
ITArray outcards = tmp.getTArray("opcard");
|
||||||
for (int i = 0; i < outcards.size(); i++) {
|
for (int i = 0; i < outcards.size(); i++) {
|
||||||
Util.removeCard(changShaCardInhand,outcards.getInt(i),1);
|
Util.removeCard(changShaCardInhand, outcards.getInt(i), 1);
|
||||||
}
|
}
|
||||||
System.out.println("判断吃 +++++++++" + card);
|
System.out.println("判断吃 +++++++++" + card);
|
||||||
System.out.println("判断吃 ==========" + outcards);
|
System.out.println("判断吃 ==========" + outcards);
|
||||||
|
|
@ -591,11 +597,11 @@ public class HuNanChangSha {
|
||||||
List<Integer> tmpChangSch2 = new ArrayList<>();
|
List<Integer> tmpChangSch2 = new ArrayList<>();
|
||||||
tmpChangSch2.addAll(yupanhandcard);
|
tmpChangSch2.addAll(yupanhandcard);
|
||||||
if (type == 3) {
|
if (type == 3) {
|
||||||
Util.removeCard(tmpChangSch2,card,3);
|
Util.removeCard(tmpChangSch2, card, 3);
|
||||||
}else if(type==4){
|
} else if (type == 4) {
|
||||||
Util.removeCard(tmpChangSch2,card,3);
|
Util.removeCard(tmpChangSch2, card, 3);
|
||||||
}else if(type==5){
|
} else if (type == 5) {
|
||||||
Util.removeCard(tmpChangSch2,card,4);
|
Util.removeCard(tmpChangSch2, card, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangshaWinSplitCard.checkNormalHu(tmpChangSch2, map2);
|
ChangshaWinSplitCard.checkNormalHu(tmpChangSch2, map2);
|
||||||
|
|
@ -603,7 +609,7 @@ public class HuNanChangSha {
|
||||||
System.out.println(yupanhandcard);
|
System.out.println(yupanhandcard);
|
||||||
//假设补牌
|
//假设补牌
|
||||||
//如果下听不能不能补牌
|
//如果下听不能不能补牌
|
||||||
if(beforelisten){
|
if (beforelisten) {
|
||||||
System.out.println("b补");
|
System.out.println("b补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
|
|
@ -613,9 +619,9 @@ public class HuNanChangSha {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//去一张下听?
|
//去一张下听?
|
||||||
Map<Integer,List<Integer>> afterDahuOpbg = changShaSuanFaTest.quyizhangDahuTingPai(yupanhandcard,chowGroup,pongGroup,gangdepai);
|
Map<Integer, List<Integer>> afterDahuOpbg = changShaSuanFaTest.quyizhangDahuTingPai(yupanhandcard, chowGroup, pongGroup, gangdepai);
|
||||||
Map<Integer,List<Integer>> afterOpbg = changShaSuanFaTest.quyizhangTingPai(yupanhandcard);
|
Map<Integer, List<Integer>> afterOpbg = changShaSuanFaTest.quyizhangTingPai(yupanhandcard);
|
||||||
if(type==4) {
|
if (type == 4) {
|
||||||
if (afterDahuOpbg.size() > 0 || afterOpbg.size() > 0) {
|
if (afterDahuOpbg.size() > 0 || afterOpbg.size() > 0) {
|
||||||
System.out.println("bs补");
|
System.out.println("bs补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
|
|
@ -627,11 +633,11 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.size() > 0 && weight==3) {
|
if (map.size() > 0 && weight == 3) {
|
||||||
|
|
||||||
if (map2.size() > 0) {
|
if (map2.size() > 0) {
|
||||||
//判断补牌后
|
//判断补牌后
|
||||||
if (Integer.parseInt(map2.get("remainingMelds").toString())>Integer.parseInt(map.get("remainingMelds").toString())&&Integer.parseInt(map.get("remainingMelds").toString())<=2){
|
if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) && Integer.parseInt(map.get("remainingMelds").toString()) <= 2) {
|
||||||
System.out.println("b补");
|
System.out.println("b补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
|
|
@ -639,11 +645,11 @@ public class HuNanChangSha {
|
||||||
client.send("612", params, response -> {
|
client.send("612", params, response -> {
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
//判断七对
|
//判断七对
|
||||||
int dh = changShaSuanFaTest.checkDahu(yupanhandcard,chowGroup,pongGroup,gangdepai);
|
int dh = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
|
||||||
if (dh>0){
|
if (dh > 0) {
|
||||||
System.out.println("不补");
|
System.out.println("不补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
|
|
@ -723,7 +729,7 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", id);
|
params.putInt("id", id);
|
||||||
|
|
@ -765,11 +771,9 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String actionCardBak2(ITObject param, TaurusClient client) {
|
public String actionCardBak2(ITObject param, TaurusClient client) {
|
||||||
ITArray tipList = param.getTArray("tip_list");
|
ITArray tipList = param.getTArray("tip_list");
|
||||||
log.info("tipList" +tipList);
|
// log.info("tipList" +tipList);
|
||||||
//tipList[{opcard=[207, 208], weight=1, id=1, type=1, card=206}]
|
//tipList[{opcard=[207, 208], weight=1, id=1, type=1, card=206}]
|
||||||
boolean chiflag = false;//吃
|
boolean chiflag = false;//吃
|
||||||
boolean pengflag = false; //碰
|
boolean pengflag = false; //碰
|
||||||
|
|
@ -787,7 +791,7 @@ public class HuNanChangSha {
|
||||||
int id = firstTip.getInt("id");
|
int id = firstTip.getInt("id");
|
||||||
int weight = firstTip.getInt("weight");
|
int weight = firstTip.getInt("weight");
|
||||||
card = firstTip.getInt("card");
|
card = firstTip.getInt("card");
|
||||||
if (type == 6){
|
if (type == 6) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", id);
|
params.putInt("id", id);
|
||||||
|
|
@ -795,21 +799,21 @@ public class HuNanChangSha {
|
||||||
});
|
});
|
||||||
return "胡牌";
|
return "胡牌";
|
||||||
}
|
}
|
||||||
if (type == 1){
|
if (type == 1) {
|
||||||
chiflag = true;
|
chiflag = true;
|
||||||
}
|
}
|
||||||
if (type == 2){
|
if (type == 2) {
|
||||||
pengflag = true;
|
pengflag = true;
|
||||||
}
|
}
|
||||||
if (type == 3 && weight ==3){
|
if (type == 3 && weight == 3) {
|
||||||
//补
|
//补
|
||||||
bupai = true;
|
bupai = true;
|
||||||
}
|
}
|
||||||
if (type == 3 && weight ==4){
|
if (type == 3 && weight == 4) {
|
||||||
//杠
|
//杠
|
||||||
minggang = true;
|
minggang = true;
|
||||||
}
|
}
|
||||||
if (type == 5){
|
if (type == 5) {
|
||||||
penggang = true;
|
penggang = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -843,8 +847,6 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理吃 问题
|
* 处理吃 问题
|
||||||
* @param tipList
|
* @param tipList
|
||||||
|
|
@ -1016,10 +1018,11 @@ public class HuNanChangSha {
|
||||||
client.send("612", params, response -> {});
|
client.send("612", params, response -> {});
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理杠碰胡操作
|
* 处理杠碰胡操作
|
||||||
*
|
*
|
||||||
* @param param 消息参数
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
|
@ -1682,8 +1685,6 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public static List<Integer> getOtherCards1(List<Integer> integers, int card) {
|
public static List<Integer> getOtherCards1(List<Integer> integers, int card) {
|
||||||
List<Integer> result = new ArrayList<>();
|
List<Integer> result = new ArrayList<>();
|
||||||
for (Integer num : integers) {
|
for (Integer num : integers) {
|
||||||
|
|
@ -1762,7 +1763,6 @@ public class HuNanChangSha {
|
||||||
resultList.addAll(zigang);
|
resultList.addAll(zigang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 长沙麻将出牌
|
// 长沙麻将出牌
|
||||||
String changShaOutCard = changShaSuanFaTest.outCardSuanFa(changShaCardInhand, pongGroup, chowGroup, gangdepai, resultList);
|
String changShaOutCard = changShaSuanFaTest.outCardSuanFa(changShaCardInhand, pongGroup, chowGroup, gangdepai, resultList);
|
||||||
// String changShaOutCard = changShaSuanFaTest.outCardSuanFa(list, changShaCard,pongGroup);
|
// String changShaOutCard = changShaSuanFaTest.outCardSuanFa(list, changShaCard,pongGroup);
|
||||||
|
|
@ -1791,12 +1791,12 @@ public class HuNanChangSha {
|
||||||
changShachuguopai.add(cardToOut);
|
changShachuguopai.add(cardToOut);
|
||||||
// 从手牌中移除
|
// 从手牌中移除
|
||||||
changShaCardInhand.remove(Integer.valueOf(cardToOut));
|
changShaCardInhand.remove(Integer.valueOf(cardToOut));
|
||||||
|
|
||||||
|
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
client.send("611", params, response -> {
|
client.send("611", params, response -> {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1844,7 +1844,7 @@ public class HuNanChangSha {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HuNanChangSha huNanChangSha = new HuNanChangSha();
|
HuNanChangSha huNanChangSha = new HuNanChangSha();
|
||||||
ITObject params = TObject.newInstance();
|
ITObject params = TObject.newInstance();
|
||||||
TaurusClient tc = new TaurusClient("127.0.0.1","10", TaurusClient.ConnectionProtocol.Tcp);
|
TaurusClient tc = new TaurusClient("127.0.0.1", "10", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
List<Integer> hands1 = new ArrayList<>();
|
List<Integer> hands1 = new ArrayList<>();
|
||||||
hands1.add(209);
|
hands1.add(209);
|
||||||
hands1.add(209);
|
hands1.add(209);
|
||||||
|
|
@ -1864,19 +1864,19 @@ public class HuNanChangSha {
|
||||||
//hands1.add(103);
|
//hands1.add(103);
|
||||||
//hands1.add(102);
|
//hands1.add(102);
|
||||||
|
|
||||||
int card= 203;
|
int card = 203;
|
||||||
huNanChangSha.changShaCardInhand.addAll(hands1);
|
huNanChangSha.changShaCardInhand.addAll(hands1);
|
||||||
TArray tiplist= new TArray();
|
TArray tiplist = new TArray();
|
||||||
ITArray opcard = TArray.newInstance();
|
ITArray opcard = TArray.newInstance();
|
||||||
opcard.addInt(102);
|
opcard.addInt(102);
|
||||||
// opcard.addInt(205);
|
// opcard.addInt(205);
|
||||||
|
|
||||||
// opcard.addInt(203);
|
// opcard.addInt(203);
|
||||||
TObject tob = new TObject();
|
TObject tob = new TObject();
|
||||||
tob.putInt("weight",3);
|
tob.putInt("weight", 3);
|
||||||
tob.putInt("id",1);
|
tob.putInt("id", 1);
|
||||||
tob.putInt("type",4);
|
tob.putInt("type", 4);
|
||||||
tob.putInt("card",card);
|
tob.putInt("card", card);
|
||||||
tob.putTArray("opcard", opcard);
|
tob.putTArray("opcard", opcard);
|
||||||
//tiplist.addTObject(tob);
|
//tiplist.addTObject(tob);
|
||||||
|
|
||||||
|
|
@ -1884,10 +1884,10 @@ public class HuNanChangSha {
|
||||||
// opcard2.addInt(106);
|
// opcard2.addInt(106);
|
||||||
opcard2.addInt(107);
|
opcard2.addInt(107);
|
||||||
TObject tob2 = new TObject();
|
TObject tob2 = new TObject();
|
||||||
tob2.putInt("weight",5);
|
tob2.putInt("weight", 5);
|
||||||
tob2.putInt("id",2);
|
tob2.putInt("id", 2);
|
||||||
tob2.putInt("type",5);
|
tob2.putInt("type", 5);
|
||||||
tob2.putInt("card",card);
|
tob2.putInt("card", card);
|
||||||
tob2.putTArray("opcard", opcard2);
|
tob2.putTArray("opcard", opcard2);
|
||||||
// tiplist.addTObject(tob2);
|
// tiplist.addTObject(tob2);
|
||||||
|
|
||||||
|
|
@ -1895,16 +1895,15 @@ public class HuNanChangSha {
|
||||||
opcard3.addInt(204);
|
opcard3.addInt(204);
|
||||||
opcard3.addInt(205);
|
opcard3.addInt(205);
|
||||||
TObject tob3 = new TObject();
|
TObject tob3 = new TObject();
|
||||||
tob3.putInt("weight",1);
|
tob3.putInt("weight", 1);
|
||||||
tob3.putInt("id",1);
|
tob3.putInt("id", 1);
|
||||||
tob3.putInt("type",1);
|
tob3.putInt("type", 1);
|
||||||
tob3.putInt("card",card);
|
tob3.putInt("card", card);
|
||||||
tob3.putTArray("opcard", opcard3);
|
tob3.putTArray("opcard", opcard3);
|
||||||
tiplist.addTObject(tob3);
|
tiplist.addTObject(tob3);
|
||||||
|
|
||||||
|
|
||||||
|
params.putTArray("tip_list", tiplist);
|
||||||
params.putTArray("tip_list",tiplist);
|
|
||||||
System.out.println(params);
|
System.out.println(params);
|
||||||
//已经吃掉数据
|
//已经吃掉数据
|
||||||
// huNanChangSha.chowGroup.add(205);
|
// huNanChangSha.chowGroup.add(205);
|
||||||
|
|
@ -1917,7 +1916,7 @@ public class HuNanChangSha {
|
||||||
// huNanChangSha.chowGroup.add(206);
|
// huNanChangSha.chowGroup.add(206);
|
||||||
//huNanChangSha.chowGroup.add(204);
|
//huNanChangSha.chowGroup.add(204);
|
||||||
//huNanChangSha.chowGroup.add(205);
|
//huNanChangSha.chowGroup.add(205);
|
||||||
String res = huNanChangSha.actionCard(params,tc);
|
String res = huNanChangSha.actionCard(params, tc);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -957,7 +957,8 @@ public class JiQiRens {
|
||||||
//[TCP->822] data:{"tip_list":[{"type":8,"id":1,"opcard":[],"weight":8,"card":0}],"types":[{"type":21,"value":1}]}
|
//[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}]}
|
//板胡Event [TCP->823] data:{"type":8,"seat":1,"data":[{"opcard":[204,204,204,108,108,108],"type":21,"value":1}]}
|
||||||
if ("811".equalsIgnoreCase(command)) {//初始化收手牌
|
if ("811".equalsIgnoreCase(command)) {//初始化收手牌
|
||||||
huNanChangSha.cardInHead(command, message, client);
|
Map<String, Object> d = null;
|
||||||
|
// huNanChangSha.cardInHead(command, message, client);
|
||||||
} else if ("812".equalsIgnoreCase(command)) {//出牌广播
|
} 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}
|
//{"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 outcard_map = param.getTArray("outcard_map");
|
||||||
|
|
@ -1054,9 +1055,10 @@ public class JiQiRens {
|
||||||
HuNanChangSha.drawCard(command, message);
|
HuNanChangSha.drawCard(command, message);
|
||||||
} else if ("819".equalsIgnoreCase(command)) {
|
} else if ("819".equalsIgnoreCase(command)) {
|
||||||
//摸牌
|
//摸牌
|
||||||
huNanChangSha.getCard(command, message);
|
// huNanChangSha.getCard(command, message);
|
||||||
} else if ("813".equalsIgnoreCase(command)) {//出牌提示
|
} else if ("813".equalsIgnoreCase(command)) {//出牌提示
|
||||||
huNanChangSha.outCard(client,playerOutcardsMap,playerchisMap,playerpengsMap,playermingsMap,playerzisMap);
|
|
||||||
|
// huNanChangSha.outCard(client,playerOutcardsMap,playerchisMap,playerpengsMap,playermingsMap,playerzisMap,null);
|
||||||
} else if ("814".equalsIgnoreCase(command)) {
|
} else if ("814".equalsIgnoreCase(command)) {
|
||||||
//放招提示
|
//放招提示
|
||||||
huNanChangSha.actionCard(param, client);
|
huNanChangSha.actionCard(param, client);
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,609 @@
|
||||||
|
package taurus.newRobot;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.events.Event;
|
||||||
|
import com.taurus.core.events.IEventListener;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.ICallback;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import hunan.HuNanChangSha;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
import redis.clients.jedis.Response;
|
||||||
|
import taurus.client.Message;
|
||||||
|
import taurus.client.MessageResponse;
|
||||||
|
import taurus.client.SocketCode;
|
||||||
|
import taurus.client.TaurusClient;
|
||||||
|
import taurus.client.business.AccountBusiness;
|
||||||
|
import taurus.client.business.GroupRoomBusiness;
|
||||||
|
import taurus.util.ChangShaSuanFaTest;
|
||||||
|
import taurus.util.TinHuChi;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class jiqiren {
|
||||||
|
|
||||||
|
public String wanfaId = "";
|
||||||
|
// 会话标识
|
||||||
|
private String session = "";
|
||||||
|
// 访问令牌
|
||||||
|
public String token = "";
|
||||||
|
|
||||||
|
// 客户端连接对象
|
||||||
|
private TaurusClient client = null;
|
||||||
|
|
||||||
|
|
||||||
|
private Map<String, Object> mapclient = new HashMap<>();
|
||||||
|
|
||||||
|
public TaurusClient getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient(TaurusClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
//进入真人房间
|
||||||
|
public void tcp_jiqirenzhenren(String id) {
|
||||||
|
Jedis jedis0 = Redis.use().getJedis();
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
Jedis jedis2 = Redis.use("group1_db2").getJedis();
|
||||||
|
|
||||||
|
String roomKey = "";
|
||||||
|
String roomId = id.substring(id.indexOf(":") + 1);
|
||||||
|
roomKey = "room:" + roomId;
|
||||||
|
//玩法id
|
||||||
|
String gpid = jedis0.hget(roomKey, "gpid");
|
||||||
|
//圈子id
|
||||||
|
String group = jedis0.hget(roomKey, "group");
|
||||||
|
//获取玩法对应的机器人 g{330800}:play:10
|
||||||
|
String playKey = "g{" + group + "}:play:" + gpid;
|
||||||
|
|
||||||
|
|
||||||
|
String players1 = jedis0.hget(roomKey, "players");
|
||||||
|
|
||||||
|
if (jedis11.hget(playKey, "leftover_robot") != null) {
|
||||||
|
//玩法配置的机器人数量
|
||||||
|
String leftover_robot = jedis11.hget(playKey, "leftover_robot");
|
||||||
|
//机器人主动找真人
|
||||||
|
if (players1 != null && !players1.equals("[]")) {
|
||||||
|
List<String> availableRobots1 = getAvailableRobots1();
|
||||||
|
|
||||||
|
String players = jedis0.hget(roomKey, "players");
|
||||||
|
players = players.substring(1, players.length() - 1);
|
||||||
|
|
||||||
|
String[] playerIds1 = players.split(",");
|
||||||
|
|
||||||
|
String maxPlayers = jedis0.hget(roomKey, "maxPlayers");
|
||||||
|
if (Integer.parseInt(maxPlayers) == 2) {
|
||||||
|
if (playerIds1.length == 1) {
|
||||||
|
//循环playerIds
|
||||||
|
for (int i = 0; i < playerIds1.length; i++) {
|
||||||
|
String playeid = playerIds1[i];
|
||||||
|
if (!availableRobots1.contains(playeid) && Integer.parseInt(leftover_robot) > 0) {
|
||||||
|
Map<String, String> stringStringMap = jedis2.hgetAll(playKey);
|
||||||
|
List<String> zeroValueKeys = getKeysWithValueZero(stringStringMap);
|
||||||
|
System.out.println("值为0的机器人ID: " + zeroValueKeys);
|
||||||
|
String randomKeyFromList = getRandomKeyFromList(zeroValueKeys);
|
||||||
|
System.out.println("随机给的用户id----" + randomKeyFromList);
|
||||||
|
|
||||||
|
|
||||||
|
wanfaId = jedis0.hget(roomKey, "game");
|
||||||
|
|
||||||
|
if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将
|
||||||
|
//client = new TaurusClient("8.138.242.190:6421", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("10".equalsIgnoreCase(wanfaId)) {
|
||||||
|
client = new TaurusClient("127.0.0.1:6311", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
//TaurusClient client1=getClient();
|
||||||
|
client.connect();
|
||||||
|
mapclient.put(randomKeyFromList, client);
|
||||||
|
}
|
||||||
|
if ("66".equalsIgnoreCase(wanfaId)) {
|
||||||
|
// client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ITObject object = null;
|
||||||
|
AccountBusiness accountBusiness = null;
|
||||||
|
accountBusiness = new AccountBusiness();
|
||||||
|
// 登录获取session跟token
|
||||||
|
|
||||||
|
if (jedis0.keys("{user}:" + randomKeyFromList + "_token").size() != 0) {
|
||||||
|
|
||||||
|
Set<String> keys1 = jedis0.keys("{user}:" + randomKeyFromList + "_token");
|
||||||
|
if (keys1 == null) {
|
||||||
|
try {
|
||||||
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ITObject validate = TObject.newInstance();
|
||||||
|
validate.putString("token", object.getString("token"));
|
||||||
|
token = object.getString("token");
|
||||||
|
session = accountBusiness.getSession();
|
||||||
|
} else {
|
||||||
|
Set<String> keys = jedis0.smembers("{user}:" + randomKeyFromList + "_token");
|
||||||
|
List<String> keyList = new ArrayList<>(keys);
|
||||||
|
session = "{user}:" + randomKeyFromList;
|
||||||
|
token = keyList.get(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
try {
|
||||||
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ITObject validate = TObject.newInstance();
|
||||||
|
validate.putString("token", object.getString("token"));
|
||||||
|
token = object.getString("token");
|
||||||
|
session = accountBusiness.getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String roomKey1 = "room:" + roomId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(group), roomKey1, session, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
joinRoom(Integer.parseInt(randomKeyFromList)); //进入房间
|
||||||
|
|
||||||
|
|
||||||
|
jedis2.hset(playKey, randomKeyFromList, "1");
|
||||||
|
String robortInfoKey = "{robortInfo}:" + randomKeyFromList;
|
||||||
|
jedis2.hset(robortInfoKey, "circleId", group);
|
||||||
|
jedis2.hset(robortInfoKey, "pid", gpid);
|
||||||
|
jedis2.hset(robortInfoKey, "room_id", roomId);
|
||||||
|
ready(); //准备
|
||||||
|
|
||||||
|
jedis11.hincrBy(playKey, "leftover_robot", -1);
|
||||||
|
lianjiejiqiren lianjiejiqiren = new lianjiejiqiren();
|
||||||
|
lianjiejiqiren.token = token;
|
||||||
|
lianjiejiqiren.session = session;
|
||||||
|
lianjiejiqiren.lianjie(client, wanfaId, mapclient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(roomKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//进入中括号的房间
|
||||||
|
public void tcp_jiqirezhongkouhao(String id) {
|
||||||
|
Jedis jedis0 = Redis.use().getJedis();
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
Jedis jedis2 = Redis.use("group1_db2").getJedis();
|
||||||
|
String roomKey = "";
|
||||||
|
String roomId = id.substring(id.indexOf(":") + 1);
|
||||||
|
roomKey = "room:" + roomId;
|
||||||
|
//玩法id
|
||||||
|
String gpid = jedis0.hget(roomKey, "gpid");
|
||||||
|
//圈子id
|
||||||
|
String group = jedis0.hget(roomKey, "group");
|
||||||
|
//获取玩法对应的机器人 g{330800}:play:10
|
||||||
|
String playKey = "g{" + group + "}:play:" + gpid;
|
||||||
|
String players1 = jedis0.hget(roomKey, "players");
|
||||||
|
|
||||||
|
if (jedis11.hget(playKey, "leftover_robot") != null && players1 != null) {
|
||||||
|
//玩法配置的机器人数量
|
||||||
|
String leftover_robot = jedis11.hget(playKey, "leftover_robot");
|
||||||
|
//机器人进入退出的房间
|
||||||
|
if (players1.equals("[]")) {
|
||||||
|
String maxPlayers = jedis0.hget(roomKey, "maxPlayers");
|
||||||
|
if (Integer.parseInt(maxPlayers) == 2) {
|
||||||
|
|
||||||
|
if (Integer.parseInt(leftover_robot) > 0) {
|
||||||
|
int count = countValuesEqualToOne(jedis2, playKey);
|
||||||
|
System.out.println("count 数量 +++++++++++++++++++++" + count);
|
||||||
|
if (count < 2) {
|
||||||
|
Map<String, String> stringStringMap = jedis2.hgetAll(playKey);
|
||||||
|
List<String> zeroValueKeys = getKeysWithValueZero(stringStringMap);
|
||||||
|
System.out.println("值为0的机器人ID: " + zeroValueKeys);
|
||||||
|
String randomKeyFromList = getRandomKeyFromList(zeroValueKeys);
|
||||||
|
System.out.println("随机给的用户id----" + randomKeyFromList);
|
||||||
|
|
||||||
|
wanfaId = jedis0.hget(roomKey, "game");
|
||||||
|
|
||||||
|
if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将
|
||||||
|
// client = new TaurusClient("8.138.242.190:6421", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
}
|
||||||
|
if ("10".equalsIgnoreCase(wanfaId)) {
|
||||||
|
client = new TaurusClient("127.0.0.1:6311", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
client.connect();
|
||||||
|
mapclient.put(randomKeyFromList, client);
|
||||||
|
}
|
||||||
|
if ("66".equalsIgnoreCase(wanfaId)) {
|
||||||
|
// client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ITObject object = null;
|
||||||
|
AccountBusiness accountBusiness = null;
|
||||||
|
accountBusiness = new AccountBusiness();
|
||||||
|
// 登录获取session跟token
|
||||||
|
|
||||||
|
if (jedis0.keys("{user}:" + randomKeyFromList + "_token").size() != 0) {
|
||||||
|
|
||||||
|
Set<String> keys1 = jedis0.keys("{user}:" + randomKeyFromList + "_token");
|
||||||
|
if (keys1 == null) {
|
||||||
|
try {
|
||||||
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ITObject validate = TObject.newInstance();
|
||||||
|
validate.putString("token", object.getString("token"));
|
||||||
|
token = object.getString("token");
|
||||||
|
session = accountBusiness.getSession();
|
||||||
|
} else {
|
||||||
|
Set<String> keys = jedis0.smembers("{user}:" + randomKeyFromList + "_token");
|
||||||
|
List<String> keyList = new ArrayList<>(keys);
|
||||||
|
session = "{user}:" + randomKeyFromList;
|
||||||
|
token = keyList.get(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
try {
|
||||||
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
ITObject validate = TObject.newInstance();
|
||||||
|
validate.putString("token", object.getString("token"));
|
||||||
|
token = object.getString("token");
|
||||||
|
session = accountBusiness.getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String roomKey1 = "room:" + roomId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(group), roomKey1, session, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
joinRoom(Integer.parseInt(randomKeyFromList)); //进入房间
|
||||||
|
|
||||||
|
|
||||||
|
jedis2.hset(playKey, randomKeyFromList, "1");
|
||||||
|
String robortInfoKey = "{robortInfo}:" + randomKeyFromList;
|
||||||
|
jedis2.hset(robortInfoKey, "circleId", group);
|
||||||
|
jedis2.hset(robortInfoKey, "pid", gpid);
|
||||||
|
jedis2.hset(robortInfoKey, "room_id", roomId);
|
||||||
|
ready(); //准备
|
||||||
|
|
||||||
|
jedis11.hincrBy(playKey, "leftover_robot", -1);
|
||||||
|
lianjiejiqiren lianjiejiqiren = new lianjiejiqiren();
|
||||||
|
lianjiejiqiren.token = token;
|
||||||
|
lianjiejiqiren.session = session;
|
||||||
|
lianjiejiqiren.lianjie(client, wanfaId, mapclient);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jedis0.close();
|
||||||
|
jedis2.close();
|
||||||
|
jedis11.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//创建房间,进入房间
|
||||||
|
public void createRoomsForCircle(String circleId, Map<String, Integer> playRoomMap) {
|
||||||
|
Jedis jedis2 = Redis.use("group1_db2").getJedis();
|
||||||
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
|
Jedis jedis0 = Redis.use().getJedis();
|
||||||
|
// 按玩法ID排序处理
|
||||||
|
List<Map.Entry<String, Integer>> sortedPlays = playRoomMap.entrySet().stream()
|
||||||
|
.sorted(Map.Entry.comparingByKey())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (Map.Entry<String, Integer> entry : sortedPlays) {
|
||||||
|
String playId = entry.getKey();
|
||||||
|
int requiredRooms = entry.getValue();
|
||||||
|
|
||||||
|
if (requiredRooms <= 0) {
|
||||||
|
System.out.println("玩法 " + playId + ": 跳过创建 (需求数=" + requiredRooms + ")");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isPlaying = true;
|
||||||
|
//获取所有房间
|
||||||
|
Set<String> roomIds = jedis0.keys("room:*");
|
||||||
|
for (String id : roomIds) {
|
||||||
|
String roomId = id.substring(id.indexOf(":") + 1);
|
||||||
|
String roomKey = "room:" + roomId;
|
||||||
|
String players = jedis0.hget(roomKey, "players");
|
||||||
|
if (players != null) {
|
||||||
|
if (players.equals("[]")) {
|
||||||
|
isPlaying = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("玩法 " + playId + ": 创建 " + requiredRooms + " 个房间");
|
||||||
|
|
||||||
|
List<Object> roomsForPlay = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 1; i <= requiredRooms; i++) {
|
||||||
|
try {
|
||||||
|
String keys = "g{" + circleId + "}:play:" + playId;
|
||||||
|
if (jedis11.hget(keys, "leftover_robot") != null && isPlaying) {
|
||||||
|
String leftover_robot = jedis11.hget(keys, "leftover_robot");
|
||||||
|
if (Integer.parseInt(leftover_robot) > 0) {
|
||||||
|
Map<String, String> stringStringMap = jedis2.hgetAll(keys);
|
||||||
|
|
||||||
|
|
||||||
|
List<String> zeroValueKeys = getKeysWithValueZero(stringStringMap);
|
||||||
|
System.out.println("值为0的机器人ID: " + zeroValueKeys);
|
||||||
|
String randomKeyFromList = getRandomKeyFromList(zeroValueKeys);
|
||||||
|
System.out.println("随机给的用户id----" + randomKeyFromList);
|
||||||
|
|
||||||
|
jedis2.hset(keys, randomKeyFromList, "1");
|
||||||
|
|
||||||
|
ITObject object = null;
|
||||||
|
AccountBusiness accountBusiness = null;
|
||||||
|
accountBusiness = new AccountBusiness();
|
||||||
|
|
||||||
|
// 登录获取session跟token
|
||||||
|
if (jedis0.keys("{user}:" + randomKeyFromList + "_token").size() != 0) {
|
||||||
|
Set<String> keys1 = jedis0.keys("{user}:" + randomKeyFromList + "_token");
|
||||||
|
if (keys1 == null) {
|
||||||
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456");
|
||||||
|
ITObject validate = TObject.newInstance();
|
||||||
|
validate.putString("token", object.getString("token"));
|
||||||
|
token = object.getString("token");
|
||||||
|
session = accountBusiness.getSession();
|
||||||
|
} else {
|
||||||
|
Set<String> keys2 = jedis0.smembers("{user}:" + randomKeyFromList + "_token");
|
||||||
|
List<String> keyList = new ArrayList<>(keys2);
|
||||||
|
session = "{user}:" + randomKeyFromList;
|
||||||
|
token = keyList.get(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(randomKeyFromList), "123456");
|
||||||
|
ITObject validate = TObject.newInstance();
|
||||||
|
validate.putString("token", object.getString("token"));
|
||||||
|
token = object.getString("token");
|
||||||
|
session = accountBusiness.getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 调用原有的房间匹配逻辑
|
||||||
|
Object room = GroupRoomBusiness.matchRoom(Integer.parseInt(circleId), Integer.parseInt(playId), session, "Android", false);
|
||||||
|
String game = jedis0.hget(String.valueOf(room), "game");
|
||||||
|
wanfaId = String.valueOf(game);
|
||||||
|
String roomKey = String.valueOf(room);
|
||||||
|
System.out.println("roomkey--------" + roomKey);
|
||||||
|
|
||||||
|
client = null;
|
||||||
|
|
||||||
|
System.out.println("wanfaId" + wanfaId);
|
||||||
|
|
||||||
|
|
||||||
|
if ("22".equalsIgnoreCase(wanfaId)) { //湖南红中麻将
|
||||||
|
client = new TaurusClient("8.138.242.190:6421", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("10".equalsIgnoreCase(wanfaId)) {
|
||||||
|
client = new TaurusClient("127.0.0.1:6311", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
// client.setSession(session);
|
||||||
|
client.connect();
|
||||||
|
mapclient.put(randomKeyFromList, client);
|
||||||
|
}
|
||||||
|
System.out.println("clinet 111 " + client);
|
||||||
|
|
||||||
|
if ("66".equalsIgnoreCase(wanfaId)) {
|
||||||
|
client = new TaurusClient("8.138.242.190:6841", "game", TaurusClient.ConnectionProtocol.Tcp);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("id ++++++" + mapclient);
|
||||||
|
System.out.println("mapclient----" + mapclient);
|
||||||
|
ITObject roomInfos = GroupRoomBusiness.joinRoom(Integer.parseInt(circleId), roomKey, this.session, null);
|
||||||
|
String roomId = roomInfos.getString("room_id");
|
||||||
|
String robort = "{robortInfo}:" + randomKeyFromList;
|
||||||
|
jedis2.hset(robort, "room_id", roomId);
|
||||||
|
jedis2.hset(robort, "circleId", circleId);
|
||||||
|
jedis2.hset(robort, "pid", playId);
|
||||||
|
|
||||||
|
|
||||||
|
joinRoom(Integer.parseInt(randomKeyFromList)); //进入房间
|
||||||
|
|
||||||
|
|
||||||
|
String playKey1 = "g{" + circleId + "}:play:" + playId;
|
||||||
|
|
||||||
|
jedis11.hincrBy(playKey1, "leftover_robot", -1);
|
||||||
|
|
||||||
|
lianjiejiqiren lianjiejiqiren = new lianjiejiqiren();
|
||||||
|
lianjiejiqiren.token = token;
|
||||||
|
lianjiejiqiren.session = session;
|
||||||
|
lianjiejiqiren.lianjie(client, wanfaId, mapclient);
|
||||||
|
ready(); //准备
|
||||||
|
|
||||||
|
if (room != null) {
|
||||||
|
roomsForPlay.add(room);
|
||||||
|
System.out.println(" 第 " + i + " 个房间创建成功");
|
||||||
|
} else {
|
||||||
|
System.out.println(" 第 " + i + " 个房间创建失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
System.err.println("创建过程被中断");
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("创建房间时出错: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jedis2.close();
|
||||||
|
jedis11.close();
|
||||||
|
jedis0.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计Hash中值为"1"的字段数量
|
||||||
|
*/
|
||||||
|
public static int countValuesEqualToOne(Jedis jedis, String key) {
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
Map<String, String> hashData = jedis.hgetAll(key);
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : hashData.entrySet()) {
|
||||||
|
if ("1".equals(entry.getValue())) {
|
||||||
|
count++;
|
||||||
|
System.out.println("找到字段: " + entry.getKey() + " = " + entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//获取所有机器人
|
||||||
|
public List<String> getAvailableRobots1() {
|
||||||
|
Jedis jedis2 = Redis.use("group1_db2").getJedis();
|
||||||
|
|
||||||
|
Set<String> allRobotKeys = jedis2.keys("{robot}:*");
|
||||||
|
List<String> availableRobots = new ArrayList<>();
|
||||||
|
|
||||||
|
// 使用Pipeline提高效率
|
||||||
|
Pipeline pipeline = jedis2.pipelined();
|
||||||
|
List<Response<String>> responses = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String robotKey : allRobotKeys) {
|
||||||
|
responses.add(pipeline.hget(robotKey, "start"));
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline.sync();
|
||||||
|
|
||||||
|
// 提取机器人ID并筛选
|
||||||
|
int index = 0;
|
||||||
|
for (String robotKey : allRobotKeys) {
|
||||||
|
String startStatus = responses.get(index).get();
|
||||||
|
|
||||||
|
String robotId = robotKey.substring(robotKey.indexOf(":") + 1);
|
||||||
|
availableRobots.add(robotId);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
jedis2.close();
|
||||||
|
return availableRobots;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//获取状态为0的机器人
|
||||||
|
public static List<String> getKeysWithValueZero(Map<String, String> robotData) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : robotData.entrySet()) {
|
||||||
|
if ("0".equals(entry.getValue())) {
|
||||||
|
result.add(entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//随机分配机器人
|
||||||
|
public String getRandomKeyFromList(List<String> zeroValueKeys) {
|
||||||
|
if (zeroValueKeys == null || zeroValueKeys.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
|
int randomIndex = random.nextInt(zeroValueKeys.size());
|
||||||
|
return zeroValueKeys.get(randomIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
//监听
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入房间方法
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String joinRoom(int playerId) {
|
||||||
|
try {
|
||||||
|
// 添加2秒延迟
|
||||||
|
Thread.sleep(5000);
|
||||||
|
|
||||||
|
ITObject params = TObject.newInstance();
|
||||||
|
params.putString("session", session + "," + token);
|
||||||
|
|
||||||
|
client.send("1002", params, response -> {
|
||||||
|
ITObject obj = response.messageData.param.getTObject("tableInfo");
|
||||||
|
});
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程休眠方法
|
||||||
|
*
|
||||||
|
* @param time 休眠时间(毫秒)
|
||||||
|
*/
|
||||||
|
public static void sleepTime(int time) {
|
||||||
|
try {
|
||||||
|
// 添加延迟
|
||||||
|
Thread.sleep(time);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备方法
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String ready() {
|
||||||
|
try {
|
||||||
|
// 添加1秒延迟
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ITObject params = TObject.newInstance();
|
||||||
|
params.putString("session", session + "," + token);
|
||||||
|
|
||||||
|
client.send("1003", params, new ICallback<MessageResponse>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void action(MessageResponse messageResponse) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,852 @@
|
||||||
|
|
||||||
|
package taurus.newRobot;
|
||||||
|
|
||||||
|
import com.taurus.core.entity.ITArray;
|
||||||
|
import com.taurus.core.entity.ITObject;
|
||||||
|
import com.taurus.core.entity.TObject;
|
||||||
|
import com.taurus.core.events.Event;
|
||||||
|
import com.taurus.core.events.IEventListener;
|
||||||
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
|
import com.taurus.core.util.ICallback;
|
||||||
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import hunan.HuNanChangSha;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import taurus.client.Message;
|
||||||
|
import taurus.client.MessageResponse;
|
||||||
|
import taurus.client.SocketCode;
|
||||||
|
import taurus.client.TaurusClient;
|
||||||
|
import taurus.util.ChangShaSuanFaTest;
|
||||||
|
import taurus.util.TinHuChi;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class lianjiejiqiren {
|
||||||
|
|
||||||
|
// 会话标识
|
||||||
|
public String session = "";
|
||||||
|
// 访问令牌
|
||||||
|
public String token = "";
|
||||||
|
|
||||||
|
private HuNanChangSha huNanChangSha = new HuNanChangSha();
|
||||||
|
|
||||||
|
private Map<Integer, List<Integer>> playerOutcardsMap = new HashMap<>();
|
||||||
|
|
||||||
|
private Map<Integer, List<Integer>> playerchisMap = new HashMap<>();
|
||||||
|
|
||||||
|
private Map<Integer, List<Integer>> playerpengsMap = new HashMap<>();
|
||||||
|
|
||||||
|
private Map<Integer, List<Integer>> playermingsMap = new HashMap<>();
|
||||||
|
|
||||||
|
private Map<Integer, List<Integer>> playerzisMap = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
public void lianjie(TaurusClient client, String wanfaId, Map<String, Object> mapclient) {
|
||||||
|
// 添加事件监听器处理网络消息
|
||||||
|
client.addEventListener(TaurusClient.NetClientEvent.OnEvent, new IEventListener() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event event) {
|
||||||
|
|
||||||
|
// 获取 msg
|
||||||
|
Message message = (Message) event.getParameter("msg");
|
||||||
|
if (message == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ITObject param = message.param;
|
||||||
|
//回调协议号
|
||||||
|
String command = message.command;
|
||||||
|
|
||||||
|
//根据玩法id 调用不同的回调
|
||||||
|
if (StringUtil.isNotEmpty(command)) {
|
||||||
|
if ("66".equalsIgnoreCase(wanfaId)) {//跑的快
|
||||||
|
// if ("2011".equalsIgnoreCase(command)) { //跑的快 初始化手牌
|
||||||
|
// huNanPaoDeKuai.paoDeKuaiCardInHead(param, client);
|
||||||
|
// } else if ("2021".equalsIgnoreCase(command)) { //出牌广播
|
||||||
|
// huNanPaoDeKuai.paoDekuaiChupaiGuangBo(param);
|
||||||
|
// } else if ("2004".equalsIgnoreCase(command)) { //出牌提示事件,牌权
|
||||||
|
// Integer player = param.getInt("player");
|
||||||
|
// Integer seat1 = param.getInt("seat");
|
||||||
|
//
|
||||||
|
// if (seat1 != null) {
|
||||||
|
// huNanPaoDeKuai.seat = seat1;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //出牌
|
||||||
|
// huNanPaoDeKuai.outCard(client);
|
||||||
|
// } else if ("2007".equalsIgnoreCase(command)) { //结算准备
|
||||||
|
// //type为1 为大结算 type为0为小结算
|
||||||
|
// Integer type = param.getInt("type");
|
||||||
|
//
|
||||||
|
// if (type == 0) {
|
||||||
|
// huNanPaoDeKuai.getSeatRemainHistory().clear();
|
||||||
|
// huNanPaoDeKuai.getPaoDekuaiCardInhand().clear();
|
||||||
|
// ITArray card_list = huNanPaoDeKuai.getCard_list().getTArray("card_list");
|
||||||
|
// card_list.clear();
|
||||||
|
// ready();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (type == 1) {
|
||||||
|
// Jedis jedis11s = Redis.use("group1_db11").getJedis();
|
||||||
|
// try {
|
||||||
|
// String key = "g{" + groupId + "}:play:" + pid;
|
||||||
|
// jedis11s.hincrBy(key, "leftover_robot", 1);
|
||||||
|
// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId);
|
||||||
|
// try {
|
||||||
|
// DataBase.use().executeUpdate(sql);
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// } finally {
|
||||||
|
// jedis11s.close();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// } else if ("2009".equalsIgnoreCase(command)) {
|
||||||
|
// Jedis jedis21 = Redis.use().getJedis();
|
||||||
|
// sleepTime(3000);
|
||||||
|
//
|
||||||
|
// ITObject params = TObject.newInstance();
|
||||||
|
// String[] playerIds2 = null;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Set<String> roomIds = jedis21.keys("room:*");
|
||||||
|
// String roomKey = "";
|
||||||
|
// //拿到所有的机器人
|
||||||
|
// List<Integer> 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<String> 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<String> roomIds = jedis21.keys("room:*");
|
||||||
|
// String roomKey = "";
|
||||||
|
// //拿到所有的机器人
|
||||||
|
// List<Integer> 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<String> roomIds = scanRooms(jedis0, "room:*");
|
||||||
|
// String[] playerIds = null;
|
||||||
|
// for (String roomId : roomIds) {
|
||||||
|
// String rid = roomId.substring(roomId.indexOf(":") + 1);
|
||||||
|
// String roomKey = "room:" + rid;
|
||||||
|
// if (jedis0.hget(roomKey, "players") != null) {
|
||||||
|
// String players = jedis0.hget(roomKey, "players");
|
||||||
|
// if (!players.equals("[]")) {
|
||||||
|
// players = players.substring(1, players.length() - 1);
|
||||||
|
// playerIds = players.split(",");
|
||||||
|
// for (String pyids : playerIds) {
|
||||||
|
// if (Integer.parseInt(pyids) == playerId) {
|
||||||
|
// jedis0.del(roomId);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
} else if ("17".equalsIgnoreCase(wanfaId)) { //字牌放炮罚
|
||||||
|
|
||||||
|
// if ("811".equalsIgnoreCase(command)) { //初始化手牌
|
||||||
|
// huNanFangPaoFa.cardInHead(command, message, client);
|
||||||
|
//
|
||||||
|
// } else if ("819".equalsIgnoreCase(command)) { //摸牌
|
||||||
|
// huNanFangPaoFa.getCard(command, message);
|
||||||
|
// } else if ("813".equalsIgnoreCase(command)) { //出牌 牌权
|
||||||
|
// sleepTime(1500);
|
||||||
|
// huNanFangPaoFa.outCard(client);
|
||||||
|
// } else if ("812".equalsIgnoreCase(command)) { //出牌广播
|
||||||
|
// HuNanFangPaoFa.drawCard(command, message);
|
||||||
|
// } else if ("814".equalsIgnoreCase(command)) { //可执行的 操作 吃碰 偎提胡
|
||||||
|
// huNanFangPaoFa.actionCard(param, client);
|
||||||
|
// } else if ("817".equalsIgnoreCase(command)) { //结算
|
||||||
|
// huNanFangPaoFa.getFangPaoFaCardInhand().clear();
|
||||||
|
// ready();
|
||||||
|
// } else if ("822".equalsIgnoreCase(command)) { //放跑提示
|
||||||
|
//
|
||||||
|
// HuNanFangPaoFa.fangPaoTipEvent(message, client);
|
||||||
|
// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用
|
||||||
|
// try {
|
||||||
|
// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId);
|
||||||
|
// DataBase.use().executeUpdate(sql);
|
||||||
|
//
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
} else if ("108".equalsIgnoreCase(wanfaId)) {//转转麻将
|
||||||
|
// if ("811".equalsIgnoreCase(command)) {//初始化收手牌
|
||||||
|
// huNanZhuanZhuan.cardInHead(command, message, client);
|
||||||
|
// } else if ("812".equalsIgnoreCase(command)) {//出牌广播
|
||||||
|
// HuNanZhuanZhuan.drawCard(command, message);
|
||||||
|
// } else if ("819".equalsIgnoreCase(command)) {//摸牌
|
||||||
|
//
|
||||||
|
// huNanZhuanZhuan.getCard(command, message);
|
||||||
|
// } else if ("813".equalsIgnoreCase(command)) {//出牌提示
|
||||||
|
//// sleepTime(1500);
|
||||||
|
// huNanZhuanZhuan.outCard(client);
|
||||||
|
// } else if ("814".equalsIgnoreCase(command)) {//放招提示
|
||||||
|
// huNanZhuanZhuan.actionCard(param, client);
|
||||||
|
// } else if ("817".equalsIgnoreCase(command)) {//结算
|
||||||
|
// huNanZhuanZhuan.getZhuanZhuanCardInhand().clear();
|
||||||
|
// huNanZhuanZhuan.getZhuanZhuanchuguopai().clear();
|
||||||
|
// ready();
|
||||||
|
// } else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作
|
||||||
|
// huNanZhuanZhuan.shanchuchuguopai(param);
|
||||||
|
// } else if ("820".equalsIgnoreCase(command)) {//换牌提示
|
||||||
|
// HuNanZhuanZhuan.changePlayer(command, message);
|
||||||
|
// } else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用
|
||||||
|
// try {
|
||||||
|
// String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId);
|
||||||
|
// DataBase.use().executeUpdate(sql);
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
} else if ("10".equalsIgnoreCase(wanfaId)) {
|
||||||
|
//长沙麻将 机器人处理事件
|
||||||
|
if ("811".equalsIgnoreCase(command)) {//初始化收手牌
|
||||||
|
// System.out.println("初始化手牌" + session);
|
||||||
|
Jedis jedis222 = Redis.use("group1_db2").getJedis();
|
||||||
|
for (Map.Entry<String, Object> entry : mapclient.entrySet()) {
|
||||||
|
System.out.println("mapclient++++++++++++++++++++++++++++++++"+mapclient);
|
||||||
|
System.out.println("client++++++++++++++++++++++++++++++++++"+client);
|
||||||
|
TaurusClient taurusClient = (TaurusClient) entry.getValue();
|
||||||
|
if (client.getId() == taurusClient.getId()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
System.out.println("key+++++++++++++++++++++++++++++++++++" + key);
|
||||||
|
if (jedis222.hget("{robortInfo}:" + key, "circleId") != null && jedis222.hget("{robortInfo}:" + key, "pid") != null) {
|
||||||
|
String circleId = jedis222.hget("{robortInfo}:" + key, "circleId");
|
||||||
|
System.out.println("circleId +++++++++++++++++++++++++"+circleId);
|
||||||
|
String pid = jedis222.hget("{robortInfo}:" + key, "pid");
|
||||||
|
System.out.println("pid +++++++++++++++++++++++++"+pid);
|
||||||
|
String getStart = "g{" + circleId + "}:play:" + pid;
|
||||||
|
if (!pid.equals("0")){
|
||||||
|
jedis222.hset(getStart, key, "2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jedis222.close();
|
||||||
|
huNanChangSha.cardInHead(command, message, client);
|
||||||
|
System.out.println("client " + client);
|
||||||
|
} else if ("812".equalsIgnoreCase(command)) {//出牌广播
|
||||||
|
//{"opzicards":[{"opzicards":[],"playerId":101555}],"opmingcards":[{"opmingcards":[],"playerId":101555}],"outcard_map":[{"outcards":[209,205],"playerId":101555},{"outcards":[],"playerId":112233}],"card":205,"opchicards":[{"opchicards":[105,103],"playerId":101555}],"oppengcards":[{"oppengcards":[],"playerId":101555}],"seat":1}
|
||||||
|
ITArray outcard_map = param.getTArray("outcard_map");
|
||||||
|
ITArray opchicards = param.getTArray("opchicards");
|
||||||
|
ITArray oppengcards = param.getTArray("oppengcards");
|
||||||
|
ITArray opmingcards = param.getTArray("opmingcards");
|
||||||
|
ITArray opzicards = param.getTArray("opzicards");
|
||||||
|
|
||||||
|
// 清空旧数据,用新数据完全覆盖
|
||||||
|
playerOutcardsMap.clear();
|
||||||
|
playerchisMap.clear();
|
||||||
|
playerpengsMap.clear();
|
||||||
|
playermingsMap.clear();
|
||||||
|
playerzisMap.clear();
|
||||||
|
//出过的牌
|
||||||
|
if (outcard_map != null) {
|
||||||
|
for (int i = 0; i < outcard_map.size(); i++) {
|
||||||
|
ITObject playerData = outcard_map.getTObject(i);
|
||||||
|
int playerId = playerData.getInt("playerId");
|
||||||
|
ITArray outcardsArray = playerData.getTArray("outcards");
|
||||||
|
|
||||||
|
// 转换为List<Integer>
|
||||||
|
List<Integer> 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<Integer> 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<Integer> 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<Integer> 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<Integer> outziList = new ArrayList<>();
|
||||||
|
for (int j = 0; j < outziArray.size(); j++) {
|
||||||
|
outziList.add(outziArray.getInt(j));
|
||||||
|
}
|
||||||
|
playerzisMap.put(playerId, outziList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HuNanChangSha.drawCard(command, message);
|
||||||
|
} else if ("819".equalsIgnoreCase(command)) {
|
||||||
|
for (Map.Entry<String, Object> entry : mapclient.entrySet()) {
|
||||||
|
TaurusClient taurusClient = (TaurusClient) entry.getValue();
|
||||||
|
if (client == taurusClient) {
|
||||||
|
//摸牌
|
||||||
|
huNanChangSha.getCard(command, message, taurusClient,mapclient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ("813".equalsIgnoreCase(command)) {//出牌提示
|
||||||
|
System.out.println("出牌提示 ++++++++++++++++++++++++++++++++");
|
||||||
|
System.out.println("mapclient ++++++++++++++++" + mapclient);
|
||||||
|
|
||||||
|
System.out.println("进入出牌11111111111111112222222");
|
||||||
|
System.out.println("client4444444444444444" + client);
|
||||||
|
huNanChangSha.outCard(client, playerOutcardsMap, playerchisMap, playerpengsMap, playermingsMap, playerzisMap);
|
||||||
|
|
||||||
|
|
||||||
|
} else if ("814".equalsIgnoreCase(command)) {
|
||||||
|
//吃碰杠
|
||||||
|
huNanChangSha.actionCard(param, client);
|
||||||
|
|
||||||
|
} else if ("2009".equalsIgnoreCase(command)) {
|
||||||
|
//db0
|
||||||
|
Jedis jedis22 = Redis.use().getJedis();
|
||||||
|
//db2
|
||||||
|
Jedis jedis33 = Redis.use("group1_db2").getJedis();
|
||||||
|
|
||||||
|
Jedis jedis = Redis.use("group1_db0").getJedis();
|
||||||
|
Integer aid = param.getInt("aid");
|
||||||
|
String getKey = "{robortInfo}:" + aid;
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("param ++++++++++++++++ " + param);
|
||||||
|
|
||||||
|
ITObject params = TObject.newInstance();
|
||||||
|
|
||||||
|
String[] playerIds2 = null;
|
||||||
|
|
||||||
|
if (jedis33.hget(getKey, "pid") != null) {
|
||||||
|
String circleId1 = jedis33.hget(getKey, "circleId");
|
||||||
|
String pid = jedis33.hget(getKey, "pid");
|
||||||
|
|
||||||
|
String key = "g{" + circleId1 + "}:play:" + pid;
|
||||||
|
if (jedis33.hget(getKey, "room_id") != null) {
|
||||||
|
String roomid = jedis33.hget(getKey, "room_id");
|
||||||
|
|
||||||
|
String roomKey = "room:" + roomid;
|
||||||
|
|
||||||
|
if (jedis22.hget(roomKey, "players") != null) {
|
||||||
|
String players = jedis22.hget(roomKey, "players");
|
||||||
|
if (!players.equals("[]")) {
|
||||||
|
players = players.substring(1, players.length() - 1);
|
||||||
|
playerIds2 = players.split(",");
|
||||||
|
if (playerIds2.length == 1) {
|
||||||
|
if (!pid.equals("0")) {
|
||||||
|
Jedis jedis20 = Redis.use("group1_db11").getJedis();
|
||||||
|
System.out.println("进入 -------------------------");
|
||||||
|
jedis20.hincrBy(key, "leftover_robot", 1);
|
||||||
|
jedis20.close();
|
||||||
|
System.out.println("mapclient--------------" + mapclient);
|
||||||
|
|
||||||
|
String room_id = jedis33.hget(getKey, "room_id");
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : mapclient.entrySet()) {
|
||||||
|
String key1 = entry.getKey();
|
||||||
|
if (Integer.parseInt(key1) == aid) {
|
||||||
|
// 获取指定field的值
|
||||||
|
String value = jedis33.hget(key, String.valueOf(aid));
|
||||||
|
if (!value.equals("2")) {
|
||||||
|
sleepTime(4000);
|
||||||
|
jedis33.hset(getKey, "circleId", "0");
|
||||||
|
jedis33.hset(getKey, "pid", "0");
|
||||||
|
jedis33.hset(getKey, "room_id", "0");
|
||||||
|
//退出修改机器人状态
|
||||||
|
jedis33.hset(key, String.valueOf(aid), "0");
|
||||||
|
TaurusClient taurusClient = (TaurusClient) entry.getValue();
|
||||||
|
taurusClient.send("1005", params, response -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jedis33.close();
|
||||||
|
jedis22.close();
|
||||||
|
jedis.close();
|
||||||
|
}
|
||||||
|
} else if ("817".equalsIgnoreCase(command)) {//结算
|
||||||
|
huNanChangSha.getChangShaCardInhand().clear();
|
||||||
|
huNanChangSha.getChuGuoCardInhand().clear();
|
||||||
|
huNanChangSha.getpongGroup().clear();
|
||||||
|
huNanChangSha.getchowGroup().clear();
|
||||||
|
TinHuChi.lastTingCount = 0;
|
||||||
|
TinHuChi.isMoreThanLast = false;
|
||||||
|
ChangShaSuanFaTest.isTin = false;
|
||||||
|
ChangShaSuanFaTest.isChi = false;
|
||||||
|
ChangShaSuanFaTest.isPeng = false;
|
||||||
|
ChangShaSuanFaTest.tinCards.clear();
|
||||||
|
Integer type = param.getInt("type");
|
||||||
|
if (type == 1 || type == 2) { //为1为大结算 为2为解散
|
||||||
|
Jedis jedis11s = Redis.use("group1_db11").getJedis();
|
||||||
|
try {
|
||||||
|
|
||||||
|
//db2
|
||||||
|
Jedis jedis21 = Redis.use("group1_db2").getJedis();
|
||||||
|
try {
|
||||||
|
for (Map.Entry<String, Object> entry : mapclient.entrySet()) {
|
||||||
|
|
||||||
|
TaurusClient taurusClient = (TaurusClient) entry.getValue();
|
||||||
|
if (client == taurusClient) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if (jedis21.hget("{robortInfo}:" + key, "circleId") != null && jedis21.hget("{robortInfo}:" + key, "pid") != null) {
|
||||||
|
String circleId = jedis21.hget("{robortInfo}:" + key, "circleId");
|
||||||
|
String pid = jedis21.hget("{robortInfo}:" + key, "pid");
|
||||||
|
String getStart = "g{" + circleId + "}:play:" + pid;
|
||||||
|
jedis21.hset(getStart, key, "0");
|
||||||
|
|
||||||
|
jedis11s.hincrBy(getStart, "leftover_robot", 1);
|
||||||
|
|
||||||
|
jedis21.hset("{robortInfo}:" + key, "circleId", "0");
|
||||||
|
jedis21.hset("{robortInfo}:" + key, "pid", "0");
|
||||||
|
jedis21.hset("{robortInfo}:" + key, "room_id", "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
jedis21.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
jedis11s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (count != null && count.containsKey(pid)) {
|
||||||
|
// Integer value = count.get(pid);
|
||||||
|
//
|
||||||
|
// // 如果找到了对应的 pid
|
||||||
|
// Jedis jedis12 = Redis.use("group1_db11").getJedis();
|
||||||
|
//
|
||||||
|
// String shangxianRobot = jedis12.hget(playKey, "shangxian_robot");
|
||||||
|
// String leftoverRobot = jedis12.hget(playKey, "leftover_robot");
|
||||||
|
//
|
||||||
|
// if (shangxianRobot != null && leftoverRobot != null) {
|
||||||
|
// if (value == 0) {
|
||||||
|
// jedis12.hset(playKey, "leftover_robot", shangxianRobot);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// jedis12.close();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
ready(client);
|
||||||
|
//写定时器
|
||||||
|
|
||||||
|
} else if ("815".equalsIgnoreCase(command)) { //服务器通知客户端有玩家执行了操作
|
||||||
|
//[TCP->815] data:{"playerid":101555,"card":104,"opcard":[105,103],"from_seat":2,"type":1,"opengang":false}
|
||||||
|
huNanChangSha.shanchuchuguopai(param);
|
||||||
|
|
||||||
|
} else if ("820".equalsIgnoreCase(command)) {//换牌提示
|
||||||
|
huNanChangSha.changePlayer(command, message);
|
||||||
|
} else if ("2008".equalsIgnoreCase(command)) { //解散房间时候恢复机器人账号可以使用
|
||||||
|
|
||||||
|
// Set<String> roomIds = scanRooms(jedis0, "room:*");
|
||||||
|
// String[] playerIds = null;
|
||||||
|
// for (String roomId : roomIds) {
|
||||||
|
// String rid = roomId.substring(roomId.indexOf(":") + 1);
|
||||||
|
// String roomKey = "room:" + rid;
|
||||||
|
//
|
||||||
|
// if (jedis0.hget(roomKey, "players") != null) {
|
||||||
|
// String players = jedis0.hget(roomKey, "players");
|
||||||
|
//
|
||||||
|
// if (!players.equals("[]")) {
|
||||||
|
// players = players.substring(1, players.length() - 1);
|
||||||
|
// playerIds = players.split(",");
|
||||||
|
//
|
||||||
|
// for (String pyids : playerIds) {
|
||||||
|
//
|
||||||
|
// if (Integer.parseInt(pyids) == playerId) {
|
||||||
|
// jedis0.del(roomId);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
} else if ("825".equalsIgnoreCase(command)) {
|
||||||
|
ITObject params = TObject.newInstance();
|
||||||
|
params.putInt("qi", 0);
|
||||||
|
params.putInt("id", 1);
|
||||||
|
client.send("612", params, response -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
} else if ("822".equalsIgnoreCase(command)) {
|
||||||
|
ITObject params = TObject.newInstance();
|
||||||
|
//params.putInt("qi", 0);
|
||||||
|
params.putInt("id", 1);
|
||||||
|
//[TCP->822] data:{"tip_list":[{"type":8,"id":1,"opcard":[],"weight":8,"card":0}],"types":[{"type":21,"value":1}]}
|
||||||
|
//板胡Event [TCP->823] data:{"type":8,"seat":1,"data":[{"opcard":[204,204,204,108,108,108],"type":21,"value":1}]}
|
||||||
|
|
||||||
|
client.send("612", params, response -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
} else if ("835".equalsIgnoreCase(command)) { //听牌天听
|
||||||
|
ITObject params = TObject.newInstance();
|
||||||
|
params.putInt("qi", 0);
|
||||||
|
params.putInt("id", 1);
|
||||||
|
client.send("612", params, response -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//END 长沙麻将
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 添加连接状态监听器
|
||||||
|
client.addEventListener(TaurusClient.NetClientEvent.Connect, new
|
||||||
|
|
||||||
|
IEventListener() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event event) {
|
||||||
|
SocketCode code = (SocketCode) event.getParameter("code");
|
||||||
|
if (code == SocketCode.Connect) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 准备方法
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String ready(TaurusClient client) {
|
||||||
|
try {
|
||||||
|
// 添加1秒延迟
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// cardInhand = new ArrayList<Integer>();
|
||||||
|
// HuNanHongZhong.hongZhongCardInhand();
|
||||||
|
// HuNanFangPaoFa.fangPaoFaCardInhand();
|
||||||
|
|
||||||
|
ITObject params = TObject.newInstance();
|
||||||
|
params.putString("session", session + "," + token);
|
||||||
|
|
||||||
|
client.send("1003", params, new ICallback<MessageResponse>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void action(MessageResponse messageResponse) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void sleepTime(int time) {
|
||||||
|
try {
|
||||||
|
// 添加延迟
|
||||||
|
Thread.sleep(time);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import com.taurus.core.plugin.PluginService;
|
import com.taurus.core.plugin.PluginService;
|
||||||
import hunan.DoTest;
|
//import hunan.DoTest;
|
||||||
import hunan.HuNanChangSha;
|
import hunan.HuNanChangSha;
|
||||||
import hunan.HuNanHongZhong;
|
import hunan.HuNanHongZhong;
|
||||||
import hunan.JiQiRens;
|
//import hunan.JiQiRens;
|
||||||
import taurus.client.NetManager;
|
import taurus.client.NetManager;
|
||||||
import taurus.newRobot.AddRedisRobot;
|
import taurus.newRobot.AddRedisRobot;
|
||||||
import taurus.newRobot.AddRoomRobot;
|
import taurus.newRobot.AddRoomRobot;
|
||||||
|
|
@ -59,7 +59,7 @@ public class Test {
|
||||||
// AddRedisRobot addRedisRobot = new AddRedisRobot();
|
// AddRedisRobot addRedisRobot = new AddRedisRobot();
|
||||||
// addRedisRobot.getData();
|
// addRedisRobot.getData();
|
||||||
|
|
||||||
AddRoomRobot addRoomRobot = new AddRoomRobot();
|
AddRoomRobot addRoomRobot =new AddRoomRobot();
|
||||||
addRoomRobot.addRoom();
|
addRoomRobot.addRoom();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue