Beispiel #1
0
def refreshQuestState(userId, questType, totalValue):
    """
    刷新指定任务类型的任务状态
    """
    isComplete = False
    clientId = util.getClientId(userId)
    for taskConf in config.getMainQuestTaskConf(clientId).values():
        if questType == taskConf["type"] and totalValue >= taskConf["num"]:
            state = getTask(userId, taskConf["taskId"])[QuestIndex.State]
            if state == QuestState.Default:
                setTask(userId, clientId, taskConf["taskId"],
                        [QuestState.Completed,
                         int(time.time())])
                isComplete = True
    if isComplete:
        refreshQuestModuleTip(userId, clientId)
        isIn, roomId, tableId, seatId = util.isInFishTable(userId)
        if isIn:
            mo = MsgPack()
            mo.setCmd("table_call")
            mo.setParam("action", "task_update")
            mo.setParam("gameId", FISH_GAMEID)
            mo.setParam("clientId", util.getClientId(userId))
            mo.setParam("userId", userId)
            mo.setParam("roomId", roomId)
            mo.setParam("tableId", tableId)
            mo.setParam("seatId", seatId)
            router.sendTableServer(mo, roomId)
Beispiel #2
0
def _getSectionStar(userId, clientId, sectionId):
    """
    获取章节总星级 已经完成的任务
    """
    sectionData = getSection(userId, sectionId)
    totalStar = sum([
        config.getMainQuestTaskConf(clientId, _taskId).get("star", 0)
        for _taskId in sectionData[SectionIndex.FinishTasks]
    ])
    return totalStar
Beispiel #3
0
def isFinishAllTask(userId, questType):
    """
    是否已完成指定类型的所有任务
    """
    clientId = util.getClientId(userId)
    for _, taskConf in config.getMainQuestTaskConf(clientId).iteritems():
        if questType == taskConf["type"]:
            state = getTask(userId, taskConf["taskId"])[QuestIndex.State]
            if state == QuestState.Default:
                return False
    return True
Beispiel #4
0
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)
Beispiel #5
0
 def refreshaHoldCoin(self):
     """
     刷新持有金币任务数据
     """
     if self.holdCoin != self.player.holdCoin:
         self.holdCoin = self.player.holdCoin
         finishTask = None
         for taskConf in self.allHoldCoinTask:
             if self.holdCoin >= taskConf["num"]:
                 finishTask = taskConf
         if finishTask:
             self.syncTaskData()
             self.allHoldCoinTask.remove(finishTask)
         if self.currTask and self.currTask[
                 "type"] == QuestType.HoldCoin and self.currTask[
                     "state"] == QuestState.Default:
             taskConf = config.getMainQuestTaskConf(self.player.clientId,
                                                    self.currTask["taskId"])
             self.currTask["progress"] = [
                 min(self.holdCoin, taskConf["num"]), taskConf["num"]
             ]
             pushCurrTask(self.player.userId, task=self.currTask)
Beispiel #6
0
def getTaskInfo(userId, clientId, taskId, lang):
    """
    获得单个任务信息
    """
    taskConf = config.getMainQuestTaskConf(clientId, taskId)
    state = getTask(userId, taskConf["taskId"])[QuestIndex.State]
    if state == QuestState.Default:
        value = getQuestTypeData(userId, taskConf["type"])
        if taskConf["type"] == QuestType.RobberyProfit:
            value = 0
        if value >= taskConf["num"]:
            state = QuestState.Completed
            setTask(userId, clientId, taskConf["taskId"],
                    [state, int(time.time())])  # 任务完成时间
        progress = [min(value, taskConf["num"]), taskConf["num"]]
    else:
        progress = [taskConf["num"], taskConf["num"]]  # 完成的进度
    # 招财珠价值任务客户端使用是否完成显示.
    if taskConf["type"] == QuestType.RobberyProfit and taskConf["num"] != 0:
        progress = [val / taskConf["num"] for val in progress]
    taskDict = {}
    taskDict["taskId"] = taskConf["taskId"]
    taskDict["state"] = state
    taskDict["type"] = taskConf["type"]
    taskDict["title"] = taskConf["title"]
    descId = taskConf["desc"]
    desc = config.getMultiLangTextConf(str(descId), lang=lang)
    if desc:
        taskDict["desc"] = desc % util.formatScore(
            taskConf["num"], lang=lang) if "%s" in desc else desc
    taskDict["progress"] = progress
    taskDict["normalRewards"] = taskConf["normalRewards"]
    chestRewards = taskConf["chestRewards"]
    taskDict["chestInfo"] = chest_system.getChestInfo(
        chestRewards[0]["name"]) if chestRewards else {}
    taskDict["taskLevel"] = taskConf["star"]
    return taskDict