Search in sources :

Example 1 with Notice

use of com.code.server.constant.response.Notice 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)

Example 2 with Notice

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

the class RoomDouDiZhuPlus method quitRoom.

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;
    }
    List<Long> noticeList = new ArrayList<>();
    noticeList.addAll(this.getUsers());
    // 删除玩家房间映射关系
    roomRemoveUser(userId);
    if (this.createUser == userId) {
        // 房主解散
        Notice n = new Notice();
        n.setMessage("roomNum " + this.getRoomId() + " :has destroy success!");
        MsgSender.sendMsg2Player(new ResponseVo("roomService", "destroyRoom", n), noticeList);
        RoomManager.removeRoom(this.roomId);
    }
    noticeQuitRoom(userId);
    return 0;
}
Also used : Notice(com.code.server.constant.response.Notice) ArrayList(java.util.ArrayList) ResponseVo(com.code.server.constant.response.ResponseVo)

Aggregations

Notice (com.code.server.constant.response.Notice)2 ResponseVo (com.code.server.constant.response.ResponseVo)2 UserBean (com.code.server.constant.game.UserBean)1 UserOfRoom (com.code.server.constant.response.UserOfRoom)1 ArrayList (java.util.ArrayList)1