Search in sources :

Example 11 with TimerNode

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

the class RoomCow method createCowRoom.

public static int createCowRoom(long userId, int gameNumber, int personNumber, int multiple, String gameType, String roomType, boolean isAA, boolean isJoin) throws DataNotFoundException {
    RoomCow room = getRoomInstance(roomType);
    room.personNumber = personNumber;
    room.roomId = getRoomIdStr(genRoomId());
    room.createUser = userId;
    room.gameType = gameType;
    room.roomType = roomType;
    room.isAA = isAA;
    room.isCreaterJoin = isJoin;
    room.multiple = multiple;
    room.bankerId = userId;
    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", "createCowRoom", 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)

Example 12 with TimerNode

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

the class RoomDouDiZhu method createRoom.

public static int createRoom(long userId, int gameNumber, int multiple, String gameType, String roomType, boolean isAA, boolean isJoin, boolean showChat, String clubId, String clubRoomModel) throws DataNotFoundException {
    RoomDouDiZhu room = getRoomInstance(roomType);
    room.personNumber = PERSONNUM;
    room.roomId = getRoomIdStr(genRoomId());
    room.createUser = userId;
    room.gameType = gameType;
    room.roomType = roomType;
    room.isAA = isAA;
    room.isCreaterJoin = isJoin;
    room.showChat = showChat;
    room.setClubId(clubId);
    room.setClubRoomModel(clubRoomModel);
    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());
            // todo 删除房间
            return ErrorCode.CANNOT_JOIN_ROOM_NO_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", "createRoom", 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)

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