Пример #1
0
    def processEnterGame(cls, evt):
        # # 检查当前已结束赛季并发放赛季奖励, 只发放上一期的
        if ftlog.is_debug():
            ftlog.debug('============= processEnterGame userId=', evt.userId)
        _, intClientId = sessiondata.getClientIdNum(evt.userId)
        if intClientId == 24105:
            latestTwoIssues = SegmentMatchHelper.getIssueStateList()[-2:]
            for issuestate in reversed(latestTwoIssues):
                if issuestate['state'] == 0:
                    continue

                # 判断用户有没有结算此赛季
                userData = SegmentMatchHelper.getUserSegmentDataIssue(
                    evt.userId, issuestate['issue']) or UserSegmentDataIssue()
                if userData and userData.segmentRewardsState == UserSegmentDataIssue.IDEAL:
                    # 结算 发奖
                    settlementRanking(evt.userId, issuestate['issue'])

        segmentConf = getSegmentConf()
        if segmentConf.closed:
            return

        if evt.dayFirst:
            # 检查用户是否已经发送
            if not gamedata.getGameAttrInt(evt.userId, DIZHU_GAMEID,
                                           'wxNotice'):
                # 保存消息记录
                gamedata.setGameAttr(evt.userId, DIZHU_GAMEID, 'wxNotice', 1)

                # 新用户发送一条额外消息
                mailstr = '游戏公告#如有任何意见建议,欢迎加客服微信:Tuyoo_taozi,进入官方群反馈'
                message.send(DIZHU_GAMEID, message.MESSAGE_TYPE_SYSTEM,
                             evt.userId, mailstr)

        # 同步钻石为用户道具
        if not segmentdata.getSegmentAttr(evt.userId, DIZHU_GAMEID,
                                          'diamondConvert'):
            segmentdata.setSegmentAttr(evt.userId, DIZHU_GAMEID,
                                       'diamondConvert', 1)
            userDiamond = userdata.getAttr(evt.userId, 'diamond')
            if userDiamond:
                # count
                user_remote.consumeAssets(DIZHU_GAMEID, evt.userId,
                                          [{
                                              'itemId': 'user:diamond',
                                              'count': userDiamond
                                          }], 'DIZHU_SEGMENT_DIAMOND_CONVERT',
                                          0)
                contentItems = TYContentItem.decodeList([{
                    'itemId': 'item:1311',
                    'count': userDiamond
                }])
                from dizhu.entity import dizhu_util
                dizhu_util.sendRewardItems(evt.userId, contentItems, None,
                                           'DIZHU_SEGMENT_DIAMOND_CONVERT', 0)
                ftlog.info('DizhuSegmentRewardsHelper diamondConvert userId=',
                           evt.userId, 'userDiamond=', userDiamond)
Пример #2
0
 def processUserTableRewards(cls, userId, winlose):
     ''' 处理牌局结束用户的奖励 '''
     gameWinRewardConf = getSegmentConf().gameWinReward
     # 判断condition
     condList = gameWinRewardConf.get('conditions')
     if condList and winlose.isWin:
         for condD in condList:
             cond = UserConditionRegister.decodeFromDict(condD)
             clientId = sessiondata.getClientId(userId)
             retCheck = cond.check(DIZHU_GAMEID,
                                   userId,
                                   clientId,
                                   pktimestamp.getCurrentTimestamp(),
                                   winlose=winlose)
             if retCheck:
                 reward = gameWinRewardConf.get('reward')
                 if reward:
                     try:
                         contentItems = TYContentItem.decodeList([reward])
                         from dizhu.entity import dizhu_util
                         dizhu_util.sendRewardItems(
                             userId, contentItems, None,
                             'DIZHU_SEGMENT_TABLE_WIN', 0)
                         ret = SegmentMatchHelper.addUserSegmentTableWinRewardCount(
                             userId, reward['count'])
                         if ret:
                             retMsg = ''
                             if cond.TYPE_ID == UserConditionSegmentWinDoubles.TYPE_ID:
                                 retMsg = '满贯'
                             elif cond.TYPE_ID == UserConditionSegmentChuntian.TYPE_ID:
                                 retMsg = '春天'
                             retReward = {
                                 'itemId': reward['itemId'],
                                 'count': reward['count'],
                                 'des': retMsg
                             }
                             ftlog.info(
                                 'DizhuSegmentRewardsHelper.processUserTableRewards',
                                 'userId=', userId, 'typeId=', cond.TYPE_ID,
                                 'reward=', retReward)
                             return retReward
                         else:
                             return None
                     except Exception, e:
                         ftlog.error(
                             'DizhuSegmentRewardsHelper.processUserTableRewards',
                             'userId=', userId, 'gameWinRewardConf=',
                             gameWinRewardConf, 'errmsg=', e.message)
Пример #3
0
 def hasReward(self, userId):
     ''' 是否有奖励 '''
     latestTwoIssues = SegmentMatchHelper.getIssueStateList()[-2:]
     ret = False
     for issuestate in reversed(latestTwoIssues):
         if issuestate['state'] == 0:
             continue
         # 判断用户有没有结算此赛季
         userData = SegmentMatchHelper.getUserSegmentDataIssue(
             userId, issuestate['issue']) or UserSegmentDataIssue()
         if userData and userData.segmentRewardsState == UserSegmentDataIssue.IDEAL:
             # 获取奖励
             rewards = getSegmentConf().getSeasonRewards(userData.segment)
             if rewards:
                 return True
     return ret
Пример #4
0
    def _segment_recover(cls, userId, gameId, clientId):
        # 段位复活数据
        errmsg = '你的保段复活费用不足'
        success = 0
        userRecoverData = SegmentMatchHelper.getUserSegmentRecoverData(userId)
        if userRecoverData.active:
            totalRecoverCount = userRecoverData.totalRecoverCount
            recoverConf = getSegmentConf().segmentRecover
            others = recoverConf.get('buy', {}).get('itemCount', {}).get('others', 10)
            needCount = recoverConf.get('buy', {}).get('itemCount', {}).get(str(totalRecoverCount), others)
            itemId = recoverConf.get('buy', {}).get('itemId')
            # 判断用户参赛券否够
            contentItemList = [{'itemId': itemId, 'count': needCount}]
            assetKindId, count = user_remote.consumeAssets(DIZHU_GAMEID, userId, contentItemList,
                                                           'SEGMENT_MATCH_RECOVER_FEE', 0)

            ftlog.info('SegmentMatchHandler.collectFee',
                       'userId=', userId,
                       'fees=', contentItemList,
                       'assetKindId=', assetKindId,
                       'count=', count)

            if not assetKindId:
                errmsg = 'ok'
                success = 1
                # 广播事件
                TGDizhu.getEventBus().publishEvent(SegmentRecoverEvent(userId, gameId))

        msg = MsgPack()
        msg.setCmd('dizhu')
        msg.setResult('action', 'segment_recover')
        msg.setResult('gameId', gameId)
        msg.setResult('userId', userId)
        msg.setResult('success', success)
        msg.setResult('errmsg', errmsg)

        if ftlog.is_debug():
            ftlog.debug('SegmentMatchHandler._segment_recover'
                        'userId=', userId,
                        'gameId=', gameId,
                        'clientId=', clientId,
                        'userRecoverData=', userRecoverData.toDict(),
                        'msg=', msg._ht)

        return msg
Пример #5
0
def processSegmentTableWinlose(roomId, tableId, userId, isWin, isDizhu, winUserId,
                         winlose, finalTableChip, winDoubles, bomb, chuntian,
                         winslam, topValidCard, baseScore, punishState=0, outCardSeconds=0, leadWin=0, **kwargs):

    from dizhu.game import TGDizhu
    from hall.game import TGHall
    ebus = TGDizhu.getEventBus()
    hallBus = TGHall.getEventBus()
    assist = kwargs.get('assist', 0)
    validMaxOutCard = kwargs.get('validMaxOutCard', 0)
    if ftlog.is_debug():
        ftlog.debug('processSegmentTableWinlose userId=', userId,
                    'assist', assist,
                    'validMaxOutCard', validMaxOutCard)
    winloseObj = Winlose(winUserId, topValidCard, isWin, isDizhu, winlose, finalTableChip, winDoubles, bomb, chuntian > 1,
                         winslam, baseScore, punishState=punishState, outCardSeconds=outCardSeconds, leadWin=leadWin,
                         assist=assist, validMaxOutCard=validMaxOutCard)

    rankInfo = wx_official.getRankInfo(userId)
    ebus.publishEvent(SegmentTableWinloseEvent(DIZHU_GAMEID, userId, roomId, tableId, winloseObj, rankInfo=rankInfo))
    # 处理牌桌奖励
    segmentInfo = SegmentMatchHelper.getUserSegmentInfo(userId, SegmentMatchHelper.getCurrentIssue())

    # 处理打出高倍公众号消息
    if winDoubles >= 64:
        hallBus.publishEvent(OfficialMessageEvent(DIZHU_GAMEID, userId, dizhuconf.MULTI))

    # 处理保段
    recoverConsume = None
    recoverInfo = SegmentMatchHelper.getUserSegmentRecoverData(userId)
    segmentRecoverConf = getSegmentConf().segmentRecover
    if recoverInfo.active:
        if _isRecoverForShare(userId):
            recoverConsume = {
                'type': 'share'
            }
        else:

            itemId = segmentRecoverConf.get('buy', {}).get('itemId')
            itemCount = segmentRecoverConf.get('buy', {}).get('itemCount', {})
            desc = segmentRecoverConf.get('buy', {}).get('desc', {})
            count = itemCount.get(str(recoverInfo.totalRecoverCount)) or itemCount.get('others', 10)
            userAssets = hallitem.itemSystem.loadUserAssets(userId)
            userItemCount = userAssets.balance(HALL_GAMEID, itemId, pktimestamp.getCurrentTimestamp()) or 0
            if userItemCount >= count:
                recoverConsume = {
                    'type': 'buy',
                    'itemId': itemId,
                    'count': count,
                    'desc': desc
                }

    # 获取连胜任务奖励
    winStreakRewards = None
    currentWinStreak = 0
    isAsync = None
    rewardId = None
    if SegmentWinStreakTaskHelper.isActive():
        _, winStreakRewards, currentWinStreak, isAsync = SegmentWinStreakTaskHelper.updateUserWinStreak(userId, isWin, punishState)

    # 处理九连胜公众号消息
    if currentWinStreak == 9:
        hallBus.publishEvent(OfficialMessageEvent(DIZHU_GAMEID, userId, dizhuconf.WINSTREAK))

    # 发送宝箱逻辑
    winStreakChestConf = TreasureChestHelper.getWinStreakConf(currentWinStreak)
    if TreasureChestHelper.isValidUser(userId) and winStreakRewards and winStreakChestConf:
        TGDizhu.getEventBus().publishEvent(TreasureChestEvent(DIZHU_GAMEID, userId, TREASURE_CHEST_TYPE_AS_WINSTREAK, None, winStreak=currentWinStreak))
    # 处理分享得奖
    elif isAsync and winStreakRewards:
        from dizhu.game import TGDizhu
        rewards = []
        for rewardInfo in winStreakRewards:
            rewards.append({'itemId': rewardInfo['itemId'], 'count': rewardInfo['count']})
            rewardId = RewardAsyncHelper.genRewardId()
            TGDizhu.getEventBus().publishEvent(UserRewardAsyncEvent(DIZHU_GAMEID, userId, REWARD_ASYNC_TYPE_AS_WINSTREAK, rewardId, rewards, winStreak=currentWinStreak))

    return {
        'tableRewards': DizhuSegmentRewardsHelper.processUserTableRewards(userId, winloseObj),
        'segmentInfo': segmentInfo,
        'recoverConsume': recoverConsume,
        'treasureChest': winStreakChestConf,
        'winStreakRewards': {
            'winStreak': currentWinStreak,
            'winStreakReward': winStreakRewards,
            'rewardId': rewardId
        }
    }