def _getLevelFundsRewardState(userId, clientId, idx, mode, lf_rewards=None, lf_funds=None): """ 获取玩家指定成长基金奖励领取状态 """ lf_rewards = lf_rewards or _getRewardsState(userId, mode) lf_funds = lf_funds or _getBoughtFunds(userId, mode) userLv = util.getGunLevelVal(userId, mode) rewardsState = [] fundsConf = config.getLevelFundsConf(clientId, mode) rewardsConf = fundsConf.get("rewards", {}) levelRewardsConf = rewardsConf.get(str(idx), []) hasTip = False for lvData in levelRewardsConf: lv = lvData["level"] rewardsData = lf_rewards.get(str(lv), [0, 0]) # 0表示未领取,1表示可领取,2表示已领取,数据库存档中只存储0和2两种状态. free_state = 1 if rewardsData[0] == 0 and lv <= userLv else rewardsData[0] funds_state = 1 if idx in lf_funds and rewardsData[1] == 0 and lv <= userLv else rewardsData[1] rewardsState.append({ "level": lv, "free_rewards": lvData["free_rewards"], "funds_rewards": lvData["funds_rewards"], "free_state": free_state, "funds_state": funds_state }) hasTip = hasTip or free_state == 1 or funds_state == 1 if ftlog.is_debug(): ftlog.debug("level_funds, userId =", userId, "idx =", idx, "lf_funds =", lf_funds, "lf_rewards =", lf_rewards, "userLv =", userLv, "hasTip =", hasTip, "rewardsState =", rewardsState, "mode =", mode) return hasTip, rewardsState
def doSendLevelGift(userId, clientId): """ 获取升级礼包数据 """ message = MsgPack() message.setCmd("levelGiftData") message.setResult("gameId", FISH_GAMEID) message.setResult("userId", userId) giftInfo = [] if not util.isVersionLimit(userId) and not util.isPurchaseLimit(userId) and util.isFinishAllNewbieTask(userId): levelGiftConf = config.getLevelGiftConf() gunLv = util.getGunLevelVal(userId, config.MULTIPLE_MODE) for giftId, giftConf in levelGiftConf.iteritems(): if _isBought(userId, giftId): continue if not (giftConf["minLevel"] <= gunLv <= giftConf["maxLevel"]): continue now = int(time.time()) timeout = giftConf["showTime"] * 60 data = weakdata.getDayFishData(userId, WeakData.LevelUpCountDownData, []) if not data: weakdata.setDayFishData(userId, WeakData.LevelUpCountDownData, json.dumps([giftId, now])) else: if data[0] == giftId: if timeout - (now - data[1]) > 0: timeout = timeout - (now - data[1]) else: timeout = 0 else: weakdata.setDayFishData(userId, WeakData.LevelUpCountDownData, json.dumps([giftId, now])) giftInfo.append(getGiftDetail(giftConf, util.getLanguage(userId, clientId), timeout)) message.setResult("giftInfo", giftInfo) router.sendToUser(message, userId) return giftInfo
def getTodayQuest(userId): """ 获取当日所有每日任务配置 """ activeLv = 0 groupIdList = config.getDailyQuestGroupOrder() gunLevel_m = util.getGunLevelVal(userId, config.MULTIPLE_MODE) todayQuest = {} dailyQuestConf = config.getDailyQuestConf() questInfo = getUserQuestInfoData(userId) if len(questInfo) == 0: key = _getUserDailyQuestGroupLvKey(userId) groupLvData = gamedata.getGameAttrJson(userId, FISH_GAMEID, key, {}) update = False for groupId in groupIdList: groupId = str(groupId) lvData = groupLvData.get(groupId, [1, 0, 0]) lv = lvData[0] if lvData[1] >= 2: lv += 1 taskId, _lv = getQuestTaskId(groupId, lv, gunLevel_m, userId) if _lv != lvData[0]: update = True groupLvData[groupId] = [_lv, 0, lvData[2]] if taskId: questInfo[str(taskId)] = [0, QuestTaskState.Normal] todayQuest[int(taskId)] = dailyQuestConf.get(str(taskId)) activeLv += dailyQuestConf.get(str(taskId)).get("activeLv", 0) setUserQuestInfoData(userId, questInfo) if update: gamedata.setGameAttr(userId, FISH_GAMEID, key, json.dumps(groupLvData)) else: questInfo = getUserQuestInfoData(userId) for taskId, _ in questInfo.iteritems(): taskId = int(taskId) _quest = dailyQuestConf.get(str(taskId)) if _quest: todayQuest[taskId] = _quest activeLv += _quest.get("activeLv", 0) activeLv = int(activeLv) old = activeLv activeLvList = sorted([int(key) for key in config.getDailyQuestRewardConf().keys()]) if activeLv <= activeLvList[0]: activeLv = activeLvList[0] elif activeLv >= activeLvList[-1]: activeLv = activeLvList[-1] else: for val in activeLvList: if old >= val: activeLv = val if ftlog.is_debug(): ftlog.debug("daily_quest, userId =", userId, "questInfo =", questInfo, "activeLv =", activeLv, old, activeLvList) return todayQuest, activeLv
def sendMinigameInfo(roomId, userId, mode): """ 发送小游戏信息 """ bigRoomId, _ = util.getBigRoomId(roomId) subkey = "%s_%d" % (bigRoomId, mode) mgType = config.getSuperBossCommonConf().get(str(subkey), {}).get("mgType", "") key = "%s_%d" % (mgType, mode) mo = MsgPack() mo.setCmd("superboss_minigame_info") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("roomId", roomId) mo.setResult("mode", mode) mo.setResult("type", mgType) data = {} if mgType in MINIGAME_TYPE_LIST: conf = config.getSuperBossMiniGameConf() superbossPlayedTimes = weakdata.getDayFishData(userId, WeakData.superbossMGPlayedTimes, {}) playedTimes = superbossPlayedTimes.get(key, 0) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level maxTimesList = conf.get("info", {}).get(key, {}).get("maxTimes", []) maxTimes = maxTimesList[vipLevel] if maxTimesList and len(maxTimesList) > vipLevel else 0 remainTimes = max(0, maxTimes - playedTimes) if maxTimes >= 0 else -1 currencyList = conf.get("info", {}).get(key, {}).get("currencyList", []) items = config.rwcopy(conf.get("game", {}).get(key, [])) gunLevelVal = util.getGunLevelVal(userId, config.MULTIPLE_MODE) lang = util.getLanguage(userId) itemsinfo = [] for item in items: if gunLevelVal >= item["level"]: item["des"] = config.getMultiLangTextConf(item["des"], lang=lang) if item["des"] else "" itemsinfo.append(item) if mgType == "box": for iteminfo in itemsinfo: rewards = iteminfo["rewards"] groupIdx = util.selectIdxByWeight([int(reward.keys()[0]) for reward in rewards]) iteminfo["rewards"] = rewards[groupIdx].values()[0] iteminfo["groupIdx"] = groupIdx mo.setResult("showItemsList", currencyList) data = {"remainTimes": remainTimes, "items": itemsinfo} else: ftlog.warn("minigame, type error, userId =", userId, "roomId =", roomId, "mode =", mode, "mgType =", mgType) mo.setResult("data", data) router.sendToUser(mo, userId) if ftlog.is_debug(): ftlog.debug("minigame, userId =", userId, "mode =", mode, "mo =", mo)
def _triggerLevelUpEvent(event): """ 炮台升级/升倍率事件弹出升级礼包 """ userId = event.userId clientId = util.getClientId(userId) mode = event.gameMode if mode != 1: return gunLv = util.getGunLevelVal(userId, mode) levelGiftConf = config.getLevelGiftConf() for giftId, giftConf in levelGiftConf.iteritems(): if not giftConf["minLevel"] <= gunLv <= giftConf["maxLevel"]: continue if not _isBought(userId, giftId): doSendLevelGift(userId, clientId) break
def _getFundsList(userId, clientId, mode): """ 获取玩家可以使用的成长基金索引列表 """ userLv = util.getGunLevelVal(userId, mode) fundsConf = config.getLevelFundsConf(clientId, mode) canBuyIdxs = fundsConf.get("canBuyIdx") funds = fundsConf.get("funds") lf_funds = _getBoughtFunds(userId, mode) userIdxs = {} for idx in lf_funds + canBuyIdxs: if len(funds) >= idx > 0: if mode == 1 and userLv < funds[idx - 1].get("showLevel", 0): continue _type = funds[idx - 1].get("type") if str(_type) not in userIdxs: userIdxs[str(_type)] = idx return sorted(userIdxs.values())
def _isUnlockGun(userId, gunConf, mode): from newfish.entity.honor import honor_system _isUnlocked = False vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level gunLevelVal = util.getGunLevelVal(userId, mode) if not gunConf: return _isUnlocked if gunConf.get("gunId") == 0: _isUnlocked = True elif gunConf.get("unlockType") == 0: _isUnlocked = True elif gunConf.get("unlockType") == 1 and vipLevel >= gunConf["unlockValue"]: _isUnlocked = True elif gunConf.get("unlockType") == 2 and gunConf[ "unlockValue"] in honor_system.getOwnedHonors(userId): _isUnlocked = True elif gunConf.get( "unlockType") == 3 and gunLevelVal >= gunConf["unlockValue"]: _isUnlocked = True return _isUnlocked
def isCanEquip(userId, gunId, mode): """ 皮肤炮是否可以装配(条件同解锁,但是只检测当前模式是否可以装备) """ clientId = util.getClientId(userId) gunConf = config.getGunConf(gunId, clientId, 1, mode) _isCanEquip = False if gunConf: from newfish.entity.honor import honor_system vipLevel = hallvip.userVipSystem.getVipInfo(userId).get("level", 0) gunLevelVal = util.getGunLevelVal(userId, mode) if gunId == 0: _isCanEquip = True elif gunConf["equipType"] == 0: _isCanEquip = True elif gunConf["equipType"] == 1 and vipLevel >= gunConf["equipValue"]: _isCanEquip = True elif gunConf["equipType"] == 2 and gunConf[ "equipValue"] in honor_system.getOwnedHonors(userId): _isCanEquip = True elif gunConf["equipType"] == 3 and gunLevelVal >= gunConf["equipValue"]: _isCanEquip = True return _isCanEquip
def isShow(userId, clientId, mode): """是否展示""" userLv = util.getGunLevelVal(userId, mode) fundsConf = config.getLevelFundsConf(clientId, mode) funds = fundsConf.get("funds", []) userIdxs = _getFundsList(userId, clientId, mode) lf_funds = _getBoughtFunds(userId, mode) lf_rewards = _getRewardsState(userId, mode) isAllTaken = False if set(userIdxs) == set(lf_funds): isAllTaken = True rewardsConf = fundsConf.get("rewards") for idx in userIdxs: if not isAllTaken: break rewardsData = rewardsConf.get(str(idx), []) for lvData in rewardsData: lv = lvData["level"] # 判断免费和基金奖励的领取状态是否都为2,即均为已领取状态. if userLv < lv or sum(lf_rewards.get(str(lv), [0, 0])) != 4: isAllTaken = False break return userLv, funds, userIdxs, lf_funds, lf_rewards, isAllTaken
def doBuyLevelGift(userId, clientId, buyType, productId, itemId=0): """ 购买升级礼包 """ levelGift = config.getLevelGiftConf() giftId = 0 for val in levelGift.values(): if val.get("productId") == productId: giftId = val["giftId"] break if giftId == 0: return levelGiftConf = levelGift.get(str(giftId), {}) commonRewards = [] if _isBought(userId, giftId): code = 1 elif buyType == config.BT_DIAMOND: price = levelGiftConf.get("discountPrice", 0) price, isSucc = store.getUseRebateItemPrice(userId, itemId, price, buyType, productId, clientId) code = 0 if price > 0: consumeCount = 0 if isSucc: # 用优惠券 store.autoConvertVoucherToDiamond(userId, price) consumeCount, final = userchip.incrDiamond(userId, FISH_GAMEID, -abs(price), 0, "BI_NFISH_BUY_LEVEL_GIFT_CONSUME", int(config.DIAMOND_KINDID), util.getClientId(userId), param01=productId) if not isSucc or abs(consumeCount) != price: code = 2 _sendBuyLevelGiftRet(userId, clientId, productId, code, commonRewards) return else: code = 4 else: code = 3 if code == 0: # 记录存档 boughtGift = gamedata.getGameAttrJson(userId, FISH_GAMEID, GameData.buyLevelGift, []) boughtGift.append(int(giftId)) gamedata.setGameAttr(userId, FISH_GAMEID, GameData.buyLevelGift, json.dumps(boughtGift)) # 升级炮倍率 gunLv = util.getGunLevelVal(userId, config.MULTIPLE_MODE) if gunLv < levelGiftConf["levelUp"]: gunLevel = gunLv for level in config.getGunLevelKeysConf(config.MULTIPLE_MODE): value = config.getGunLevelConf(level, config.MULTIPLE_MODE) if value["levelValue"] == levelGiftConf["levelUp"]: gunLevel = level break gamedata.setGameAttr(userId, FISH_GAMEID, GameData.gunLevel_m, gunLevel) from newfish.game import TGFish from newfish.entity.event import GunLevelUpEvent event = GunLevelUpEvent(userId, FISH_GAMEID, gamedata.getGameAttr(userId, FISH_GAMEID, GameData.level), gunLevel, config.MULTIPLE_MODE) TGFish.getEventBus().publishEvent(event) bireport.reportGameEvent("BI_NFISH_GE_LEVEL_UP", userId, FISH_GAMEID, 0, 0, 0, config.MULTIPLE_MODE, 0, 0, [gunLevel], util.getClientId(userId)) # 发奖励 rewards = levelGiftConf.get("rewards", []) # 资产/道具 code = util.addRewards(userId, rewards, "BI_NFISH_BUY_ITEM_GAIN", int(giftId), param01=int(giftId)) commonRewards.extend(rewards) _sendBuyLevelGiftRet(userId, clientId, productId, code, commonRewards) util.addProductBuyEvent(userId, productId, clientId)
def refreshDailyQuestGroupLv(userId): """ 刷新每日任务难度等级 """ gunLevel_m = util.getGunLevelVal(userId, config.MULTIPLE_MODE) curDayStartTs = util.getDayStartTimestamp(int(time.time())) initLv = getInitQuestLv(userId) dailyQuestConf = config.getDailyQuestConf() key = _getUserDailyQuestGroupLvKey(userId) groupLvData = gamedata.getGameAttrJson(userId, FISH_GAMEID, key, {}) questInfo = getUserQuestInfoData(userId) for taskId, state in questInfo.iteritems(): state = state[-1] if ftlog.is_debug(): ftlog.debug("daily_quest, userId =", userId, taskId, state, dailyQuestConf.get(str(taskId), {})) groupId = dailyQuestConf.get(str(taskId), {}).get("groupId", 0) if groupId: groupId = str(groupId) if groupId in groupLvData.keys(): # 玩家没有连续登陆, 清零难度经验进度 ts = 0 if len(groupLvData[groupId]) > 2: ts = groupLvData[groupId][2] dayStartTs = util.getDayStartTimestamp(ts) if dayStartTs + 86400 < curDayStartTs: groupLvData[groupId][1] = 0 if ftlog.is_debug(): ftlog.debug("daily_quest, userId =", userId, "groupId =", groupId, "reset exp !") else: if state >= QuestTaskState.Complete: # 完成任务增加难度经验 if groupLvData[groupId][1] < 2: groupLvData[groupId][1] += 1 if ftlog.is_debug(): ftlog.debug("daily_quest, userId =", userId, "groupId =", groupId, "increase exp !") else: # 未完成任务, 且前一天游戏时长超过20分钟则削减难度经验 _key = GameData.playGameTime % (FISH_GAMEID, userId, dayStartTs) playGameTime = daobase.executeUserCmd(userId, "GET", _key) or 0 if playGameTime >= 20: # 降级变更为1天不完成并且游戏时长大于20分钟就降级,即满足要求+1,不满足-2 if groupLvData[groupId][1] > -2 and groupLvData[groupId][0] > 1: groupLvData[groupId][1] -= 2 # 1 if ftlog.is_debug(): ftlog.debug("daily_quest, userId =", userId, "groupId =", groupId, "decrease exp !") # if groupLvData[groupId][1] >= 2: # groupLvData[groupId][0] += 1 # groupLvData[groupId][1] = 0 # ftlog.debug("daily_quest, userId =", userId, "groupId =", groupId, "increase lv !") if groupLvData[groupId][1] <= -2 and groupLvData[groupId][0] > 1: groupLvData[groupId][0] -= 1 groupLvData[groupId][1] = 0 if ftlog.is_debug(): ftlog.debug("daily_quest, userId =", userId, "groupId =", groupId, "decrease lv !") groupLvData[groupId][2] = curDayStartTs else: _, lv = getQuestTaskId(groupId, initLv, gunLevel_m, userId) groupLvData[groupId] = [lv, 0, curDayStartTs] # groupLvData[groupId][0] = min(10, max(1, groupLvData[groupId][0])) if len(groupLvData) == 0: groupIdList = config.getDailyQuestGroupOrder() for groupId in groupIdList: _, lv = getQuestTaskId(groupId, initLv, gunLevel_m, userId) groupLvData[groupId] = [lv, 0, curDayStartTs] else: for k in groupLvData.keys(): groupLvData[k][2] = curDayStartTs gamedata.setGameAttr(userId, FISH_GAMEID, key, json.dumps(groupLvData)) if ftlog.is_debug(): ftlog.debug("daily_quest, user ="******"groupLvData =", groupLvData)
def getLevelFundsRewards(userId, clientId, productId, level=0, rewardType=0): """ 领取基金奖励 """ code = 0 rewards = [] rewardsState = [] isQuickGet = (level == 0) # 根据商品Id确定游戏模式. mode = config.CLASSIC_MODE for _m in [config.CLASSIC_MODE, config.MULTIPLE_MODE]: fundsConf = config.getLevelFundsConf(clientId, _m) for val in fundsConf.get("funds"): if val.get("productId") == productId: mode = _m break lf_rewards = _getRewardsState(userId, mode) lf_funds = _getBoughtFunds(userId, mode) userLv = util.getGunLevelVal(userId, mode) fundsConf = config.getLevelFundsConf(clientId, mode) funds = fundsConf.get("funds") rewardsConf = fundsConf.get("rewards") rewardsTypeStr = ["free_rewards", "funds_rewards"] if rewardType in [0, 1]: for val in funds: if val.get("productId") != productId: continue rewardsData = rewardsConf.get(str(val["idx"])) isChanged = False for lvData in rewardsData: lv = lvData["level"] if (isQuickGet and lv <= userLv) or (not isQuickGet and lv == level): lf_rewards.setdefault(str(lv), [0, 0]) # 一键领取时需要检测两种奖励是否可以领取。 typeList = [rewardType] if isQuickGet: typeList = [0, 1] for _type in typeList: if lf_rewards[str(lv)][_type] == 0 and (_type == 0 or val["idx"] in lf_funds): isChanged = True lf_rewards[str(lv)][_type] = 2 for _reward in lvData[rewardsTypeStr[_type]]: itemId = _reward["name"] if util.isChestRewardId(itemId): chestRewards = {} chestRewards["chestId"] = itemId chestRewards["rewards"] = chest_system.getChestRewards(userId, itemId) chest_system.deliveryChestRewards(userId, itemId, chestRewards["rewards"], "BI_NFISH_GET_LEVEL_FUNDS", param01=lv, param02=_type) rewards.append(chestRewards) else: rewards.append([_reward]) util.addRewards(userId, [_reward], "BI_NFISH_GET_LEVEL_FUNDS", param01=lv, param02=_type) if _type == 0 and lvData.get("rechargeBonus", 0) > 0: util.incrUserRechargeBonus(userId, lvData["rechargeBonus"]) if isChanged: daobase.executeUserCmd(userId, "HSET", _getRdKey(userId, mode), GameData.lf_rewards, json.dumps(lf_rewards)) hasTip, rewardsState = _getLevelFundsRewardState(userId, clientId, val["idx"], mode, lf_funds=lf_funds, lf_rewards=lf_rewards) if not hasTip: if mode == 1: module_tip.cancelModuleTipEvent(userId, "levelfundsNew", productId) else: module_tip.cancelModuleTipEvent(userId, "levelfunds", productId) break else: code = 1 else: code = 2 message = MsgPack() message.setCmd("levelFundsRewards") message.setResult("gameId", config.FISH_GAMEID) message.setResult("userId", userId) message.setResult("productId", productId) message.setResult("code", code) message.setResult("rewards", rewards) message.setResult("rewardType", rewardType) message.setResult("rewardsState", rewardsState) router.sendToUser(message, userId)