Search in sources :

Example 36 with ResponseVo

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

the class GameClubService method createRoomModel.

/**
 * 创建房间model
 *
 * @param createCommand
 * @param userId
 * @param clubId
 * @param gameType
 * @param gameNumber
 * @param desc
 * @return
 */
public int createRoomModel(KafkaMsgKey msgKey, long userId, String clubId, String createCommand, String gameType, int gameNumber, String desc) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    if (club.getPresident() != userId) {
        return ErrorCode.CLUB_NOT_PRESIDENT;
    }
    if (club.getClubInfo().getRoomModels().size() >= ROOM_LIMIT) {
        return ErrorCode.CLUB_NOT_MODEL_LIMIT;
    }
    // 初始化 房间数据
    initRoomData();
    StaticDataProto.RoomData roomData = DataManager.data.getRoomDataMap().get(gameType);
    if (roomData == null || !roomData.getMoneyMap().containsKey(gameNumber)) {
        return ErrorCode.REQUEST_PARAM_ERROR;
    }
    RoomModel roomModel = new RoomModel();
    String id = "" + IdWorker.getDefaultInstance().nextId();
    roomModel.setId(id);
    JsonNode jsonNode = JsonUtil.readTree(createCommand);
    String serviceName = jsonNode.path("service").asText();
    // 设置创建命令
    createCommand = setRoomModelCommand(createCommand, clubId, id);
    roomModel.setCreateCommand(createCommand);
    roomModel.setDesc(desc);
    roomModel.setTime(System.currentTimeMillis());
    roomModel.setMoney(roomData.getMoneyMap().get(gameNumber));
    roomModel.setServiceName(serviceName);
    club.getClubInfo().getRoomModels().add(roomModel);
    sendMsg(msgKey, new ResponseVo("clubService", "createRoomModel", roomModel));
    // 实例化房间
    initRoomInstance(club);
    return 0;
}
Also used : StaticDataProto(com.code.server.constant.data.StaticDataProto) Club(com.code.server.db.model.Club) JsonNode(com.fasterxml.jackson.databind.JsonNode) RoomModel(com.code.server.constant.club.RoomModel) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 37 with ResponseVo

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

the class GameClubService method quitClub.

/**
 * 退出俱乐部
 *
 * @param msgKey
 * @param userId
 * @param clubId
 * @return
 */
public int quitClub(KafkaMsgKey msgKey, long userId, String clubId) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    // todo
    // 删除
    clubRemoveMember(club, userId);
    sendMsg(msgKey, new ResponseVo("clubService", "quitClub", "ok"));
    return 0;
}
Also used : Club(com.code.server.db.model.Club) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 38 with ResponseVo

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

the class GameClubService method lookClub.

/**
 * 查看俱乐部
 *
 * @param msgKey
 * @param userId
 * @return
 */
public int lookClub(KafkaMsgKey msgKey, long userId) {
    List<ClubVo> list = new ArrayList<>();
    List<String> clubs = ClubManager.getInstance().getUserClubs(userId);
    for (String clubId : clubs) {
        list.add(getClubVo_simple(ClubManager.getInstance().getClubById(clubId)));
    }
    sendMsg(msgKey, new ResponseVo("clubService", "lookClub", list));
    return 0;
}
Also used : ClubVo(com.code.server.constant.response.ClubVo) ArrayList(java.util.ArrayList) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 39 with ResponseVo

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

the class GameClubService method getClubInfo.

/**
 * 获得俱乐部信息
 *
 * @param msgKey
 * @param userId
 * @param clubId
 * @return
 */
public int getClubInfo(KafkaMsgKey msgKey, long userId, String clubId) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    // 刷新房间
    initRoomInstance(club);
    boolean isPresident = club.getPresident() == userId;
    ClubVo clubVo = getClubVo_simple(club);
    clubVo.getRoomModels().addAll(club.getClubInfo().getRoomModels());
    // 玩家在线情况
    clubVo.getMember().addAll(club.getClubInfo().getMember().values());
    clubVo.getMember().forEach(clubMember -> {
        String gateId = RedisManager.getUserRedisService().getGateId(clubMember.getUserId());
        boolean online = gateId != null;
        clubMember.setOnline(online);
    });
    club.getClubInfo().getRoomInstance().values().forEach(roomInstance -> {
        if (roomInstance.getRoomId() != null) {
            clubVo.getRoomInstance().add(getRoomInstanceVo(roomInstance));
        }
    });
    // 房间情况
    if (isPresident) {
        clubVo.getApplyList().addAll(club.getClubInfo().getApplyList());
    }
    // todo 初始化数据
    // todo 更改玩家真实信息
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (isPresident) {
        club.setPresidentName(userBean.getUsername());
    }
    ClubMember clubMember = club.getClubInfo().getMember().get("" + userId);
    clubMember.setName(userBean.getUsername());
    clubMember.setImage(userBean.getImage());
    // 发送结果
    sendMsg(msgKey, new ResponseVo("clubService", "getClubInfo", clubVo));
    return 0;
}
Also used : ClubVo(com.code.server.constant.response.ClubVo) UserBean(com.code.server.constant.game.UserBean) Club(com.code.server.db.model.Club) ClubMember(com.code.server.constant.club.ClubMember) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 40 with ResponseVo

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

the class GameClubService method charge.

/**
 * 充值
 *
 * @param msgKey
 * @param userId
 * @param clubId
 * @param money
 * @return
 */
public int charge(KafkaMsgKey msgKey, long userId, String clubId, int money) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    if (club.getPresident() != userId) {
        return ErrorCode.CLUB_NOT_PRESIDENT;
    }
    if (money <= 0) {
        return ErrorCode.REQUEST_PARAM_ERROR;
    }
    if (RedisManager.getUserRedisService().getUserMoney(userId) < money) {
        return ErrorCode.NOT_HAVE_MORE_MONEY;
    }
    // 加钱
    club.setMoney(club.getMoney() + money);
    RedisManager.getUserRedisService().addUserMoney(userId, -money);
    sendMsg(msgKey, new ResponseVo("clubService", "charge", "ok"));
    // 记录
    ClubCharge clubCharge = new ClubCharge();
    clubCharge.setClubId(clubId);
    clubCharge.setNum(money);
    clubCharge.setNowMoney(club.getMoney());
    clubCharge.setChargeTime(LocalDateTime.now().toString());
    clubChargeService.getClubChargeDao().save(clubCharge);
    return 0;
}
Also used : ClubCharge(com.code.server.db.model.ClubCharge) Club(com.code.server.db.model.Club) 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