Search in sources :

Example 1 with UserOfRoom

use of com.code.server.constant.response.UserOfRoom in project summer by foxsugar.

the class RoomDouDiZhuGold method quitRoom.

@Override
public int quitRoom(long userId) {
    if (!this.users.contains(userId)) {
        return ErrorCode.CANNOT_QUIT_ROOM_NOT_EXIST;
    }
    if (isInGame) {
        return ErrorCode.CANNOT_QUIT_ROOM_IS_IN_GAME;
    }
    // 删除玩家房间映射关系
    roomRemoveUser(userId);
    boolean isInFullRoom = false;
    if (this.users.size() == personNumber) {
        isInFullRoom = true;
    }
    if (isInFullRoom) {
        RoomManager.removeRoom(this);
    }
    // 删除
    if (this.users.size() == 0) {
        RoomManager.removeRoomFromMap(this);
    }
    Notice n = new Notice();
    n.setMessage("quit room success!");
    ResponseVo result = new ResponseVo("roomService", "quitRoom", n);
    MsgSender.sendMsg2Player(result, userId);
    UserOfRoom userOfRoom = new UserOfRoom();
    List<Long> noticeList = this.getUsers();
    int inRoomNumber = this.getUsers().size();
    int readyNumber = 0;
    for (int i : this.getUserStatus().values()) {
        if (i == STATUS_READY) {
            readyNumber++;
        }
    }
    for (UserBean userBean : RedisManager.getUserRedisService().getUserBeans(users)) {
        userOfRoom.getUserList().add(userBean.toVo());
    }
    userOfRoom.setInRoomNumber(inRoomNumber);
    userOfRoom.setReadyNumber(readyNumber);
    ResponseVo noticeResult = new ResponseVo("roomService", "roomNotice", userOfRoom);
    MsgSender.sendMsg2Player(noticeResult, noticeList);
    return 0;
}
Also used : Notice(com.code.server.constant.response.Notice) UserBean(com.code.server.constant.game.UserBean) UserOfRoom(com.code.server.constant.response.UserOfRoom) ResponseVo(com.code.server.constant.response.ResponseVo)

Aggregations

UserBean (com.code.server.constant.game.UserBean)1 Notice (com.code.server.constant.response.Notice)1 ResponseVo (com.code.server.constant.response.ResponseVo)1 UserOfRoom (com.code.server.constant.response.UserOfRoom)1