Search in sources :

Example 6 with Club

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

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

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

Example 9 with Club

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

the class GameClubService method kickUser.

public int kickUser(KafkaMsgKey msgKey, long userId, String clubId, long kickUser) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    if (club.getPresident() != userId) {
        return ErrorCode.CLUB_NOT_PRESIDENT;
    }
    clubRemoveMember(club, kickUser);
    sendMsg(msgKey, new ResponseVo("clubService", "kickUser", "ok"));
    return 0;
}
Also used : Club(com.code.server.db.model.Club) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 10 with Club

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

the class GameClubService method getClubRecord.

/**
 * 获得俱乐部战绩
 *
 * @param msgKey
 * @param userId
 * @param clubId
 * @return
 */
public int getClubRecord(KafkaMsgKey msgKey, long userId, String clubId) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    if (club.getPresident() != userId) {
        return ErrorCode.CLUB_NOT_PRESIDENT;
    }
    ClubRecord clubRecord = clubRecordService.getClubRecordDao().getClubRecordById(clubId);
    sendMsg(msgKey, new ResponseVo("clubService", "getClubRecord", clubRecord));
    return 0;
}
Also used : Club(com.code.server.db.model.Club) ClubRecord(com.code.server.db.model.ClubRecord) 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