def getRewardInfo(cls, userId, scoreActivity): rewardInfo = scoreActivity.getUserRewardInfo( userId, scoreActivity.actId) if scoreActivity else None if ftlog.is_debug(): ftlog.debug('activityGetRewardInfo userId=', userId, 'rankId=', scoreActivity.actId, 'rewardInfo=', rewardInfo) luckyCardCount = UserBag.getAssetsCount(userId, 'item:4167') return {'rewardInfo': rewardInfo, 'luckyCardCount': luckyCardCount}
def _checkHasEnoughQuickSigninItem(self, userId, fee): # 检查参物品数量 from dizhu.activities.toolbox import UserBag quickSigninItem = UserBag.getAssetsCount(userId, fee.assetKindId) if ftlog.is_debug(): ftlog.debug('DizhuCtrlRoomArenaMatch._do_room__quicksignin_item', 'gameId=', self.gameId, 'userId=', userId, 'itemKind=', fee.assetKindId, 'itemCount=', fee.count, 'quickSigninItemRemaining=', quickSigninItem) if not quickSigninItem or quickSigninItem < fee.count: return 0 return 1
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
def buildFeesList(cls, userId, fees): ret = [] # 返回付费列表[{type,desc,selected,img},{...}] # 不用写单位的道具类型集合 notNeedUnit = set(['user:chip', 'user:exp', 'user:charm', 'ddz:master.score']); for fee in fees: assetKind = hallitem.itemSystem.findAssetKind(fee.assetKindId) if fee.count > 0 and assetKind: desc = '' if fee.assetKindId in notNeedUnit: desc = str(fee.count) + assetKind.displayName else: desc = str(fee.count) + assetKind.units + assetKind.displayName from dizhu.activities.toolbox import UserBag myCount = UserBag.getAssetsCount(userId, fee.assetKindId) ret.append({'type':fee.assetKindId, 'desc':desc, 'img':assetKind.pic, 'selected':False, 'fulfilled':1 if myCount >= fee.count else 0}) return ret
def checkAssetsEnough(cls, userId): ''' 检测抽奖需要的花费是否足够 ''' conf = getWarmupSystemConfig() consumeAssets = conf.get('expensesAssets', {}) requireItemId = consumeAssets.get('itemId') requireItemCount = consumeAssets.get('count', 0) if not requireItemId: return False userHaveAssetsCount = UserBag.getAssetsCount(userId, requireItemId) ftlog.debug('WarmUpSystemHelper.checkAssetsEnough', 'userId=', userId, 'consumeAssets=', consumeAssets, 'userHaveAssetsCount=', userHaveAssetsCount) return userHaveAssetsCount >= requireItemCount
def getFeesDiscount(userId, rooms): # 折扣报名比赛 取玩家背包中的物品确认是否有折扣 for room in rooms: matchCondition = room.get('matchCondition', {}) discountItems = matchCondition.get('discountItems') if discountItems: for item in discountItems: itemId = item.get('itemId') userHaveAssetsCount = UserBag.getAssetsCount(userId, itemId) if userHaveAssetsCount > 0: discount = item.get('discount', 1) desc = item.get('desc', "") room['signupFee']['desc'] = desc room['signupFee']['saledesc'] = item.get('oldPrice', "") room['signupFee']['sale'] = int(float(discount) * 10) room['entry'] = desc room['hasOtherDiscount'] = True break return rooms
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
def _onGameRoundFinish(self, userId, bigRoomId, isWin): isOpen = self.checkActivityActive(userId) if not isOpen: return roundConf = None for conf in self._scoreUpWay.get('roundAndWins', {}): if bigRoomId in conf.openRoomIds: roundConf = conf break if not roundConf: if ftlog.is_debug(): ftlog.debug('ActivityScoreRanking _onGameRoundFinish userId=', userId, 'bigRoomId=', bigRoomId, 'not in activity', 'conf=', self._scoreUpWay.get('roundAndWins', {})) return todayIssueNum = calcDailyIssueNum() totalIssueNum = self._issueNum scoreDelta = roundConf.scorePerRound if isWin: scoreDelta += roundConf.scorePerWin # 道具积分加成 if self._itemAddition.get('open'): rate = self.itemAddition.get('rate', 1) itemId = self.itemAddition.get('itemId') # 判断用户有没有道具 if itemId and rate and UserBag.getAssetsCount(userId, itemId): if ftlog.is_debug(): ftlog.debug( 'ActivityScoreRanking _onGameRoundFinish scoreAddition userId=', userId, 'roomId=', bigRoomId, 'winLose=', isWin, 'scoreDelta=', scoreDelta, 'additionScore=', int(round(scoreDelta * rate)), 'finalScoreDelta=', scoreDelta + int(round(scoreDelta * rate))) scoreDelta += int(round(scoreDelta * rate)) name, purl = userdata.getAttrs(userId, ['name', 'purl']) # 日榜 userData = loadOrCreateUserData(userId, self.actId, todayIssueNum) maxRoundScore = 0 if userData.roundScoreList: for index in range(len(userData.roundScoreList)): if bigRoomId in userData.roundScoreList[index].get( 'openRoomList'): maxRoundScore = userData.roundScoreList[index].get( 'score', 0) del userData.roundScoreList[index] break scoreDelta = min(scoreDelta, roundConf.maxScore - maxRoundScore) userData.score += scoreDelta maxRoundScore += scoreDelta userData.name = name userData.roundScoreList.append({ 'score': maxRoundScore, 'openRoomList': roundConf.openRoomIds }) if self._dibaoScore: if userData.score >= self._dibaoScore and userData.dibaoStu == RewardState.ST_NO_REWARD: userData.dibaoStu = RewardState.ST_HAS_REWARD if ftlog.is_debug(): ftlog.debug( 'ActivityScoreRanking _onGameRoundFinish userId=', userData.toDict()) saveUserData(userData) insertRankList(self.actId, todayIssueNum, userId, userData.score, self.rewardLimit) # 总榜 totalUserData = loadOrCreateUserData(userId, self.actId, totalIssueNum) totalUserData.score += scoreDelta totalUserData.name = name saveUserData(totalUserData) insertRankList(self.actId, totalIssueNum, userId, totalUserData.score, self.rewardLimit) if ftlog.is_debug(): ftlog.debug('ActivityScoreRanking _onGameRoundFinish userId=', userId, 'roomId=', bigRoomId, 'winLose=', isWin, 'scoreDelta=', scoreDelta)