def triggerUserLoginEvent(event): """ 用户登录事件 """ userId = event.userId clientId = event.clientId currSectionId = gamedata.getGameAttr(userId, FISH_GAMEID, GameData.currSectionId) if not currSectionId: currSectionId = int( config.getMainQuestSectionConf(clientId).keys()[0]) # 初始化第一章第一节 gamedata.setGameAttr(userId, FISH_GAMEID, GameData.currSectionId, currSectionId) sectionConf = config.getMainQuestSectionConf(clientId, currSectionId) gamedata.setGameAttr(userId, FISH_GAMEID, GameData.mainQuestDisplay, sectionConf["display"]) isIn, _, _, _ = util.isInFishTable(userId) if not isIn: # setQuestTypeData(userId, QuestType.HoldCoin, userchip.getChip(userId)) # setQuestTypeData(userId, QuestType.HoldGoldBullet, util.balanceItem(userId, config.GOLD_BULLET_KINDID)) setQuestTypeData(userId, QuestType.UserLevelUp, gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.level)) # 用户等级 setQuestTypeData(userId, QuestType.LevelUp, util.getGunX( gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.gunLevel_m), config.MULTIPLE_MODE)) # 皮肤炮等级 setQuestTypeData( userId, QuestType.AchievementLevel, gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.achievementLevel)) # 荣耀任务等级 refreshHigherSkillLevel(userId) # 技能达到16级以上的任务 refreshQuestModuleTip(userId, clientId)
def refreshQuestModuleTip(userId, clientId): """ 刷新当前章节小红点提示数据 """ currSectionId = gamedata.getGameAttr(userId, FISH_GAMEID, GameData.currSectionId) if currSectionId: sectionConf = config.getMainQuestSectionConf(clientId, currSectionId) taskIds = [] totalStar = _getSectionStar(userId, clientId, currSectionId) for _taskId in sectionConf["taskIds"]: state = getTask(userId, _taskId)[QuestIndex.State] if state == QuestState.Completed: taskIds.append(_taskId) module_tip.resetModuleTip(userId, "mainquest") sectionData = getSection(userId, currSectionId) state = sectionData[SectionIndex.State] if state == QuestState.Completed: module_tip.addModuleTipEvent(userId, "mainquest", currSectionId) if taskIds: module_tip.addModuleTipEvent(userId, "mainquest", taskIds) # 检查主线任务增加的星级能否解锁对应星级奖励. for val in sectionConf["starRewards"]: if totalStar >= val["star"] and val["star"] not in sectionData[ SectionIndex.TakenStars]: module_tip.addModuleTipEvent(userId, "mainquest", "star_%d" % val["star"])
def refreshCurrSectionId(userId, clientId): """ 刷新当前主线任务章节ID """ sectionIds = map(int, sorted(config.getMainQuestSectionConf(clientId).keys())) currSectionId = gamedata.getGameAttr(userId, FISH_GAMEID, GameData.currSectionId) sectionConf = config.getMainQuestSectionConf(clientId, currSectionId) if sectionConf and currSectionId != sectionIds[-1]: sectionData = getSection(userId, currSectionId) finishTaskIds = sectionData[SectionIndex.FinishTasks] state = sectionData[SectionIndex.State] if len(set(sectionConf["taskIds"]) - set(finishTaskIds)) == 0 and state == QuestState.Received: switchToNextSection(userId, clientId, currSectionId)
def switchToNextSection(userId, clientId, currSectionId): """ 主线任务切换到下一个章节 """ sectionIds = map(int, sorted(config.getMainQuestSectionConf(clientId).keys())) if currSectionId == sectionIds[-1]: # 完成所有的章节任务 gamedata.setGameAttr(userId, FISH_GAMEID, GameData.finishAllMainQuest, 1) return index = min(sectionIds.index(currSectionId) + 1, len(sectionIds) - 1) sectionId = sectionIds[index] gamedata.setGameAttr(userId, FISH_GAMEID, GameData.currSectionId, sectionId) sectionConf = config.getMainQuestSectionConf(clientId, sectionId) gamedata.setGameAttr(userId, FISH_GAMEID, GameData.mainQuestDisplay, sectionConf["display"]) # 是否在渔场中显示 refreshQuestModuleTip(userId, clientId)
def getMainQuestData(userId, clientId): """ 获取主线任务数据 """ mainQuestDict = {} try: if not isFinishAllMainQuest(userId): currSectionId = gamedata.getGameAttr( userId, FISH_GAMEID, GameData.currSectionId) # 当前章节 642000 if currSectionId: sectionConf = config.getMainQuestSectionConf( clientId, currSectionId) finishTaskIds = getSection( userId, currSectionId)[SectionIndex.FinishTasks] mainQuestDict["sectionId"] = sectionConf["sectionId"] mainQuestDict["sortId"] = sectionConf["sortId"] mainQuestDict["progress"] = [ len(finishTaskIds), len(sectionConf["taskIds"]) ] # mainQuestDict["honorId"] = sectionConf["honorId"] # 勋章Id # mainQuestDict["sectionRewards"] = sectionConf["rewards"] # 章节奖励 # mainQuestDict["state"] = getSection(userId, sectionConf["sectionId"])[SectionIndex.State] # 章节奖励状态 mainQuestDict["display"] = gamedata.getGameAttrInt( userId, FISH_GAMEID, GameData.mainQuestDisplay) mainQuestDict["tasks"] = getSectionTasksInfo( userId, sectionConf["sectionId"]) # 章节小任务 starRewards = [] sectionData = getSection(userId, currSectionId) # 获取章节数据 gotReward = [] for val in sectionConf["starRewards"]: chestRewards = [] for v in val["rewards"]: itemId = v["itemId"] if util.isChestRewardId(itemId): chestRewards.append({ "chestId": itemId, "chestInfo": chest_system.getChestInfo(itemId) }) starRewards.append({ "rewards": val["rewards"], "finishedStar": val["star"], "chestRewards": chestRewards }) if int(val["star"]) in sectionData[ SectionIndex.TakenStars]: gotReward.append(int(val["star"])) mainQuestDict["rewardData"] = starRewards mainQuestDict["finishedStar"] = _getSectionStar( userId, clientId, currSectionId) mainQuestDict["gotReward"] = gotReward except: ftlog.error() return mainQuestDict
def getQuestRewards(userId, clientId, taskId): """ 领取单个主线任务奖励 """ mo = MsgPack() mo.setCmd("task") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("taskId", taskId) mo.setResult("action", "mainReward") code = 3 taskConf = config.getMainQuestTaskConf(clientId, taskId) if taskConf: state = getTask(userId, taskId)[QuestIndex.State] if state == QuestState.Default: code = 2 elif state == QuestState.Received: code = 1 else: code = 0 chestInfo = {} rewards = [] rewards.extend(taskConf["normalRewards"]) chestRewards = taskConf["chestRewards"] if chestRewards: chestId = chestRewards[0]["name"] chestInfo = chest_system.getChestInfo(chestId) _rewards = chest_system.getChestRewards(userId, chestId) rewards.extend(_rewards) setTask( userId, clientId, taskId, [QuestState.Received, int(time.time())]) # 领取任务奖励 util.addRewards(userId, rewards, "BI_NFISH_MAIN_QUEST_REWARDS", int(taskId)) module_tip.cancelModuleTipEvent(userId, "mainquest", taskId) # 检查主线任务增加的星级能否解锁对应星级奖励. sectionId = getSectionId(taskId) sectionData = getSection(userId, sectionId) sectionConf = config.getMainQuestSectionConf(clientId, sectionId) totalStar = _getSectionStar(userId, clientId, sectionId) for val in sectionConf["starRewards"]: if totalStar >= val["star"] and val["star"] not in sectionData[ SectionIndex.TakenStars]: module_tip.addModuleTipEvent(userId, "mainquest", "star_%d" % val["star"]) mo.setResult("chestInfo", chestInfo) # 宝箱奖励 mo.setResult("rewards", rewards) bireport.reportGameEvent("BI_NFISH_GE_MAIN_QUEST_TASKID", userId, FISH_GAMEID, 0, 0, 0, 0, 0, 0, [taskId], clientId) mo.setResult("code", code) router.sendToUser(mo, userId) pushCurrTask(userId)
def getSectionTasksInfo(userId, sectionId=None): """ 获取该章节下的所有任务信息 """ sectionId = sectionId or gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.currSectionId) tasks = [] if sectionId: clientId = util.getClientId(userId) lang = util.getLanguage(userId) sectionConf = config.getMainQuestSectionConf(clientId, sectionId) for taskId in sectionConf["taskIds"]: taskDict = getTaskInfo(userId, clientId, taskId, lang) tasks.append(taskDict) return tasks
def setTask(userId, clientId, taskId, data): """ 设置主线任务状态等数据 """ daobase.executeUserCmd(userId, "HSET", _getMainQuestKey(userId), taskId, json.dumps(data)) if data[QuestIndex.State] == QuestState.Received: sectionId = getSectionId(taskId) sectionConf = config.getMainQuestSectionConf(clientId, sectionId) sectionData = getSection(userId, sectionId) if taskId not in sectionData[SectionIndex.FinishTasks]: sectionData[SectionIndex.FinishTasks].append(taskId) # 已完成该章节所有任务,可领取章节奖励 if len( set(sectionConf["taskIds"]) - set(sectionData[SectionIndex.FinishTasks])) <= 0: sectionData[SectionIndex.State] = QuestState.Completed sectionData[SectionIndex.FinishTime] = int(time.time()) module_tip.addModuleTipEvent(userId, "mainquest", sectionId) setSection(userId, sectionId, sectionData)
def getCurrTaskInfo(userId): """ 获得当前任务信息 """ currSectionId = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.currSectionId) if currSectionId: clientId = util.getClientId(userId) lang = util.getLanguage(userId) sectionConf = config.getMainQuestSectionConf(clientId, currSectionId) defaultTasks, completeTasks, receiveTasks = [], [], [] for _taskId in sectionConf.get("taskIds", []): taskDict = getTaskInfo(userId, clientId, _taskId, lang) if taskDict["state"] == QuestState.Default: defaultTasks.append(taskDict) elif taskDict["state"] == QuestState.Completed: completeTasks.append(taskDict) elif taskDict["state"] == QuestState.Received: receiveTasks.append(taskDict) completeTasks.extend(defaultTasks) if completeTasks: return completeTasks[0] return {}
def getSectionStarRewards(userId, clientId, sectionId, star): """ 领取章节星级奖励 """ mo = MsgPack() mo.setCmd("task") mo.setResult("gameId", FISH_GAMEID) mo.setResult("userId", userId) mo.setResult("action", "sectionStarReward") mo.setResult("star", star) code = 1 # honorId = 0 sectionConf = config.getMainQuestSectionConf(clientId, sectionId) currSectionId = gamedata.getGameAttr(userId, FISH_GAMEID, GameData.currSectionId) gotReward = [] # 检查领取的章节是否为当前生效章节. if sectionConf and sectionId == currSectionId: sectionData = getSection(userId, sectionId) # 检查该星级是否已经领取过. star = int(star) if star not in sectionData[SectionIndex.TakenStars]: starRewards = sectionConf["starRewards"] stars = [] for val in starRewards: stars.append(val["star"]) if val["star"] == star: code = 0 rewards = { "name": val["rewards"][0]["itemId"], "count": val["rewards"][0]["count"] } sectionData[SectionIndex.TakenStars].append(star) gotReward = sectionData[SectionIndex.TakenStars] sectionData[SectionIndex.FinishTime] = int(time.time()) kindId = rewards["name"] if util.isChestRewardId(kindId): rewards = chest_system.getChestRewards(userId, kindId) chest_system.deliveryChestRewards( userId, kindId, rewards, "BI_NFISH_MAIN_QUEST_STAR_REWARDS", param01=star) else: util.addRewards(userId, [rewards], "BI_NFISH_MAIN_QUEST_STAR_REWARDS", int(sectionId), star) module_tip.cancelModuleTipEvent(userId, "mainquest", "star_%d" % star) mo.setResult("rewards", rewards) if code == 0: # 章节任务全部完成并且星级奖励全部领取即可跳转章节. finishTaskIds = sectionData[SectionIndex.FinishTasks] if len(set(sectionConf["taskIds"]) - set(finishTaskIds)) == 0 and len( set(stars) - set(sectionData[SectionIndex.TakenStars])) == 0: # honorId = sectionConf["honorId"] sectionData[ SectionIndex.State] = QuestState.Received # 领取星级奖励 module_tip.cancelModuleTipEvent(userId, "mainquest", sectionId) switchToNextSection(userId, clientId, currSectionId) # 解锁下一个章节 from newfish.game import TGFish event = MainQuestSectionFinishEvent( userId, FISH_GAMEID, sectionId, currSectionId) TGFish.getEventBus().publishEvent(event) setSection(userId, sectionId, sectionData) # 保存当前章节数据 mo.setResult("code", code) mo.setResult("gotReward", gotReward) router.sendToUser(mo, userId) pushCurrTask(userId)