def chooseReward(self, userId, matchId, rank):
    if ftlog.is_debug():
        ftlog.debug('MatchLottery userId=', userId, 'matchId=', matchId,
                    'rank=', rank)

    if not self.matchList:
        d = dizhuconf.getMatchLotteryConf()
        self.decodeFromDict(d)

    if not self.checkMatchRank(userId, matchId):
        ftlog.warn('MatchLottery.checkMatchRank failed. userId=', userId,
                   'matchId=', matchId, 'rank=', rank)
        return None, None

    items = self.getMatchLotteryConf(matchId, rank)
    if not items:
        ftlog.warn('MatchLottery.checkMatchRank failed. no items. userId=',
                   userId, 'matchId=', matchId, 'rank=', rank)
        return None, None

    weights = 0
    for item in items:
        weights += item.get('weight', 0)
    r = random.randint(0, weights)
    lotteryReward = []
    weightTotal = 0
    for item in items:
        weightTotal += item.get('weight', 0)
        if r <= weightTotal:
            lotteryReward.append({
                'itemId': str(item.get('itemId')),
                'count': item.get('count')
            })
            break
    lotteryReward = items[-1] if not lotteryReward else lotteryReward

    if ftlog.is_debug():
        ftlog.debug('MatchLottery weights=', weights, 'r=', r, 'userId=',
                    userId, 'lotteryReward=', lotteryReward)

    if lotteryReward:
        contentItems = TYContentItem.decodeList(lotteryReward)
        assetList = dizhu_util.sendRewardItems(userId, contentItems, '',
                                               'DIZHU_MATCH_LOTTERY', 0)

        ftlog.info('MatchLottery.chooseReward userId=', userId, 'matchId=',
                   matchId, 'lotteryReward=', lotteryReward, 'assetList=',
                   assetList)

    for i in items:
        assetKind = hallitem.itemSystem.findAssetKind(i['itemId'])
        i['img'] = assetKind.pic
        i['des'] = assetKind.desc
        i['name'] = assetKind.displayName

    if ftlog.is_debug():
        ftlog.debug('MatchLottery.chooseReward userId=', userId, 'matchId=',
                    matchId, 'rank=', rank, 'lotteryReward=', lotteryReward)

    return lotteryReward, items
Esempio n. 2
0
def returnSignInfFees(userId, roomId, fees):
    #获取用户报名券信息
    roomId = gdata.getBigRoomId(roomId)
    jstr = daobase.executeRePlayCmd('hget', 'match:discount:6', userId)
    match_discounts = strutil.loads(jstr) if jstr else []
    if match_discounts:
        for discount in match_discounts:
            itemId = discount.get('itemId', '')
            matchId = discount.get('matchId', '')
            if matchId == roomId:
                for fee in fees:
                    if fee['itemId'] == ASSET_DIAMOND_KIND_ID:
                        discounted = 10
                        lottery_conf = dizhuconf.getMatchLotteryConf()
                        discountItems = lottery_conf.get('discountItem')
                        for discountItem in discountItems:
                            if itemId == discountItem.get('itemId', ''):
                                discounted = discountItem.get('discount', 10)

                        fee['count'] = fee['count'] * discounted / 10
                        fees.append({'itemId':itemId, 'count':1})
                        delMatchLotteryInfo(userId, roomId)
                break
    ftlog.debug('returnSignInfFees userId=', userId, 'roomId=', roomId, 'fees=', fees, 'match_discounts=', match_discounts)
    return fees
Esempio n. 3
0
    def checkMatchRank(cls, userId, matchId, rank):
        matchId = gdata.getBigRoomId(matchId)
        lottery_conf = dizhuconf.getMatchLotteryConf()
        lottery_switch = lottery_conf.get('open')
        if not lottery_switch:
            return False

        # 钻石数量为0触发
        user_diamond = userdata.getAttrInt(userId, 'diamond')
        if user_diamond != 0:
            return False

        # 身上没有任何报名券 触发
        discount_conf = lottery_conf.get('discountItem', [])
        if not discount_conf:
            return False

        for discountItem in discount_conf:
            itemId = discountItem.get('itemId')
            userHaveAssetsCount = UserBag.getAssetsCount(userId, itemId)
            if userHaveAssetsCount != 0:
                return False

        match_conf = lottery_conf.get('matchList', {}).get(str(matchId), [])
        if not match_conf:
            return False
        for conf in match_conf:
            beginRank = conf['beginRank']
            endRank = conf['endRank']
            if beginRank <= rank <= endRank:
                if ftlog.is_debug():
                    ftlog.debug('checkMatchRank userId=', userId, 'matchId=', matchId, 'return True')
                return True

        # 若是客户端请求则需要验证排名信息
        # histories = MatchHistoryHandler.getMatchHistory(userId, recordId, 1, mixId)
        # for history in histories:
        #     recordRank = history.get('rank')
        #     if rank != recordRank:
        #         return False
        #     timestamp = history.get('timestamp')
        #     currtimestamp = pktimestamp.getCurrentTimestamp()
        #     if (currtimestamp - timestamp) > 300:
        #         return False

        if ftlog.is_debug():
            ftlog.debug('checkMatchRank userId=', userId, 'matchId=', matchId, 'return False')
        return False
Esempio n. 4
0
    def getMatchLotteryConf(self, roomId, rank):
        lottery_conf = dizhuconf.getMatchLotteryConf()
        self.decodeFromDict(lottery_conf)

        bigRoomId = gdata.getBigRoomId(roomId)
        discount_conf = lottery_conf.get('matchList')
        room_discount_conf = discount_conf.get(str(bigRoomId)) if discount_conf else None
        if room_discount_conf:
            for conf in room_discount_conf:
                beginRank = conf.get('beginRank')
                endRank = conf.get('endRank')
                items = conf.get('items')
                if beginRank <= rank <= endRank:
                    if ftlog.is_debug():
                        ftlog.debug('getMatchLotteryConf. roomId=', roomId, 'rank=', rank, 'items=', items,
                                    'room_discount_conf=', room_discount_conf)
                    return items
        return None
Esempio n. 5
0
def changeSignInFees(userId, matchId, fees):
    matchId = gdata.getBigRoomId(matchId)
    lottery_conf = dizhuconf.getMatchLotteryConf()
    discountItems = lottery_conf.get('discountItem')
    changedItemId = None
    ftlog.debug('changeSignInFees userId=', userId, 'matchId=', matchId, 'fees before=', fees)
    for discount in discountItems:
        discountList = discount.get('discountList', [])
        if matchId in discountList:
            itemId = discount.get('itemId', '')
            discountPoint = discount.get('discount', '')
            if UserBag.getAssetsCount(userId, itemId) > 0:
                for fee in fees:
                    if fee.get('itemId', '') == ASSET_DIAMOND_KIND_ID:
                        fee['count'] = int(discountPoint * fee['count'] /10)
                        saveMatchLotteryInfo(userId, [{'itemId':itemId, 'matchId':matchId}])
                        fees.append({'itemId':itemId, 'count':1})
                        changedItemId = fee.get('itemId', '')
                        break
                break
    ftlog.debug('changeSignInFees userId=', userId, 'fees=', fees)
    return fees, changedItemId