Search in sources :

Example 21 with ResponseVo

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

the class GameInfoNiuyezi method ting.

/**
 * 听
 *
 * @param userId
 * @param card
 * @return
 */
public int ting(long userId, String card) {
    if (isAlreadyHu) {
        return ErrorCode.CAN_NOT_TING;
    }
    PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
    if (playerCardsInfo == null) {
        return ErrorCode.USER_ERROR;
    }
    OperateReqResp operateReqResp = new OperateReqResp();
    operateReqResp.setOperateType(OperateReqResp.type_ting);
    operateReqResp.setUserId(userId);
    operateReqResp.setCard(card);
    ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
    List<String> temp = new ArrayList<>();
    temp.addAll(playerCardsInfo.getCards());
    temp.remove(card);
    // 不多一张
    boolean isCan = playerCardsInfo.isCanTing(temp);
    if (isCan) {
        this.disCard = card;
        // 上个出牌的人
        this.lastPlayUserId = userId;
        // 上个操作的人
        lastOperateUserId = userId;
        // 听
        playerCardsInfo.ting(card);
        // 通知其他玩家听
        MsgSender.sendMsg2Player(vo, users);
        // 回放
        replay.getOperate().add(operateReqResp);
        // 通知其他玩家出牌信息
        PlayCardResp playCardResp = new PlayCardResp();
        playCardResp.setUserId(userId);
        playCardResp.setCard(card);
        ResponseVo chupaiVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_PLAY_CARD, playCardResp);
        MsgSender.sendMsg2Player(chupaiVo, users);
        // 其他人能做的操作
        for (Map.Entry<Long, PlayerCardsInfoMj> entry : playerCardsInfos.entrySet()) {
            OperateResp operateResp = new OperateResp();
            // 其他玩家的处理 碰杠等 如果有加入等待列表(要等待这些玩家"过")
            if (userId != entry.getKey()) {
                // 通知其他玩家出了什么牌 自己能有什么操作
                PlayerCardsInfoMj playerInfo = entry.getValue();
                boolean isCanGang = playerInfo.isCanGangAddThisCard(card);
                boolean isCanPeng = playerInfo.isCanPengAddThisCard(card);
                boolean isCanHu;
                isCanHu = playerInfo.isCanHu_dianpao(card);
                boolean isCanChi = playerInfo.isHasChi(card);
                boolean isCanChiTing = playerInfo.isCanChiTing(card);
                boolean isCanPengTing = playerInfo.isCanPengTing(card);
                // 设置返回结果
                operateResp.setCanBeOperate(isCanChi, isCanPeng, isCanGang, false, isCanHu, isCanChiTing, isCanPengTing);
                // 设置自己能做的操作
                playerInfo.setCanBeOperate(isCanChi, isCanPeng, isCanGang, false, isCanHu, isCanChiTing, isCanPengTing);
                boolean isWait = isCanGang || isCanPeng || isCanHu || isCanChi || isCanChiTing || isCanPengTing;
                if (isWait) {
                    this.waitingforList.add(new WaitDetail(entry.getKey(), isCanHu, isCanGang, isCanPeng, isCanChi, isCanChiTing, isCanPengTing));
                }
            }
            // 可能的操作
            ResponseVo OperateVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OPERATE, operateResp);
            MsgSender.sendMsg2Player(OperateVo, entry.getKey());
        }
        resetCanBeOperate(playerCardsInfo);
        // 如果等待列表为空 就轮到下个人摸牌
        if (this.waitingforList.size() == 0) {
            long nextId = nextTurnId(turnId);
            mopai(nextId, "userId : " + userId + " 出牌");
        } else {
            // todo 一炮多响
            if (this.room.isYipaoduoxiang && waitingforList.stream().filter(waitDetail -> waitDetail.isHu).count() >= 2) {
                handleYiPaoDuoXiang();
            } else {
                // 比较
                compare(waitingforList);
            }
        }
    }
    return 0;
}
Also used : ResponseVo(com.code.server.constant.response.ResponseVo) List(java.util.List) Map(java.util.Map) com.code.server.game.mahjong.response(com.code.server.game.mahjong.response) MsgSender(com.code.server.game.room.kafka.MsgSender) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ResponseVo(com.code.server.constant.response.ResponseVo) Map(java.util.Map)

Example 22 with ResponseVo

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

the class GameInfoSongYuan method doGang.

protected void doGang(PlayerCardsInfoMj playerCardsInfo, long userId) {
    OperateReqResp operateReqResp = new OperateReqResp();
    operateReqResp.setOperateType(OperateReqResp.type_gang);
    ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
    // 删除弃牌
    deleteDisCard(lastPlayUserId, disCard);
    playerCardsInfo.gang_discard(room, this, lastPlayUserId, disCard);
    // 谁出的牌
    operateReqResp.setFromUserId(lastPlayUserId);
    operateReqResp.setUserId(userId);
    operateReqResp.setCard(disCard);
    operateReqResp.setIsMing(true);
    // 通知所有人有杠
    MsgSender.sendMsg2Player(vo, users);
    mopai(userId, "杠后摸牌 点杠");
    turnId = userId;
    this.disCard = null;
    lastOperateUserId = userId;
    resetOtherOperate(userId);
}
Also used : ResponseVo(com.code.server.constant.response.ResponseVo)

Example 23 with ResponseVo

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

the class GameInfoSongYuan method doChi.

protected void doChi(PlayerCardsInfoMj playerCardsInfo, long userId, String one, String two) {
    deleteDisCard(lastPlayUserId, disCard);
    List<String> chiCards = new ArrayList<>();
    chiCards.add(one);
    chiCards.add(disCard);
    chiCards.add(two);
    OperateReqResp operateReqResp = new OperateReqResp();
    operateReqResp.setOperateType(OperateReqResp.type_chi);
    operateReqResp.setUserId(userId);
    operateReqResp.setChiCards(chiCards);
    operateReqResp.setFromUserId(lastPlayUserId);
    ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
    // 通知其他玩家听
    MsgSender.sendMsg2Player(vo, users);
    // 吃
    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;
    playerCardsInfo.canBeHu = false;
    resetOtherOperate(userId);
}
Also used : ResponseVo(com.code.server.constant.response.ResponseVo)

Example 24 with ResponseVo

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

the class GameInfoSongYuan method mopai.

/**
 * 摸牌
 *
 * @param userId
 */
@Override
protected void mopai(long userId, String... wz) {
    if (isAlreadyHu) {
        return;
    }
    System.err.println("摸牌=============================== : " + userId);
    // 还剩最后四张牌
    List<Long> huList = new ArrayList<>();
    if (remainCards.size() == users.size()) {
        System.out.println("处理海底捞");
        // 海底捞
        handleHaidilao(userId, huList);
    }
    if (huList.size() > 0) {
        handleHu(playerCardsInfos.get(huList.get(0)));
        return;
    }
    // 荒庄
    PlayerCardsInfoMj playerCardsInfo = playerCardsInfos.get(userId);
    if (playerCardsInfo.isHuangzhuang(this)) {
        handleHuangzhuang(userId);
        return;
    }
    if (playerCardsInfo.isMoreOneCard()) {
        if (wz.length > 0) {
            logger.info("====1操作后的摸牌 : " + wz[0]);
        }
        logger.info("===1 more one card 抓牌时多一张牌");
        logger.info("操作列表: " + playerCardsInfo.operateList.toString());
    }
    // 拿出一张
    String card = null;
    // 有换牌需求
    if (isTest && playerCardsInfo.nextNeedCard != -1) {
        String needCard = getCardByTypeFromRemainCards(playerCardsInfo.nextNeedCard);
        playerCardsInfo.nextNeedCard = -1;
        if (needCard != null) {
            card = needCard;
            remainCards.remove(needCard);
        } else {
            card = remainCards.remove(0);
        }
    } else {
        card = remainCards.remove(0);
    }
    playerCardsInfo.mopai(card);
    // 
    turnId = userId;
    this.lastMoPaiUserId = userId;
    lastOperateUserId = userId;
    this.catchCard = card;
    // 把摸到的牌 推给摸牌的玩家
    int remainSize = remainCards.size();
    for (long user : users) {
        GetCardResp getCardResp = new GetCardResp();
        getCardResp.setRemainNum(remainSize);
        getCardResp.setUserId(userId);
        if (user == userId) {
            getCardResp.setCard(card);
        }
        ResponseVo responseVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_GET_CARD, getCardResp);
        MsgSender.sendMsg2Player(responseVo, user);
        // 能做的操作全置成不能
        PlayerCardsInfoMj other = playerCardsInfos.get(user);
        resetCanBeOperate(other);
    }
    // 已经胡了
    if (playerCardsInfo.isAlreadyHu) {
        playerCardsInfo.hu_zm(room, this, card);
        handleHu(playerCardsInfo);
        return;
    }
    boolean isCanGang = playerCardsInfo.isHasGang();
    // 多一张
    boolean isCanTing = playerCardsInfo.isCanTing(playerCardsInfo.cards);
    boolean isCanHu = playerCardsInfo.isCanHu_zimo(catchCard);
    // 能做的操作
    playerCardsInfo.setCanBeGang(isCanGang);
    playerCardsInfo.setCanBePeng(false);
    playerCardsInfo.setCanBeHu(isCanHu);
    playerCardsInfo.setCanBeTing(isCanTing);
    OperateResp resp = new OperateResp();
    resp.setIsCanGang(isCanGang);
    resp.setIsCanHu(isCanHu);
    resp.setIsCanTing(isCanTing);
    // 可能的操作
    ResponseVo OperateResponseVo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OPERATE, resp);
    MsgSender.sendMsg2Player(OperateResponseVo, userId);
}
Also used : ResponseVo(com.code.server.constant.response.ResponseVo)

Example 25 with ResponseVo

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

the class GameInfoSongYuan method doChiTing.

protected void doChiTing(PlayerCardsInfoMj playerCardsInfo, long userId, String one, String two) {
    deleteDisCard(lastPlayUserId, disCard);
    List<String> chiCards = new ArrayList<>();
    chiCards.add(one);
    chiCards.add(disCard);
    chiCards.add(two);
    OperateReqResp operateReqResp = new OperateReqResp();
    operateReqResp.setOperateType(OperateReqResp.type_chi_ting);
    operateReqResp.setUserId(userId);
    operateReqResp.setChiCards(chiCards);
    operateReqResp.setFromUserId(lastPlayUserId);
    ResponseVo vo = new ResponseVo(ResponseType.SERVICE_TYPE_GAMELOGIC, ResponseType.METHOD_TYPE_OTHER_OPERATE, operateReqResp);
    // 通知其他玩家听
    MsgSender.sendMsg2Player(vo, users);
    // 吃
    playerCardsInfo.chi(disCard, one, two);
    // 吃完只能听
    turnId = userId;
    // 通知客户端 操作
    OperateResp operateResp = new OperateResp();
    // 客户端特殊处理
    operateResp.setIsCanTing(false);
    operateResp.setIsCanGang(false);
    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 = true;
    playerCardsInfo.canBeChiTing = false;
    playerCardsInfo.canBeGang = false;
    resetOtherOperate(userId);
}
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