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);
}
}
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);
}
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);
}
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);
}
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());
}
}
Aggregations