Esempio n. 1
0
def calcUserScore(userId, rankingDefine, playCount, chipDelta, winStreak,
                  vipLevel):
    '''
    根据参数计算积分
    '''
    score = chipDelta * rankingDefine.exchangeRate
    if playCount >= rankingDefine.playCounts:
        score *= rankingDefine.playCountsDecayRate

    # 月卡加成
    monthCardPlus = 0
    if rankingDefine.monthCardItem and UserBag.isHaveAssets(
            userId, rankingDefine.monthCardItem) and chipDelta > 0:
        monthCardPlus = rankingDefine.monthCardPlus

    # 荣耀月卡加成
    honorCardPlus = 0
    if rankingDefine.honorCardItem and UserBag.isHaveAssets(
            userId, rankingDefine.honorCardItem) and chipDelta > 0:
        honorCardPlus = rankingDefine.honorCardPlus

    if chipDelta > 0:
        winsPlusRate = rankingDefine.winsPlusRate if winStreak > 1 else 0
        vipPlusRate = rankingDefine.findVipPlusRate(vipLevel)
        score *= (1 + vipPlusRate + winsPlusRate + monthCardPlus +
                  honorCardPlus)
    return int(round(score))
Esempio n. 2
0
 def checkCondition(self, userId, charged_rmb):
     ftlog.debug('GiftboxEntry.checkCondition:begin',
                 'userId=', userId,
                 'charged_rmb=', charged_rmb,
                 'itemId=', self._itemId)
     if not UserBag.isHaveAssets(userId, self._itemId, DIZHU_GAMEID):
         ftlog.debug('GiftboxEntry.checkCondition:',
                     'userId=', userId, 
                     'item not found')
         return False
     if charged_rmb < self._rmb:
         ftlog.debug('GiftboxEntry.checkCondition:',
                     'userId=', userId, 
                     'charged_rmb < rmblimit')
         return False 
     return True
Esempio n. 3
0
def fillScoreRankListInfo(roomId, userId, delta):
    conf = getConf()
    if not conf or conf.closed:
        return None

    bigRoomId = gdata.getBigRoomId(roomId)
    rankConf = conf.rankDefineForRoomId(bigRoomId)
    if not rankConf:
        return None

    clientVer = SessionDizhuVersion.getVersionNumber(userId)
    if clientVer < conf.minVer or rankConf.switch != 1:
        return None

    if rankConf.isOutOfTime():
        return {"open": 0, "info": rankConf.tips}

    issueNum = calcIssueNum()
    userData = loadOrCreateUserData(userId, rankConf.rankId, issueNum)

    # vip积分加成
    vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel
    vipScoreUp = rankConf.findVipPlusRate(int(
        vipLevel.level)) if delta > 0 else 0

    # 连胜加成
    winStreak = gamedata.getGameAttrInt(userId, DIZHU_GAMEID, 'winstreak')
    winsPlus = rankConf.winsPlusRate if winStreak > 1 else 0

    # 月卡加成
    monthCardPlus = 0
    if rankConf.monthCardItem and UserBag.isHaveAssets(
            userId, rankConf.monthCardItem) and delta > 0:
        monthCardPlus = rankConf.monthCardPlus

    # 荣耀月卡加成
    honorCardPlus = 0
    if rankConf.honorCardItem and UserBag.isHaveAssets(
            userId, rankConf.honorCardItem) and delta > 0:
        honorCardPlus = rankConf.honorCardPlus

    # 金币转换积分的比例
    exchangeRate = rankConf.exchangeRate
    # 胜场积分缩减 后台结算后胜场加1,前端结算积分后胜场已加1,前端展示时取未加1的显示
    decayRate = 1
    todayPlayCount = userData.todayPlayCount - 1 if userData.todayPlayCount > 0 else 0
    if rankConf.playCounts and rankConf.playCountsDecayRate:
        decayRate = rankConf.playCountsDecayRate if todayPlayCount >= rankConf.playCounts else 1

    # 积分结果四舍五入
    scoreUp = (1 + vipScoreUp + winsPlus + monthCardPlus +
               honorCardPlus) if delta > 0 else 1
    score = int(round(delta * decayRate * exchangeRate * scoreUp))

    rate = [{
        "key": "VIP",
        "value": vipScoreUp
    }, {
        "key": "月卡",
        "value": monthCardPlus
    }, {
        "key": "连胜",
        "value": winsPlus
    }, {
        "key": "荣耀月卡",
        "value": honorCardPlus
    }]
    d = {
        "open": 1,
        "rankId": rankConf.rankId,
        "delta": score,
        "rate": rate,
        "info": rankConf.tips
    }

    if ftlog.is_debug():
        ftlog.debug('fillScoreRankListInfo roomId=', roomId, 'rankId=',
                    rankConf.rankId, 'exchangeRate=', exchangeRate,
                    'todayPlayCountDecayRate=', decayRate, 'honorCardPlus=',
                    honorCardPlus, 'sst.delta=', delta, 'global.winStreak=',
                    winStreak, 'todayPlayCount=', userData.todayPlayCount,
                    'rate=', rate, 'd=', d)
    return d