修改红中打包问题

master
miaoqingshuai 2026-06-16 21:29:17 +08:00
parent 4ea9fea6f0
commit f22e96c4d4
5 changed files with 464 additions and 397 deletions

View File

@ -25,6 +25,25 @@
</dependencies> </dependencies>
<!-- -->
<!-- <build>-->
<!-- <finalName>robot</finalName>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
<!-- <version>3.6.1</version>-->
<!-- <configuration>-->
<!-- &lt;!&ndash; <compilerArgument>-parameters</compilerArgument> &ndash;&gt;-->
<!-- <source>1.8</source>-->
<!-- <target>1.8</target>-->
<!-- <encoding>UTF-8</encoding>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<build> <build>
<finalName>robot</finalName> <finalName>robot</finalName>
@ -41,7 +60,29 @@
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>robot.mj.EXMainServer</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -36,11 +36,11 @@ public class Config {
/** 游戏服务器主机地址 */ /** 游戏服务器主机地址 */
/*public static final String GAME_SERVER_HOST = "8.134.76.43"; /*public static final String GAME_SERVER_HOST = "8.134.76.43";
public static final String DEFAULT_GROUP_ID = "762479";*/ public static final String DEFAULT_GROUP_ID = "762479";*/
public static final String DEFAULT_GROUP_ID = "426149"; public static final String DEFAULT_GROUP_ID = "383709";
public static final String GAME_SERVER_HOST = "127.0.0.1"; public static final String GAME_SERVER_HOST = "8.163.97.101";
/** 游戏服务器端口 */ /** 游戏服务器端口 */
public static final String GAME_SERVER_PORT = "6421"; public static final String GAME_SERVER_PORT = "26421";
/** 默认密码 */ /** 默认密码 */
public static final String DEFAULT_PASSWORD = "123456"; public static final String DEFAULT_PASSWORD = "123456";

View File

@ -416,6 +416,8 @@ public class EXGameController extends GameController {
//成功响应后才建立映射关系 //成功响应后才建立映射关系
synchronized (robotRoomMapping) { synchronized (robotRoomMapping) {
robotRoomMapping.put(robotUser.getConnecId(), robotUser); robotRoomMapping.put(robotUser.getConnecId(), robotUser);
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
} }
log.info("机器人{"+robotId+"}已成功加入房间{"+roomId+"},建立映射关系"); log.info("机器人{"+robotId+"}已成功加入房间{"+roomId+"},建立映射关系");

View File

@ -8,8 +8,8 @@ import com.taurus.core.events.Event;
import com.taurus.core.events.IEventListener; import com.taurus.core.events.IEventListener;
import com.taurus.core.plugin.redis.Redis; import com.taurus.core.plugin.redis.Redis;
import com.taurus.core.util.ICallback; import com.taurus.core.util.ICallback;
import com.taurus.core.util.Logger;
import com.taurus.core.util.StringUtil; import com.taurus.core.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import robot.mj.business.AccountBusiness; import robot.mj.business.AccountBusiness;
import robot.mj.handler.HuNanHongZhong; import robot.mj.handler.HuNanHongZhong;
@ -20,6 +20,7 @@ import taurus.client.TaurusClient;
import taurus.client.SocketCode; import taurus.client.SocketCode;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import taurus.util.ROBOTEventType; import taurus.util.ROBOTEventType;
import com.taurus.core.util.Logger;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
@ -31,8 +32,9 @@ import static robot.mj.thread.ThreadPoolConfig.scheduleDelay;
* - * -
*/ */
public class RobotConnectionManager { public class RobotConnectionManager {
private static final Logger log = Logger.getLogger(RobotConnectionManager.class);
private static final Logger log = LoggerFactory.getLogger(RobotConnectionManager.class); // private static final Logger log = LoggerFactory.getLogger(RobotConnectionManager.class);
private static final Map<String, HuNanHongZhong> huNanHongZhongInstances = new ConcurrentHashMap<>(); private static final Map<String, HuNanHongZhong> huNanHongZhongInstances = new ConcurrentHashMap<>();
//记录活跃连接 用于资源清理判断 //记录活跃连接 用于资源清理判断
@ -45,8 +47,8 @@ public class RobotConnectionManager {
private static final long MAX_CONNECTION_LIFETIME = 5 * 60 * 1000; private static final long MAX_CONNECTION_LIFETIME = 5 * 60 * 1000;
private final EXGameController exGameController; private final EXGameController exGameController;
private final String host= Config.GAME_SERVER_HOST; private final String host = Config.GAME_SERVER_HOST;
private final int port= Integer.parseInt(Config.GAME_SERVER_PORT); private final int port = Integer.parseInt(Config.GAME_SERVER_PORT);
public RobotConnectionManager() { public RobotConnectionManager() {
exGameController = new EXGameController(); exGameController = new EXGameController();
@ -208,14 +210,14 @@ public class RobotConnectionManager {
ITObject param = message.param; ITObject param = message.param;
//回调协议号 //回调协议号
String command = message.command; String command = message.command;
log.info("收到游戏协议 " + command);
//根据玩法 ID 处理不同的回调 //根据玩法 ID 处理不同的回调
if (StringUtil.isNotEmpty(command)) { if (StringUtil.isNotEmpty(command)) {
//直接处理协议 //直接处理协议
handleProtocol(command, message, client, connecId); handleProtocol(command, message, client, connecId);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("处理游戏协议时发生异常connecId: {}, command: {}", connecId, ((Message)event.getParameter("msg")).command, e); log.error("处理游戏协议时发生异常connecId: {}, command: {}", connecId, ((Message) event.getParameter("msg")).command, e);
} }
} }
}; };
@ -243,14 +245,14 @@ public class RobotConnectionManager {
* 线 * 线
*/ */
public void reconnectToGameServer(MessageResponse response, RobotUser robotUser, TaurusClient client) { public void reconnectToGameServer(MessageResponse response, RobotUser robotUser, TaurusClient client) {
String connecId = robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId(); String connecId = robotUser.getCurrentRoomId() + "_" + robotUser.getRobotId();
//先设置机器人状态为准备状态 //先设置机器人状态为准备状态
robotUser.setStatus(ROBOTEventType.ROBOT_INTOROOM_READY); robotUser.setStatus(ROBOTEventType.ROBOT_INTOROOM_READY);
if(client.isConnected()){ if (client.isConnected()) {
try { try {
log.info(String.valueOf(response.messageData.param)); log.info(String.valueOf(response.messageData.param));
if (response.messageData.param==null) { if (response.messageData.param == null) {
log.info("警告reconnectToGameServer 重连时未获取到参数"); log.info("警告reconnectToGameServer 重连时未获取到参数");
return; return;
} }
@ -363,10 +365,10 @@ public class RobotConnectionManager {
} }
} }
} }
}finally { } finally {
} }
}else { } else {
renconnect(robotUser); renconnect(robotUser);
} }
} }
@ -376,6 +378,19 @@ public class RobotConnectionManager {
*/ */
private void handleProtocol(String command, Message message, TaurusClient client, String connecId) { private void handleProtocol(String command, Message message, TaurusClient client, String connecId) {
RobotUser robotUser = robotRoomMapping.get(connecId); RobotUser robotUser = robotRoomMapping.get(connecId);
log.info("connecId " + connecId);
for (Map.Entry<String, RobotUser> entry : robotRoomMapping.entrySet()) {
String key = entry.getKey();
RobotUser user = entry.getValue();
log.info("Key" + key);
log.info("user seat" + user.getSeat());
log.info("user connecId" + user.getConnecId());
log.info("user robotId" + user.getRobotId());
log.info("robotRoomMapping " + robotRoomMapping);
}
//更新连接的最后访问时间 //更新连接的最后访问时间
EXGameController.updateLastAccessTime(connecId); EXGameController.updateLastAccessTime(connecId);
@ -409,7 +424,7 @@ public class RobotConnectionManager {
} }
//摸牌 //摸牌
else if ("819".equalsIgnoreCase(command)) { else if ("819".equalsIgnoreCase(command)) {
huNanHongZhong.getCard(command, message); huNanHongZhong.getCard(command, message, robotUser);
//处理完协议后保存到Redis //处理完协议后保存到Redis
HuNanHongZhong currentInstance = huNanHongZhongInstances.get(connecId); HuNanHongZhong currentInstance = huNanHongZhongInstances.get(connecId);
currentInstance.saveToRedis(connecId); currentInstance.saveToRedis(connecId);
@ -470,7 +485,7 @@ public class RobotConnectionManager {
String roomKey = String.valueOf(robotUser.getCurrentRoomId()); String roomKey = String.valueOf(robotUser.getCurrentRoomId());
//查询该房间的玩家信息 //查询该房间的玩家信息
String playersStr = jedis.hget("room:"+roomKey, "players"); String playersStr = jedis.hget("room:" + roomKey, "players");
if (!playersStr.equals("[]")) { if (!playersStr.equals("[]")) {
String players = playersStr.substring(1, playersStr.length() - 1); String players = playersStr.substring(1, playersStr.length() - 1);
String[] playerIds = players.split(","); String[] playerIds = players.split(",");
@ -487,7 +502,7 @@ public class RobotConnectionManager {
//更新机器人剩余数量 //更新机器人剩余数量
updateLeftoverRobot(robotId); updateLeftoverRobot(robotId);
disconnectFromGameServer(connecId); disconnectFromGameServer(connecId);
log.info("2002发送退出房间协议1005robotId: {"+robotId+"}"); log.info("2002发送退出房间协议1005robotId: {" + robotId + "}");
}); });
} }
} }
@ -501,7 +516,7 @@ public class RobotConnectionManager {
} }
} }
}, 6, TimeUnit.SECONDS); }, 6, TimeUnit.SECONDS);
log.info("玩家{"+ robotUser.getCurrentRoomId()+"}加入房间:"+ param); log.info("玩家{" + robotUser.getCurrentRoomId() + "}加入房间:" + param);
} }
//玩家退出房间也要检查 //玩家退出房间也要检查
else if ("2002".equalsIgnoreCase(command)) { else if ("2002".equalsIgnoreCase(command)) {
@ -512,7 +527,7 @@ public class RobotConnectionManager {
String roomKey = String.valueOf(robotUser.getCurrentRoomId()); String roomKey = String.valueOf(robotUser.getCurrentRoomId());
//查询该房间的玩家信息 //查询该房间的玩家信息
String playersStr = jedis.hget("room:"+roomKey, "players"); String playersStr = jedis.hget("room:" + roomKey, "players");
if (!playersStr.equals("[]")) { if (!playersStr.equals("[]")) {
String players = playersStr.substring(1, playersStr.length() - 1); String players = playersStr.substring(1, playersStr.length() - 1);
String[] playerIds = players.split(","); String[] playerIds = players.split(",");
@ -529,7 +544,7 @@ public class RobotConnectionManager {
//更新机器人剩余数量 //更新机器人剩余数量
updateLeftoverRobot(robotId); updateLeftoverRobot(robotId);
disconnectFromGameServer(connecId); disconnectFromGameServer(connecId);
log.info("2002发送退出房间协议1005robotId: {"+robotId+"}"); log.info("2002发送退出房间协议1005robotId: {" + robotId + "}");
}); });
} }
} }
@ -549,14 +564,13 @@ public class RobotConnectionManager {
//更新机器人剩余数量 //更新机器人剩余数量
updateLeftoverRobot(robotId); updateLeftoverRobot(robotId);
disconnectFromGameServer(connecId); disconnectFromGameServer(connecId);
log.info("2005玩家发送解散房间协议robotId: {"+robotId+"}"); log.info("2005玩家发送解散房间协议robotId: {" + robotId + "}");
} }
//解散房间时候恢复机器人账号可以使用 //解散房间时候恢复机器人账号可以使用
else if ("2008".equalsIgnoreCase(command)) { else if ("2008".equalsIgnoreCase(command)) {
updateLeftoverRobot(Integer.parseInt(robotUser.getRobotId())); updateLeftoverRobot(Integer.parseInt(robotUser.getRobotId()));
disconnectFromGameServer(connecId); disconnectFromGameServer(connecId);
} } else if ("2009".equalsIgnoreCase(command)) {
else if ("2009".equalsIgnoreCase(command)) {
scheduleDelay(() -> { scheduleDelay(() -> {
Jedis jedis = null; Jedis jedis = null;
try { try {
@ -583,7 +597,7 @@ public class RobotConnectionManager {
disconnectFromGameServer(connecId); disconnectFromGameServer(connecId);
//更新机器人剩余数量 //更新机器人剩余数量
updateLeftoverRobot(paramRobotId); updateLeftoverRobot(paramRobotId);
log.info("2009发送退出房间协议1005robotId: {"+paramRobotId+"}"); log.info("2009发送退出房间协议1005robotId: {" + paramRobotId + "}");
}); });
} }
} }
@ -613,7 +627,7 @@ public class RobotConnectionManager {
/** /**
* leftover_robot 退 * leftover_robot 退
*/ */
private void updateLeftoverRobot(int robotId) { private void updateLeftoverRobot ( int robotId){
Jedis jedis2 = Redis.use("group1_db2").getJedis(); Jedis jedis2 = Redis.use("group1_db2").getJedis();
try { try {
@ -621,7 +635,7 @@ public class RobotConnectionManager {
jedis2.hset("{grobot}:" + robotId, "start", "0"); jedis2.hset("{grobot}:" + robotId, "start", "0");
log.info("机器人 {"+robotId+"} 退出房间修改gallrobot为0"); log.info("机器人 {" + robotId + "} 退出房间修改gallrobot为0");
} finally { } finally {
jedis2.close(); jedis2.close();
} }
@ -630,37 +644,38 @@ public class RobotConnectionManager {
/** /**
* *
*/ */
public void login(RobotUser robotUser){ public void login (RobotUser robotUser){
log.info("开始机器人登录robotId: {"+robotUser.getRobotId()+"}"); log.info("开始机器人登录robotId: {" + robotUser.getRobotId() + "}");
ITObject object = null; ITObject object = null;
AccountBusiness accountBusiness = null; AccountBusiness accountBusiness = null;
accountBusiness = new AccountBusiness(); accountBusiness = new AccountBusiness();
try { try {
//先快速登录 //先快速登录
object = accountBusiness.fastLogin(Integer.parseInt(robotUser.getRobotId())); object = accountBusiness.fastLogin(Integer.parseInt(robotUser.getRobotId()));
log.info("机器人登录成功robotId: {"+robotUser.getRobotId()+"}"); log.info("机器人登录成功robotId: {" + robotUser.getRobotId() + "}");
if(object==null){ if (object == null) {
object = accountBusiness.idPasswordLogin(Integer.parseInt(robotUser.getRobotId()), robotUser.getPassword()); object = accountBusiness.idPasswordLogin(Integer.parseInt(robotUser.getRobotId()), robotUser.getPassword());
} }
ITObject finalObject = object; ITObject finalObject = object;
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
if (finalObject != null) { if (finalObject != null) {
//判断是否有房间 //判断是否有房间
if(finalObject.getTObject("account")!=null){ if (finalObject.getTObject("account") != null) {
ITObject validate = TObject.newInstance(); ITObject validate = TObject.newInstance();
validate.putString("token", finalObject.getString("token")); validate.putString("token", finalObject.getString("token"));
robotUser.setToken(finalObject.getString("token"));; robotUser.setToken(finalObject.getString("token"));
robotUser.setLoginsession("{user}:"+robotUser.getRobotId()); ;
robotUser.setLoginsession("{user}:" + robotUser.getRobotId());
if (robotUser.getLoginsession() != null) { if (robotUser.getLoginsession() != null) {
robotUser.setIsLogin(true); robotUser.setIsLogin(true);
} }
if(finalObject.getTObject("account").get("roomid")!=null){ if (finalObject.getTObject("account").get("roomid") != null) {
String roomid = finalObject.getTObject("account").get("roomid").toString(); String roomid = finalObject.getTObject("account").get("roomid").toString();
robotUser.setCurrentRoomId(Integer.parseInt(roomid)); robotUser.setCurrentRoomId(Integer.parseInt(roomid));
connectGame(robotUser); connectGame(robotUser);
robotUser.setConnecId(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId()); robotUser.setConnecId(robotUser.getCurrentRoomId() + "_" + robotUser.getRobotId());
log.info("重启获取的机器人还有当前房间,准备加入: "+robotUser.getConnecId()); log.info("重启获取的机器人还有当前房间,准备加入: " + robotUser.getConnecId());
exGameController.webGroupJoinRoom(robotUser); exGameController.webGroupJoinRoom(robotUser);
} }
} }
@ -671,13 +686,13 @@ public class RobotConnectionManager {
} }
} }
public void connectGame(RobotUser robotUser){ public void connectGame (RobotUser robotUser){
if(robotUser.isLogin){ if (robotUser.isLogin) {
if(robotUser.getClient()==null){ if (robotUser.getClient() == null) {
TaurusClient client = new TaurusClient(robotUser.getGameHost()+":"+robotUser.getGamePort(), "hz"+robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp); TaurusClient client = new TaurusClient(robotUser.getGameHost() + ":" + robotUser.getGamePort(), "hz" + robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp);
client.setSession(robotUser.getLoginsession()); client.setSession(robotUser.getLoginsession());
client.connect(); client.connect();
setupEventListeners(client, robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId()); setupEventListeners(client, robotUser.getCurrentRoomId() + "_" + robotUser.getRobotId());
robotUser.setIsconnect(client.isConnected()); robotUser.setIsconnect(client.isConnected());
try { try {
Thread.sleep(1000); Thread.sleep(1000);
@ -685,15 +700,15 @@ public class RobotConnectionManager {
log.error("连接超时异常"); log.error("连接超时异常");
} }
robotUser.setClient(client); robotUser.setClient(client);
EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId(), robotUser); EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId() + "_" + robotUser.getRobotId(), robotUser);
}else{ } else {
log.info("机器人已连接,准备加入房间"); log.info("机器人已连接,准备加入房间");
log.info("client.isConnected()"+robotUser.getClient().isConnected()); log.info("client.isConnected()" + robotUser.getClient().isConnected());
if(robotUser.getClient().isConnected()){ if (robotUser.getClient().isConnected()) {
robotUser.setIsconnect(true); robotUser.setIsconnect(true);
}else{ } else {
log.info("reconnect"+robotUser.getClient().getGameID()); log.info("reconnect" + robotUser.getClient().getGameID());
TaurusClient client = new TaurusClient(robotUser.getGameHost()+":"+robotUser.getGamePort(), "hz"+robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp); TaurusClient client = new TaurusClient(robotUser.getGameHost() + ":" + robotUser.getGamePort(), "hz" + robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp);
client.setSession(robotUser.getLoginsession()); client.setSession(robotUser.getLoginsession());
client.connect(); client.connect();
robotUser.setIsconnect(client.isConnected()); robotUser.setIsconnect(client.isConnected());
@ -703,7 +718,7 @@ public class RobotConnectionManager {
log.error("连接超时异常"); log.error("连接超时异常");
} }
robotUser.setClient(client); robotUser.setClient(client);
EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId(), robotUser); EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId() + "_" + robotUser.getRobotId(), robotUser);
} }
} }
} }
@ -712,10 +727,10 @@ public class RobotConnectionManager {
/** /**
* *
*/ */
public void renconnect(RobotUser robotUser){ public void renconnect (RobotUser robotUser){
TaurusClient client = robotUser.getClient(); TaurusClient client = robotUser.getClient();
if(client!=null){ if (client != null) {
if(client.isConnected()){ if (client.isConnected()) {
client.connect(); client.connect();
robotUser.setIsconnect(client.isConnected()); robotUser.setIsconnect(client.isConnected());
} }
@ -725,16 +740,16 @@ public class RobotConnectionManager {
/** /**
* connecId * connecId
*/ */
public TaurusClient getGameClient(String connecId) { public TaurusClient getGameClient (String connecId){
return robotRoomMapping.get(connecId) != null ? robotRoomMapping.get(connecId).getClient() : null; return robotRoomMapping.get(connecId) != null ? robotRoomMapping.get(connecId).getClient() : null;
} }
public int getTime(){ public int getTime () {
return Integer.parseInt((System.currentTimeMillis() + "").substring(0, 10)); return Integer.parseInt((System.currentTimeMillis() + "").substring(0, 10));
} }
public static void sleepTime(int time) { public static void sleepTime ( int time){
try { try {
//添加延迟 //添加延迟
Thread.sleep(time); Thread.sleep(time);
@ -743,4 +758,4 @@ public class RobotConnectionManager {
} }
} }
} }

View File

@ -6,22 +6,26 @@ import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject; import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TObject; import com.taurus.core.entity.TObject;
import com.taurus.core.plugin.redis.Redis; import com.taurus.core.plugin.redis.Redis;
import com.taurus.core.util.Logger;
import com.taurus.core.util.StringUtil; import com.taurus.core.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import robot.mj.info.RobotUser;
import taurus.client.Message; import taurus.client.Message;
import taurus.client.TaurusClient; import taurus.client.TaurusClient;
import taurus.util.CardUtil; import taurus.util.CardUtil;
import taurus.util.HongZhongSuanFaTest; import taurus.util.HongZhongSuanFaTest;
import taurus.util.Util; import taurus.util.Util;
import com.taurus.core.util.Logger;
import java.util.*; import java.util.*;
import static robot.mj.thread.ThreadPoolConfig.getBusinessThreadPool; import static robot.mj.thread.ThreadPoolConfig.getBusinessThreadPool;
public class HuNanHongZhong { public class HuNanHongZhong {
private static final Logger log = LoggerFactory.getLogger(HuNanHongZhong.class); // private static final Logger log = LoggerFactory.getLogger(HuNanHongZhong.class);
private static final Logger log = Logger.getLogger(HuNanHongZhong.class);
//红中麻将手牌 //红中麻将手牌
private final List<Integer> hongZhongCardInhand = new ArrayList<>(); private final List<Integer> hongZhongCardInhand = new ArrayList<>();
@ -92,9 +96,9 @@ public class HuNanHongZhong {
} }
/** /**
* JSONRedis * JSONRedis
*
* @param connecId ID * @param connecId ID
*/ */
public void saveToRedis(String connecId) { public void saveToRedis(String connecId) {
@ -122,6 +126,7 @@ public class HuNanHongZhong {
/** /**
* Redis * Redis
*
* @param connecId ID * @param connecId ID
* @return * @return
*/ */
@ -140,14 +145,16 @@ public class HuNanHongZhong {
if (stateMap.containsKey("hongZhongCardInhand")) { if (stateMap.containsKey("hongZhongCardInhand")) {
hongZhongCardInhand.clear(); hongZhongCardInhand.clear();
List<Integer> handCards = gson.fromJson(stateMap.get("hongZhongCardInhand"), List<Integer> handCards = gson.fromJson(stateMap.get("hongZhongCardInhand"),
new TypeToken<List<Integer>>(){}.getType()); new TypeToken<List<Integer>>() {
}.getType());
if (handCards != null) hongZhongCardInhand.addAll(handCards); if (handCards != null) hongZhongCardInhand.addAll(handCards);
} }
if (stateMap.containsKey("hongZhongchuguopai")) { if (stateMap.containsKey("hongZhongchuguopai")) {
hongZhongchuguopai.clear(); hongZhongchuguopai.clear();
List<Integer> handCards = gson.fromJson(stateMap.get("hongZhongchuguopai"), List<Integer> handCards = gson.fromJson(stateMap.get("hongZhongchuguopai"),
new TypeToken<List<Integer>>(){}.getType()); new TypeToken<List<Integer>>() {
}.getType());
if (handCards != null) hongZhongchuguopai.addAll(handCards); if (handCards != null) hongZhongchuguopai.addAll(handCards);
} }
@ -167,6 +174,7 @@ public class HuNanHongZhong {
/** /**
* Redis * Redis
*
* @param connecId ID * @param connecId ID
*/ */
public static void removeFromRedis(String connecId) { public static void removeFromRedis(String connecId) {
@ -184,6 +192,7 @@ public class HuNanHongZhong {
/** /**
* *
*
* @param handCard * @param handCard
*/ */
public void updateHandCard(List<Integer> handCard) { public void updateHandCard(List<Integer> handCard) {
@ -227,18 +236,19 @@ public class HuNanHongZhong {
* @param message * @param message
* @return * @return
*/ */
public String getCard(String command, Message message) { public String getCard(String command, Message message, RobotUser robotUser) {
log.info("摸牌协议-----{} message---{}", command, message);
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;
} }
// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106} log.info("819机器人摸牌所有参数" + param);
log.info("轮到用户:{}的用户摸牌, 牌为:{}", param.getInt("player"), param.getInt("card")); Integer seat1 = param.getInt("seat");
log.debug("用户id: {}", playerId); Integer seat2 = robotUser.getSeat();
log.debug("座位号: {}", param.getInt("seat")); log.info("819摸牌 后台发的座位号" + seat1);
if (param.getInt("player") != null) { log.info("819摸牌 机器人座位号" + seat2);
if (Objects.equals(seat1, seat2)) {
int drawnCard = param.getInt("card"); int drawnCard = param.getInt("card");
hongZhongSuanFaTest.drawnCards = drawnCard; hongZhongSuanFaTest.drawnCards = drawnCard;
@ -440,7 +450,7 @@ public class HuNanHongZhong {
// 红中麻将出牌 // 红中麻将出牌
String hongzhongOutCard = hongZhongSuanFaTest.outCardSuanFa(hongZhongCardInhand, hongZhongCard); String hongzhongOutCard = hongZhongSuanFaTest.outCardSuanFa(hongZhongCardInhand, hongZhongCard);
// String hongzhongOutCard = hongZhongSuanFaTest.outCardSuanFa(list, hongZhongCard); // String hongzhongOutCard = hongZhongSuanFaTest.outCardSuanFa(list, hongZhongCard);
ITObject params = TObject.newInstance(); ITObject params = TObject.newInstance();
int cardToOut; int cardToOut;
if (StringUtil.isNotEmpty(hongzhongOutCard)) { if (StringUtil.isNotEmpty(hongzhongOutCard)) {
@ -459,20 +469,19 @@ public class HuNanHongZhong {
params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend)); params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
} }
params.putTArray("card_list", CardUtil.maJiangToTArray(hongZhongCardInhand)); params.putTArray("card_list", CardUtil.maJiangToTArray(hongZhongCardInhand));
log.info("机器人牌============{}", params);
// 将当前出的牌添加到历史出牌列表 // 将当前出的牌添加到历史出牌列表
hongZhongchuguopai.add(cardToOut); hongZhongchuguopai.add(cardToOut);
// 从手牌中移除 // 从手牌中移除
hongZhongCardInhand.remove(Integer.valueOf(cardToOut)); hongZhongCardInhand.remove(Integer.valueOf(cardToOut));
log.info("出牌: {}", cardToOut); log.info("机器人 出牌"+ cardToOut);
log.info("目前机器人剩余手牌{}", hongZhongCardInhand.toString()); log.info("目前机器人剩余手牌"+ hongZhongCardInhand);
params.putString("session", session + "," + token); params.putString("session", session + "," + token);
log.info("机器人params" + params);
//使用线程池替代CompletableFuture.runAsync + Thread.sleep //使用线程池替代CompletableFuture.runAsync + Thread.sleep
getBusinessThreadPool().execute(() -> { getBusinessThreadPool().execute(() -> {
try { try {
int ot = new Random().nextInt(2); int ot = new Random().nextInt(2);
Thread.sleep(ot * 1000+1000); Thread.sleep(ot * 1000 + 1000);
client.send("611", params, response -> { client.send("611", params, response -> {
}); });
@ -482,7 +491,7 @@ public class HuNanHongZhong {
}); });
}catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
} }
return null; return null;