Ejemplo n.º 1
0
def doTreasureBox(userId, gameId, bigRoomId, datas, tbconfiger):
    ftlog.debug('LoopWinTask.doTreasureBox userId=', userId
                , ' bigRoomId=', bigRoomId
                , ' datas:', datas
                , ' uChip:', hallrpcutil.getChip(userId))
    # 判定房间配置
    if not tbconfiger or not tbconfiger.get('reward', None) :
        ftlog.debug('LoopWinTask.doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId, 'not tbox room !')
        return
    
    # 活动加成
    dRatio = _getDoubleInfos(gameId)
    notifyMsg(userId, gameId, bigRoomId, datas, tbconfiger, dRatio)
    
    # tips = getTreasureTableTip(gameId, bigRoomId)
    # 更新宝箱状态 
    datas[LASTTIME] = int(time.time())
    datas[WINTIMES] = 0
    _setTbData(userId, gameId, bigRoomId, datas)
   
    rewards = tbconfiger['reward']
    content = tycontent.decodeFromDict(rewards)
    sitems = content.getItems()
    for si in sitems:
        si.count = int(si.count * dRatio)

    # 发送道具
    contentItems = content.getItemsDict()
    aslist = hallrpcutil.addAssets(userId,
                                   gameId,
                                   contentItems,
                                   'TASK_OPEN_TBOX_REWARD',
                                   bigRoomId)
    ftlog.debug('LoopWinTask.doTreasureBox->userIds=', userId, 'bigRoomId=', bigRoomId, datas)
Ejemplo n.º 2
0
    def process_interactive_expression(cls, userId, gameId, seatId, chat_msg,
                                       target_player_uid, base_chip,
                                       chat_chip):
        """
        处理消费金币的表情
        """
        config = cls.get_interactive_expression_config(base_chip, chat_chip)
        emoId = str(chat_msg.get('emoId', -1))
        if emoId == -1:
            ftlog.warn('MTableExpression chat msg illegal', chat_msg, config)
            return False

        info = config
        # 底分限制
        chip = hallrpcutil.getChip(userId)
        ftlog.debug('MTableExpression info:', info, 'chip:', chip, caller=cls)
        if chip >= info['chip_limit'] + info['cost'] \
                and TYPlayer.isHuman(userId):
            trueDelta, _ = hallrpcutil.incrChip(userId, gameId, -info['cost'],
                                                0, "EMOTICON_CONSUME",
                                                chat_msg['emoId'])

            if trueDelta != -info['cost']:  # 失败
                ftlog.warn('MTableExpression coin not enougth: ', chip,
                           info['chip_limit'], info['cost'])
                return False
            # 金币发生变化,通知前端
            hallrpcutil.sendDataChangeNotify(userId, gameId, 'udata')
            tybireport.gcoin('out.interactive_expression', gameId,
                             info['cost'])
        else:
            ftlog.warn('MTableExpression insufficient', chip,
                       info['chip_limit'], info['cost'])

        return True
Ejemplo n.º 3
0
 def autoProcessListenCharge(self, seatId):
     '''
     监听用户充值是否成功
     '''
     uChip = hallrpcutil.getChip(self.table.player[seatId].userId)
     # 判断用户现在的金币是否大于buyIn
     buyIn = self.table.roomConfig.get(MTDefine.BUYIN_CHIP, 0)
     # 用户外面的金币大于的话,则充值成功
     if uChip >= buyIn:
         self.table.processCharge(seatId, MChargeProcessor.ASK_CHARGE_OK)
Ejemplo n.º 4
0
    def updateProcessor(self, actionId, seatId, chargeResult, dis=''):
        '''
        更新某个玩家的购买结果
        '''
        if self.getState() != MTableState.TABLE_STATE_CHARGE:
            return False

        if chargeResult == self.ASK_CHARGE_NO:
            self.chargeState[seatId] = self.CHARGE_FAIL
            ftlog.debug('MChargeProcessor.updateProcessor player name:',
                        self.players[seatId].name, 'confirmLoose')
            self.players[seatId].confirmLoose()
        else:
            self.chargeState[seatId] = self.CHARGE_OK
            # 带入金币
            userId = self.players[seatId].userId
            # 钻石数量
            uDiamond = userchip.getDiamond(userId)
            tfinal, final, delta = userchip.setTableChipToN(
                userId, self.gameId, self.chargeChip[seatId] +
                self.players[seatId].getTableCoin(self.gameId, self.tableId),
                'CHIP_TO_TABLE_TCHIP', 0, tysessiondata.getClientId(userId),
                self.tableId)
            dis += '已为您带入' + str(
                self.chargeChip[seatId]) + '金币,还有' + str(tfinal) + '金币,继续游戏...'
            ftlog.info(
                'Majiang2.logAnalyse userId:', userId, 'tableCoin:',
                self.players[seatId].getTableCoin(self.gameId, self.tableId),
                'ChargeChip:', self.chargeChip[seatId], 'tableId:',
                self.tableId, 'ChargeChip')
            self.players[seatId].setCoin(hallrpcutil.getChip(userId))
            tableCoin = hallrpcutil.getTableChip(userId, self.gameId,
                                                 self.tableId)
            self.players[seatId].setTableCoin(tableCoin)
            # 通知前端背包金币发生变化
            datachangenotify.sendDataChangeNotify(self.gameId, userId, 'udata')
            ftlog.debug(
                'MChargeProcessor.updateProcessor setTableChipToN, tfinal:',
                tfinal, ' final:', final, ' delta:', delta, ' uChip:',
                self.players[seatId].coin, ' tableChip:',
                self.players[seatId].getTableCoin(self.gameId,
                                                  self.tableId), ' userId:',
                userId, ' gameId:', self.gameId, ' seatId:', seatId)
            self.msgProcessor.table_call_coin_detail(seatId,
                                                     self.chargeChip[seatId],
                                                     final, uDiamond)
        self.msgProcessor.table_call_charged(seatId, actionId,
                                             self.chargeState[seatId], dis)
        if self.isAllCharged():
            self.reset()
        return True
Ejemplo n.º 5
0
    def _canQuickEnterRoom(cls, userId, gameId, roomId, isOnly):

        try:
            chip = hallrpcutil.getChip(userId)
            if ftlog.is_debug():
                ftlog.debug(tyconfig.getRoomDefine(roomId).configure)
            roomConfig = tyconfig.getRoomDefine(roomId).configure
            if ftlog.is_debug():
                ftlog.debug('userId =', userId, 'minCoin =',
                            roomConfig.get('minCoin'), 'maxCoin =',
                            roomConfig.get('maxCoin'), 'minCoinQS =',
                            roomConfig.get('minCoinQS'), 'maxCoinQS =',
                            roomConfig.get('maxCoinQS'), 'chip =', chip,
                            'isOnly =', isOnly)
            if isOnly:
                minCoinQs = roomConfig['minCoin']
                maxCoinQs = roomConfig['maxCoin']
            else:
                minCoinQs = roomConfig['minCoinQS']
                maxCoinQs = roomConfig['maxCoinQS']
            ismatch = roomConfig.get('ismatch')

            if ismatch or minCoinQs <= 0:
                return TYRoom.ENTER_ROOM_REASON_NOT_QUALIFIED

            if ftlog.is_debug():
                ftlog.debug('roomId =',
                            roomId,
                            'minCoinQs =',
                            minCoinQs,
                            'maxCoinQs =',
                            maxCoinQs,
                            'chip =',
                            chip,
                            caller=cls)

            if chip < minCoinQs:
                return TYRoom.ENTER_ROOM_REASON_LESS_MIN
            if maxCoinQs > 0 and chip >= maxCoinQs:
                return TYRoom.ENTER_ROOM_REASON_GREATER_MAX

            return TYRoom.ENTER_ROOM_REASON_OK

        except Exception as e:
            ftlog.error(e)
            return TYRoom.ENTER_ROOM_REASON_INNER_ERROR
Ejemplo n.º 6
0
def doTreasureBox(userId, gameId, bigRoomId, datas, historyWinStreaks,
                  hasGetCoupon, tableConfig):
    # 发送奖励
    ftlog.debug('WinStreakTask.doTreasureBox userId=', userId, ' bigRoomId=',
                bigRoomId, ' datas:', datas, ' uChip:',
                hallrpcutil.getChip(userId), ' hasGetCoupon:', hasGetCoupon)
    tbconfiger = _getWinStreakInfo(tableConfig, datas[WIN_COUNT])
    ftlog.debug('WinStreakTask.doTreasureBox tbConfiger:', tbconfiger)
    # 判定房间配置
    if not tbconfiger or not tbconfiger.get('rewards', None):
        ftlog.debug('WinStreakTask.doTreasureBox->userIds=', userId,
                    'bigRoomId=', bigRoomId, 'not tbox room !')
        return
    rewards = tbconfiger['rewards']

    # 判断奖品是否为奖劵
    rewardCouponFlag = 0
    if 'items' in rewards and 'itemId' in rewards['items'][0]:
        itemId = rewards['items'][0]['itemId']
        if itemId == 'user:coupon':
            rewardCouponFlag = 1

    ftlog.debug('WinStreakTask.doTreasureBox hasGetCoupon:', hasGetCoupon,
                'rewardCouponFlag:', rewardCouponFlag)

    if (not hasGetCoupon) and rewardCouponFlag:
        firstGetCoupon = True
    else:
        firstGetCoupon = False
    ftlog.debug('WinStreakTask.doTreasureBox firstGetCoupon:', firstGetCoupon)
    notifyMsg(userId, gameId, bigRoomId, datas, historyWinStreaks, False,
              firstGetCoupon, tableConfig, True)

    content = tycontent.decodeFromDict(rewards)
    sitems = content.getItems()
    for si in sitems:
        si.count = int(si.count)
    # 发送道具
    contentItems = content.getItemsDict()
    aslist = hallrpcutil.addAssets(userId, gameId, contentItems,
                                   'TASK_OPEN_TBOX_REWARD', bigRoomId)
    ftlog.debug('winStreakTask.doTreasureBox->userIds=', userId, 'bigRoomId=',
                bigRoomId, datas)

    # 返回是否第一次获得奖卷
    return rewardCouponFlag
Ejemplo n.º 7
0
 def reportBiGameEvent(self,
                       eventId,
                       userId,
                       roomId,
                       tableId,
                       roundId,
                       detalChip,
                       state1,
                       state2,
                       cardlist,
                       tag=''):
     finalUserChip = hallrpcutil.getChip(userId)
     finalTableChip = 0
     clientId = tysessiondata.getClientId(userId)
     tybireport.reportGameEvent(eventId, userId, self.gameId, roomId,
                                tableId, roundId, detalChip, state1, state2,
                                cardlist, clientId, finalTableChip,
                                finalUserChip)
Ejemplo n.º 8
0
    def checkSitCondition(self, userId):
        chip = hallrpcutil.getChip(userId)

        if chip < self.roomConf['minCoin']:
            ftlog.warn("chip not enough",
                       "|userId, roomId:",
                       userId,
                       self.roomId,
                       caller=self)
            return False, TYRoom.ENTER_ROOM_REASON_LESS_MIN

        if self.roomConf['maxCoin'] > 0 and chip > self.roomConf['maxCoin']:
            ftlog.warn("chip too much",
                       "|userId, roomId:",
                       userId,
                       self.roomId,
                       caller=self)
            return False, TYRoom.ENTER_ROOM_REASON_GREATER_MAX

        return True, TYRoom.ENTER_ROOM_REASON_OK
Ejemplo n.º 9
0
    def _canQuickEnterRoom(cls,
                           userId,
                           gameId,
                           roomId,
                           isUserChoosed,
                           where='roomlist'):
        '''
        是用户选择的,校验用户金币是否在[minCoin, maxCoin]之间
        牌桌内的快速开始,校验用户的金币是否在[minCoin, maxTableCoin]之间
        是服务推荐的,校验用户的金币是否在[minCoinQS, maxCoinQS]之间
        
        房间的minCoin/maxCoin可以重叠
        minCoinQS/maxCoinQS最好不要重叠
        '''
        if isFriendRoom(roomId):
            return TYRoom.ENTER_ROOM_REASON_NOT_QUALIFIED

        try:
            chip = hallrpcutil.getChip(userId)
            ftlog.debug('MajiangQuickStartCoin:',
                        tyconfig.getRoomDefine(roomId).configure,
                        caller=cls)
            roomConfig = tyconfig.getRoomDefine(roomId).configure
            ismatch = roomConfig.get('ismatch')
            isBigMatch = False
            if roomConfig.get('typeName', '') == 'majiang_bigmatch':
                isBigMatch = True
            if ismatch and not isBigMatch:
                return cls._canQuickEnterMatch(userId, gameId, roomId, chip)

            if isUserChoosed:
                minCoinQs = roomConfig[MTDefine.MIN_COIN]
                maxCoinQs = roomConfig[MTDefine.MAX_COIN]
                if where == 'table':
                    maxCoinQs = roomConfig.get(MTDefine.MAX_TABLE_COIN,
                                               maxCoinQs)
                    ftlog.debug('quick_start from table, maxCoinQS:',
                                maxCoinQs)
            else:
                minCoinQs = roomConfig[MTDefine.MIN_COIN_QS]
                maxCoinQs = roomConfig[MTDefine.MAX_COIN_QS]

            ftlog.debug('MajiangQuickStartCoin roomId:',
                        roomId,
                        'minCoinQs:',
                        minCoinQs,
                        'maxCoinQs:',
                        maxCoinQs,
                        'chip:',
                        chip,
                        caller=cls)

            if chip < minCoinQs and (minCoinQs != -1):
                return TYRoom.ENTER_ROOM_REASON_LESS_MIN

            if maxCoinQs > 0 and chip > maxCoinQs:
                return TYRoom.ENTER_ROOM_REASON_GREATER_MAX

            return TYRoom.ENTER_ROOM_REASON_OK

        except Exception as e:
            ftlog.error(e)
            return TYRoom.ENTER_ROOM_REASON_INNER_ERROR
Ejemplo n.º 10
0
    def autoChargeCoin(self, seatId):
        '''
        继续下一局时的自动带入金币
        '''
        if self.players[seatId].isRobot():
            return

        # 免费场 不提示充值引导
        if self.roomConfig.get('level', MTDefine.FREE) == MTDefine.FREE:
            return

        baseChip = self.tableConfig.get(MTDefine.BASE_CHIP, 0)
        if baseChip < 0:
            baseChip = 0

        userId = self.players[seatId].userId
        uChip = userchip.getChip(userId)
        uDiamond = userchip.getDiamond(userId)
        tableCoin = userchip.getTableChip(userId, self.gameId, self.tableId)
        if tableCoin != self.players[seatId].getTableCoin(
                self.gameId, self.tableId):
            self.players[seatId].setTableCoin(tableCoin)

        buyIn = self.roomConfig.get(MTDefine.BUYIN_CHIP, 0)
        ftlog.debug(
            'MChargeProcessor.autoChargeCoin baseChip:', baseChip,
            ' tableCoin:',
            self.players[seatId].getTableCoin(self.gameId,
                                              self.tableId), ' uChip:', uChip,
            ' buyIn:', buyIn, ' roomConfig:', self.roomConfig)

        clientId = Majiang2Util.getClientId(userId)
        # 第一次带入的时候,要么buyIn==tableCoin 要么uChip为0
        if buyIn > tableCoin and uChip != 0:
            changeChip = uChip
            # 大于一倍 则让玩家牌桌金币为buyIn 否则全部带入
            if uChip + tableCoin > buyIn:
                changeChip = buyIn - tableCoin

            tfinal, final, delta = hallrpcutil.setTableChipToN(
                userId, self.gameId, changeChip +
                self.players[seatId].getTableCoin(self.gameId, self.tableId),
                'CHIP_TO_TABLE_TCHIP', 0, clientId, self.tableId)
            ftlog.info(
                'Majiang2.logAnalyse userId:', userId, 'tableCoin:',
                self.players[seatId].getTableCoin(self.gameId,
                                                  self.tableId), 'ChargeChip:',
                changeChip, 'tableId:', self.tableId, 'ChargeChip')
            self.players[seatId].setCoin(hallrpcutil.getChip(userId))
            tableCoin = hallrpcutil.getTableChip(userId, self.gameId,
                                                 self.tableId)
            self.players[seatId].setTableCoin(tableCoin)
            # 通知前端金币发生变化
            datachangenotify.sendDataChangeNotify(self.gameId, userId, 'udata')
            ftlog.debug(
                'MChargeProcessor.autoChargeCoin setTableChipToN, tfinal:',
                tfinal, ' final:', final, ' delta:', delta, ' uChip:',
                self.players[seatId].coin, ' tableChip:',
                self.players[seatId].getTableCoin(self.gameId,
                                                  self.tableId), ' userId:',
                userId, ' gameId:', self.gameId, ' seatId:', seatId)
            # 通知前端积分变化
            allCoin = [0 for _ in range(self.playerCount)]
            allTableCoin = [0 for _ in range(self.playerCount)]
            for i in range(self.playerCount):
                if self.players[i]:
                    allCoin[i] = userchip.getChip(self.players[i].userId)
                    allTableCoin[i] = userchip.getTableChip(
                        self.players[i].userId, self.gameId, self.tableId)
            currentScore = [0 for _ in range(self.playerCount)]
            delta = [0 for _ in range(self.playerCount)]
            self.msgProcessor.table_call_score(allCoin, allTableCoin,
                                               currentScore, delta, False)

            self.msgProcessor.table_call_coin_detail(seatId, changeChip, final,
                                                     uDiamond)