Search in sources :

Example 1 with GameResultDouDizhu

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

the class GameDouDiZhuPlus method sendResult.

protected void sendResult(boolean isReopen, boolean isDizhuWin) {
    GameResultDouDizhu gameResultDouDizhu = new GameResultDouDizhu();
    gameResultDouDizhu.setGoldRoomType(room.getGoldRoomType() * tableScore);
    gameResultDouDizhu.setMultiple(multiple);
    gameResultDouDizhu.setSpring(isSpring);
    gameResultDouDizhu.setDizhuWin(isDizhuWin);
    gameResultDouDizhu.setReopen(isReopen);
    gameResultDouDizhu.setTableCards(tableCards);
    /*        for (PlayerCardInfoDouDiZhu playerCardInfo : playerCardInfos.values()) {
            gameResultDouDizhu.getPlayerCardInfos().add(playerCardInfo.toVo());
        }
        //分数结算到房卡

        this.users.forEach(userId -> {
            RedisManager.getUserRedisService().addUserMoney(userId, this.room.getUserScores().get(userId));
        });*/
    ArrayList<Long> tempList = new ArrayList<>();
    tempList.addAll(this.users);
    tempList.remove(dizhu);
    double dizhuOfHave = RedisManager.getUserRedisService().getUserMoney(dizhu);
    double person1OfHave = RedisManager.getUserRedisService().getUserMoney(tempList.get(0));
    double person2OfHave = RedisManager.getUserRedisService().getUserMoney(tempList.get(1));
    double dizhuOfGame = this.room.getUserScores().get(dizhu);
    double person1OfGame = this.room.getUserScores().get(tempList.get(0));
    double person2OfGame = this.room.getUserScores().get(tempList.get(1));
    if (dizhuOfGame > 0) {
        // 地主赢
        if (person1OfGame + person1OfHave <= 0) {
            // 豆不够
            RedisManager.getUserRedisService().addUserMoney(tempList.get(0), -person1OfHave);
            RedisManager.getUserRedisService().addUserMoney(dizhu, person1OfHave);
        } else {
            RedisManager.getUserRedisService().addUserMoney(tempList.get(0), person1OfGame);
            RedisManager.getUserRedisService().addUserMoney(dizhu, -person1OfGame);
        }
        if (person2OfGame + person2OfHave <= 0) {
            RedisManager.getUserRedisService().addUserMoney(tempList.get(1), -person2OfHave);
            RedisManager.getUserRedisService().addUserMoney(dizhu, person2OfHave);
        } else {
            RedisManager.getUserRedisService().addUserMoney(tempList.get(1), person2OfGame);
            RedisManager.getUserRedisService().addUserMoney(dizhu, -person2OfGame);
        }
    } else {
        // 地主输
        if (dizhuOfGame + dizhuOfHave >= 0) {
            // 豆充足
            RedisManager.getUserRedisService().addUserMoney(dizhu, dizhuOfGame);
            RedisManager.getUserRedisService().addUserMoney(tempList.get(0), person1OfGame);
            RedisManager.getUserRedisService().addUserMoney(tempList.get(1), person2OfGame);
        } else {
            RedisManager.getUserRedisService().addUserMoney(dizhu, -dizhuOfHave);
            RedisManager.getUserRedisService().addUserMoney(tempList.get(0), person1OfGame / (person1OfGame + person2OfGame) * dizhuOfHave);
            RedisManager.getUserRedisService().addUserMoney(tempList.get(1), person2OfGame / (person1OfGame + person2OfGame) * dizhuOfHave);
        }
    }
    for (Long l : this.room.getUserScores().keySet()) {
        this.room.getUserScores().put(l, this.room.getUserScores().get(l));
    }
    // 将room保存到playerCardInfos
    for (PlayerCardInfoDouDiZhu playerCardInfo : playerCardInfos.values()) {
        playerCardInfo.setScore(this.room.getUserScores().get(playerCardInfo.getUserId()));
        gameResultDouDizhu.getPlayerCardInfos().add(playerCardInfo.toVo());
    }
    gameResultDouDizhu.getUserScores().putAll(this.room.getUserScores());
    MsgSender.sendMsg2Player("gameService", "gameResult", gameResultDouDizhu, users);
    replay.setResult(gameResultDouDizhu);
    pushScoreChange();
    a: for (Long l : room.getUsers()) {
        if (RedisManager.getUserRedisService().getUserMoney(l) < RoomDouDiZhuPlus.needsMoney.get(room.getGoldRoomType())) {
            room.clearReadyStatus(true);
            List<UserOfResult> userOfResultList = this.room.getUserOfResult();
            // 存储返回
            GameOfResult gameOfResult = new GameOfResult();
            gameOfResult.setUserList(userOfResultList);
            MsgSender.sendMsg2Player("gameService", "gameFinalResult", gameOfResult, users);
            RoomManager.removeRoom(room.getRoomId());
            // 战绩
            this.room.genRoomRecord();
            break a;
        }
    }
}
Also used : GameResultDouDizhu(com.code.server.constant.response.GameResultDouDizhu) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GameOfResult(com.code.server.constant.response.GameOfResult)

Aggregations

GameOfResult (com.code.server.constant.response.GameOfResult)1 GameResultDouDizhu (com.code.server.constant.response.GameResultDouDizhu)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1