Пример #1
0
def checkModuleTip(bigRoomId, userId, mode):
    """
    检查是否可以玩小游戏
    """
    subkey = "%s_%d" % (bigRoomId, mode)
    mgType = config.getSuperBossCommonConf().get(str(subkey), {}).get("mgType", "")
    key = "%s_%d" % (mgType, mode)
    isCanPlay = False
    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
        items = conf.get("items", {}).get(key, [])
        isCanPlay = False
        if remainTimes == -1 or remainTimes > 0:
            for _item in items:
                for _val in _item.get("costs"):
                    if util.balanceItem(userId, _val["name"]) < _val["count"]:
                        break
                else:
                    isCanPlay = True
                    break
    tipKey = "minigame"
    if isCanPlay:
        module_tip.addModuleTipEvent(userId, "superboss", tipKey)
    if ftlog.is_debug():
        ftlog.debug("minigame, userId =", userId, "tipKey =", tipKey, isCanPlay, "key =", key)
Пример #2
0
def sendBuyLevelFundsRet(userId, clientId, productId, idx, code, mode):
    """
    返回购买成长基金结果
    """
    message = MsgPack()
    message.setCmd("buyLevelFunds")
    message.setResult("gameId", config.FISH_GAMEID)
    message.setResult("userId", userId)
    message.setResult("productId", productId)
    message.setResult("code", code)
    rewardsState = []
    if code == 0:
        message.setResult("state", 1)
        hasTip, rewardsState = _getLevelFundsRewardState(userId, clientId, idx, mode)
        if hasTip:
            if mode == 1:
                module_tip.addModuleTipEvent(userId, "levelfundsNew", productId)
            else:
                module_tip.addModuleTipEvent(userId, "levelfunds", productId)
        else:
            if mode == 1:
                module_tip.cancelModuleTipEvent(userId, "levelfundsNew", productId)
            else:
                module_tip.cancelModuleTipEvent(userId, "levelfunds", productId)
    message.setResult("rewardsState", rewardsState)
    router.sendToUser(message, userId)
Пример #3
0
def checkModuleTip(mgType, userId, mode):
    """
    检查是否可以兑换
    """
    key = "%s_%d" % (mgType, mode)
    exchangedTimes = weakdata.getDayFishData(userId,
                                             WeakData.superbossExchangedTimes,
                                             {})
    exchangedTimes = exchangedTimes.get(key, {})
    conf = config.getSuperBossExchangeConf()
    exchangeItems = []
    isCanExchanged = False
    for idx, val in enumerate(
            conf.get("exchange", {}).get(key, {}).get("exchangeItems", [])):
        remainTimes = val["exchangeTimes"]
        remainTimes = max(0, remainTimes - exchangedTimes.get(
            str(val["idx"]), 0)) if remainTimes >= 0 else remainTimes
        exchangeItems.append({
            "costItems": val["costItems"],
            "gainItems": val["gainItems"],
            "remainTimes": remainTimes
        })
        if not isCanExchanged and _isExchangeChance(userId, remainTimes,
                                                    val["costItems"]):
            isCanExchanged = True
    tipKey = "convert"
    if isCanExchanged:
        module_tip.addModuleTipEvent(userId, "superboss", tipKey)
Пример #4
0
def addShareInvitedUserId(shareUserId, invitedUserId, isNewUser=False):
    """
    添加分享邀请人信息
    :param shareUserId: 分享卡片的分享者
    :param invitedUserId: 点击卡片的被邀请者
    :param isNewUser: 是否为新用户
    """
    inviteCount = weakdata.getDayFishData(shareUserId, "inviteCount", 0)
    if inviteCount < config.getCommonValueByKey("inviteLimitCount", 99999):
        if not isNewUser:
            inviteOldUserCount = weakdata.getDayFishData(shareUserId, "inviteOldUserCount", 0)
            if inviteOldUserCount > config.getCommonValueByKey("inviteLimitOldCount", 99999):
                return
            weakdata.incrDayFishData(shareUserId, "inviteOldUserCount", 1)
        inviteList = gamedata.getGameAttrJson(shareUserId, FISH_GAMEID, GameData.inviteList, [])
        inviteId = gamedata.incrGameAttr(shareUserId, FISH_GAMEID, GameData.inviteId, 1)
        inviteData = {
            "inviteId": inviteId,
            "userId": invitedUserId,
            "inviteTime": int(time.time()),
            "isNewUser": isNewUser,
            "isAppUser": 1 if util.isAppClient(invitedUserId) else 0
        }
        inviteList.append(inviteData)
        gamedata.setGameAttr(shareUserId, FISH_GAMEID, GameData.inviteList, json.dumps(inviteList))
        weakdata.incrDayFishData(shareUserId, "inviteCount", 1)
        module_tip.addModuleTipEvent(shareUserId, "invite", inviteId)
        getShareTaskInfo(shareUserId)
        from newfish.game import TGFish
        from newfish.entity.event import InvitedFinishEvent
        event = InvitedFinishEvent(shareUserId, FISH_GAMEID)
        TGFish.getEventBus().publishEvent(event)
Пример #5
0
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")
Пример #6
0
def _triggerMainQuestSectionFinishEvent(event):
    """
    主线任务章节完成事件
    """
    userId = event.userId
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    currSectionId = event.sectionId
    honorIds = []
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            if conf["type"] != AchieveType.CompleteMainQuestSection:  # 完成主线任务
                continue
            taskClass = FishAchievementTask(userId, conf)
            finishAllMainQuest = gamedata.getGameAttr(
                userId, FISH_GAMEID, GameData.finishAllMainQuest)
            curSectionIdx = currSectionId / 1000 % 640  # 1、2、3、4、5
            # 所有章节都已完成
            if finishAllMainQuest:
                taskClass.taskData["progress"] = conf["target"]["num"]
            else:
                taskClass.taskData["progress"] = min(curSectionIdx,
                                                     conf["target"]["num"])
            taskClass.updateProgress(taskClass.taskData["progress"])
            if taskClass.isComplete():
                honorIds.append(int(honorId))
    if honorIds:
        module_tip.addModuleTipEvent(userId, "achievement", honorIds)
Пример #7
0
def _triggerNewbieTaskCompleteEvent(event):
    """
    新手任务完成
    """
    userId = event.userId
    checkinDay = getCheckinDay(userId)
    if checkinDay:
        module_tip.addModuleTipEvent(userId, "checkin", checkinDay)
Пример #8
0
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)
Пример #9
0
def getQuestReward(userId, taskId, rewardflyPos):
    """
    领取每日任务奖励
    """
    code = 1
    reason = 2
    rewards = []
    questInfo = getUserQuestInfoData(userId)
    progress, state = questInfo.get(str(taskId), [0, QuestTaskState.Normal])
    # 未达到领取条件
    if state == QuestTaskState.Normal:
        reason = 2
    # 已经领取过奖励
    elif state == QuestTaskState.Received:
        reason = 1
    elif state == QuestTaskState.Complete:
        reason = 0
        questInfo[str(taskId)] = [progress, QuestTaskState.Received]
        setUserQuestInfoData(userId, questInfo)
        module_tip.cancelModuleTipEvent(userId, "task", taskId)     # -1
        todayQuest, activeLv = getTodayQuest(userId)
        quest = todayQuest.get(taskId, {})
        rewards = _processQuestReward(userId, quest)                # quest.get("rewards", [])
        code = util.addRewards(userId, rewards, "DTASK_REWARD")
        taskLevel = quest.get("taskLevel", 0)
        # 更新周奖励的星级
        finishedWeekStar = _incrDailyQuestWeekStar(userId, taskLevel)
        questData = getDailyQuestData(userId)
        finishedStar = questData.get("finishedStar", 0)
        all = len(questInfo) == len(config.getDailyQuestGroupOrder())
        dailyQuestRewardFinishedStars = config.getDailyQuestRewardFinishedStars("day", all)
        for star in dailyQuestRewardFinishedStars:
            if finishedStar >= star > finishedStar - taskLevel:
                module_tip.addModuleTipEvent(userId, "task", star)
                break
        dailyQuestRewardFinishedWeekStars = config.getDailyQuestRewardFinishedStars("week", all)
        for star in dailyQuestRewardFinishedWeekStars:
            if finishedWeekStar >= star > finishedWeekStar - taskLevel:
                module_tip.addModuleTipEvent(userId, "task", star)
                break
        from newfish.entity.event import DailyTaskRewardEvent
        from newfish.game import TGFish
        event = DailyTaskRewardEvent(userId, FISH_GAMEID, taskId, taskLevel)
        TGFish.getEventBus().publishEvent(event)
    mo = MsgPack()
    mo.setCmd("task")
    mo.setResult("gameId", FISH_GAMEID)
    mo.setResult("userId", userId)
    mo.setResult("action", "questReward")
    mo.setResult("taskId", taskId)
    mo.setResult("rewardflyPos", rewardflyPos)
    mo.setResult("reason", reason)
    if reason == 0:
        mo.setResult("code", code)
        mo.setResult("rewards", rewards)
    router.sendToUser(mo, userId)
Пример #10
0
def _dealTips(userId, mailInfos, mailSenderType):
    """
    更新邮箱小红点
    """
    # 兼容处理老玩家数据。
    module_tip.cancelModuleTipEvent(userId, "mail", 0)
    module_tip.cancelModuleTipEvent(userId, "mail", mailSenderType)
    for mailInfo in mailInfos:
        if mailInfo["state"] == MailState.Default:
            module_tip.addModuleTipEvent(userId, "mail", mailSenderType)
            return
Пример #11
0
def _triggerLevelUpEvent(event):
    userId = event.userId
    userLevel = event.level
    levels = gamedata.getGameAttrJson(userId, config.FISH_GAMEID,
                                      GameData.levelRewards, [])
    clientId = util.getClientId(userId)
    levelRewards = config.getLevelRewards(clientId)
    for level, rewards in levelRewards.iteritems():
        if rewards and level not in levels:
            if level <= userLevel:
                module_tip.addModuleTipEvent(userId, "levelRewards", level)
            break
Пример #12
0
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)
Пример #13
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)
Пример #14
0
def _triggerPrizeWheelSpinEvent(event):
    userId = event.userId
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            if conf["type"] == AchieveType.LevelPrizeWheelNum:  # 轮盘次数
                taskClass = FishAchievementTask(userId, conf)
                if taskClass.addProgress(1):
                    module_tip.addModuleTipEvent(userId, "achievement",
                                                 int(honorId))
Пример #15
0
def _incQuestValue(userId, taskType, incVlaue, resetTime=0, fishPool=0, fpMultiple=0, gunX=0):
    """
    更新每日任务进度并检测;任务是否完成
    """
    if util.getDayStartTimestamp(resetTime) != util.getDayStartTimestamp(int(time.time())):
        resetTime = weakdata.getDayFishData(userId, "resetTime")
        if not resetTime:
            weakdata.setDayFishData(userId, WeakData.resetTime, int(time.time()))
            refreshDailyQuestData(userId)
    key = _getUserDailyQuestKey(userId)
    newValue = daobase.executeUserCmd(userId, "HINCRBY", key, str(taskType), incVlaue)
    confs = config.getDailyQuestConfsByType(taskType)
    todayQuest, _ = getTodayQuest(userId)
    questInfo = getUserQuestInfoData(userId)
    update = False
    for conf in confs:
        if conf and conf["taskId"] in todayQuest:
            if isinstance(conf.get("fishPool"), list) and conf.get("fishPool") and fishPool not in conf.get("fishPool"):
                continue
            if conf.get("fpMultiple", 0) > 0 and fpMultiple < conf.get("fpMultiple", 0):
                continue
            if conf.get("gunX", 0) > 0 and gunX < conf.get("gunX", 0):
                continue
            taskId = conf["taskId"]
            targetsNum = conf.get("targetsNum")
            process, state = questInfo.get(str(taskId), [0, QuestTaskState.Normal])
            # if newValue >= targetsNum and newValue - incVlaue < targetsNum:
            if state == QuestTaskState.Normal:
                update = True
                questInfo[str(taskId)] = [process + incVlaue, state]
                if process < targetsNum <= process + incVlaue:
                    questInfo[str(taskId)] = [targetsNum, QuestTaskState.Complete]
                    quest = todayQuest[taskId]
                    _sendQuestFinished(userId, quest)
                    module_tip.addModuleTipEvent(userId, "task", taskId)
                    taskLevel = conf.get("taskLevel", 0)
                    # questData = getDailyQuestData(userId)
                    # finishedStar = questData.get("finishedStar", 0)
                    # dailyQuestRewardFinishedStars = config.getDailyQuestRewardFinishedStars()
                    # for star in dailyQuestRewardFinishedStars:
                    #     if finishedStar >= star and finishedStar - taskLevel < star:
                    #         module_tip.addModuleTipEvent(userId, "task", star)
                    #         break
                    # 发送完成任务事件
                    from newfish.entity.event import DailyTaskFinishEvent
                    from newfish.game import TGFish
                    event = DailyTaskFinishEvent(userId, FISH_GAMEID, int(conf["taskId"]), taskLevel)
                    TGFish.getEventBus().publishEvent(event)
                    bireport.reportGameEvent("BI_NFISH_GE_TASK_FINISHED", userId, FISH_GAMEID, 0,
                                             0, int(conf["taskId"]), int(taskLevel), 0, 0, [], util.getClientId(userId))
    if update:
        setUserQuestInfoData(userId, questInfo)
Пример #16
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
Пример #17
0
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")
Пример #18
0
def _matchOverEvent(event):
    userId = event.userId
    rank = event.rank
    roomId = event.bigRoomId
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            if conf["type"] == AchieveType.TotalRankMatch:  # 回馈赛累计排名
                taskClass = FishAchievementTask(userId, conf)
                if rank <= conf["target"]["top"] and taskClass.addProgress(1):
                    module_tip.addModuleTipEvent(userId, "achievement",
                                                 int(honorId))
Пример #19
0
def _triggerMainQuestSectionFinishEvent(event):
    """
    主线任务章节完成事件
    """
    userId = event.userId
    honorId = event.honorId / 100
    honorLevel = event.honorId % 100
    allHonorConf = config.getHonorConf()
    honorInfo = getHonor(userId, honorId)
    for _, honorConf in allHonorConf.iteritems():
        if (honorConf["honorType"] == 2 and honorConf["honorId"] == honorId
                and honorLevel > honorInfo[INDEX_LEVEL]):
            addNewHonor(userId, honorId, honorLevel)
            module_tip.addModuleTipEvent(userId, "achievement", int(honorId))
            break
Пример #20
0
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")
Пример #21
0
def _gainChestEvent(event):
    from newfish.entity.chest.chest_system import ChestFromType
    userId = event.userId
    chestFrom = event.chestFrom
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            if conf["type"] == AchieveType.ReceiveWeekChest:  # 领取周宝箱
                if chestFrom == ChestFromType.Daily_Quest_Week_Chest:
                    taskClass = FishAchievementTask(userId, conf)
                    if taskClass.addProgress(1):
                        module_tip.addModuleTipEvent(userId, "achievement",
                                                     int(honorId))
Пример #22
0
def updateUnReadNotice(userId, clientId, allConfigs=None, readNotice=None):
    """
    是否有未读的活动
    """
    hasUnRead = False
    tipsIds = []
    allConfigs = allConfigs or _getAllNoticeConfigs(userId, clientId)
    readNotice = readNotice or _getNoticeReadInfo(userId)
    for notConf in allConfigs:
        if notConf["Id"] not in readNotice:
            hasUnRead = True
            tipsIds.append(notConf["Id"])
    module_tip.resetModuleTip(userId, "noticenew")
    if hasUnRead:
        tipsIds.append(0)
    module_tip.addModuleTipEvent(userId, "noticenew", tipsIds)
Пример #23
0
def addProgress(userId, taskLevel):
    """
    增加任务进度
    """
    taskIds = []
    returnerMission = getReturnerMissionData(userId)
    if returnerMission:
        # 未解锁的任务进度为最后一个已解锁的任务进度
        notUnlockedProgress = 0
        for taskConf in config.getReturnerMissionConf("tasks"):
            if taskConf["taskId"] in returnerMission["tasks"]:
                taskData = returnerMission["tasks"][taskConf["taskId"]]
                if taskData["state"] == 1:
                    taskData["progress"] += taskLevel
                    taskData["progress"] = min(taskData["progress"], taskConf["value"])
                    notUnlockedProgress = taskData["progress"]
                    if taskData["progress"] >= taskConf["value"]:
                        taskData["state"] = 2
                        taskData["progress"] = taskConf["value"]
                elif taskData["state"] == 0:
                    taskData["progress"] = max(taskData["progress"], notUnlockedProgress)
                if taskData["state"] == 2:
                    taskIds.append(taskConf["taskId"])
        gamedata.setGameAttr(userId, FISH_GAMEID, GameData.returnerMission, json.dumps(returnerMission))
    taskIds and module_tip.addModuleTipEvent(userId, "returnerMission", taskIds)
Пример #24
0
def _starfishChangeEvent(event):
    userId = event.userId
    count = event.count
    roomId = event.roomId
    if not roomId:
        return
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            if conf["type"] == AchieveType.CollectStar:  # 海星收集
                taskClass = FishAchievementTask(userId, conf)
                if taskClass.addProgress(count):
                    module_tip.addModuleTipEvent(userId, "achievement",
                                                 int(honorId))
Пример #25
0
def _RankOverEvent(event):
    userId = event.userId
    rank = event.rank
    rankId = event.rankId
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            if conf["type"] == AchieveType.TotalRankRobbery:  # 比赛获得胜利
                targetInfo = conf.get("target")
                if int(rankId) == int(targetInfo.get("rankId")):
                    taskClass = FishAchievementTask(userId, conf)
                    if taskClass.addProgress(1):
                        module_tip.addModuleTipEvent(userId, "achievement",
                                                     int(honorId))
Пример #26
0
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")
Пример #27
0
def addShareGroupId(userId, groupId):
    """
    添加分享到群的群ID
    """
    shareGroupIds = weakdata.getDayFishData(userId, "shareGroupIds", [])
    if ftlog.is_debug():
        ftlog.debug("addShareGroupId", userId, groupId, shareGroupIds)
    if groupId and groupId not in shareGroupIds:
        shareGroupIds.append(groupId)
        weakdata.setDayFishData(userId, WeakData.shareGroupIds, json.dumps(shareGroupIds))
        shareGroupTotalCount = config.getCommonValueByKey("shareGroupTotalCount")
        isReceiveReward = weakdata.getDayFishData(userId, "shareGroupReward", 0)
        if not isReceiveReward and len(shareGroupIds) >= shareGroupTotalCount:
            weakdata.setDayFishData(userId, WeakData.shareGroupReward, 1)
            if not util.isVersionLimit(userId):
                module_tip.addModuleTipEvent(userId, "invite", 0)
        getShareTaskInfo(userId)
Пример #28
0
def _EnterRoomEvent(userId, roomId, isMath):
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            if conf["type"] == AchieveType.JoinMatch and isMath:  # 参加比赛多少场
                targetRoomId = conf["target"].get("roomId")
                if not targetRoomId or targetRoomId == roomId:
                    taskClass = FishAchievementTask(userId, conf)
                    if taskClass.addProgress(1):
                        module_tip.addModuleTipEvent(userId, "achievement",
                                                     int(honorId))
            elif conf["type"] == AchieveType.EnterRobbery:  # 参加招财模式多少次
                if util.getRoomTypeName(
                        roomId) == config.FISH_ROBBERY:  # 获取房间名
                    taskClass = FishAchievementTask(userId, conf)
                    if taskClass.addProgress(1):
                        module_tip.addModuleTipEvent(userId, "achievement",
                                                     int(honorId))
Пример #29
0
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)
Пример #30
0
def _updateSkillProgress(userId):
    """更新技能数据"""
    achConfigs = getAchievementAllTask(userId)
    if not achConfigs:
        return
    levelMap, starMap = fish_achievement_task.getSkillMaxLevel(userId)
    honorIds = []
    for honorId, tasksConf in achConfigs.iteritems():
        for _, conf in tasksConf.iteritems():
            taskClass = FishAchievementTask(userId, conf)
            if conf["type"] == AchieveType.SkillUp:  # 技能最高级
                targetInfo = conf["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)