Search in sources :

Example 1 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class PokerApplication method main.

public static void main(String[] args) throws RegisterFailedException, IOException {
    SpringApplication.run(PokerApplication.class, args);
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    // 加载数据
    DataManager.initData(serverConfig.getDataFile());
    // 注册
    RedisManager.getGameRedisService().register(serverConfig.getServerType(), serverConfig.getServerId());
    // timer
    ThreadPool.execute(GameTimer.getInstance()::fire);
    // 心跳
    GameTimer.addTimerNode(new TimerNode(System.currentTimeMillis(), IConstant.SECOND_5, true, () -> RedisManager.getGameRedisService().heart(serverConfig.getServerId())));
    // 机器人线程
    RobotManager robotManager = RobotManager.getInstance();
    // 添加斗地主的机器人
    robotManager.addRobot(new DouDiZhuGoldRobot());
    robotManager.addRobot(new CowRobot());
    robotManager.addRobot(new TTZRobot());
    ThreadPool.getInstance().executor.execute(robotManager);
// MsgConsumer.startAConsumer("gameService", serverConfig.getServerId(), MsgDispatch::dispatch);
// MsgConsumer.startAConsumer("reconnService", serverConfig.getServerId(), MsgDispatch::dispatch);
// MsgConsumer.startAConsumer("pokerRoomService", serverConfig.getServerId(), MsgDispatch::dispatch);
// MsgConsumer.startAConsumer("roomService", serverConfig.getServerId(), RoomMsgDispatch::dispatch);
}
Also used : RobotManager(com.code.server.game.poker.robot.RobotManager) ServerConfig(com.code.server.game.poker.config.ServerConfig) CowRobot(com.code.server.game.poker.cow.CowRobot) DouDiZhuGoldRobot(com.code.server.game.poker.doudizhu.DouDiZhuGoldRobot) TTZRobot(com.code.server.game.poker.tuitongzi.TTZRobot) TimerNode(com.code.server.util.timer.TimerNode)

Example 2 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class RoomGuessCar method guessCar.

public int guessCar(long userId, int redOrGreen) {
    if (this.state == STATE_BET) {
        return ErrorCode.STATE_ERROR;
    }
    if (redOrGreen != 0 && redOrGreen != 1) {
        return ErrorCode.STATE_ERROR;
    }
    this.state = STATE_BET;
    GameGuessCar gameGuessCar = new GameGuessCar();
    gameGuessCar.startGame(users, this, redOrGreen);
    this.game = gameGuessCar;
    this.record.add(redOrGreen);
    long time = 20000;
    this.betEndTimerNode = new TimerNode(System.currentTimeMillis(), time, false, gameGuessCar::sendResult);
    GameTimer.addTimerNode(betEndTimerNode);
    MsgSender.sendMsg2Player("pokerRoomService", "guessCar", time, this.bankerId);
    return 0;
}
Also used : TimerNode(com.code.server.util.timer.TimerNode)

Example 3 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class RoomTuiTongZi method createRoom.

public static int createRoom(long userId, String roomType, String gameType, int gameNumber, int personNumber, boolean isJoin, int multiple) throws DataNotFoundException {
    RoomTuiTongZi room = getRoomInstance(roomType);
    room.personNumber = personNumber;
    room.roomId = getRoomIdStr(genRoomId());
    room.createUser = userId;
    room.gameType = gameType;
    room.isCreaterJoin = isJoin;
    room.multiple = multiple;
    room.bankerId = userId;
    room.roomType = roomType;
    room.init(gameNumber, multiple);
    int code = room.joinRoom(userId, isJoin);
    if (code != 0) {
        return code;
    }
    // 代建房 定时解散
    if (!isJoin) {
        // 给代建房 开房者 扣钱
        if (RedisManager.getUserRedisService().getUserMoney(userId) < room.createNeedMoney) {
            RoomManager.removeRoom(room.getRoomId());
            return ErrorCode.CANNOT_CREATE_ROOM_MONEY;
        }
        room.spendMoney();
        TimerNode prepareRoomNode = new TimerNode(System.currentTimeMillis(), IConstant.HOUR_1, false, room::dissolutionRoom);
        room.prepareRoomTimerNode = prepareRoomNode;
        GameTimer.addTimerNode(prepareRoomNode);
    }
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    RoomManager.addRoom(room.roomId, "" + serverConfig.getServerId(), room);
    IdWorker idWorker = new IdWorker(serverConfig.getServerId(), 0);
    room.setUuid(idWorker.nextId());
    MsgSender.sendMsg2Player(new ResponseVo("pokerRoomService", "createTTZRoom", room.toVo(userId)), userId);
    return 0;
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) IdWorker(com.code.server.util.IdWorker) TimerNode(com.code.server.util.timer.TimerNode) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 4 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class Room method dissolution.

public int dissolution(long userId, boolean agreeOrNot, String methodName) {
    if (!this.users.contains(userId)) {
        return ErrorCode.CANNOT_FIND_THIS_USER;
    }
    this.userStatus.put(userId, agreeOrNot ? STATUS_AGREE_DISSOLUTION : STATUS_DISSOLUTION);
    // 第一个点解散
    if (agreeOrNot && !isHasDissolutionRequest) {
        dissloutionUser = userId;
        isCanDissloution = true;
        this.isHasDissolutionRequest = true;
        // 第一次申请 五分钟后解散
        long start = System.currentTimeMillis();
        TimerNode node = new TimerNode(start, FIVE_MIN, false, () -> {
            if (isCanDissloution) {
                dissolutionRoom();
            }
        });
        this.timerNode = node;
        GameTimer.addTimerNode(node);
    }
    ArrayList<AnswerUser> answerUsers = new ArrayList<>();
    for (int i = 0; i < this.users.size(); i++) {
        AnswerUser answerUser = new AnswerUser();
        answerUser.setUserId(this.users.get(i) + "");
        if (this.userStatus.get(this.users.get(i)) == STATUS_DISSOLUTION) {
            answerUser.setAnswer("3");
        } else if (this.userStatus.get(this.users.get(i)) == STATUS_AGREE_DISSOLUTION) {
            answerUser.setAnswer("2");
        } else {
            answerUser.setAnswer("1");
        }
        answerUsers.add(answerUser);
    }
    AskQuitRoom accept = new AskQuitRoom();
    accept.setUserId(userId + "");
    accept.setAnswerList(answerUsers);
    MsgSender.sendMsg2Player(new ResponseVo("roomService", "noticeAnswerIfDissolveRoom", accept), this.users);
    int agreeNum = 0;
    int disAgreeNum = 0;
    for (int status : userStatus.values()) {
        if (status == STATUS_AGREE_DISSOLUTION) {
            agreeNum += 1;
        }
        if (status == STATUS_DISSOLUTION) {
            disAgreeNum += 1;
        }
    }
    // 同意解散
    if (agreeNum >= personNumber - 1 && agreeNum >= 2) {
        GameTimer.removeNode(timerNode);
        dissolutionRoom();
    }
    // 不同意的人数大于2 解散取消
    if (disAgreeNum >= 1) {
        for (Map.Entry<Long, Integer> entry : userStatus.entrySet()) {
            // 回到游戏状态
            entry.setValue(STATUS_IN_GAME);
            this.isHasDissolutionRequest = false;
            GameTimer.removeNode(timerNode);
        }
    }
    AskQuitRoom accept1 = new AskQuitRoom();
    accept1.setUserId("" + userId);
    MsgSender.sendMsg2Player("roomService", "noticeDissolveRoom", accept1, users);
    AskQuitRoom send = new AskQuitRoom();
    send.setNote("ok");
    MsgSender.sendMsg2Player("roomService", methodName, send, userId);
    return 0;
}
Also used : TimerNode(com.code.server.util.timer.TimerNode)

Example 5 with TimerNode

use of com.code.server.util.timer.TimerNode in project summer by foxsugar.

the class RpcManager method checkGameRpcServerWork.

public void checkGameRpcServerWork() {
    long time = System.currentTimeMillis();
    GameTimer.addTimerNode(new TimerNode(time, 1000L * 5, true, () -> {
        if (RpcManager.getInstance().gameRpcServer != null && !RpcManager.getInstance().gameRpcServer.isServing()) {
            RpcManager.getInstance().gameRpcServer.stop();
            RpcManager.getInstance().gameRpcServer = null;
            ThreadPool.getInstance().executor.execute(() -> {
                RpcManager.getInstance().startGameRpcServer();
            });
        }
    }));
}
Also used : TimerNode(com.code.server.util.timer.TimerNode)

Aggregations

TimerNode (com.code.server.util.timer.TimerNode)12 ServerConfig (com.code.server.game.poker.config.ServerConfig)7 IdWorker (com.code.server.util.IdWorker)6 ResponseVo (com.code.server.constant.response.ResponseVo)4 ServerConfig (com.code.server.game.mahjong.config.ServerConfig)1 CowRobot (com.code.server.game.poker.cow.CowRobot)1 DouDiZhuGoldRobot (com.code.server.game.poker.doudizhu.DouDiZhuGoldRobot)1 RobotManager (com.code.server.game.poker.robot.RobotManager)1 TTZRobot (com.code.server.game.poker.tuitongzi.TTZRobot)1