Search in sources :

Example 1 with GameRecord

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

the class Game method genRecord.

protected void genRecord(Map<Long, Double> scores, Room room, long id) {
    Map<String, Object> data = new HashMap<>();
    data.put("count", scores.size());
    data.put("room_uuid", room.getUuid());
    data.put("replay_id", id);
    GameRecord gameRecord = new GameRecord();
    gameRecord.setCurGameNumber(room.getCurGameNumber());
    scores.forEach((key, value) -> {
        UserRecord userRecord = new UserRecord();
        userRecord.setScore(value);
        userRecord.setUserId(key);
        userRecord.setRoomId(room.getRoomId());
        UserBean userBean = RedisManager.getUserRedisService().getUserBean(key);
        if (userBean != null) {
            userRecord.setName(userBean.getUsername());
        }
        gameRecord.getRecords().add(userRecord);
    });
    data.put("record", JsonUtil.toJson(gameRecord));
    KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_GAME_RECORD);
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, data);
}
Also used : UserRecord(com.code.server.constant.game.UserRecord) UserBean(com.code.server.constant.game.UserBean) HashMap(java.util.HashMap) MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) GameRecord(com.code.server.constant.game.GameRecord)

Aggregations

GameRecord (com.code.server.constant.game.GameRecord)1 UserBean (com.code.server.constant.game.UserBean)1 UserRecord (com.code.server.constant.game.UserRecord)1 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)1 MsgProducer (com.code.server.kafka.MsgProducer)1 HashMap (java.util.HashMap)1