Search in sources :

Example 1 with Room

use of com.code.server.game.room.Room in project summer by foxsugar.

the class RoomDouDiZhuGold method joinGoldRoom.

/*public static String getRoomIdStr() {
        return System.currentTimeMillis()+"" + random.nextInt(999999);
    }*/
// 金币场加入房间
public static int joinGoldRoom(long userId, Double goldRoomType, String roomType, String gameType) throws DataNotFoundException {
    if (RedisManager.getUserRedisService().getRoomId(userId) != null) {
        return ErrorCode.CANNOT_CREATE_ROOM_USER_HAS_IN_ROOM;
    }
    if (RedisManager.getUserRedisService().getUserMoney(userId) < needMoney.get(goldRoomType)) {
        return ErrorCode.CANNOT_JOIN_ROOM_NO_MONEY;
    }
    Room nullRoom = RoomManager.getNullRoom(goldRoomType);
    if (nullRoom == null) {
        switch(roomType) {
            case "2":
                nullRoom = new RoomDouDiZhuGold();
                break;
            case "3":
                nullRoom = new RoomDouDiZhuPlus();
                break;
            default:
                nullRoom = new RoomDouDiZhuPlus();
                break;
        }
        nullRoom.setPersonNumber(PERSONNUM);
        nullRoom.setRoomId(getRoomIdStr(genRoomId()));
        nullRoom.setCreateUser(userId);
        nullRoom.setGoldRoomType(goldRoomType);
        nullRoom.setGameType(GAMETYPE_LONGQI);
        nullRoom.setRoomType(roomType);
        nullRoom.setAA(true);
        nullRoom.setCreaterJoin(true);
        nullRoom.init(1, -1);
        nullRoom.setCreateType(1);
    }
    nullRoom.joinRoom(userId, true);
    /*ArrayList<Long> userslist = new ArrayList<>();
        userslist.add(userId);
        HashMap<Long, Integer> userStatusMap = new HashMap<>();
        userStatusMap.put(userId, 0);
        HashMap<Long, Double> userScoresMap = new HashMap<>();
        userScoresMap.put(userId, 0D);
        HashMap<Long, RoomStatistics> roomStatisticsMap = new HashMap<>();
        roomStatisticsMap.put(userId, new RoomStatistics(userId));

        room.setUsers(userslist);
        room.setUserStatus(userStatusMap);
        room.setUserScores(userScoresMap);
        room.setRoomStatisticsMap(roomStatisticsMap);*/
    // room.getReady(userId);//准备
    // list.add(room);
    ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
    RoomManager.addRoom(nullRoom.getRoomId(), "" + serverConfig.getServerId(), nullRoom);
    IdWorker idWorker = new IdWorker(serverConfig.getServerId(), 0);
    nullRoom.setUuid(idWorker.nextId());
    MsgSender.sendMsg2Player(new ResponseVo("pokerRoomService", "joinGoldRoom", nullRoom.toVo(userId)), userId);
    return 0;
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) IdWorker(com.code.server.util.IdWorker) UserOfRoom(com.code.server.constant.response.UserOfRoom) Room(com.code.server.game.room.Room) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 2 with Room

use of com.code.server.game.room.Room in project summer by foxsugar.

the class RoomManager method removeRoom.

// 删除满房间,添加不满房间
public static void removeRoom(Room room) {
    List<Room> list = fullGoldRoom.get(room.getGoldRoomType());
    ArrayList<Room> templist = new ArrayList<>();
    templist.addAll(list);
    if (list != null) {
        for (Room m : list) {
            if (m.getRoomId().equals(room.getRoomId())) {
                templist.remove(m);
            }
        }
    }
    // templist.add(room);
    fullGoldRoom.put(room.getGoldRoomType(), templist);
    List<Room> fulllist = notFullGoldRoom.get(room.getGoldRoomType());
    fulllist.add(room);
    notFullGoldRoom.put(room.getGoldRoomType(), fulllist);
}
Also used : ArrayList(java.util.ArrayList) Room(com.code.server.game.room.Room) IfaceRoom(com.code.server.game.room.IfaceRoom)

Example 3 with Room

use of com.code.server.game.room.Room in project summer by foxsugar.

the class RoomManager method addRoom.

public static void addRoom(String roomId, String serverId, Room room) {
    if (room.isGoldRoom()) {
        if (room.getUsers().size() >= room.getPersonNumber()) {
            // 加入已满的
            RoomManager.addRoom2Map(room);
            // 删掉未满的
            RoomManager.removeRoomFromMap(room);
        } else {
            List<Room> list = notFullGoldRoom.get(room.getGoldRoomType());
            if (list == null) {
                list = new ArrayList<>();
            }
            ArrayList<Room> templist = new ArrayList<>();
            templist.addAll(list);
            for (Room m : list) {
                if (m.getRoomId().equals(room.getRoomId())) {
                    templist.remove(m);
                }
            }
            templist.add(room);
            notFullGoldRoom.put(room.getGoldRoomType(), templist);
        }
    }
    getInstance().rooms.put(roomId, room);
    robotRoom.add(room);
    RedisManager.getRoomRedisService().setServerId(roomId, serverId);
    // 加入代开房列表
    if (!room.isCreaterJoin()) {
        RedisManager.getUserRedisService().addPerpareRoom(room.getCreateUser(), room.getPrepareRoomVo());
    }
}
Also used : ArrayList(java.util.ArrayList) Room(com.code.server.game.room.Room) IfaceRoom(com.code.server.game.room.IfaceRoom)

Example 4 with Room

use of com.code.server.game.room.Room in project summer by foxsugar.

the class RoomManager method removeRoom.

public static void removeRoom(String roomId) {
    // 本地内存删除room
    IfaceRoom room = getInstance().rooms.get(roomId);
    getInstance().rooms.remove(roomId);
    RedisManager.removeRoomAllInfo(roomId);
    // 删除代开房
    if (room != null && room instanceof Room) {
        Room rm = (Room) room;
        if (!rm.isCreaterJoin()) {
            RedisManager.getUserRedisService().removePerpareRoom(rm.getCreateUser(), rm.getRoomId());
        // if (prepareRoom.containsKey(rm.getCreateUser())) {
        // prepareRoom.get(rm.getCreateUser()).remove(rm.getRoomId());
        // }
        }
    }
    robotRoom.remove(room);
}
Also used : IfaceRoom(com.code.server.game.room.IfaceRoom) Room(com.code.server.game.room.Room) IfaceRoom(com.code.server.game.room.IfaceRoom)

Example 5 with Room

use of com.code.server.game.room.Room in project summer by foxsugar.

the class RoomManager method addRoom2Map.

public static void addRoom2Map(Room room) {
    List<Room> list = notFullGoldRoom.get(room.getGoldRoomType());
    if (list == null) {
        list = new ArrayList<>();
    }
    ArrayList<Room> templist = new ArrayList<>();
    templist.addAll(list);
    for (Room m : list) {
        if (m.getRoomId().equals(room.getRoomId())) {
            templist.remove(m);
        }
    }
    templist.add(room);
    fullGoldRoom.put(room.getGoldRoomType(), templist);
}
Also used : ArrayList(java.util.ArrayList) Room(com.code.server.game.room.Room) IfaceRoom(com.code.server.game.room.IfaceRoom)

Aggregations

Room (com.code.server.game.room.Room)6 IfaceRoom (com.code.server.game.room.IfaceRoom)5 ArrayList (java.util.ArrayList)4 ResponseVo (com.code.server.constant.response.ResponseVo)1 UserOfRoom (com.code.server.constant.response.UserOfRoom)1 ServerConfig (com.code.server.game.poker.config.ServerConfig)1 IdWorker (com.code.server.util.IdWorker)1