Esempio n. 1
0
class SettlementPolicySegment(SettlementPolicy):
    def __init__(self):
        self._punishPolicy = PunishPolicyNormal(True)

    def calcResult(self, gameRound):
        ret = GameResult(gameRound)
        if gameRound.firstWinSeat:
            self._forGameOver(ret)
        else:
            self._forGameAbort(ret)
        return ret

    def settlement(self, gameResult):
        gameRound = gameResult.gameRound
        if gameRound.firstWinSeat:
            return self._settlementForOver(gameResult)
        return self._settlementForAbort(gameResult)

    def _calcWinlose(self, result):
        assert result.dizhuStatement
        for sst in result.seatStatements:
            if sst != result.dizhuStatement:
                # 地主输赢本农民的积分
                seatWinlose = sst.seat.status.totalMulti * result.baseScore
                ftlog.debug(
                    'SettlementPolicyFSegment._calcWinlose', 'roundId=',
                    result.gameRound.roundId, 'userId=', sst.seat.userId,
                    'result=',
                    (type(result.gameRound.result), result.gameRound.result),
                    'seatWinlose=', (type(seatWinlose), seatWinlose))
                # 本农民输赢积分
                seatDelta = seatWinlose if result.gameRound.result == GameRound.RESULT_NONGMIN_WIN else -seatWinlose
                sst.delta = seatDelta
                sst.final += seatDelta
                result.dizhuStatement.delta -= seatDelta
                result.dizhuStatement.final -= seatDelta

    def _forGameAbort(self, gameResult):
        return gameResult

    def _forGameOver(self, gameResult):
        # 收服务费
        # 计算输赢
        self._calcWinlose(gameResult)
        # 托管包赔
        self._punishPolicy.punish(gameResult)
        return gameResult

    def _settlementForOver(self, result):
        roomId = result.gameRound.table.roomId
        tableId = result.gameRound.table.tableId
        winUserId = result.gameRound.firstWinSeat.userId
        bombCount = result.gameRound.bombCount
        chuntian = 2 if result.gameRound.isChuntian else 1
        topCardList = result.gameRound.topValidCards.cards

        punishNM = None
        outCardTimes = []
        for sst in result.seatStatements:
            if sst != result.dizhuStatement and sst.isPunish:
                punishNM = sst
            seatStatus = sst.seat.status
            outCardTimes.append(seatStatus.outCardTimes)
        maxOutCardTimes = max(outCardTimes)

        punishStates = []
        for sst in result.seatStatements:
            # 机器人
            if sst.seat.player.isAI:
                punishStates.append(0)
                winloseInfo = {}
                rewardInfo = winloseInfo.get('tableRewards')
                segmentInfo = winloseInfo.get('segmentInfo', {})
                recoverInfo = winloseInfo.get('recoverConsume')
                winStreakRewardInfo = winloseInfo.get('winStreakRewards')
                treasureChestInfo = winloseInfo.get('treasureChest')

                sst.segmentInfo = segmentInfo
                sst.rewardInfo = rewardInfo
                sst.recoverInfo = recoverInfo
                sst.winStreakRewardInfo = winStreakRewardInfo
                sst.treasureChestInfo = treasureChestInfo

                sst.seat.player.segment = segmentInfo.get(
                    'segment', random.randint(1, 3))
                sst.seat.player.currentStar = segmentInfo.get('currentStar', 1)
                sst.seat.player._datas.update({
                    'segment':
                    sst.seat.player.segment,
                    'currentStar':
                    sst.seat.player.currentStar
                })
                continue
            player = sst.seat.player
            sst.skillscoreInfo = dict(player.getData('skillScoreInfo', {}))
            sst.skillscoreInfo['addScore'] = 0
            sst.winStreak = 0
            sst.expInfo = [
                player.getData('slevel', 0),
                player.getData('exp', 0), 0,
                player.getData('nextexp', 0),
                player.getData('title', '')
            ]
            sst.seat.player.score = sst.final

            punishState = 0
            if sst.isPunish:
                punishState = 1
            elif punishNM and sst != punishNM and sst != result.dizhuStatement:
                punishState = 2

            punishStates.append(punishState)

            leadWin = 0
            assist = 0
            validMaxOutCard = 0

            seatStatus = sst.seat.status
            if sst != result.dizhuStatement and len(seatStatus.cards) == 0:
                leadWin = 1
            if sst != result.dizhuStatement and len(
                    seatStatus.cards) != 0 and sst.isWin:
                assist = 1
            if seatStatus.outCardTimes == maxOutCardTimes and sst.isWin:
                validMaxOutCard = 1

            if ftlog.is_debug():
                ftlog.debug('_settlementForOver userId=', player.userId,
                            'assist', assist, 'validMaxOutCard',
                            validMaxOutCard)
            winloseInfo = user_segment_remote.processSegmentTableWinlose(
                roomId,
                tableId,
                player.userId,
                sst.isWin,
                sst == result.dizhuStatement,
                winUserId,
                sst.delta,
                0,
                sst.seat.status.totalMulti,
                bombCount,
                chuntian,
                result.slam,
                topCardList,
                result.gameRound.baseScore,
                punishState,
                seatStatus.outCardSeconds,
                leadWin,
                assist=assist,
                validMaxOutCard=validMaxOutCard)

            rewardInfo = winloseInfo.get('tableRewards')
            segmentInfo = winloseInfo.get('segmentInfo')
            recoverInfo = winloseInfo.get('recoverConsume')
            winStreakRewardInfo = winloseInfo.get('winStreakRewards')
            treasureChestInfo = winloseInfo.get('treasureChest')

            sst.segmentInfo = segmentInfo
            sst.rewardInfo = rewardInfo
            sst.recoverInfo = recoverInfo
            sst.winStreakRewardInfo = winStreakRewardInfo
            sst.treasureChestInfo = treasureChestInfo

            sst.seat.player.segment = segmentInfo.get('segment')
            sst.seat.player.currentStar = segmentInfo.get('currentStar')
            sst.seat.player.updateSegmentDatas()

        if ftlog.is_debug():
            ftlog.debug('SettlementPolicySegment._settlement', 'punishNM=',
                        punishNM.seat.userId if punishNM else None,
                        'punishState=', punishStates, 'infos=',
                        [(sst.seat.userId, sst.seat.player.score, sst.delta,
                          sst.rewardInfo, sst.segmentInfo, sst.isPunish)
                         for sst in result.seatStatements])

    def _settlementForAbort(self, result):
        pass
Esempio n. 2
0
 def __init__(self):
     self._punishPolicy = PunishPolicyNormal(True)
Esempio n. 3
0
class SettlementPolicyFree(SettlementPolicy):
    def __init__(self):
        super(SettlementPolicyFree, self).__init__()
        self._punishPolicy = PunishPolicyNormal(True)
    
    def calcResult(self, gameRound):
        ret = GameResult(gameRound)
        if gameRound.firstWinSeat:
            self._calcForGameOver(ret)
        else:
            self._calcForGameAbort(ret)
        return ret
    
    def settlement(self, gameResult):
        if gameResult.gameRound.firstWinSeat:
            self._settlementForGameOver(gameResult)
        else:
            self._settlementForGameAbort(gameResult)

    def _settlementForGameAbort(self, gameResult):
        for sst in gameResult.seatStatements:
            sst.seat.player.score = sst.final

    def _settlementForGameOver(self, gameResult):
        roomId = gameResult.gameRound.table.roomId
        tableId = gameResult.gameRound.table.tableId
        roundNum = gameResult.gameRound.roundNum
        winUserId = gameResult.gameRound.firstWinSeat.userId
        bombCount = gameResult.gameRound.bombCount
        chuntian = 2 if gameResult.gameRound.isChuntian else 1
        playMode = gameResult.gameRound.table.playMode.name
        topCardList = gameResult.gameRound.topValidCards.cards

        outCardTimes = []
        for sst in gameResult.seatStatements:
            seatStatus = sst.seat.status
            outCardTimes.append(seatStatus.outCardTimes)
        maxOutCardTimes = max(outCardTimes)
        
        for sst in gameResult.seatStatements:
            userId = sst.seat.userId
            clientId = sst.seat.player.clientId

            assist = 0
            validMaxOutCard = 0
            seatStatus = sst.seat.status
            if sst != gameResult.dizhuStatement and len(seatStatus.cards) != 0 and sst.isWin:
                assist = 1
            if seatStatus.outCardTimes == maxOutCardTimes and sst.isWin:
                validMaxOutCard = 1

            finalChip, expInfo, skillScoreInfo \
                = new_table_winlose.doFreeTableWinloseUT(userId, roomId, tableId, roundNum, clientId,
                                                         winUserId, sst.isWin, sst.winStreak, sst == gameResult.dizhuStatement,
                                                         sst.delta, sst.final, gameResult.gameRound.baseScore,
                                                         sst.seat.status.totalMulti, bombCount, chuntian, gameResult.slam,
                                                         playMode, topCardList, assist=assist, validMaxOutCard=validMaxOutCard)
            ftlog.info('SettlementPolicyFree._settlementForGameOver',
                       'roomId=', gameResult.gameRound.table.roomId,
                       'tableId=', gameResult.gameRound.table.tableId,
                       'roundId=', gameResult.gameRound.roundId,
                       'winStreak=', sst.winStreak,
                       'fee=', sst.fee,
                       'delta=', sst.delta,
                       'winnerTax=', sst.winnerTax,
                       'baseScore=', gameResult.gameRound.baseScore,
                       'totalMulti=', sst.seat.status.totalMulti,
                       'sstFinal=', sst.final,
                       'userId=', userId,
                       'finalChip=', finalChip)
            sst.skillscoreInfo = skillScoreInfo
            sst.seat.player.chip = finalChip
            sst.seat.player.score = sst.final
            explevel, title = gameexp.getLevelInfo(DIZHU_GAMEID, expInfo[0])
            nextExp = gameexp.getNextLevelExp(DIZHU_GAMEID, explevel)
            sst.expInfo = [explevel, expInfo[0], expInfo[1], nextExp, title]
            pt = sst.seat.player.datas.get('plays', 0)
            sst.seat.player.datas['plays'] = pt + 1
            if sst.isWin:
                wt = sst.seat.player.datas.get('wins', 0)
                sst.seat.player.datas['wins'] = wt + 1
            sst.seat.player.score = sst.final
        ftlog.info('SettlementPolicyFree._settlementForGameOver',
                   'roomId=', gameResult.gameRound.table.roomId,
                   'tableId=', gameResult.gameRound.table.tableId,
                   'roundId=', gameResult.gameRound.roundId,
                   'infos=', [(sst.seat.userId, sst.seat.player.score, sst.delta) for sst in gameResult.seatStatements])

    def _calcWinlose(self, gameResult):
        assert(gameResult.dizhuStatement)
        for sst in gameResult.seatStatements:
            if sst != gameResult.dizhuStatement:
                # 地主输赢本农民的积分
                seatWinlose = sst.seat.status.totalMulti * gameResult.baseScore
                if ftlog.is_debug():
                    ftlog.debug('SettlementPolicyFree._calcWinlose',
                                'roundId=', gameResult.gameRound.roundId,
                                'userId=', sst.seat.userId,
                                'dizhuUserId=', gameResult.dizhuStatement.seat.userId,
                                'result=', (type(gameResult.gameRound.result), gameResult.gameRound.result),
                                'baseScore=', gameResult.baseScore,
                                'totalMulti=', sst.seat.status.totalMulti,
                                'seatWinlose=', (type(seatWinlose), seatWinlose))
                # 本农民输赢积分
                seatDelta = seatWinlose if gameResult.gameRound.result == GameRound.RESULT_NONGMIN_WIN else -seatWinlose
                sst.delta = seatDelta
                sst.final += seatDelta
                gameResult.dizhuStatement.delta -= seatDelta
                gameResult.dizhuStatement.final -= seatDelta

    def _calcForGameAbort(self, gameResult):
        return gameResult
    
    def _calcForGameOver(self, gameResult):
        # 收服务费
        # 计算输赢
        self._calcWinlose(gameResult)
        # 托管包赔
        self._punishPolicy.punish(gameResult)
        return gameResult
Esempio n. 4
0
 def __init__(self):
     super(SettlementPolicyFree, self).__init__()
     self._punishPolicy = PunishPolicyNormal(True)
Esempio n. 5
0
 def __init__(self):
     super(SettlementPolicyNormal, self).__init__()
     self._punishPolicy = PunishPolicyNormal(False)
Esempio n. 6
0
class SettlementPolicyNormal(SettlementPolicy):
    def __init__(self):
        super(SettlementPolicyNormal, self).__init__()
        self._punishPolicy = PunishPolicyNormal(False)

    def calcResult(self, gameRound):
        ret = GameResult(gameRound)
        if gameRound.firstWinSeat:
            self._calcForGameOver(ret)
        else:
            self._calcForGameAbort(ret)
        return ret

    def settlement(self, gameResult):
        if gameResult.gameRound.firstWinSeat:
            self._settlementForGameOver(gameResult)
        else:
            self._settlementForGameAbort(gameResult)

    def _calcForGameAbort(self, gameResult):
        return gameResult

    def _calcForGameOver(self, gameResult):
        # 收服务费
        roomFeeConf = dizhuconf.getRoomFeeConf()
        self._calcFee(gameResult, roomFeeConf)
        # 计算输赢
        self._calcWinlose(gameResult)
        # 托管包赔
        self._punishPolicy.punish(gameResult)
        # 抽成
        self._calcWinnerTax(gameResult, roomFeeConf)
        return gameResult

    def _calcFee(self, result, roomFeeConf):
        basicRate = roomFeeConf.get('basic', 1)
        highMulti = roomFeeConf.get('high_multi', 32)

        for sst in result.seatStatements:
            sst.fee = result.gameRound.table.runConf.roomFee
            if sst.seat.status.totalMulti > highMulti and sst.isWin:
                sst.fixedFee += result.gameRound.table.runConf.fixedRoomFee
            sst.fee = min(abs(int(sst.fee * basicRate)), sst.final)
            sst.final -= sst.fee
            sst.fixedFee = min(sst.fixedFee, sst.final)
            sst.final -= sst.fixedFee
            if ftlog.is_debug():
                ftlog.debug('SettlementPolicyNormal._calcFee', 'userId=',
                            sst.seat.player.userId, 'roomId=',
                            result.gameRound.table.roomId, 'roomFee=',
                            result.gameRound.table.runConf.roomFee,
                            'fixedRoomFee=',
                            result.gameRound.table.runConf.fixedRoomFee,
                            'fee=', sst.fee, 'fixedFee=', sst.fixedFee,
                            'sst.final=', sst.final, 'sst.fee=', sst.fee,
                            'sst.feeMulti=', sst.feeMulti)

    def _calcWinlose(self, result):
        assert (result.dizhuStatement)
        dizhuWinloseLimit = min(
            result.dizhuStatement.final,
            result.dizhuStatement.seat.status.totalMulti * result.baseScore)
        winCoinLimit = result.gameRound.table.runConf.winCoinLimit
        if winCoinLimit > 0:
            dizhuWinloseLimit = min(dizhuWinloseLimit, winCoinLimit)
        for sst in result.seatStatements:
            if sst != result.dizhuStatement:
                # 本农民在所有农民输赢中所占的比例
                ratio = float(sst.seat.status.totalMulti
                              ) / result.dizhuStatement.seat.status.totalMulti
                # 地主输赢本农民的积分
                dizhuWinloseMe = int(dizhuWinloseLimit * ratio)
                # 本农民输赢积分
                seatWinlose = min(sst.final, dizhuWinloseMe)
                seatDelta = seatWinlose if result.gameRound.result == GameRound.RESULT_NONGMIN_WIN else -seatWinlose
                if ftlog.is_debug():
                    ftlog.debug('SettlementPolicyNormal._calcWinlose',
                                'roundId=', result.gameRound.roundId, 'seat=',
                                (sst.seat.userId, sst.seat.seatId), 'ratio=',
                                ratio, 'seatFinal=', sst.final, 'seatDelta=',
                                seatDelta, 'dizhuWinloseMe=', dizhuWinloseMe,
                                'seatWinlose=', seatWinlose)
                sst.delta = seatDelta
                sst.final += seatDelta
                result.dizhuStatement.delta -= seatDelta
                result.dizhuStatement.final -= seatDelta
                assert (result.dizhuStatement.final >= 0)

    def _calcWinnerTax(self, result, roomFeeConf):
        winnerTaxRate = roomFeeConf.get('winner_chip', 0)
        if winnerTaxRate > 0:
            for sst in result.seatStatements:
                if sst.delta > 0:
                    sst.winnerTax = min(sst.delta,
                                        int(sst.delta * winnerTaxRate))
                    if sst.winnerTax > 0:
                        sst.final -= sst.winnerTax

    def _settlementForGameAbort(self, gameResult):
        for sst in gameResult.seatStatements:
            sst.seat.player.score = sst.final
            new_table_remote._setLastTableChip(sst.seat.player.userId, True,
                                               sst.final)

    def _settlementForGameOver(self, gameResult):
        roomId = gameResult.gameRound.table.roomId
        tableId = gameResult.gameRound.table.tableId
        roundNum = gameResult.gameRound.roundNum
        winUserId = gameResult.gameRound.firstWinSeat.userId
        bombCount = gameResult.gameRound.bombCount
        chuntian = 2 if gameResult.gameRound.isChuntian else 1
        playMode = gameResult.gameRound.table.playMode.name
        topCardList = gameResult.gameRound.topValidCards.cards

        for sst in gameResult.seatStatements:
            # 服务费
            userId = sst.seat.userId
            clientId = sst.seat.player.clientId
            sst.seat.player.score = sst.final
            finalTableChip, finalChip, expInfo, skillScoreInfo \
                = new_table_winlose.doTableWinloseUT(userId, roomId, tableId, roundNum, clientId,
                                                     sst.isWin, sst.winStreak, winUserId, sst == gameResult.dizhuStatement,
                                                     sst.fee, sst.cardNoteFee, sst.delta, sst.systemPaid, sst.winnerTax,
                                                     gameResult.gameRound.baseScore, sst.seat.status.totalMulti,
                                                     bombCount, chuntian, gameResult.slam, playMode, topCardList, fixedFee=sst.fixedFee)
            ftlog.info(
                'SettlementPolicyNormal._settlementForGameOver', 'roomId=',
                gameResult.gameRound.table.roomId, 'tableId=',
                gameResult.gameRound.table.tableId, 'roundId=',
                gameResult.gameRound.roundId, 'cardNoteFee=', sst.cardNoteFee,
                'fee=', sst.fee, 'delta=', sst.delta, 'winnerTax=',
                sst.winnerTax, 'baseScore=', gameResult.gameRound.baseScore,
                'totalMulti=', sst.seat.status.totalMulti, 'sstFinal=',
                sst.final, 'userId=', userId, 'fixedFee=', sst.fixedFee,
                'finalTableChip=', finalTableChip, 'finalChip=', finalChip)
            sst.skillscoreInfo = skillScoreInfo
            sst.seat.player.chip = finalChip
            sst.seat.player.score = sst.final = finalTableChip
            explevel, title = gameexp.getLevelInfo(DIZHU_GAMEID, expInfo[0])
            nextExp = gameexp.getNextLevelExp(DIZHU_GAMEID, explevel)
            sst.expInfo = [explevel, expInfo[0], expInfo[1], nextExp, title]
            pt = sst.seat.player.datas.get('plays', 0)
            sst.seat.player.datas['plays'] = pt + 1
            if sst.isWin:
                wt = sst.seat.player.datas.get('wins', 0)
                sst.seat.player.datas['wins'] = wt + 1
Esempio n. 7
0
class SettlementPolicyFree(SettlementPolicy):
    def __init__(self):
        super(SettlementPolicyFree, self).__init__()
        self._punishPolicy = PunishPolicyNormal(True)

    def calcResult(self, gameRound):
        ret = GameResult(gameRound)
        if gameRound.firstWinSeat:
            self._calcForGameOver(ret)
        else:
            self._calcForGameAbort(ret)
        return ret

    def settlement(self, gameResult):
        if gameResult.gameRound.firstWinSeat:
            self._settlementForGameOver(gameResult)
        else:
            self._settlementForGameAbort(gameResult)

    def _calcForGameAbort(self, gameResult):
        return gameResult

    def _calcForGameOver(self, gameResult):
        # 收服务费
        if gameResult.gameRound.table.runConf.roomFee > 0:
            self._calcFee(gameResult)
        # 计算输赢
        self._calcWinloseFree(gameResult)
        # 托管包赔
        self._punishPolicy.punish(gameResult)
        # 抽成
        self._calcWinnerTax(gameResult)
        return gameResult

    def _calcFee(self, gameResult):
        roomFeeConf = dizhuconf.getRoomFeeConf()
        basicRate = roomFeeConf.get('basic', 1)
        highMulti = roomFeeConf.get('high_multi', 32)

        for sst in gameResult.seatStatements:
            sst.fee = gameResult.gameRound.table.runConf.roomFee
            if sst.seat.status.totalMulti > highMulti and sst.isWin:
                sst.fixedFee += gameResult.gameRound.table.runConf.fixedRoomFee
            sst.fee = min(abs(int(sst.fee * basicRate)), sst.final)
            sst.final -= sst.fee
            sst.fixedFee = min(sst.fixedFee, sst.final)
            sst.final -= sst.fixedFee

            if ftlog.is_debug():
                ftlog.debug('SettlementPolicyFree._calcFee', 'userId=',
                            sst.seat.player.userId, 'roomId=',
                            gameResult.gameRound.table.roomId, 'roomFee=',
                            gameResult.gameRound.table.runConf.roomFee,
                            'fixedRoomFee=',
                            gameResult.gameRound.table.runConf.fixedRoomFee,
                            'fixedFee=', sst.fixedFee, 'sst.final=', sst.final,
                            'sst.fee=', sst.fee, 'sst.feeMulti=', sst.feeMulti)

    def _calcWinloseFree(self, gameResult):
        assert (gameResult.dizhuStatement)
        chipControlLine = gameResult.gameRound.table.runConf.chipControlLine
        winCoinLimit = gameResult.gameRound.table.runConf.winCoinLimit
        for sst in gameResult.seatStatements:
            # 地主输赢本农民的积分
            seatWinlose = sst.seat.status.totalMulti * gameResult.baseScore
            seatWinlose = min(
                seatWinlose, winCoinLimit) if winCoinLimit > 0 else seatWinlose
            # 农民\地主输赢积分
            seatDelta = seatWinlose if gameResult.gameRound.result == GameRound.RESULT_NONGMIN_WIN else -seatWinlose
            if sst == gameResult.dizhuStatement:
                seatDelta = seatWinlose if gameResult.gameRound.result == GameRound.RESULT_DIZHU_WIN else -seatWinlose
            # 小于 目标金币值 赢牌奖励有上限
            if chipControlLine > 0 and sst.final < chipControlLine:
                seatDelta = min(seatDelta, chipControlLine)

            sst.deltaScore(seatDelta)
            if sst.final < 0:
                gameResult.systemRecovery += sst.final
                sst.systemPaid -= sst.final
                sst.deltaScore(-sst.final)

            ftlog.info('SettlementPolicyFree._calcWinlose', 'roundId=',
                       gameResult.gameRound.roundId, 'userId=',
                       sst.seat.userId, 'dizhuUserId=',
                       gameResult.dizhuStatement.seat.userId, 'result=',
                       (type(gameResult.gameRound.result),
                        gameResult.gameRound.result), 'baseScore=',
                       gameResult.baseScore, 'totalMulti=',
                       sst.seat.status.totalMulti, 'seatWinlose=',
                       (type(seatWinlose), seatWinlose), 'seatDelta=',
                       seatDelta, 'gameResult.systemRecovery=',
                       seatDelta - sst.delta, 'systemPaid=', sst.systemPaid,
                       'delta=', sst.delta, 'final=', sst.final)

    def _calcWinnerTax(self, result):
        winnerTaxRate = result.gameRound.table.runConf.winnerTaxMulti
        if winnerTaxRate > 0:
            for sst in result.seatStatements:
                if sst.delta > 0:
                    sst.winnerTax = min(sst.delta,
                                        int(sst.delta * winnerTaxRate))
                    if sst.winnerTax > 0:
                        sst.final -= sst.winnerTax

    def _settlementForGameAbort(self, gameResult):
        for sst in gameResult.seatStatements:
            sst.seat.player.score = sst.final
            new_table_remote._setLastTableChip(sst.seat.player.userId, True,
                                               sst.final)

    def _settlementForGameOver(self, gameResult):
        roomId = gameResult.gameRound.table.roomId
        tableId = gameResult.gameRound.table.tableId
        roundNum = gameResult.gameRound.roundNum
        winUserId = gameResult.gameRound.firstWinSeat.userId
        bombCount = gameResult.gameRound.bombCount
        chuntian = 2 if gameResult.gameRound.isChuntian else 1
        playMode = gameResult.gameRound.table.playMode.name
        topCardList = gameResult.gameRound.topValidCards.cards

        outCardTimes = []
        for sst in gameResult.seatStatements:
            seatStatus = sst.seat.status
            outCardTimes.append(seatStatus.outCardTimes)
        maxOutCardTimes = max(outCardTimes)

        for sst in gameResult.seatStatements:
            # 服务费
            userId = sst.seat.userId
            clientId = sst.seat.player.clientId
            sst.seat.player.score = sst.final

            assist = 0
            validMaxOutCard = 0
            seatStatus = sst.seat.status
            if sst != gameResult.dizhuStatement and len(
                    seatStatus.cards) != 0 and sst.isWin:
                assist = 1
            if seatStatus.outCardTimes == maxOutCardTimes and sst.isWin:
                validMaxOutCard = 1

            finalTableChip, finalChip, expInfo, skillScoreInfo \
                = new_table_winlose.doTableWinloseUT(userId, roomId, tableId, roundNum, clientId,
                                                     sst.isWin, sst.winStreak, winUserId, sst == gameResult.dizhuStatement,
                                                     sst.fee, sst.cardNoteFee, sst.delta, sst.systemPaid, sst.winnerTax,
                                                     gameResult.gameRound.baseScore, sst.seat.status.totalMulti,
                                                     bombCount, chuntian, gameResult.slam, playMode, topCardList, fixedFee=sst.fixedFee,
                                                     assist=assist, outCardSeconds=seatStatus.outCardSeconds, validMaxOutCard=validMaxOutCard)
            ftlog.info(
                'SettlementPolicyFree._settlementForGameOver', 'roomId=',
                gameResult.gameRound.table.roomId, 'tableId=',
                gameResult.gameRound.table.tableId, 'roundId=',
                gameResult.gameRound.roundId, 'resultWinLose=',
                gameResult.gameRound.result, 'cardNoteFee=', sst.cardNoteFee,
                'fee=', sst.fee, 'delta=', sst.delta, 'winnerTax=',
                sst.winnerTax, 'baseScore=', gameResult.gameRound.baseScore,
                'totalMulti=', sst.seat.status.totalMulti, 'sstFinal=',
                sst.final, 'systemPaid=', sst.systemPaid, 'userId=', userId,
                'winStreak=',
                gamedata.getGameAttrInt(sst.seat.player.userId, DIZHU_GAMEID,
                                        'winstreak'), 'finalTableChip=',
                finalTableChip, 'fixedFee=', sst.fixedFee, 'finalChip=',
                finalChip)
            sst.skillscoreInfo = skillScoreInfo
            sst.seat.player.chip = finalChip
            sst.seat.player.score = sst.final = finalTableChip
            explevel, title = gameexp.getLevelInfo(DIZHU_GAMEID, expInfo[0])
            nextExp = gameexp.getNextLevelExp(DIZHU_GAMEID, explevel)
            sst.expInfo = [explevel, expInfo[0], expInfo[1], nextExp, title]
            pt = sst.seat.player.datas.get('plays', 0)
            sst.seat.player.datas['plays'] = pt + 1
            sst.winStreak = gamedata.getGameAttrInt(sst.seat.player.userId,
                                                    DIZHU_GAMEID, 'winstreak')
            if sst.isWin:
                wt = sst.seat.player.datas.get('wins', 0)
                sst.seat.player.datas['wins'] = wt + 1
Esempio n. 8
0
 def __init__(self):
     super(DefaultSettlementPolicy, self).__init__()
     self._punishPolicy = PunishPolicyNormal(False)
     self.settlementPolicyNormal = SettlementPolicyNormal()
     self.settlementPolicyFree = SettlementPolicyFree()
Esempio n. 9
0
class SettlementPolicyFriendTable(SettlementPolicy):
    def __init__(self):
        self._punishPolicy = PunishPolicyNormal(True)

    def calcResult(self, gameRound):
        ret = GameResult(gameRound)
        if gameRound.firstWinSeat:
            self._forGameOver(ret)
        else:
            self._forGameAbort(ret)
        return ret

    def settlement(self, gameResult):
        gameRound = gameResult.gameRound
        if gameRound.firstWinSeat:
            return self._settlementForOver(gameResult)
        return self._settlementForAbort(gameResult)

    def _calcWinlose(self, result):
        assert (result.dizhuStatement)
        for sst in result.seatStatements:
            if sst != result.dizhuStatement:
                # 地主输赢本农民的积分
                seatWinlose = sst.seat.status.totalMulti * result.baseScore
                ftlog.debug(
                    'SettlementPolicyFriendTable._calcWinlose', 'roundId=',
                    result.gameRound.roundId, 'userId=', sst.seat.userId,
                    'result=',
                    (type(result.gameRound.result), result.gameRound.result),
                    'seatWinlose=', (type(seatWinlose), seatWinlose))
                # 本农民输赢积分
                seatDelta = seatWinlose if result.gameRound.result == GameRound.RESULT_NONGMIN_WIN else -seatWinlose
                sst.delta = seatDelta
                sst.final += seatDelta
                result.dizhuStatement.delta -= seatDelta
                result.dizhuStatement.final -= seatDelta

    def _forGameAbort(self, gameResult):
        return gameResult

    def _forGameOver(self, gameResult):
        # 收服务费
        # 计算输赢
        self._calcWinlose(gameResult)
        # 托管包赔
        self._punishPolicy.punish(gameResult)
        return gameResult

    def _settlementForOver(self, result):
        for sst in result.seatStatements:
            player = sst.seat.player
            sst.skillscoreInfo = dict(player.getData('skillScoreInfo', {}))
            sst.skillscoreInfo['addScore'] = 0
            sst.winStreak = 0
            sst.expInfo = [
                player.getData('slevel', 0),
                player.getData('exp', 0), 0,
                player.getData('nextexp', 0),
                player.getData('title', '')
            ]
            sst.seat.player.score = sst.final
        if ftlog.is_debug():
            ftlog.debug('SettlementPolicyFriendTable._settlement', 'infos=',
                        [(sst.seat.userId, sst.seat.player.score, sst.delta)
                         for sst in result.seatStatements])

    def _settlementForAbort(self, result):
        pass