Search in sources :

Example 1 with RoomModel

use of com.code.server.constant.club.RoomModel 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 2 with RoomModel

use of com.code.server.constant.club.RoomModel 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 3 with RoomModel

use of com.code.server.constant.club.RoomModel 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 4 with RoomModel

use of com.code.server.constant.club.RoomModel in project summer by foxsugar.

the class GameClubService method cludGameStart.

/**
 * 俱乐部游戏开始
 *
 * @param clubId
 * @param clubModelId
 * @return
 */
public int cludGameStart(String clubId, String clubModelId) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club != null) {
        synchronized (club.lock) {
            // 删除一个房间
            club.getClubInfo().getRoomInstance().remove(clubModelId);
            // 统计
            RoomModel roomModel = getRoomModel(club, clubModelId);
            if (roomModel != null) {
                String today = LocalDate.now().toString();
                ClubStatistics clubStatistics = roomModel.getStatisticsMap().get(today);
                if (clubStatistics == null) {
                    clubStatistics = new ClubStatistics();
                }
                clubStatistics.setOpenNum(clubStatistics.getOpenNum() + 1);
                clubStatistics.setConsumeNum(clubStatistics.getConsumeNum() + roomModel.getMoney());
                roomModel.getStatisticsMap().put(today, clubStatistics);
                // 删除七天前的
                roomModel.getStatisticsMap().remove(LocalDate.now().minusDays(7).toString());
            }
        }
        initRoomInstance(club);
    }
    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 5 with RoomModel

use of com.code.server.constant.club.RoomModel in project summer by foxsugar.

the class GameClubService method initRoomInstance.

/**
 * 初始化俱乐部
 *
 * @param club
 */
public static void initRoomInstance(Club club) {
    System.out.println("init------------------");
    synchronized (club.lock) {
        // 清理房间状态 如果房间已不存在 则去掉roomId (比如逻辑服务器重启)
        List<String> removeList = new ArrayList<>();
        for (Map.Entry<String, RoomInstance> entry : club.getClubInfo().getRoomInstance().entrySet()) {
            if (entry.getValue().getRoomId() != null && RedisManager.getRoomRedisService().getServerId(entry.getValue().getRoomId()) == null) {
                removeList.add(entry.getKey());
            }
        }
        removeList.forEach(modelKey -> club.getClubInfo().getRoomInstance().remove(modelKey));
        // 创建这几个消失的房间
        for (String s : removeList) {
            RoomModel roomModel = getRoomModel(club, s);
            createRoom(club, roomModel);
        }
        // 创建
        for (RoomModel roomModel : club.getClubInfo().getRoomModels()) {
            // 没有这个类型的房间 && 钱够
            RoomInstance roomInstance = club.getClubInfo().getRoomInstance().get(roomModel.getId());
            boolean flag1 = roomInstance == null || roomInstance.getRoomId() == null;
            boolean flag2 = club.getMoney() >= roomModel.getMoney();
            boolean flag3 = !removeList.contains(roomModel.getId());
            if (flag1 && flag2 && flag3) {
                createRoom(club, roomModel);
                // 减钱
                int moneyNow = club.getMoney() - roomModel.getMoney();
                club.setMoney(moneyNow);
            // 统计
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) RoomInstance(com.code.server.constant.club.RoomInstance) RoomModel(com.code.server.constant.club.RoomModel) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RoomModel (com.code.server.constant.club.RoomModel)7 Club (com.code.server.db.model.Club)5 ResponseVo (com.code.server.constant.response.ResponseVo)3 ClubStatistics (com.code.server.constant.club.ClubStatistics)2 StaticDataProto (com.code.server.constant.data.StaticDataProto)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 RoomInstance (com.code.server.constant.club.RoomInstance)1 Record (com.code.server.constant.game.Record)1 RoomRecord (com.code.server.constant.game.RoomRecord)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1