Search in sources :

Example 1 with Club

use of com.code.server.db.model.Club in project summer by foxsugar.

the class GameClubService method invite.

/**
 * 邀请其他玩家
 *
 * @param msgKey
 * @param clubId
 * @param roomId
 * @param inviteUser
 * @return
 */
public int invite(KafkaMsgKey msgKey, String clubId, String roomId, String inviteUser, String roomModel, String name) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    Map<String, Object> result = new HashMap<>();
    result.put("clubId", clubId);
    result.put("roomId", roomId);
    result.put("inviteUser", inviteUser);
    result.put("roomModelInfo", getRoomModel(club, roomModel));
    result.put("name", name);
    msgProducer.send();
    sendMsg2Player(new ResponseVo("clubService", "inviteUser", result), Long.valueOf(inviteUser));
    sendMsg(msgKey, new ResponseVo("clubService", "invite", "ok"));
    return 0;
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) HashMap(java.util.HashMap) Club(com.code.server.db.model.Club) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 2 with Club

use of com.code.server.db.model.Club in project summer by foxsugar.

the class GameClubService method clubDrawBack.

/**
 * 俱乐部房间退钱
 *
 * @param clubId
 * @param clubModelId
 */
public int clubDrawBack(String clubId, String clubModelId) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club != null) {
        RoomModel roomModel = getRoomModel(club, clubModelId);
        if (roomModel != null) {
            int money = roomModel.getMoney();
            synchronized (club.lock) {
                club.setMoney(club.getMoney() + money);
                // 统计减去消耗
                String today = LocalDate.now().toString();
                ClubStatistics clubStatistics = roomModel.getStatisticsMap().get(today);
                if (clubStatistics != null) {
                    clubStatistics.setConsumeNum(clubStatistics.getConsumeNum() - roomModel.getMoney());
                }
            }
        }
    }
    return 0;
}
Also used : Club(com.code.server.db.model.Club) ClubStatistics(com.code.server.constant.club.ClubStatistics) RoomModel(com.code.server.constant.club.RoomModel)

Example 3 with Club

use of com.code.server.db.model.Club in project summer by foxsugar.

the class GameClubService method setRoomModel.

/**
 * 修改房间模式
 *
 * @param msgKey
 * @param userId
 * @param clubId
 * @param roomModelId
 * @param createCommand
 * @param gameType
 * @param gameNumber
 * @param desc
 * @return
 */
public int setRoomModel(KafkaMsgKey msgKey, long userId, String clubId, String roomModelId, 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;
    }
    // 初始化 房间数据
    initRoomData();
    StaticDataProto.RoomData roomData = DataManager.data.getRoomDataMap().get(gameType);
    if (roomData == null || !roomData.getMoneyMap().containsKey(gameNumber)) {
        return ErrorCode.REQUEST_PARAM_ERROR;
    }
    JsonNode jsonNode = JsonUtil.readTree(createCommand);
    String serviceName = jsonNode.path("service").asText();
    // 设置创建命令
    RoomModel roomModel = getRoomModel(club, roomModelId);
    if (roomModel == null) {
        return ErrorCode.REQUEST_PARAM_ERROR;
    }
    createCommand = setRoomModelCommand(createCommand, clubId, roomModel.getId());
    roomModel.setCreateCommand(createCommand);
    roomModel.setDesc(desc);
    roomModel.setTime(System.currentTimeMillis());
    roomModel.setMoney(roomData.getMoneyMap().get(gameNumber));
    roomModel.setServiceName(serviceName);
    sendMsg(msgKey, new ResponseVo("clubService", "setRoomModel", 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 4 with Club

use of com.code.server.db.model.Club 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 5 with Club

use of com.code.server.db.model.Club 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)

Aggregations

Club (com.code.server.db.model.Club)19 ResponseVo (com.code.server.constant.response.ResponseVo)17 ClubMember (com.code.server.constant.club.ClubMember)5 RoomModel (com.code.server.constant.club.RoomModel)5 UserBean (com.code.server.constant.game.UserBean)3 ClubStatistics (com.code.server.constant.club.ClubStatistics)2 StaticDataProto (com.code.server.constant.data.StaticDataProto)2 ClubCharge (com.code.server.db.model.ClubCharge)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ClubVo (com.code.server.constant.response.ClubVo)1 ClubRecord (com.code.server.db.model.ClubRecord)1 MsgProducer (com.code.server.kafka.MsgProducer)1