Пример #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 check(self, gameId, userId, clientId, timestamp, **kwargs):
     issue = SegmentMatchHelper.getCurrentIssue()
     if not issue:
         return False
     currentUserData = SegmentMatchHelper.getUserSegmentDataIssue(
         userId, issue)
     if not currentUserData:
         return False
     segment = currentUserData.segment
     if (self.startSegment == -1 or segment >= self.startSegment) and (
             self.endSegment == -1 or segment <= self.endSegment):
         return True
     return False
Пример #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 getSeasonReward(self, userId):
     # 检查当前已结束赛季并发放赛季奖励, 只发放上一期的
     latestTwoIssues = SegmentMatchHelper.getIssueStateList()[-2:]
     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:
             # 结算 发奖
             assetList, _ = settlementRanking(userId, issuestate['issue'])
             return [{
                 'itemId': atup[0].kindId,
                 'name': atup[0].displayName,
                 'url': atup[0].pic,
                 'count': atup[1]
             } for atup in assetList] if assetList else []
     return []
Пример #5
0
 def _get_segment_info(cls, userId, gameId, clientId, issue):
     segmentInfo = SegmentMatchHelper.getUserSegmentInfo(userId, issue)
     msg = MsgPack()
     msg.setCmd('dizhu')
     msg.setResult('action', 'segment_info')
     msg.setResult('gameId', gameId)
     msg.setResult('userId', userId)
     msg.setResult('clientId', clientId)
     msg.setResult('segmentInfo', segmentInfo)
     return msg
Пример #6
0
 def _get_segment_rules(cls, userId, gameId, clientId):
     rules = SegmentMatchHelper.getSegmentMatchRules()
     msg = MsgPack()
     msg.setCmd('dizhu')
     msg.setResult('action', 'segment_rules')
     msg.setResult('gameId', gameId)
     msg.setResult('userId', userId)
     msg.setResult('clientId', clientId)
     msg.setResult('rules', rules)
     return msg
Пример #7
0
def _processRecover(userId, burialId):
    userRecoverData = SegmentMatchHelper.getUserSegmentRecoverData(userId)
    leftCount = 0
    if userRecoverData.active:
        dataStr = loadUserBehaviorData(userId)
        if dataStr:
            userData = UserShareBehaviorData(userId).fromDict(
                json.loads(dataStr))
            userData.increaseBurialWatchCount(burialId)
            saveUserBehaviorData(userId, json.dumps(userData.toDict()))
            burialConf = getBurialConf(burialId)
            leftCount = userData.getBurialLeftCount(burialConf)

            userRecoverData.shareRecoverCount += 1
            SegmentMatchHelper.saveUserSegmentRecoverData(
                userId, userRecoverData)

            # 广播事件
            TGDizhu.getEventBus().publishEvent(
                SegmentRecoverEvent(userId, DIZHU_GAMEID))
    return leftCount
Пример #8
0
 def handleRequest(self, userId, clientId, action, msg):
     actId = self.actId
     ret = {}
     if action == self.ACTION_SEASON_INFO:
         ret = SegmentMatchHelper.getSegmentMatchRules()
     elif action == self.ACTION_SEASON_GET_REWARD:
         ret = self.getSeasonReward(userId)
     if ftlog.is_debug():
         ftlog.debug('ActivityWxSeasonInfo.handleRequest', 'userId=',
                     userId, 'action=', action, 'clientId=', clientId,
                     'actId=', actId, 'msg=', msg, 'ret=', ret)
     return ret
Пример #9
0
    def _get_segment_rank_list(cls, userId, gameId, clientId, start, stop, preIssue):
        rankList = []
        rank = -1
        issues = SegmentMatchHelper.getIssueStateList()
        if issues:
            if preIssue:
                if len(issues) > 1:
                    rankList, start, stop = SegmentMatchHelper.getSegmentRankList(issues[-2]['issue'], start, stop)
                    rank = SegmentMatchHelper.getUserRealRank(userId, issues[-2]['issue'])
                else:
                    pass
            else:
                rankList, start, stop = SegmentMatchHelper.getSegmentRankList(issues[-1]['issue'], start, stop)
                rank = SegmentMatchHelper.getUserRealRank(userId, issues[-1]['issue'])

        if ftlog.is_debug():
            ftlog.debug('SegmentMatchHandler._get_segment_rank_list',
                        'userId=', userId,
                        'gameId=', gameId,
                        'clientId=', clientId,
                        'start=', start,
                        'stop=', stop,
                        'preIssue=', preIssue,
                        'issues=', issues,
                        'rankList=', rankList)

        msg = MsgPack()
        msg.setCmd('dizhu')
        msg.setResult('action', 'segment_rank_list')
        msg.setResult('gameId', gameId)
        msg.setResult('userId', userId)
        msg.setResult('clientId', clientId)
        msg.setResult('rankList', rankList)
        msg.setResult('preIssue', preIssue)
        msg.setResult('rank', rank)
        msg.setResult('start', start)
        msg.setResult('stop', stop)
        return msg
Пример #10
0
def _isRecoverForShare(userId):
    try:
        d = configure.getGameJson(DIZHU_GAMEID, 'match.segment', {}, 0)
        shareInfo = d.get('segmentRecover', {}).get('share', {})
        if not shareInfo:
            return False
        maxCount = shareInfo.get('maxCount', 0)
        userRecoverData = SegmentMatchHelper.getUserSegmentRecoverData(userId)
        shareRecoverCount = userRecoverData.shareRecoverCount
        if shareRecoverCount < maxCount:
            return True
        return False
    except Exception:
        return False
Пример #11
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)
Пример #12
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
Пример #13
0
def get_user_segment(uid):
    issue = SegmentMatchHelper.getCurrentIssue()
    userSegmentIssue = SegmentMatchHelper.getUserSegmentDataIssue(uid, issue)
    if not userSegmentIssue:
        return 0
    return userSegmentIssue.segment
Пример #14
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
        }
    }
Пример #15
0
def doGetUserSegment(userId, **kwargs):
    userSegmentData = SegmentMatchHelper.getUserSegmentDataIssue(
        userId,
        SegmentMatchHelper.getCurrentIssue()) or UserSegmentDataIssue()
    return userSegmentData.segment, userSegmentData.currentStar