Search in sources :

Example 51 with ResponseVo

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

the class GameUserService method shareWX.

public int shareWX(KafkaMsgKey msgKey, String game) {
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(msgKey.getUserId());
    if (userBean == null) {
        return ErrorCode.YOU_HAVE_NOT_LOGIN;
    }
    long lastShareTime = userBean.getUserInfo().getLastShareTime();
    long now = System.currentTimeMillis();
    if (DateUtil.isSameDate(lastShareTime, now)) {
        return ErrorCode.CANNOT_SHARE;
    }
    double money = getShareMoney(game);
    int shareCount = userBean.getUserInfo().getShareWXCount();
    // 加钱
    double nowMoney = RedisManager.getUserRedisService().addUserMoney(msgKey.getUserId(), money);
    userBean.setMoney(nowMoney);
    // 分享时间
    userBean.getUserInfo().setLastShareTime(now);
    // 分享次数
    userBean.getUserInfo().setShareWXCount(shareCount + 1);
    // 保存
    RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
    // 分享记录
    Charge charge = new Charge();
    charge.setOrderId("" + IdWorker.getDefaultInstance().nextId());
    charge.setUsername(userBean.getUsername());
    charge.setMoney(money);
    charge.setMoney_point(money);
    charge.setCreatetime(new Date());
    charge.setCallbacktime(new Date());
    charge.setRecharge_source("" + IChargeType.SHARE);
    charge.setStatus(1);
    chargeService.save(charge);
    ResponseVo vo = new ResponseVo("userService", "shareWX", 0);
    sendMsg(msgKey, vo);
    return 0;
}
Also used : Charge(com.code.server.db.model.Charge) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 52 with ResponseVo

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

the class UserServiceMsgDispatch method dispatchMsg.

public void dispatchMsg(KafkaMsgKey msgKey, JsonNode params) {
    String service = params.get("service").asText();
    String method = params.get("method").asText();
    JsonNode node = params.get("params");
    int rtn = dispatchUserService(msgKey, method, node, params);
    if (rtn != 0) {
        ResponseVo vo = new ResponseVo(service, method, rtn);
        kafkaMsgProducer.send2Partition(IKafaTopic.GATE_TOPIC, msgKey.getPartition(), "" + msgKey.getUserId(), vo);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 53 with ResponseVo

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

the class GameInfo method chi.

public int chi(long userId, String one, String two) {
    PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
    boolean isCanChi = playerCardsInfo.isCanChiThisCard(disCard, one, two);
    if (!isCanChi) {
        return ErrorCode.CAN_NOT_CHI;
    }
    if (disCard == null || !playerCardsInfo.canBeChi) {
        return ErrorCode.CAN_NOT_CHI;
    }
    // 从等待列表删除
    // if (waitingforList.size() > 0) {
    WaitDetail waitDetail = waitingforList.get(0);
    if (waitDetail != null && waitDetail.myUserId == userId && waitDetail.isChi) {
        waitingforList.clear();
    } else {
        return ErrorCode.NOT_TURN;
    }
    // }
    OperateReqResp operateReqResp = new OperateReqResp();
    operateReqResp.setOperateType(OperateReqResp.type_chi);
    operateReqResp.setUserId(userId);
    ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
    // 通知其他玩家听
    MsgSender.sendMsg2Player(vo, users);
    // 回放
    replay.getOperate().add(operateReqResp);
    // 吃
    playerCardsInfo.chi(disCard, one, two);
    // 吃完能听,杠,不能胡
    // 多一张牌
    boolean isCanTing = playerCardsInfo.isCanTing(playerCardsInfo.cards);
    boolean isCanGang = playerCardsInfo.isHasGang();
    turnId = userId;
    // 通知客户端 操作
    OperateResp operateResp = new OperateResp();
    operateResp.setIsCanTing(isCanTing);
    operateResp.setIsCanGang(isCanGang);
    ResponseVo operateVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OPERATE, operateResp);
    MsgSender.sendMsg2Player(operateVo, userId);
    this.disCard = null;
    // 自己将能做的处理
    playerCardsInfo.canBeChi = false;
    playerCardsInfo.canBeTing = isCanTing;
    playerCardsInfo.canBeGang = isCanGang;
    return 0;
}
Also used : ResponseVo(com.code.server.constant.response.ResponseVo)

Example 54 with ResponseVo

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

the class GameInfo method fapai.

/**
 * 发牌
 */
public void fapai() {
    // 打乱顺序
    Collections.shuffle(remainCards);
    for (int i = 0; i < playerSize; i++) {
        PlayerCardsInfoMj playerCardsInfo = PlayerCardsInfoFactory.getInstance(room);
        playerCardsInfo.setGameInfo(this);
        long userId = users.get(i);
        // 设置id
        playerCardsInfo.setUserId(userId);
        List<String> playerCards = new ArrayList<>();
        // 发牌
        for (int j = 0; j < cardSize; j++) {
            playerCards.add(remainCards.remove(0));
        }
        // 初始化
        playerCardsInfo.init(playerCards);
        // 放进map
        playerCardsInfos.put(userId, playerCardsInfo);
        // 发牌状态通知
        HandCardsResp resp = new HandCardsResp();
        resp.setCards(playerCards);
        ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_GET_HAND_CARDS, resp);
        MsgSender.sendMsg2Player(vo, userId);
    }
    doAfterFapai();
    // 回放的牌信息
    for (PlayerCardsInfoMj playerCardsInfoMj : playerCardsInfos.values()) {
        List<String> cs = new ArrayList<>();
        cs.addAll(playerCardsInfoMj.getCards());
        replay.getCards().put(playerCardsInfoMj.getUserId(), cs);
    }
    // 第一个人抓牌
    mopai(firstTurn, "发牌");
}
Also used : ResponseVo(com.code.server.constant.response.ResponseVo)

Example 55 with ResponseVo

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

the class GameInfo method sendResult.

/**
 * 发送结果
 *
 * @param isHasWinner
 * @param winnerId
 * @param yipaoduoxiang
 */
protected void sendResult(boolean isHasWinner, Long winnerId, List<Long> yipaoduoxiang) {
    ResultResp result = new ResultResp();
    ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_RESULT, result);
    if (isHasWinner) {
        if (yipaoduoxiang == null) {
            result.setWinnerId(winnerId);
        } else {
            result.setYipaoduoxiang(yipaoduoxiang);
        }
        result.setBaoCard(baoCard);
    }
    List<PlayerCardsResp> list = new ArrayList<>();
    for (PlayerCardsInfoMj info : playerCardsInfos.values()) {
        PlayerCardsResp resp = new PlayerCardsResp(info);
        resp.setAllScore(room.getUserScores().get(info.getUserId()));
        list.add(resp);
    }
    result.setUserInfos(list);
    result.setLaZhuang(this.room.laZhuang);
    result.setLaZhuangStatus(this.room.laZhuangStatus);
    MsgSender.sendMsg2Player(vo, users);
    // 回放
    replay.setResult(result);
    // 生成记录
    genRecord();
}
Also used : 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