Search in sources :

Example 26 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class GameClubService method createClub.

/**
 * 创建俱乐部
 *
 * @param msgKey
 * @param userId
 * @param clubName
 * @param wx
 * @param area
 * @param desc
 * @return
 */
public int createClub(KafkaMsgKey msgKey, long userId, String clubName, String wx, String area, String desc) {
    // 钱是否够
    double money = RedisManager.getUserRedisService().getUserMoney(userId);
    if (money < getCreateMoney()) {
        return ErrorCode.CLUB_CANNOT_MONEY;
    }
    // 多于5个俱乐部 不可以创建
    int num = ClubManager.getInstance().getUserClubNum(userId);
    if (num >= JOIN_LIMIT) {
        return ErrorCode.CLUB_CANNOT_NUM;
    }
    // 人减钱
    RedisManager.getUserRedisService().addUserMoney(userId, -getCreateMoney());
    Club club = new Club();
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    // id
    club.setId(ClubManager.getInstance().getClubId());
    club.setPresident(userId);
    club.setName(clubName);
    club.setPresidentName(userBean.getUsername());
    club.setPresidentWx(wx);
    club.setArea(area);
    club.setMoney(getCreateMoney());
    club.setClubDesc(desc);
    clubAddMember(club, userBean);
    clubService.getClubDao().save(club);
    ClubManager.getInstance().getClubMap().put(club.getId(), club);
    ResponseVo vo = new ResponseVo("clubService", "createClub", club);
    sendMsg(msgKey, vo);
    return 0;
}
Also used : UserBean(com.code.server.constant.game.UserBean) Club(com.code.server.db.model.Club) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 27 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class RoomInfo method getUserOfResult.

public List<UserOfResult> getUserOfResult() {
    // 结果类
    ArrayList<UserOfResult> userOfResultList = new ArrayList<>();
    long time = System.currentTimeMillis();
    for (UserBean eachUser : RedisManager.getUserRedisService().getUserBeans(this.users)) {
        UserOfResult resultObj = new UserOfResult();
        resultObj.setUsername(eachUser.getUsername());
        resultObj.setImage(eachUser.getImage());
        resultObj.setScores(this.userScores.get(eachUser.getId()) + "");
        resultObj.setUserId(eachUser.getId());
        resultObj.setTime(time);
        if (this.getHuNum().containsKey(eachUser.getId())) {
            resultObj.setHuNum(this.getHuNum().get(eachUser.getId()));
        }
        if (this.getLianZhuangNum().containsKey(eachUser.getId())) {
            resultObj.setLianZhuangNum(this.getLianZhuangNum().get(eachUser.getId()));
        }
        if (this.getDianPaoNum().containsKey(eachUser.getId())) {
            resultObj.setDianPaoNum((this.getDianPaoNum().get(eachUser.getId())));
        }
        if (this.getMoBaoNum().containsKey(eachUser.getId())) {
            resultObj.setMoBaoNum(this.getMoBaoNum().get(eachUser.getId()));
        }
        userOfResultList.add(resultObj);
    // 删除映射关系
    // RedisManager.getUserRedisService().removeRoom(eachUser.getId());
    }
    return userOfResultList;
}
Also used : UserBean(com.code.server.constant.game.UserBean) ArrayList(java.util.ArrayList)

Example 28 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class ReconnService method reconnection.

public static int reconnection(String roomId, long userId) {
    AllMessage allMessage = new AllMessage();
    allMessage.setExist(false);
    RoomInfo roomInfo = (RoomInfo) RoomManager.getRoom(roomId);
    if (roomInfo != null) {
        allMessage.setExist(true);
        List<UserVo> userList = new ArrayList<>();
        allMessage.setRoom(getRoomInfo(roomInfo));
        allMessage.setBanker(roomInfo.getBankerId());
        allMessage.setCurGameNumber(roomInfo.getCurGameNumber());
        allMessage.setUserScores(roomInfo.getUserScores());
        allMessage.setUserStatus(roomInfo.getUserStatus());
        // 圈数
        allMessage.setCircleNum(roomInfo.getCurCircle());
        allMessage.getLaZhuang().putAll(roomInfo.getLaZhuang());
        allMessage.getLaZhuangStatus().putAll(roomInfo.getLaZhuangStatus());
        for (UserBean userBean : RedisManager.getUserRedisService().getUserBeans(roomInfo.getUsers())) {
            userList.add(userBean.toVo());
        }
        // 在线状态
        for (long uid : roomInfo.getUsers()) {
            allMessage.getOfflineStatus().put(uid, RedisManager.getUserRedisService().getGateId(uid) != null);
        }
        GameInfo gameInfo = (GameInfo) roomInfo.getGame();
        roomInfo.getReady(userId);
        if (gameInfo != null) {
            ReconnectResp reconnect = new ReconnectResp(gameInfo, userId);
            allMessage.setGameId(gameInfo.getGameId());
            allMessage.setCardNumber(gameInfo.getRemainCards().size());
            allMessage.setReconnectResp(reconnect);
        }
        allMessage.setUsers(userList);
        if (roomInfo.getTimerNode() != null) {
            long time = roomInfo.getTimerNode().getStart() + roomInfo.getTimerNode().getInterval() - System.currentTimeMillis();
            allMessage.setRemainTime(time);
        }
    }
    ResponseVo vo = new ResponseVo("reconnService", "reconnection", allMessage);
    MsgSender.sendMsg2Player(vo, userId);
    return 0;
}
Also used : AllMessage(com.code.server.game.mahjong.response.AllMessage) GameInfo(com.code.server.game.mahjong.logic.GameInfo) UserVo(com.code.server.constant.response.UserVo) UserBean(com.code.server.constant.game.UserBean) ArrayList(java.util.ArrayList) ReconnectResp(com.code.server.game.mahjong.response.ReconnectResp) RoomInfo(com.code.server.game.mahjong.logic.RoomInfo) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 29 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class RoomHitGoldFlower method getUserOfResult.

public List<UserOfResult> getUserOfResult() {
    ArrayList<UserOfResult> userOfResultList = new ArrayList<>();
    long time = System.currentTimeMillis();
    for (UserBean eachUser : RedisManager.getUserRedisService().getUserBeans(this.users)) {
        UserOfResult resultObj = new UserOfResult();
        resultObj.setUsername(eachUser.getUsername());
        resultObj.setImage(eachUser.getImage());
        if ("30".equals(getGameType())) {
            resultObj.setScores(this.userScores.get(eachUser.getId()) - 1000.0 + "");
        } else {
            resultObj.setScores(this.userScores.get(eachUser.getId()) + "");
        }
        resultObj.setUserId(eachUser.getId());
        resultObj.setTime(time);
        resultObj.setRoomStatistics(roomStatisticsMap.get(eachUser.getId()));
        // 设置牌型次数
        if (this.getBaoziNum().containsKey(eachUser.getId())) {
            resultObj.setBaoziNum(this.getBaoziNum().get(eachUser.getId()));
        }
        if (this.getTonghuashunNum().containsKey(eachUser.getId())) {
            resultObj.setTonghuashunNum(this.getTonghuashunNum().get(eachUser.getId()));
        }
        if (this.getTonghuaNum().containsKey(eachUser.getId())) {
            resultObj.setTonghuaNum(this.getTonghuaNum().get(eachUser.getId()));
        }
        if (this.getShunziNum().containsKey(eachUser.getId())) {
            resultObj.setShunziNum(this.getShunziNum().get(eachUser.getId()));
        }
        if (this.getDuiziNum().containsKey(eachUser.getId())) {
            resultObj.setDuiziNum(this.getDuiziNum().get(eachUser.getId()));
        }
        if (this.getSanpaiNum().containsKey(eachUser.getId())) {
            resultObj.setSanpaiNum(this.getSanpaiNum().get(eachUser.getId()));
        }
        userOfResultList.add(resultObj);
    }
    return userOfResultList;
}
Also used : UserBean(com.code.server.constant.game.UserBean) ArrayList(java.util.ArrayList)

Example 30 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class RedisApplication method test.

public void test() {
    UserBean userBean = new UserBean();
    userBean.setGold(1);
    HashOperations<String, String, UserBean> user_money = redisTemplate.opsForHash();
    user_money.put("testString", "1", userBean);
    Map<String, Object> params = new HashMap<>();
}
Also used : UserBean(com.code.server.constant.game.UserBean) HashMap(java.util.HashMap)

Aggregations

UserBean (com.code.server.constant.game.UserBean)32 User (com.code.server.db.model.User)12 UserService (com.code.server.db.Service.UserService)9 HashMap (java.util.HashMap)9 ResponseVo (com.code.server.constant.response.ResponseVo)8 ArrayList (java.util.ArrayList)6 Charge (com.code.server.db.model.Charge)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Date (java.util.Date)4 Club (com.code.server.db.model.Club)3 ClubMember (com.code.server.constant.club.ClubMember)2 UserRecord (com.code.server.constant.game.UserRecord)2 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)2 ChargeService (com.code.server.db.Service.ChargeService)2 MsgProducer (com.code.server.kafka.MsgProducer)2 UserRedisService (com.code.server.redis.service.UserRedisService)2 com.code.server.rpc.idl (com.code.server.rpc.idl)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 GameRecord (com.code.server.constant.game.GameRecord)1 RoomRecord (com.code.server.constant.game.RoomRecord)1