コード例 #1
0
def getGiftDetail(giftConf, hasBought, enableDayIdx, lang):
    """获取礼包的详细信息"""
    gift = {}
    gift["giftId"] = giftConf["giftId"]
    # gift["giftName"] = giftConf["giftName"]
    gift["giftName"] = config.getMultiLangTextConf(giftConf["giftName"],
                                                   lang=lang)
    gift["productId"] = giftConf["productId"]
    gift["available"] = 0
    gift["price"] = giftConf["price"]
    gift["price_direct"] = giftConf.get("price_direct", 0)
    gift["price_diamond"] = giftConf.get("price_diamond", 0)
    gift["buyType"] = giftConf["buyType"]
    gift["otherBuyType"] = giftConf.get("otherBuyType", {})
    gift["otherProductInfo"] = {}
    # 特殊处理代购券商品数据
    from newfish.entity import store
    # gift["otherProductInfo"][BT_VOUCHER] = store.getVoucherProduct(gift["otherBuyType"])
    gift["otherProductInfo"] = store.getOtherBuyProduct(
        giftConf.get("otherBuyType", {}), giftConf["buyType"])
    gift["items"] = []
    for item in giftConf["giftInfo"]:
        newItems = []
        for v in item["items"]:
            newVal = config.rwcopy(v)
            if util.isChestRewardId(v["itemId"]):
                newVal["info"] = chest_system.getChestInfo(v["itemId"])
            newItems.append(newVal)
        gift["items"].append({item["day_idx"] + 1: newItems})
    gift["hasBought"] = hasBought
    gift["enableDayIdx"] = enableDayIdx
    return gift
コード例 #2
0
ファイル: main_quest.py プロジェクト: isoundy000/learn_python
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
コード例 #3
0
ファイル: main_quest.py プロジェクト: isoundy000/learn_python
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)
コード例 #4
0
def getAllRewardList():
    """
    获取奖励列表,摇钱树界面左边显示的界面
    """
    temRewardList = []
    rewardListConf = config.getLuckyTreeConf("rewardList")
    for _val in rewardListConf:
        itemId = _val.get("reward", {}).get("name", 0)
        if util.isChestRewardId(itemId):
            chestReward = chest_system.getChestInfo(itemId)
            _val["reward"] = chestReward
        temRewardList.append(_val)
    return temRewardList
コード例 #5
0
def getInviteTasks(userId, actionType):
    weakDatas = weakdata.getDayFishDataAll(userId, FISH_GAMEID)
    taskConfs_ = config.getInviteTasks(actionType)
    taskConfs = taskConfs_.values()
    taskConfs = sorted(taskConfs, key=lambda data: data["Id"])
    if actionType == NewPlayerAction:
        taskState = strutil.loads(weakDatas.get("inviteTasks", "[]"))
        playerNums = len(strutil.loads(weakDatas.get("inviteNewPlayers", "[]")))

    else:
        taskState = strutil.loads(weakDatas.get("recallTasks", "[]"))
        playerNums = len(strutil.loads(weakDatas.get("recallPlayers", "[]")))

    taskStartIndex = len(taskState) / OneGroupNum * OneGroupNum
    taskStartIndex = min((len(taskConfs) / OneGroupNum - 1) * OneGroupNum, taskStartIndex)

    # 奖励
    taskInfos = []
    tipsTaskIds = []
    for m in range(taskStartIndex, taskStartIndex + 5):
        if m >= len(taskConfs):
            break
        taskConf = taskConfs[m]
        taskId = taskConf["Id"]
        taskInfo = {}
        taskInfo["Id"] = taskId
        rewards = []
        for _reward in taskConf["rewards"]:
            rewardMap = {}
            kindId = _reward["name"]
            rewardMap["name"] = kindId
            rewardMap["count"] = _reward["count"]
            rewardMap["info"] = {}
            if util.isChestRewardId(kindId):
                rewardMap["info"] = chest_system.getChestInfo(kindId)
            rewards.append(rewardMap)
        taskInfo["rewards"] = rewards
        taskInfo["target"] = taskConf["target"]
        state = 0
        if taskId in taskState:
            state = 2
        elif playerNums >= taskConf["target"]:
            tipsTaskIds.append(taskId)
            state = 1
        taskInfo["state"] = state
        taskInfos.append(taskInfo)

    module_tip.resetModuleTip(userId, "invitetasks")
    if tipsTaskIds:
        module_tip.addModuleTipEvent(userId, "invitetasks", tipsTaskIds)
    return taskInfos, playerNums
コード例 #6
0
ファイル: main_quest.py プロジェクト: isoundy000/learn_python
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
コード例 #7
0
def getDailyQuestData(userId):
    """
    获取玩家每日任务数据
    """
    level = util.getUserLevel(userId)
    if level < config.getCommonValueByKey("dailyQuestOpenLevel"):
        return {}
    if not util.isFinishAllNewbieTask(userId):
        return {}
    lang = util.getLanguage(userId)
    # 替换为新版任务时,重置玩家每日任务数据.
    key = _getUserDailyQuestGroupLvKey(userId)
    groupLvData = gamedata.getGameAttrJson(userId, FISH_GAMEID, key, {})
    if len(groupLvData) == 0:
        refreshDailyQuestData(userId)
    groupIdList = config.getDailyQuestGroupOrder()
    dailyQuestData = {}
    todayQuest, activeLv = getTodayQuest(userId)
    # userData = _getUserQuestData(userId)
    finishedStar = 0
    key = _getUserDailyQuestWeeklyRewardKey(userId)
    ret = json.loads(weakdata.getWeekFishData(userId, key, "{}"))
    finishedWeekStar = ret.get("star", 0)
    questInfo = getUserQuestInfoData(userId)
    tasks = []
    update = False
    questList = sorted(todayQuest.items(), key=lambda val: groupIdList.index(val[1]["groupId"]))
    all = len(todayQuest) == len(groupIdList)
    # for k, v in todayQuest.iteritems():
    for _val in questList:
        k, v = _val
        task = {}
        task["taskId"] = k
        task["taskLevel"] = v["taskLevel"]
        task["targetsNum"] = v["targetsNum"]
        # progress = userData.get(v["taskType"], 0)
        progress, state = questInfo.get(str(k), [0, QuestTaskState.Normal])
        if progress >= task["targetsNum"] or state >= QuestTaskState.Complete:
            progress = task["targetsNum"]
            # 已领取
            if state == QuestTaskState.Received:
                finishedStar += task["taskLevel"]
            elif state == QuestTaskState.Normal:
                state = QuestTaskState.Complete
                questInfo[str(k)] = [progress, state]
                update = True
        task["progress"] = progress
        task["taskState"] = state
        task["rewards"] = v["rewards"]
        task["chestRewards"] = []
        for val in v["rewards"]:
            itemId = val["name"]
            if util.isChestRewardId(itemId):
                task["chestRewards"].append({"chestId": itemId, "chestInfo": chest_system.getChestInfo(itemId)})
        # if v["taskType"] == TaskType.CoinNum and v["des"].find("%s") >= 0:
        #    task["des"] = v["des"] % util.formatScore(v["targetsNum"])
        # elif v["des"].find("%d") >= 0:
        #    task["des"] = v["des"] % v["targetsNum"]
        # else:
        #    task["des"] = v["des"]
        vDesId = v["des"]
        vDes = config.getMultiLangTextConf(str(vDesId), lang=lang)
        if v["taskType"] == TaskType.CoinNum and vDes.find("%s") >= 0:
            task["des"] = vDes % util.formatScore(v["targetsNum"], lang=lang)
        elif vDes.find("%d") >= 0:
            task["des"] = vDes % v["targetsNum"]
        elif vDes.count("{}") >= 2:
            task["des"] = vDes.format(v["gunX"], v["targetsNum"])
        else:
            task["des"] = vDes
        tasks.append(task)
    if update:
        setUserQuestInfoData(userId, questInfo)
    dailyQuestReward = config.getDailyQuestRewardConf(activeLv, all)
    gotReward = _getUserQuestRewardData(userId, "day")
    gotWeekReward = _getUserQuestRewardData(userId, "week")
    dailyQuestData["tasks"] = tasks
    rewardData = [dailyQuestReward[str(key)] for key in sorted(map(int, dailyQuestReward.keys()))]
    for v in rewardData:
        v["chestRewards"] = []
        for val in v["rewards"]:
            itemId = val["itemId"]
            if util.isChestRewardId(itemId):
                v["chestRewards"].append({"chestId": itemId, "chestInfo": chest_system.getChestInfo(itemId)})
    dailyQuestData["rewardData"] = rewardData
    dailyQuestData["finishedStar"] = finishedStar
    dailyQuestData["gotReward"] = gotReward
    dailyQuestData["finishedWeekStar"] = finishedWeekStar
    dailyQuestData["gotWeekReward"] = gotWeekReward
    dailyQuestData["refreshData"] = config.getDailyQuestRefreshConf()
    dailyQuestData["refreshedTimes"] = gamedata.getGameAttrInt(userId, FISH_GAMEID, GameData.refreshDailyQuestTimes)
    return dailyQuestData
コード例 #8
0
def getLevelRewardsData(userId):
    """
    获取等级奖励数据
    """
    clientId = util.getClientId(userId)
    userLevel = util.getUserLevel(userId)
    levels = gamedata.getGameAttrJson(userId, config.FISH_GAMEID,
                                      GameData.levelRewards, [])
    levelRewards = config.getLevelRewards(clientId)
    _level = userLevel
    _rewards = []
    if util.isFinishAllNewbieTask(userId):
        isIn, roomId, _, _ = util.isInFishTable(userId)
        if isIn and util.getRoomTypeName(roomId) in config.NORMAL_ROOM_TYPE:
            lang = util.getLanguage(userId)
            sortedLevelRewards = sorted(levelRewards.items(),
                                        key=lambda v: int(v[0]))
            for item in sortedLevelRewards:
                level, val = item
                level = int(level)
                if val and level not in levels:
                    _level = level
                    for _r in val.get("rewards", []):
                        itemId = _r["name"]
                        desId = _r.get("des")
                        if desId:
                            des = config.getMultiLangTextConf(str(desId),
                                                              lang=lang)
                        else:
                            des = ""
                        if util.isChestRewardId(itemId):
                            _rewards.append({
                                "name":
                                itemId,
                                "count":
                                _r["count"],
                                "des":
                                des,
                                "info":
                                chest_system.getChestInfo(itemId)
                            })
                        else:
                            _rewards.append({
                                "name": itemId,
                                "count": _r["count"],
                                "des": des,
                                "info": {}
                            })
                    if level <= userLevel:
                        module_tip.addModuleTipEvent(userId, "levelrewards",
                                                     _level)
                    break

    mo = MsgPack()
    mo.setCmd("levelRewardsData")
    mo.setResult("gameId", config.FISH_GAMEID)
    mo.setResult("userId", userId)
    mo.setResult("level", _level)
    mo.setResult("rewards", _rewards)
    router.sendToUser(mo, userId)
    ftlog.debug("level_rewards, userId =", userId, "userLevel =", userLevel,
                "level =", _level, "rewards =", _rewards)