def sendBenefits(self, gameId, userId, timestamp=None): ''' 发放救济金 @return: isSend(True/False), TYUserBenefits ''' if timestamp is None: timestamp = pktimestamp.getCurrentTimestamp() chip = pkuserchip.getUserChipAll(userId) if chip < self._minChip: # 用户金币低于指定数目时,发放救济金 userBenefits = self.loadUserBenefits(gameId, userId, timestamp) if not userBenefits.hasLeftTimes(): # 没有剩余次数,弹分享引导 oldtime = gamedata.getGameAttr(userId, HALL_GAMEID, 'relief_share_date') if not oldtime or datetime.fromtimestamp(oldtime).date() < datetime.fromtimestamp(timestamp).date(): # 每天最多弹一次 gamedata.setGameAttr(userId, HALL_GAMEID, 'relief_share_date', timestamp) shareId = hallshare.getShareId('Relieffund', userId, gameId) share = hallshare.findShare(shareId) if share: task = share.buildTodotask(gameId, userId, 'Relieffund') TodoTaskHelper.sendTodoTask(gameId, userId, task) return False, userBenefits # 发放救济金 userBenefits.times += 1 self._benefitsDao.saveUserBenefitsData(userId, TYUserBenefitsData(userBenefits.times, timestamp)) self._sendBenefits(gameId, userBenefits) # 通知用户金币刷新 datachangenotify.sendDataChangeNotify(gameId, userId, ['udata']) return True, userBenefits return False, self.loadUserBenefits(gameId, userId, timestamp)
def vipAutoSupplyPerDay(userId): """ vip每日自动补足 """ vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0) key = GameData.autoSupplyKey % config.CHIP_KINDID autoSupplyCount = config.getVipConf(vipLevel).get(key, 0) chips = userchip.getUserChipAll(userId) if autoSupplyCount >= 10000 and chips < autoSupplyCount and weakdata.getDayFishData( userId, key, 0) == 0: weakdata.incrDayFishData(userId, key, 1) lang = util.getLanguage(userId) rewards = [{ "name": config.CHIP_KINDID, "count": (autoSupplyCount - chips) }] message = config.getMultiLangTextConf( "ID_VIP_AUTO_SUPPLY_PER_DAY", lang=lang) % (autoSupplyCount / 10000) mail_system.sendSystemMail(userId, mail_system.MailRewardType.SystemReward, rewards, message) if ftlog.is_debug(): ftlog.debug("vipAutoSupplyPerDay", userId, vipLevel, autoSupplyCount, chips, key, autoSupplyCount - chips)
def gainAssistance(self, gameId, userId): ''' 领取江湖救急 @param gameId: gameId @param userId: userId @return: consumeCount, finalCount, sendChip ''' # 检查金币数量是否符合领取江湖救急的条件 userAllChip = pkuserchip.getUserChipAll(userId) assistanceChipUpperLimit = self._vipSystem.getAssistanceChipUpperLimit() if userAllChip >= assistanceChipUpperLimit: raise TYAssistanceChipTooMuchException(userAllChip, assistanceChipUpperLimit) timestamp = pktimestamp.getCurrentTimestamp() # 发放江湖救急金 userAssets = hallitem.itemSystem.loadUserAssets(userId) _assetKind, consumeCount, final = userAssets.consumeAsset(gameId, 'game:assistance', 1, timestamp, 'VIP_GOT_ASSISTANCE', 0) assistanceChip = self._vipSystem.getAssistanceChip() if consumeCount >= 1 and assistanceChip > 0: pkuserchip.incrChip(userId, gameId, assistanceChip, pkdaoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'VIP_GOT_ASSISTANCE', 0, 0) ftlog.debug('TYUserVipSystemImpl.gainAssistance gameId=', gameId, 'userId=', userId, 'consumeCount=', consumeCount, 'assistanceChip=', assistanceChip) return consumeCount, final, assistanceChip
def gainAssistance(self, gameId, userId): ''' 领取江湖救急 @param gameId: gameId @param userId: userId @return: consumeCount, finalCount, sendChip ''' # 检查金币数量是否符合领取江湖救急的条件 userAllChip = pkuserchip.getUserChipAll(userId) assistanceChipUpperLimit = self._vipSystem.getAssistanceChipUpperLimit( ) if userAllChip >= assistanceChipUpperLimit: raise TYAssistanceChipTooMuchException(userAllChip, assistanceChipUpperLimit) timestamp = pktimestamp.getCurrentTimestamp() # 发放江湖救急金 userAssets = hallitem.itemSystem.loadUserAssets(userId) _assetKind, consumeCount, final = userAssets.consumeAsset( gameId, 'game:assistance', 1, timestamp, 'VIP_GOT_ASSISTANCE', 0) assistanceChip = self._vipSystem.getAssistanceChip() if consumeCount >= 1 and assistanceChip > 0: pkuserchip.incrChip(userId, gameId, assistanceChip, pkdaoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 'VIP_GOT_ASSISTANCE', 0, 0) ftlog.debug('TYUserVipSystemImpl.gainAssistance gameId=', gameId, 'userId=', userId, 'consumeCount=', consumeCount, 'assistanceChip=', assistanceChip) return consumeCount, final, assistanceChip
def queryDailyFreeGive(userId, gameId): ''' :desc: 查询每日低保赠送 :param :return: { "dailyFreeGiveCountConf": dailyFreeGiveCountConf , "dailyFreeGiveAmountConf": dailyFreeGiveAmountConf , "dailyFreeGiveLimitConf": dailyFreeGiveLimitConf , "freeGiveCountLeft": freeGiveCountLeft } ''' retParam = { "dailyFreeGiveCountConf": 0, "dailyFreeGiveAmountConf": 0, "dailyFreeGiveLimitConf": 0, "freeGiveCountLeft": 0, "canRecieveFreeGive": 0 } debug('queryDailyFreeGive, userId =', userId, 'gameId =', gameId) try: dailyFreeGiveCountConf, dailyFreeGiveAmountConf, dailyFreeGiveLimitConf = getDailyFreeGiveConfig( ) if dailyFreeGiveCountConf <= 0 or dailyFreeGiveAmountConf <= 0 or dailyFreeGiveLimitConf <= 0: debug('daily free give not configured') return retParam retParam["dailyFreeGiveCountConf"] = dailyFreeGiveCountConf retParam["dailyFreeGiveAmountConf"] = dailyFreeGiveAmountConf retParam["dailyFreeGiveLimitConf"] = dailyFreeGiveLimitConf # 检查今天低保送豆的资格是否已经用完 lastFreeGiveTime, freeGiveCountLeft = loadDailyFreeGiveStatus(userId) if lastFreeGiveTime < pktimestamp.getDayStartTimestamp(): freeGiveCountLeft = dailyFreeGiveCountConf if freeGiveCountLeft <= 0: debug('free give count <= 0, userId =', userId, 'freeGiveCountLeft =', freeGiveCountLeft) return retParam retParam["freeGiveCountLeft"] = freeGiveCountLeft # 检查玩家的chip是否低于赠送下限 chip = userchip.getUserChipAll(userId) if chip >= dailyFreeGiveLimitConf: debug('user chip bigger then min, userChip =', chip, 'minChip =', dailyFreeGiveLimitConf) return retParam retParam["canRecieveFreeGive"] = 1 debug('can give user free chip, userId =', userId, 'gameId =', gameId, 'lastFreeGiveTime =', lastFreeGiveTime, 'freeGiveCountLeft =', freeGiveCountLeft) return retParam except Exception as e: ftlog.error(e)
def needSendBenefits(self, gameId, userId, timestamp=None): ''' 检查是否需要给用户发救济金 @return: True/False ''' if timestamp is None: timestamp = pktimestamp.getCurrentTimestamp() chip = pkuserchip.getUserChipAll(userId) userBenefits = self.loadUserBenefits(gameId, userId, timestamp) return userBenefits.hasLeftTimes() and chip < userBenefits.minChip
def v2DataTov3Data(userId, clientId): """ v2版本用户属性继承到v3版本 """ # 金币数量调整 totalChip = userchip.getUserChipAll(userId) incrChip = totalChip * 10 - totalChip userchip.incrChip(userId, FISH_GAMEID, incrChip, 0, "BI_NFISH_NEW_USER_REWARDS", 0, clientId) # 处理宝藏相关数据 from newfish.entity import treasure_system treasureList = config.getV2ToV3Conf("treasure") userAssets = hallitem.itemSystem.loadUserAssets(userId) for _, treasureConf in enumerate(treasureList): old_kindId = treasureConf["old_kindId"] new_kindId = treasureConf.get("new_kindId") ratio = treasureConf.get("ratio", 0) convert_kindId = treasureConf.get("convert_kindId") convert_num = treasureConf.get("convert_num", 999999) surplusCount = util.balanceItem(userId, old_kindId, userAssets) if surplusCount > 0: if new_kindId: treasureData = treasure_system.getTreasure(userId, new_kindId) if treasureData[treasure_system.INDEX_LEVEL] == 0: treasureData[treasure_system.INDEX_LEVEL] = 1 treasure_system.setTreasure(userId, new_kindId, treasureData) if convert_kindId: convertNum = min(surplusCount, convert_num) convertNum = int(math.ceil(convertNum * ratio)) rewards = [{"name": convert_kindId, "count": convertNum}] util.addRewards(userId, rewards, "BI_NFISH_NEW_USER_REWARDS", old_kindId, surplusCount) consumeItems = [{"name": old_kindId, "count": surplusCount}] util.consumeItems(userId, consumeItems, "BI_NFISH_NEW_USER_REWARDS") # 处理技能相关数据 skillList = config.getV2ToV3Conf("skill") userAssets = hallitem.itemSystem.loadUserAssets(userId) for _, skillConf in enumerate(skillList): old_kindId = skillConf["old_kindId"] ratio = skillConf.get("ratio", 0) convert_kindId = skillConf.get("convert_kindId") surplusCount = util.balanceItem(userId, old_kindId, userAssets) if surplusCount > 0: if convert_kindId: convertNum = int(math.ceil(surplusCount * ratio)) rewards = [{"name": convert_kindId, "count": convertNum}] util.addRewards(userId, rewards, "BI_NFISH_NEW_USER_REWARDS", old_kindId, surplusCount) consumeItems = [{"name": old_kindId, "count": surplusCount}] util.consumeItems(userId, consumeItems, "BI_NFISH_NEW_USER_REWARDS")
def needSendBenefits(self, gameId, userId, timestamp=None): ''' 检查是否需要给用户发救济金 @return: True/False ''' if self._checkInNotSendGameIds(userId): return False if timestamp is None: timestamp = pktimestamp.getCurrentTimestamp() chip = pkuserchip.getUserChipAll(userId) userBenefits = self.loadUserBenefits(gameId, userId, timestamp) return userBenefits.hasLeftTimes() and chip < userBenefits.minChip
def addUserVipExp(gameId, userId, toAddExp, eventId, intEventParam, productId, rmbs=-1, isAddVipExp=True): """ 增加VIP经验值 """ rmbs = int(rmbs) if rmbs == -1 and toAddExp >= 10: rmbs = toAddExp / 10 if isAddVipExp: hallvip.userVipSystem.addUserVipExp(gameId, userId, toAddExp, eventId, intEventParam) else: # 自己处理vip升级事件. from hall.game import TGHall from hall.entity.hallvip import TYUserVipLevelUpEvent vipExp = hallvip.userVipSystem.getUserVip(userId).vipExp oldVipLevel = hallvip.vipSystem.findVipLevelByVipExp(vipExp - toAddExp) userVip = hallvip.userVipSystem.getUserVip(userId) if oldVipLevel.level != userVip.vipLevel.level: lv_event = TYUserVipLevelUpEvent(FISH_GAMEID, userId, oldVipLevel, userVip, [], 0, 0) TGHall.getEventBus().publishEvent(lv_event) # vip经验发生变化. from newfish.game import TGFish event = UserVipExpChangeEvent(userId, gameId, toAddExp) TGFish.getEventBus().publishEvent(event) if ftlog.is_debug(): ftlog.debug("addUserVipExp----->event", gameId, userId, toAddExp, eventId, intEventParam, rmbs, isAddVipExp) # 上报购买商品事件. loginDays = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.loginDays) userLevel = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.level) isIn, roomId, tableId, _ = util.isInFishTable(userId) if isIn: from newfish.servers.table.rpc import table_remote table_remote.buyProduct(roomId, tableId, userId, intEventParam, userLevel, loginDays) else: from poker.entity.biz import bireport userChip = userchip.getUserChipAll(userId) bireport.reportGameEvent("BI_NFISH_BUY_PRODUCT", userId, FISH_GAMEID, roomId, intEventParam, userLevel, 0, 0, 0, [], util.getClientId(userId), loginDays, userChip) # ftlog.debug("BI_NFISH_BUY_PRODUCT", userId, roomId, intEventParam, userLevel, util.getClientId(userId), userChip) updateUserDataByRecharge(userId, productId, rmbs)
def sendBenefits(self, gameId, userId, timestamp=None): ''' 发放救济金 @return: isSend(True/False), TYUserBenefits ''' if timestamp is None: timestamp = pktimestamp.getCurrentTimestamp() if self._checkInNotSendGameIds(userId): return False, self.loadUserBenefits(gameId, userId, timestamp) chip = pkuserchip.getUserChipAll(userId) if chip < self._minChip: #添加关于版本控制的部分,当版本高于4.01且不是VIP玩家时不发送救济金 from poker.util import strutil #避免其他游戏修改调用接口,用过session来获取clientID from poker.entity.dao import sessiondata clientId = sessiondata.getClientId(userId) _, clientVer, _ = strutil.parseClientId(clientId) userVipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level if clientVer >= client_ver_judge.client_ver_451 and userVipLevel == 0: return False, self.loadUserBenefits(gameId, userId, timestamp) # 用户金币低于指定数目时,发放救济金 userBenefits = self.loadUserBenefits(gameId, userId, timestamp) if not userBenefits.hasLeftTimes(): # 没有剩余次数,弹分享引导 # oldtime = gamedata.getGameAttr(userId, HALL_GAMEID, 'relief_share_date') # if not oldtime or datetime.fromtimestamp(oldtime).date() < datetime.fromtimestamp(timestamp).date(): # # 每天最多弹一次 # gamedata.setGameAttr(userId, HALL_GAMEID, 'relief_share_date', timestamp) # shareId = hallshare.getShareId('Relieffund', userId, gameId) # share = hallshare.findShare(shareId) # if share: # task = share.buildTodotask(gameId, userId, 'Relieffund') # TodoTaskHelper.sendTodoTask(gameId, userId, task) return False, userBenefits # 发放救济金 userBenefits.times += 1 self._benefitsDao.saveUserBenefitsData(userId, TYUserBenefitsData(userBenefits.times, timestamp)) self._sendBenefits(gameId, userBenefits) # 通知用户金币刷新 datachangenotify.sendDataChangeNotify(gameId, userId, ['udata']) return True, userBenefits return False, self.loadUserBenefits(gameId, userId, timestamp)
def findRewardUsers(gameId, issue, reward, clientId): x = random.randint(1, hallroulette.soldierSysTem.getSoldierNumber()) soldier = hallroulette.soldierSysTem.getSoldierforsId(x) count = 3 while (count): if soldier: break x = random.randint(1, hallroulette.soldierSysTem.getSoldierNumber()) soldier = hallroulette.soldierSysTem.getSoldierforsId(x) count -= 1 ftlog.info('findRewardUsers.gameId=', gameId, 'issue=', issue, 'reward=', reward, 'clientId=', clientId, 'x=', x, 'soldier=', soldier) if not soldier: ftlog.info('findRewardUsers.gameId=', gameId, 'issue=', issue, 'reward=', reward, 'errorMessage=', 'not find the soldier user!') return 0, 0 nowUserId = soldier.get('userId', 0) chip = pkuserchip.getUserChipAll(nowUserId) vip = hallvip.userVipSystem.getUserVip(nowUserId).vipLevel.level userInfo = halluser.getUserInfo(nowUserId, gameId, clientId) result = {} result['chip'] = chip result['vip'] = vip result['sex'] = userInfo.get('sex', 0) result['purl'] = userInfo.get('purl', '') result['sId'] = '%07d' % x result['uId'] = nowUserId result['issue'] = issue result['name'] = userInfo.get('name', '') result['nowReward'] = reward nowRewardNumber = pkgamedata.incrGameAttr(nowUserId, 9999, 'getRewardNumber', 1) result['getRewardNumber'] = nowRewardNumber result['isCheckin'] = 0 result['checkinSoldiers'] = pkgamedata.getGameAttrInt( nowUserId, 9999, 'checkinSoldiers') ftlog.info('findRewardUsers.gameId=', gameId, 'nowUserId=', nowUserId, 'result=', result) return nowUserId, result
def getGameInfo(userId, clientId): ftlog.debug('dizhu.getGameInfo->', userId, clientId) ukeys = getInitDataKeys() uvals = gamedata.getGameAttrs(userId, DIZHU_GAMEID, ukeys) uvals = list(uvals) values = getInitDataValues() for x in xrange(len(uvals)): if uvals[x] == None: uvals[x] = values[x] gdata = dict(zip(ukeys, uvals)) level = gdata['level'] gdata['nextexp'] = getGameUserNextExp(level) gdata['title'] = getGameUserTitle(level) gdata['referrerSwitch'] = dizhuconf.getReferrerSwitch() gdata['canSetReferrer'] = getCanSetReferrer(userId) gdata['skillScoreInfo'] = skillscore.score_info(userId) gdata['charm'] = userdata.getCharm(userId) gdata['chip'] = userchip.getUserChipAll(userId) gdata['dashifen'] = getDaShiFen(userId, clientId) ftlog.debug('dizhu.getGameInfo->', userId, clientId, gdata) return gdata
def processOnLineTcpChangedEvent(evt): userId = evt.userId isOnline = evt.isOnline # 设置在线状态和在线用户集合列表, 离线时,所有通过setGameOnline设置的该用户数据均已经被删除 onlinedata.setOnlineState(userId, isOnline) if not isOnline: ctfull = timestamp.formatTimeMs() gamedata.setGameAttr(userId, HALL_GAMEID, 'offlineTime', ctfull) return # 计算其他的数据在线分组 # 分金币数量级别列表 — 德州等LED引导 richchip = hallconf.getHallPublic().get('online_rich_limit', 100000) if richchip > 0: chip = userchip.getUserChipAll(userId) if chip > richchip: onlinedata.setGameOnline(userId, HALL_GAMEID, 'rich_online_users') # 分版本 # 分等级(可能是大师分,或经验值) # 新老用户(是否第一天注册) # 有没有玩过某些游戏 # 是否有道具 # 是否充值 # 是否满足比赛报名条件 pass
def canQuickEnterRoom(cls, userId, gameId, roomId, kindId): """ 判断能否进入房间 """ try: if util.isFinishAllNewbieTask(userId): newbieRoomId = config.getCommonValueByKey("newbieRoomId") if gdata.getBigRoomId(roomId) == gdata.getBigRoomId( newbieRoomId): return cls.ENTER_ROOM_REASON_INNER_ERROR else: newbieRoomId = config.getCommonValueByKey("newbieRoomId") if gdata.getBigRoomId(roomId) != gdata.getBigRoomId( newbieRoomId): return cls.ENTER_ROOM_REASON_INNER_ERROR gameMode = util.getRoomGameMode(roomId) isOldPlayerV2 = util.isOldPlayerV2(userId) if gameMode == config.CLASSIC_MODE and not isOldPlayerV2: return cls.ENTER_ROOM_REASON_INNER_ERROR uLevel = util.getUserLevel(userId) gunLevel = util.getGunLevel(userId, gameMode) if not uLevel or not gunLevel: return cls.ENTER_ROOM_REASON_INNER_ERROR gunLevelVal = config.getGunLevelConf(gunLevel, gameMode).get( "levelValue", 1) userChip = userchip.getUserChipAll(userId) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level if ftlog.is_debug(): ftlog.debug("canQuickEnterRoom->", gdata.roomIdDefineMap()[roomId].configure) roomConf = gdata.roomIdDefineMap()[roomId].configure fee = roomConf.get("fee_%s" % kindId, {}) or roomConf.get( "fee", {}) minLevel = roomConf.get("minLevel", 1) minGunLevelVal = roomConf.get("minGunLevelVal", 1) minCoin = roomConf.get("minCoin", 1) minVip = roomConf.get("minVip", 0) timeLimit = roomConf.get("timeLimit", []) bulletLimit = roomConf.get("bulletLimit", {}) protectionLimit = roomConf.get("protectionLimit", {}) if fee: surplusCount = util.balanceItem(userId, fee["kindId"]) if surplusCount < fee["count"]: return cls.ENTER_ROOM_REASON_LESS_FEES if bulletLimit and not kindId: isCan = False for kindId in bulletLimit: surplusCount = util.balanceItem(userId, kindId) if surplusCount >= bulletLimit[kindId]: isCan = True break if not isCan: return cls.ENTER_ROOM_REASON_LESS_BULLET if timeLimit: isCan = False currentTime = int(time.time()) for timeRange in timeLimit: startTime = util.getTodayTimestampFromStr(timeRange[0]) endTime = util.getTodayTimestampFromStr(timeRange[1]) if startTime <= currentTime <= endTime: isCan = True break if not isCan: return cls.ENTER_ROOM_REASON_TIME_LIMIT if uLevel < minLevel and not kindId: if roomConf.get("typeName") == config.FISH_ROBBERY: if vipLevel >= minVip: return cls.ENTER_ROOM_REASON_OK return cls.ENTER_ROOM_REASON_LESS_LEVEL if gunLevelVal < minGunLevelVal: return cls.ENTER_ROOM_REASON_LESS_LEVEL if userChip < minCoin: return cls.ENTER_ROOM_REASON_LESS_COIN if protectionLimit: dailyProfitCoin, monthlyProfitCoin = 0, 0 if roomConf.get("typeName") == config.FISH_ROBBERY: dailyProfitCoin, monthlyProfitCoin = util.getRobberyProfitCoin( userId) elif roomConf.get("typeName") == config.FISH_POSEIDON: dailyProfitCoin, monthlyProfitCoin = util.getPoseidonProfitCoin( userId) if (dailyProfitCoin <= protectionLimit["dailyLoss"] or monthlyProfitCoin <= protectionLimit["monthlyLoss"]): return cls.ENTER_ROOM_REASON_EXCESSIVE_LOSS # 检测大奖赛开放时间 if roomConf.get("typeName") in [config.FISH_GRAND_PRIX]: state = cls.grandPrixEnterRoom(userId) if state != cls.ENTER_ROOM_REASON_OK: return state return cls.ENTER_ROOM_REASON_OK except Exception as e: ftlog.error("canQuickEnterRoom error", userId, e) return cls.ENTER_ROOM_REASON_INNER_ERROR
def receiveDailyFreeGive(userId, gameId): ''' :desc: 领取每日低保赠送 :param :return: ''' debug('receiveDailyFreeGive, userId =', userId, 'gameId =', gameId) try: dailyFreeGiveCountConf, dailyFreeGiveAmountConf, dailyFreeGiveLimitConf = getDailyFreeGiveConfig( ) if dailyFreeGiveCountConf <= 0 or dailyFreeGiveAmountConf <= 0 or dailyFreeGiveLimitConf <= 0: debug('daily free give not configured') return None # 检查玩家的chip是否低于下限 chip = userchip.getUserChipAll(userId) if chip >= dailyFreeGiveLimitConf: debug('user chip bigger then min, userChip =', chip, 'minChip =', dailyFreeGiveLimitConf) return None # 检查今天低保送豆的资格是否已经用完 lastFreeGiveTime, freeGiveCountLeft = loadDailyFreeGiveStatus(userId) if lastFreeGiveTime < pktimestamp.getDayStartTimestamp(): freeGiveCountLeft = dailyFreeGiveCountConf if freeGiveCountLeft <= 0: debug('free give count <= 0, userId =', userId, 'freeGiveCountLeft =', freeGiveCountLeft) return None debug('can give user free chip, userId =', userId, 'gameId =', gameId, 'userChip =', userchip, 'lastFreeGiveTime =', lastFreeGiveTime, 'freeGiveCountLeft =', freeGiveCountLeft) # 更新资格 lastFreeGiveTime, freeGiveCountLeft = pktimestamp.getCurrentTimestamp( ), freeGiveCountLeft - 1 saveDailyFreeGiveStatus(userId, lastFreeGiveTime, freeGiveCountLeft) # 低保赠送 userAssets = hallitem.itemSystem.loadUserAssets(userId) assetKind, _addCount, _final = userAssets.addAsset( gameId, 'user:chip', dailyFreeGiveAmountConf, lastFreeGiveTime, 'SZMJ_DAILY_FREE_GIVE_REWARD', 0) debug('user receive daily free chip, userId =', userId, 'gameId =', gameId, 'addCount =', _addCount, 'final =', _final, 'lastFreeGiveTime =', lastFreeGiveTime, 'freeGiveCountLeft =', freeGiveCountLeft) changed = [] if assetKind.keyForChangeNotify: changed.append(assetKind.keyForChangeNotify) datachangenotify.sendDataChangeNotify(gameId, userId, changed) return assetKind, _addCount, _final, freeGiveCountLeft except Exception as e: ftlog.error(e)
def findRewardUsers(gameId, issue, reward): ''' 开奖: 从本期小兵中获取一个中奖的小兵,并且返回 修改 首先,判断是否有多余的小兵,对多余的小兵进行管理 ''' needNumber = getSnatchConf().get('needNumber', 0) nowNumber = getSoldierNumber() if needNumber > nowNumber: return 0, 0, {} # 中奖序号 x = random.randint(1, needNumber) # 本期小兵list soldiers = daobase.executeMixCmd('LRANGE', CURKEY, 0, needNumber - 1) if not soldiers: return 0, 0 # 移除本期小兵,留下下一期小兵 daobase.executeMixCmd('LTRIM', CURKEY, needNumber, -1) # 开奖的时候,对每一个参与人的夺宝次数加1 uids = [] for soldier in soldiers: if soldier not in uids: pkgamedata.incrGameAttr(soldier, HALL_GAMEID, 'checkinSoldiers', 1) uids.append(soldier) # 生成中奖结果 nowUserId = soldiers[x] chip = pkuserchip.getUserChipAll(nowUserId) vip = hallvip.userVipSystem.getUserVip(nowUserId).vipLevel.level userInfo = halluser.getUserInfo(nowUserId, gameId, sessiondata.getClientId(nowUserId)) result = {} result['chip'] = chip result['vip'] = vip result['sex'] = userInfo.get('sex', 0) result['purl'] = userInfo.get('purl', '') result['sId'] = getSoldierIdByIndex(x) result['uId'] = nowUserId result['issue'] = issue result['name'] = userInfo.get('name', '') result['nowReward'] = reward # 添加夺宝次数 # 夺宝人的夺宝次数 nowRewardNumber = pkgamedata.incrGameAttr(nowUserId, HALL_GAMEID, 'getRewardNumber', 1) result['getRewardNumber'] = nowRewardNumber result['isCheckin'] = 0 # 添加夺宝人的夺宝次数 result['checkinSoldiers'] = pkgamedata.getGameAttrInt( nowUserId, HALL_GAMEID, 'checkinSoldiers') # 下发奖励的时候,全服广播,发led strLed = '恭喜' + userInfo.get( 'name', '') + '玩家在转盘夺宝活动中,斩获' + issue + '期' + reward + '大奖,不要再等了,你就是下一位夺宝王!' from hall.servers.util.rpc import user_remote as SendLed SendLed.sendHallLed(gameId, strLed, 1, 'hall') # 打印开奖日志 ftlog.hinfo('findRewardUsers.gameId=', gameId, 'issue=', issue, 'userId=', nowUserId, 'reward=', reward, 'soldiers=', soldiers, 'result=', result, 'x=', x, 'snatchConf=', getSnatchConf()) # 保存历史中奖信息 issueObj = {} issueObj['issue'] = issue issueObj['soldiers'] = soldiers issueObj['result'] = result issueObj['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # 保存本期中奖信息 daobase.executeMixCmd('HSET', HISKEYDETAIL + str(issue), 'info', json.dumps(issueObj)) daobase.executeMixCmd('LPUSH', HISKEY, issue) if daobase.executeMixCmd('LLEN', HISKEY) > 10: delIssue = daobase.executeMixCmd('RPOP', HISKEY) if ftlog.is_debug(): ftlog.debug('hallroulette.findRewardUsers delIssue:', delIssue) # 删除过期记录 if delIssue: daobase.executeMixCmd('DEL', HISKEYDETAIL + str(delIssue)) return nowUserId, result
def findRewardUsers(gameId, issue, reward): ''' 开奖: 从本期小兵中获取一个中奖的小兵,并且返回 修改 首先,判断是否有多余的小兵,对多余的小兵进行管理 ''' needNumber = getSnatchConf().get('needNumber', 0) nowNumber = getSoldierNumber() if needNumber > nowNumber: return 0, 0, {} # 中奖序号 x = random.randint(1, needNumber) # 本期小兵list soldiers = daobase.executeMixCmd('LRANGE', CURKEY, 0, needNumber - 1) if not soldiers: return 0, 0 # 移除本期小兵,留下下一期小兵 daobase.executeMixCmd('LTRIM', CURKEY, needNumber, -1) # 开奖的时候,对每一个参与人的夺宝次数加1 uids = [] for soldier in soldiers: if soldier not in uids: pkgamedata.incrGameAttr(soldier, HALL_GAMEID, 'checkinSoldiers', 1) uids.append(soldier) # 生成中奖结果 nowUserId = soldiers[x] chip = pkuserchip.getUserChipAll(nowUserId) vip = hallvip.userVipSystem.getUserVip(nowUserId).vipLevel.level userInfo = halluser.getUserInfo(nowUserId, gameId, sessiondata.getClientId(nowUserId)) result = {} result['chip'] = chip result['vip'] = vip result['sex'] = userInfo.get('sex', 0) result['purl'] = userInfo.get('purl', '') result['sId'] = getSoldierIdByIndex(x) result['uId'] = nowUserId result['issue'] = issue result['name'] = userInfo.get('name', '') result['nowReward'] = reward # 添加夺宝次数 # 夺宝人的夺宝次数 nowRewardNumber = pkgamedata.incrGameAttr(nowUserId, HALL_GAMEID, 'getRewardNumber', 1) result['getRewardNumber'] = nowRewardNumber result['isCheckin'] = 0 # 添加夺宝人的夺宝次数 result['checkinSoldiers'] = pkgamedata.getGameAttrInt(nowUserId, HALL_GAMEID, 'checkinSoldiers') # 下发奖励的时候,全服广播,发led strLed = '恭喜' + userInfo.get('name', '') + '玩家在转盘夺宝活动中,斩获' + issue + '期' + reward + '大奖,不要再等了,你就是下一位夺宝王!' from hall.servers.util.rpc import user_remote as SendLed SendLed.sendHallLed(gameId, strLed, 1, 'hall') # 打印开奖日志 ftlog.hinfo('findRewardUsers.gameId=', gameId, 'issue=', issue, 'userId=', nowUserId, 'reward=', reward, 'soldiers=', soldiers, 'result=', result, 'x=', x, 'snatchConf=', getSnatchConf()) # 保存历史中奖信息 issueObj = {} issueObj['issue'] = issue issueObj['soldiers'] = soldiers issueObj['result'] = result issueObj['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # 保存本期中奖信息 daobase.executeMixCmd('HSET', HISKEYDETAIL + str(issue), 'info', json.dumps(issueObj)) daobase.executeMixCmd('LPUSH', HISKEY, issue) if daobase.executeMixCmd('LLEN', HISKEY) > 10: delIssue = daobase.executeMixCmd('RPOP', HISKEY) if ftlog.is_debug(): ftlog.debug('hallroulette.findRewardUsers delIssue:', delIssue) # 删除过期记录 if delIssue: daobase.executeMixCmd('DEL', HISKEYDETAIL + str(delIssue)) return nowUserId, result
def userAllChip(self): if self._userAllChip is None: self._userAllChip = userchip.getUserChipAll(self.userId) return self._userAllChip