def checkSkillUpgrade(userId): """ 检查技能能否升级升星 """ upSkills = [] for skillId in config.getAllSkillId(): skillId = int(skillId) if not config.getSkillStarConf(skillId, 1, config.MULTIPLE_MODE): continue code, skill = checkSkillStatus(userId, skillId) if code != 0: continue if skill[INDEX_ORIGINAL_LEVEL] < MAX_ORIGINAL_LEVEL: skillGradeConf = config.getSkillGradeCommonConf( skillId, skill[INDEX_ORIGINAL_LEVEL] + 1) if checkUpgradeSkillItemCount(userId, skillGradeConf["consume"]): upSkills.append(skillId) if skill[INDEX_STAR_LEVEL] > 0 and skill[ INDEX_STAR_LEVEL] < MAX_STAR_LEVEL: skillStarConf = config.getSkillStarCommonConf( skillId, skill[INDEX_STAR_LEVEL] + 1) if checkUpgradeSkillItemCount(userId, skillStarConf["consume"]): upSkills.append(skillId) bireport.reportGameEvent( "BI_NFISH_GE_SKILL_UPGRADE", userId, FISH_GAMEID, 0, 0, skillId, 0, 0, 0, [skill[INDEX_STAR_LEVEL], skill[INDEX_ORIGINAL_LEVEL]], util.getClientId(userId)) module_tip.resetModuleTip(userId, "upskill") if upSkills: module_tip.addModuleTipEvent(userId, "upskill", upSkills) else: module_tip.resetModuleTipEvent(userId, "upskill")
def getLevelFundsData(userId, clientId, mode): """ 获取成长基金数据 """ message = MsgPack() message.setCmd("levelFundsData") message.setResult("gameId", config.FISH_GAMEID) message.setResult("userId", userId) if mode == -1: show = [] for m in [config.CLASSIC_MODE, config.MULTIPLE_MODE]: isAllTaken = isShow(userId, clientId, m)[-1] if isAllTaken: show.append(1) else: show.append(0) message.setResult("show", show) message.setResult("mode", mode) router.sendToUser(message, userId) return if mode == 1: module_tip.resetModuleTipEvent(userId, "levelfundsNew") else: module_tip.resetModuleTipEvent(userId, "levelfunds") userLv, funds, userIdxs, lf_funds, lf_rewards, isAllTaken = isShow(userId, clientId, mode) message.setResult("level", userLv) fundsList = [] addTipPIds = [] isIn, roomId, _, _ = util.isInFishTable(userId) if isIn and not isAllTaken and util.isFinishAllNewbieTask(userId): for idx in userIdxs: productConf = funds[idx - 1] _funds = {} productId = productConf.get("productId") _funds["Id"] = productId _funds["state"] = 1 if idx in lf_funds else 0 _funds["title"] = productConf.get("title") _funds["name"] = config.getMultiLangTextConf(productConf.get("name"), lang=util.getLanguage(userId)) _funds["price_direct"] = productConf.get("price_direct") _funds["price_diamond"] = productConf.get("price_diamond") _funds["buyType"] = productConf.get("buyType") _funds["otherBuyType"] = productConf.get("otherBuyType") from newfish.entity import store _funds["otherProductInfo"] = store.getOtherBuyProduct(productConf.get("otherBuyType"), productConf.get("buyType")) hasTip, _funds["rewardsState"] = _getLevelFundsRewardState(userId, clientId, idx, mode, lf_rewards, lf_funds) if hasTip: addTipPIds.append(productId) fundsList.append(_funds) message.setResult("fundsList", fundsList) message.setResult("mode", mode) router.sendToUser(message, userId) if addTipPIds: if ftlog.is_debug(): ftlog.debug("getLevelFundsData", mode) if mode == 1: module_tip.addModuleTipEvent(userId, "levelfundsNew", addTipPIds) else: module_tip.addModuleTipEvent(userId, "levelfunds", addTipPIds)
def checkModuleTip(bigRoomId, userId, mode): """ 检查兑换和小游戏红点状态 """ from newfish.entity.superboss import item_exchange, minigame module_tip.resetModuleTipEvent(userId, "superboss") subkey = "%s_%d" % (bigRoomId, mode) mgType = config.getSuperBossCommonConf().get(str(subkey), {}).get("mgType", "") item_exchange.checkModuleTip(mgType, userId, mode) minigame.checkModuleTip(bigRoomId, userId, mode)
def queryNewbie7DayGift(userId, clientId): """ 返回新手礼包数据 """ module_tip.resetModuleTipEvent(userId, "newbie7DaysGift") message = MsgPack() message.setCmd("newbie_7_gift_query") message.setResult("gameId", FISH_GAMEID) message.setResult("userId", userId) message.setResult("clientId", clientId) redState = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.redState) message.setResult("redState", redState) giftState = checkNewbie7DaysGiftState(userId, redState) rewardsList = [] curDayIdx = 0 newbie7DayGiftData = gamedata.getGameAttrJson(userId, FISH_GAMEID, GameData.newbie7DayGiftData) if giftState == 1 and isinstance(newbie7DayGiftData, list) and len(newbie7DayGiftData) == 2: startTS, takenDays = newbie7DayGiftData curTime = int(time.time()) curDayStartTS = util.getDayStartTimestamp(curTime) curDayIdx = (curDayStartTS - startTS) / 86400 daysConf = config.getNewbie7DaysGiftConf() # 最后一天已领取或是已过期 if daysConf[-1].get( "idx") in takenDays or curDayIdx > daysConf[-1].get("idx"): giftState = 2 curDayIdx = 0 else: for _val in daysConf: _idx = _val.get("idx") _state = 1 if _idx in takenDays else 0 _rewards = _processRewards(_val.get("rewards")) rewardsList.append({ "rewards": _rewards, "idx": _idx, "state": _state }) if _state == 0 and _idx == curDayIdx: module_tip.addModuleTipEvent(userId, "newbie7DaysGift", curDayIdx) message.setResult("nextRefreshTime", 86400 - (curTime - curDayStartTS)) message.setResult("giftState", giftState) message.setResult("rewardsList", rewardsList) message.setResult("curDayIdx", curDayIdx) ignoreClient = config.isClientIgnoredConf("clientIds", clientId, clientId) message.setResult("isPureClient", 1 if ignoreClient else 0) router.sendToUser(message, userId) if ftlog.is_debug(): ftlog.debug("newbie7DaysGift, userId =", userId, newbie7DayGiftData, "message =", message)
def refreshDailyQuestData(userId): """ 重置每日任务存档 """ # 刷新每日任务分组难度等级 refreshDailyQuestGroupLv(userId) key = _getUserDailyQuestKey(userId) daobase.executeUserCmd(userId, "DEL", key) key = _getUserDailyQuestRewardKey(userId) daobase.executeUserCmd(userId, "DEL", key) gamedata.delGameAttr(userId, FISH_GAMEID, _getUserDailyQuestInfoKey(userId)) gamedata.delGameAttr(userId, FISH_GAMEID, GameData.refreshDailyQuestTimes) module_tip.resetModuleTipEvent(userId, "task")
def refreshReturnerMissionData(userId, lastLoginTime): """ 刷新回归豪礼数据 """ currTime = int(time.time()) lastLoginTime = util.getDayStartTimestamp(lastLoginTime) returnerMissionConf = config.getReturnerMissionConf() # 判断是否激活回归豪礼 if currTime - lastLoginTime >= returnerMissionConf["daysLost"] * 24 * 3600: returnerMission = gamedata.getGameAttrJson(userId, FISH_GAMEID, GameData.returnerMission, {}) lastActiveTime = util.getDayStartTimestamp(returnerMission.get("lastActiveTime", currTime)) isActive = False if returnerMission: if currTime - lastActiveTime >= returnerMissionConf["daysBetween"] * 24 * 3600: isActive = True else: isActive = True if isActive: userLevel = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.level) vipLevel = hallvip.userVipSystem.getUserVip(userId).vipLevel.level vipExp = hallvip.userVipSystem.getUserVip(userId).vipExp returnerMission = {} returnerMission["lastActiveTime"] = currTime returnerMission["userLevel"] = userLevel returnerMission["vipExp"] = vipExp returnerMission["tasks"] = initTaskData() gamedata.setGameAttr(userId, FISH_GAMEID, GameData.returnerMission, json.dumps(returnerMission)) bireport.reportGameEvent("BI_NFISH_GE_RETURNER_MISSION", userId, FISH_GAMEID, vipLevel, vipExp, userLevel, 0, 0, 0, [], util.getClientId(userId)) returnerMission = getReturnerMissionData(userId) if returnerMission: # 解锁新任务 lastActiveTime = util.getDayStartTimestamp(returnerMission["lastActiveTime"]) fewDays = (datetime.fromtimestamp(currTime) - datetime.fromtimestamp(lastActiveTime)).days + 1 fewDays = max(1, min(fewDays, len(returnerMission["tasks"]))) # 第N天之前的任务都会解锁 isUnlock = False taskIds = [] for _index, taskConf in enumerate(config.getReturnerMissionConf("tasks")): if taskConf["taskId"] in returnerMission["tasks"]: if _index < fewDays and returnerMission["tasks"][taskConf["taskId"]]["state"] == 0: returnerMission["tasks"][taskConf["taskId"]]["state"] = 1 isUnlock = True elif returnerMission["tasks"][taskConf["taskId"]]["state"] == 2: taskIds.append(taskConf["taskId"]) if isUnlock: gamedata.setGameAttr(userId, FISH_GAMEID, GameData.returnerMission, json.dumps(returnerMission)) if taskIds: module_tip.addModuleTipEvent(userId, "returnerMission", taskIds) else: module_tip.resetModuleTipEvent(userId, "returnerMission")
def checkGunUpgrade(userId): """ 检查普通炮能否升级 """ for mode in config.GAME_MODES: gunLevelKey = GameData.gunLevel if mode == CLASSIC_MODE else GameData.gunLevel_m gunLevel = gamedata.getGameAttrInt(userId, FISH_GAMEID, gunLevelKey) if gunLevel >= config.getMaxGunLevel(mode): continue nextGunLevel = config.getNextGunLevel(gunLevel, mode) upgradeItemsConf = getUpgradeItemsConf(userId, nextGunLevel, mode=mode) if isEnough(userId, upgradeItemsConf): # 判断升级所需物品是否足够 module_tip.addModuleTipEvent(userId, "upgun", 0) # 普通炮升级小红点 else: module_tip.resetModuleTipEvent(userId, "upgun")
def checkTreasureUpgrade(userId): """ 检查宝藏能否升级 """ upTreasures = [] for kindId, _ in config.getTreasureConf().iteritems(): treasureData = getTreasure(userId, kindId) levelConf = config.getTreasureConf(kindId, level=treasureData[INDEX_LEVEL] + 1) if treasureData[INDEX_LEVEL] < len(config.getTreasureConf(kindId).get("levels", {})): consumeItems = [{"name": int(kindId), "count": int(levelConf["cost"])}] if checkUpgradeTreasureItemCount(userId, consumeItems): upTreasures.append(int(kindId)) module_tip.resetModuleTip(userId, "treasure") if upTreasures: module_tip.addModuleTipEvent(userId, "treasure", upTreasures) else: module_tip.resetModuleTipEvent(userId, "treasure")
def updateAchievementModuleTips(userId, isRefresh=False): """更新成就小红点""" module_tip.resetModuleTipEvent(userId, "achievement") taskConfigs = getAchievementAllTask(userId) if not taskConfigs: return achLevel = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.achievementLevel) receiveLevelState = daobase.executeUserCmd( userId, "HGET", fish_achievement_task.getTaskKey(userId), "levelReceived") if not receiveLevelState: if achLevel > 1: module_tip.addModuleTipEvent(userId, "achievement", 1) else: receiveLevelState = json.loads(receiveLevelState) maxLevel = max(set(receiveLevelState)) if achLevel > maxLevel: module_tip.addModuleTipEvent(userId, "achievement", 1) levelMap, starMap = {}, {} if isRefresh: levelMap, starMap = fish_achievement_task.getSkillMaxLevel(userId) honorIds = [] for honorId, configs in taskConfigs.iteritems(): for _, taskConf in configs.iteritems(): taskClass = FishAchievementTask(userId, taskConf) if isRefresh: if taskConf["type"] == AchieveType.SkillUp: # 技能最高级 targetInfo = taskConf["target"] if "star" in targetInfo: taskClass.updateProgress(starMap[int( targetInfo["star"])]) elif "condition" in targetInfo: taskClass.updateProgress(levelMap[int( targetInfo["condition"])]) if taskClass.isComplete(): honorIds.append(int(honorId)) if honorIds: module_tip.addModuleTipEvent(userId, "achievement", honorIds)
def finishCheckin(userId, rewards=None, checkinDay=None, ts=None): """ 完成签到 """ # if not rewards or not checkinDay: # kindId, rewards, checkinDay = getTodayCheckinRewards(userId) # if checkinDay: # gamedata.setGameAttr(userId, FISH_GAMEID, GameData.checkinDay, checkinDay) # weakdata.setDayFishData(userId, "isCheckin", 1) # module_tip.resetModuleTipEvent(userId, "checkin") # from newfish.game import TGFish # from newfish.entity.event import CheckinEvent # event = CheckinEvent(userId, FISH_GAMEID, checkinDay, rewards) # TGFish.getEventBus().publishEvent(event) ts = ts or int(time.time()) if not rewards or not checkinDay: checkinDay, rewards, _ = getTodayCheckinRewards(userId) if checkinDay: _isCheckContinuousBreak(userId, ts) gamedata.setGameAttr(userId, FISH_GAMEID, GameData.continuousCheckinDayTS, util.getDayStartTimestamp(int(ts)) + 86400) weakdata.setDayFishData(userId, "isCheckin", 1) module_tip.resetModuleTipEvent(userId, "checkin") vipLevel = util.getVipRealLevel(userId) # 注册当天签到不增加充值奖池. registTime = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.registTime) if util.getDayStartTimestamp(int( time.time())) > util.getDayStartTimestamp(registTime): util.increaseExtraRechargeBonus( userId, config.getVipConf(vipLevel).get("checkinRechargeBonus", 0)) from newfish.game import TGFish from newfish.entity.event import CheckinEvent event = CheckinEvent(userId, FISH_GAMEID, checkinDay, rewards) TGFish.getEventBus().publishEvent(event)