Search in sources :

Example 1 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class DouDiZhuGoldRobot method play.

@Override
public void play(GameDouDiZhu game) {
    PlayerCardInfoDouDiZhu playerInfo = game.getPlayerCardInfos().get(game.playTurn);
    if (playerInfo.cards.size() == 0) {
        return;
    }
    if (game.lastCardStruct == null || game.playTurn == game.lastCardStruct.getUserId()) {
        CardStruct cardStruct = new CardStruct();
        cardStruct.type = 1;
        cardStruct.dan = game.getPlayerCardInfos().get(game.getPlayTurn()).MinimumCards();
        cardStruct.cards = game.getPlayerCardInfos().get(game.getPlayTurn()).MinimumCards();
        cardStruct.setUserId(game.getPlayTurn());
        String roomId = game.getRoom().getRoomId();
        int partition = SpringUtil.getBean(ServerConfig.class).getServerId();
        KafkaMsgKey msgKey = new KafkaMsgKey();
        msgKey.setUserId(game.getPlayTurn());
        msgKey.setRoomId(roomId);
        msgKey.setPartition(partition);
        // {"service":"gameService","method":"play","params":{"cards":{"userId":"5","cards":[12],"type":1,"dan":[12]}}}
        Map<String, Object> put = new HashMap<>();
        put.put("cards", cardStruct);
        ResponseRobotVo result = new ResponseRobotVo("gameService", "play", put);
        SpringUtil.getBean(MsgProducer.class).send2Partition("gameService", partition, msgKey, result);
    } else {
        pass(game);
    }
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) CardStruct(com.code.server.constant.game.CardStruct) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseRobotVo(com.code.server.game.poker.robot.ResponseRobotVo)

Example 2 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class DouDiZhuGoldRobot method qiangDizhu.

@Override
public void qiangDizhu(GameDouDiZhu game) {
    String roomId = game.getRoom().getRoomId();
    int partition = SpringUtil.getBean(ServerConfig.class).getServerId();
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setUserId(game.canQiangUser);
    msgKey.setRoomId(roomId);
    msgKey.setPartition(partition);
    // 按service的名字 分topic
    // {"service":"gameService","method":"qiangDizhu","params":{"isQiang":false}}
    Map<String, Object> put = new HashMap<>();
    put.put("isQiang", false);
    ResponseRobotVo result = new ResponseRobotVo("gameService", "qiangDizhu", put);
    SpringUtil.getBean(MsgProducer.class).send2Partition("gameService", partition, msgKey, result);
}
Also used : ServerConfig(com.code.server.game.poker.config.ServerConfig) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseRobotVo(com.code.server.game.poker.robot.ResponseRobotVo)

Example 3 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class GameDouDiZhuGold method genRecord.

protected void genRecord() {
    room.setRoomType("3");
    long id = IdWorker.getDefaultInstance().nextId();
    genRecord(playerCardInfos.values().stream().collect(Collectors.toMap(PlayerCardInfoDouDiZhu::getUserId, PlayerCardInfoDouDiZhu::getScore)), room, id);
    // 回放
    replay.setId(id);
    replay.setCount(playerCardInfos.size());
    replay.setRoom_uuid(this.room.getUuid());
    replay.setRoomInfo(this.room.toVo(0));
    KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_REPLAY);
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, replay);
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Example 4 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class GameDouDiZhuPlus method genRecord.

protected void genRecord() {
    room.setRoomType("3");
    long id = IdWorker.getDefaultInstance().nextId();
    genRecord(playerCardInfos.values().stream().collect(Collectors.toMap(PlayerCardInfoDouDiZhu::getUserId, PlayerCardInfoDouDiZhu::getScore)), room, id);
    // 回放
    replay.setId(id);
    replay.setCount(playerCardInfos.size());
    replay.setRoom_uuid(this.room.getUuid());
    replay.setRoomInfo(this.room.toVo(0));
    KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_REPLAY);
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, replay);
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Example 5 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class GameGuessCar method sendResult.

// =====================================
// ==============结束操作================
// =====================================
/**
 * 发送战绩
 */
protected void sendResult() {
    double tempS = bankerCardInfos.getScore();
    // 算分
    for (PlayerCardInfoGuessCar playerCardInfo : playerCardInfos.values()) {
        if (RED == this.color) {
            playerCardInfo.setFinalScore(playerCardInfo.getFinalScore() + playerCardInfo.getRedScore() * 0.95 - playerCardInfo.getGreenScore());
            bankerCardInfos.setScore(bankerCardInfos.getScore() + playerCardInfo.getGreenScore() - playerCardInfo.getRedScore());
            RedisManager.getUserRedisService().addUserMoney(playerCardInfo.getUserId(), (playerCardInfo.getRedScore() * 0.95 - playerCardInfo.getGreenScore()));
            // RedisManager.getUserRedisService().addUserMoney(bankerCardInfos.getUserId(),(playerCardInfo.getGreenScore()-playerCardInfo.getRedScore()));
            this.room.bankerScore += (playerCardInfo.getGreenScore() - playerCardInfo.getRedScore());
        } else {
            playerCardInfo.setFinalScore(playerCardInfo.getFinalScore() + playerCardInfo.getGreenScore() * 0.95 - playerCardInfo.getRedScore());
            bankerCardInfos.setScore(bankerCardInfos.getScore() + playerCardInfo.getRedScore() - playerCardInfo.getGreenScore());
            RedisManager.getUserRedisService().addUserMoney(playerCardInfo.getUserId(), (playerCardInfo.getGreenScore() * 0.95 - playerCardInfo.getRedScore()));
            // RedisManager.getUserRedisService().addUserMoney(bankerCardInfos.getUserId(),(playerCardInfo.getRedScore()-playerCardInfo.getGreenScore()));
            this.room.bankerScore += (playerCardInfo.getRedScore() - playerCardInfo.getGreenScore());
        }
    }
    // 普通玩家
    if (playerCardInfos != null && playerCardInfos.size() > 0) {
        for (Long l : playerCardInfos.keySet()) {
            Map<String, Object> result = new HashMap<>();
            result.put("color", this.color);
            result.put("finalScore", playerCardInfos.get(l).getFinalScore());
            double add = 0;
            if (RED == this.color) {
                // 设置赢了多少
                result.put("score", playerCardInfos.get(l).getRedScore() * 2 * 0.975 - playerCardInfos.get(l).getGreenScore());
                add = playerCardInfos.get(l).getRedScore();
            } else {
                result.put("score", playerCardInfos.get(l).getGreenScore() * 2 * 0.975 - playerCardInfos.get(l).getRedScore());
                add = playerCardInfos.get(l).getGreenScore();
            }
            Map<String, Object> addGold = new HashMap<>();
            addGold.put("userId", l);
            addGold.put("gold", add / 100);
            KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_GUESS_ADD_GOLD);
            MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
            msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, addGold);
            ResponseVo vo = new ResponseVo("gameGuessService", "gameResult", result);
            MsgSender.sendMsg2Player(vo, l);
        }
    }
    /*RedisManager.getUserRedisService().setUserMoney(bankerCardInfos.getUserId(),RedisManager.getUserRedisService().getUserMoney(bankerCardInfos.getUserId()) + (bankerCardInfos.getScore()-tempS));*/
    // 庄家
    Map<String, Object> result = new HashMap<>();
    // this.room.bankerScore = bankerCardInfos.getScore();
    result.put("score", bankerCardInfos.getScore() - tempS);
    result.put("bankerScore", bankerCardInfos.getScore());
    result.put("color", this.color);
    ResponseVo vo = new ResponseVo("gameGuessService", "gameBankerResult", result);
    ResponseVo voBanker = new ResponseVo("gameGuessService", "gameResult", result);
    // MsgSender.sendMsg2Player(vo, bankerCardInfos.getUserId());
    MsgSender.sendMsg2Player(voBanker, bankerCardInfos.getUserId());
    MsgSender.sendMsg2Player(vo, this.room.getUsers());
    // 改变状态
    this.room.state = RoomGuessCar.STATE_GUESS;
    MsgSender.sendMsg2Player("gameGuessService", "stateChange", this.room.state, this.room.getUsers());
    if (this.room.bankerScore <= 50) {
        MsgSender.sendMsg2Player("gameGuessService", "gameOver", "gameOver", this.room.getUsers());
        this.room.quitRoom(this.room.getBankerId());
    }
}
Also used : HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) ResponseVo(com.code.server.constant.response.ResponseVo)

Aggregations

KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)32 MsgProducer (com.code.server.kafka.MsgProducer)25 HashMap (java.util.HashMap)14 ServerConfig (com.code.server.game.poker.config.ServerConfig)11 ResponseRobotVo (com.code.server.game.poker.robot.ResponseRobotVo)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 KafkaListener (org.springframework.kafka.annotation.KafkaListener)3 UserBean (com.code.server.constant.game.UserBean)2 UserRecord (com.code.server.constant.game.UserRecord)2 ResponseVo (com.code.server.constant.response.ResponseVo)2 UserServiceMsgDispatch (com.code.server.login.service.UserServiceMsgDispatch)2 CardStruct (com.code.server.constant.game.CardStruct)1 GameRecord (com.code.server.constant.game.GameRecord)1 RoomRecord (com.code.server.constant.game.RoomRecord)1 ClubServiceMsgDispatch (com.code.server.login.service.ClubServiceMsgDispatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1