Search in sources :

Example 6 with ResponseVo

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

the class GameDouDiZhuPlus method pushScoreChange.

public void pushScoreChange() {
    Map<Long, Double> userMoneys = new HashMap<>();
    for (Long l : users) {
        userMoneys.put(l, RedisManager.getUserRedisService().getUserMoney(l));
    }
    MsgSender.sendMsg2Player(new ResponseVo("gameService", "scoreChange", userMoneys), this.getUsers());
}
Also used : HashMap(java.util.HashMap) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 7 with ResponseVo

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

the class GameDouDiZhuPlus method startGame.

public void startGame(List<Long> users, Room room) {
    RoomDouDiZhuPlus roomDouDiZhuPlus = (RoomDouDiZhuPlus) room;
    this.users.forEach(userId -> {
        RedisManager.getUserRedisService().addUserMoney(userId, -roomDouDiZhuPlus.getUsesMoney().get(room.getGoldRoomType()));
    });
    Map<Long, Double> userScores = new HashMap<>();
    for (Long l : room.getUsers()) {
        userScores.put(l, 0.0);
    }
    room.setUserScores(userScores);
    this.room = room;
    init(users, room.getBankerId());
    updateLastOperateTime();
    // 通知其他人游戏已经开始
    MsgSender.sendMsg2Player(new ResponseVo("gameService", "gameBegin", "ok"), this.getUsers());
    RoomManager.getRobotRoom().add(room);
}
Also used : HashMap(java.util.HashMap) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 8 with ResponseVo

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

the class RoomDouDiZhu method dissolutionRoom.

// @Override
// protected Game getGameInstance() {
// switch (gameType) {
// case GAMETYPE_LINFEN:
// return new GameDouDiZhuLinFen();
// case GAMETYPE_QIANAN:
// return new GameDouDiZhuQianAn();
// case GAMETYPE_LONGQI:
// return new GameDouDiZhu();
// case GAMETYPE_LONGQI_LINFEN:
// return new GameDouDiZhuLinFenLongQi();
// case GAMETYPE_LONGQI_LINFEN_NO_QIANG:
// return new GameDouDiZhuLinFenNoQiang();
// 
// case GAMETYPE_LONGQI_NO_QIANG:
// return new GameDouDiZhuNoQiang();
// default:
// return new GameDouDiZhu();
// }
// 
// }
public void dissolutionRoom() {
    if (RoomManager.getRoom(this.roomId) == null) {
        return;
    }
    RoomManager.removeRoom(this.roomId);
    // 结果类
    List<UserOfResult> userOfResultList = getUserOfResult();
    // 代开房 并且游戏未开始
    if (!isCreaterJoin && !this.isInGame && this.curGameNumber == 1) {
        drawBack();
        GameTimer.removeNode(this.prepareRoomTimerNode);
    }
    if ((this.isInGame || !isCreaterJoin) && this.curGameNumber == 1) {
        drawBack();
    }
    this.isInGame = false;
    // 存储返回
    GameOfResult gameOfResult = new GameOfResult();
    gameOfResult.setUserList(userOfResultList);
    gameOfResult.setEndTime(LocalDateTime.now().toString());
    MsgSender.sendMsg2Player(new ResponseVo("gameService", "askNoticeDissolutionResult", gameOfResult), users);
    // 战绩
    genRoomRecord();
}
Also used : UserOfResult(com.code.server.constant.response.UserOfResult) GameOfResult(com.code.server.constant.response.GameOfResult) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 9 with ResponseVo

use of com.code.server.constant.response.ResponseVo 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 10 with ResponseVo

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

Aggregations

ResponseVo (com.code.server.constant.response.ResponseVo)125 Club (com.code.server.db.model.Club)17 HashMap (java.util.HashMap)15 UserBean (com.code.server.constant.game.UserBean)8 IdWorker (com.code.server.util.IdWorker)8 ServerConfig (com.code.server.game.poker.config.ServerConfig)7 ArrayList (java.util.ArrayList)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ClubMember (com.code.server.constant.club.ClubMember)5 Charge (com.code.server.db.model.Charge)5 User (com.code.server.db.model.User)5 GameOfResult (com.code.server.constant.response.GameOfResult)4 UserOfResult (com.code.server.constant.response.UserOfResult)4 TimerNode (com.code.server.util.timer.TimerNode)4 RoomModel (com.code.server.constant.club.RoomModel)3 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)3 com.code.server.game.mahjong.response (com.code.server.game.mahjong.response)3 MsgSender (com.code.server.game.room.kafka.MsgSender)3 MsgProducer (com.code.server.kafka.MsgProducer)3 Map (java.util.Map)3