示例#1
0
 def hasTailorClothingTicket(self, av, npc):
     for questDesc in av.quests:
         questId, fromNpcId, toNpcId, rewardId, toonProgress = questDesc
         questType = Quests.getQuestClass(questId)
         # See if this NPC is the one we are supposed to deliver to
         # You by definition have the item
         if (questType == Quests.DeliverItemQuest):
             if Quests.npcMatches(toNpcId, npc):
                 rewardId = Quests.getAvatarRewardId(av, questId)
                 rewardType = Quests.getRewardClass(rewardId)
                 if (rewardType == Quests.ClothingTicketReward):
                     return 1
                 elif (rewardType == Quests.TIPClothingTicketReward):
                     return 2
                 else:
                     # Reward was not a clothing ticket
                     continue
             else:
                 # NPC does not match
                 continue
         else:
             # Not a deliver item quest
             continue
     # Did not find it, avId does not have clothing ticket on this tailor
     return 0
示例#2
0
 def removeClothingTicket(self, av, npc):
     for questDesc in av.quests:
         questId, fromNpcId, toNpcId, rewardId, toonProgress = questDesc
         questClass = Quests.getQuestClass(questId)
         # See if this NPC is the one we are supposed to deliver to
         # You by definition have the item
         if (questClass == Quests.DeliverItemQuest):
             if Quests.npcMatches(toNpcId, npc):
                 rewardId = Quests.getAvatarRewardId(av, questId)
                 rewardClass = Quests.getRewardClass(rewardId)
                 if (rewardClass == Quests.ClothingTicketReward
                         or rewardClass == Quests.TIPClothingTicketReward):
                     # This section is much like completeQuest()
                     av.removeQuest(questId)
                     # Update the toon with the reward. This reward does nothing right
                     # now but it may in the future, so it is the right thing to do
                     reward = Quests.getReward(rewardId)
                     reward.sendRewardAI(av)
                     # Bump the reward
                     self.incrementReward(av)
                     return 1
                 else:
                     # Reward was not a clothing ticket
                     continue
             else:
                 # NPC does not match
                 continue
         else:
             # Not a deliver item quest
             continue
     # Did not find it, avId does not have clothing ticket on this tailor
     return 0
示例#3
0
    def requestInteract(self, toonId, npc):
        toon = self.air.doId2do.get(toonId)
        if not toon:
            return
        for index, quest in enumerate(self.__toonQuestsList2Quests(toon.quests)):
            questId, fromNpcId, toNpcId, rewardId, toonProgress = toon.quests[index]
            isComplete = quest.getCompletionStatus(toon, toon.quests[index], npc)
            if isComplete != Quests.COMPLETE:
                continue
            if toonId in self.air.tutorialManager.avId2fsm.keys():
                self.air.tutorialManager.avId2fsm[toonId].demand('Tunnel')
            if isinstance(quest, Quests.DeliverGagQuest):
                track, level = quest.getGagType()
                toon.inventory.setItem(track, level, toon.inventory.numItem(track, level) - quest.getNumGags())
                toon.b_setInventory(toon.inventory.makeNetString())
            nextQuest = Quests.getNextQuest(questId, npc, toon)
            if nextQuest == (Quests.NA, Quests.NA):
                if isinstance(quest, Quests.TrackChoiceQuest):
                    npc.presentTrackChoice(toonId, questId, quest.getChoices())
                    return
                rewardId = Quests.getAvatarRewardId(toon, questId)
                npc.completeQuest(toonId, questId, rewardId)
                self.completeQuest(toon, questId)
                self.giveReward(toon, rewardId)
                return
            self.completeQuest(toon, questId)
            nextQuestId = nextQuest[0]
            nextRewardId = Quests.getFinalRewardId(questId, 1)
            nextToNpcId = nextQuest[1]
            self.npcGiveQuest(npc, toon, nextQuestId, nextRewardId, nextToNpcId)
            return

        if len(self.__toonQuestsList2Quests(toon.quests)) >= toon.getQuestCarryLimit():
            self.notify.debug('Rejecting toonId %d because their quest inventory is full.' % toonId)
            npc.rejectAvatar(toonId)
            return
        if toonId in self.air.tutorialManager.avId2fsm.keys():
            if toon.getRewardHistory()[0] == 0:
                self.npcGiveQuest(npc, toon, 101, Quests.findFinalRewardId(101)[0], Quests.getQuestToNpcId(101), storeReward=True)
                self.air.tutorialManager.avId2fsm[toonId].demand('Battle')
                return
        tier = toon.getRewardHistory()[0]
        if Quests.avatarHasAllRequiredRewards(toon, tier):
            if not Quests.avatarWorkingOnRequiredRewards(toon):
                if tier != Quests.LOOPING_FINAL_TIER:
                    tier += 1
                toon.b_setRewardHistory(tier, [])
            else:
                self.notify.debug('Rejecting toonId %d because they are still working on their current tier.' % toonId)
                npc.rejectAvatarTierNotDone(toonId)
                return
        suitableQuests = Quests.chooseBestQuests(tier, npc, toon)
        if not suitableQuests:
            self.notify.debug('Rejecting toonId %d because there are no quests available!' % toonId)
            npc.rejectAvatar(toonId)
            return
        npc.presentQuestChoice(toonId, suitableQuests)
    def requestInteract(self, toonId, npc):
        toon = self.air.doId2do.get(toonId)
        if not toon:
            # TODO: Flag suspicious. They shouldn't have got this far.
            return

        # Check if the toon has any quests to turn in.
        for index, quest in enumerate(self.__toonQuestsList2Quests(toon.quests)):
            questId, fromNpcId, toNpcId, rewardId, toonProgress = toon.quests[index]
            isComplete = quest.getCompletionStatus(toon, toon.quests[index], npc)
            if isComplete != Quests.COMPLETE:
                # This quest isn't complete, skip.
                continue
            # If we're in the Toontorial, move to the next step.
            if toonId in self.air.tutorialManager.avId2fsm.keys():
                self.air.tutorialManager.avId2fsm[toonId].demand('Tunnel')
            # Take away gags if it's a DeliverGagQuest.
            if isinstance(quest, Quests.DeliverGagQuest):
                track, level = quest.getGagType()
                toon.inventory.setItem(track, level, toon.inventory.numItem(track, level) - quest.getNumGags())
                toon.b_setInventory(toon.inventory.makeNetString())
            # Check if the ToonTask has more quests to complete.
            nextQuest = Quests.getNextQuest(questId, npc, toon)
            if nextQuest == (Quests.NA, Quests.NA):
                # No more quests in the current ToonTask!
                if isinstance(quest, Quests.TrackChoiceQuest):
                    # TrackTrainingRewards are a little different, as we now
                    # have to display the gag track selection menu.
                    npc.presentTrackChoice(toonId, questId, quest.getChoices())
                    return
                # This function is pretty weird... not sure why it's even here...
                # But I'll include it just in case... (TMS says: "idk about this
                # one, maybe a single quest can have different rewards?")
                rewardId = Quests.getAvatarRewardId(toon, questId)
                npc.completeQuest(toonId, questId, rewardId)
                self.completeQuest(toon, questId)
                self.giveReward(toon, rewardId)
                return
            else:
                # We have another quest to go, sigh.
                self.completeQuest(toon, questId)
                nextQuestId = nextQuest[0]
                nextRewardId = Quests.getFinalRewardId(questId, 1)
                nextToNpcId = nextQuest[1]
                self.npcGiveQuest(npc, toon, nextQuestId, nextRewardId, nextToNpcId)
                return

        # We had no quests to hand in, maybe they want to take out a new ToonTask?
        if len(self.__toonQuestsList2Quests(toon.quests)) >= toon.getQuestCarryLimit():
            # Nope, they already have the maximum amount of concurring quests they
            # can carry. Reject them.
            self.notify.debug("Rejecting toonId %d because their quest inventory is full." % toonId)
            npc.rejectAvatar(toonId)
            return

        # Are we in the Toontorial?
        if toonId in self.air.tutorialManager.avId2fsm.keys():
            # Are we speaking to Tom?
            if toon.getRewardHistory()[0] == 0:
                self.npcGiveQuest(npc, toon, 101, Quests.findFinalRewardId(101)[0], Quests.getQuestToNpcId(101), storeReward=True) # FIXME please, i have no idea if this is correct
                self.air.tutorialManager.avId2fsm[toonId].demand('Battle')
                return

        # Are they eligible for a tier upgrade?
        tier = toon.getRewardHistory()[0]
        if Quests.avatarHasAllRequiredRewards(toon, tier):
            # They have all the rewards needed for the next tier.
            if not Quests.avatarWorkingOnRequiredRewards(toon):
                # Check to make sure they are not on the LOOPING_FINAL_TIER
                if tier != Quests.LOOPING_FINAL_TIER:
                    tier += 1

                # Set the tier
                toon.b_setRewardHistory(tier, [])
            else:
                # They're eligible for a tier upgrade, but haven't finished all
                # of their required ToonTasks yet.
                self.notify.debug("Rejecting toonId %d because they are still working on their current tier." % toonId)
                npc.rejectAvatarTierNotDone(toonId)
                return

        # Time to give them a list of "suitable" tasks!
        suitableQuests = Quests.chooseBestQuests(tier, npc, toon)
        if not suitableQuests:
            # Uh oh! There's no suitable quests for them at the moment... reject.
            self.notify.debug("Rejecting toonId %d because there are no quests available!" % toonId)
            npc.rejectAvatar(toonId)
            return

        # Tell the NPC to select some quests from the generated list.
        npc.presentQuestChoice(toonId, suitableQuests)
        return
示例#5
0
    def completeQuest(self, av, npc, questId):
        self.notify.info("completeQuest: avId: %s, npcId: %s, questId: %s" %
                         (av.getDoId(), npc.getNpcId(), questId))

        # If this is a track choice, we do not actually complete the quest,
        # We present the track choice gui. This can be cancelled which will
        # not complete the quest.
        questClass = Quests.getQuestClass(questId)
        if questClass == Quests.TrackChoiceQuest:
            self.notify.debug(
                "completeQuest: presentTrackChoice avId: %s, npcId: %s, questId: %s"
                % (av.getDoId(), npc.getNpcId(), questId))
            quest = Quests.getQuest(questId)
            tracks = quest.getChoices()
            npc.presentTrackChoice(av.getDoId(), questId, tracks)
            # Do not increment reward until avatar has chosen track
            # This happens in avatarChoseTrack
            return

        # If this is a deliver gag quest, we need to actually remove the
        # gags delivered from the player's inventory
        if questClass == Quests.DeliverGagQuest:
            self.notify.debug(
                "completeQuest: presentTrackChoice avId: %s, npcId: %s, questId: %s"
                % (av.getDoId(), npc.getNpcId(), questId))
            # Use the items from the inventory now
            quest = Quests.getQuest(questId)
            track, level = quest.getGagType()
            for i in range(0, quest.getNumGags()):
                av.inventory.useItem(track, level)
            av.d_setInventory(av.inventory.makeNetString())

        # See if this quest is part of a multiquest. If it is, we assign
        # the next part of the multiquest.
        nextQuestId, nextToNpcId = Quests.getNextQuest(questId, npc, av)
        eventLogMessage = "%s|%s|%s|%s" % (questId, npc.getNpcId(),
                                           questClass.__name__, nextQuestId)

        if nextQuestId == Quests.NA:
            rewardId = Quests.getAvatarRewardId(av, questId)
            # Update the toon with the reward
            reward = Quests.getReward(rewardId)

            # Clothing quests should have been handled by the Tailor.
            # Just to make sure
            if (reward.getType() == Quests.ClothingTicketReward):
                self.notify.warning(
                    "completeQuest: rogue ClothingTicketReward avId: %s, npcId: %s, questId: %s"
                    % (av.getDoId(), npc.getNpcId(), questId))
                npc.freeAvatar(av.getDoId())
                return

            # Nope, this is the end, dish out the reward
            av.removeQuest(questId)
            # TODO: put this in the movie
            reward.sendRewardAI(av)
            # Full heal for completing a quest
            av.toonUp(av.maxHp)
            # Tell the npc to deliver the movie which will
            # complete the quest, display the reward, and do nothing else
            npc.completeQuest(av.getDoId(), questId, rewardId)
            # Bump the reward
            self.incrementReward(av)

            eventLogMessage += "|%s|%s" % (reward.__class__.__name__,
                                           reward.getAmount())

        else:
            # Full heal for completing part of a multistage quest
            av.toonUp(av.maxHp)
            # The user is not presented with a choice here
            av.removeQuest(questId)
            nextRewardId = Quests.getQuestReward(nextQuestId, av)
            if npc.getHq():
                fromNpcId = Quests.ToonHQ
            else:
                fromNpcId = npc.getNpcId()
            self.assignQuest(av.getDoId(),
                             fromNpcId,
                             nextQuestId,
                             nextRewardId,
                             nextToNpcId,
                             startingQuest=0)
            npc.assignQuest(av.getDoId(), nextQuestId, nextRewardId,
                            nextToNpcId)
            eventLogMessage += "|next %s" % (nextQuestId)

        self.air.writeServerEvent('questComplete', av.getDoId(),
                                  eventLogMessage)
示例#6
0
    def requestInteract(self, toonId, npc):
        toon = self.air.doId2do.get(toonId)
        if not toon:
            # TODO: Flag suspicious. They shouldn't have got this far.
            return

        # Check if the toon has any quests to turn in.
        for index, quest in enumerate(self.__toonQuestsList2Quests(toon.quests)):
            questId, fromNpcId, toNpcId, rewardId, toonProgress = toon.quests[index]
            isComplete = quest.getCompletionStatus(toon, toon.quests[index], npc)
            if isComplete != Quests.COMPLETE:
                # This quest isn't complete, skip.
                continue
            # If we're in the Toontorial, move to the next step.
            if toonId in self.air.tutorialManager.avId2fsm.keys():
                self.air.tutorialManager.avId2fsm[toonId].demand('Tunnel')
            # Take away gags if it's a DeliverGagQuest.
            if isinstance(quest, Quests.DeliverGagQuest):
                track, level = quest.getGagType()
                toon.inventory.setItem(track, level, toon.inventory.numItem(track, level) - quest.getNumGags())
                toon.b_setInventory(toon.inventory.makeNetString())
            # Check if the ToonTask has more quests to complete.
            nextQuest = Quests.getNextQuest(questId, npc, toon)
            if nextQuest == (Quests.NA, Quests.NA):
                # No more quests in the current ToonTask!
                if isinstance(quest, Quests.TrackChoiceQuest):
                    # TrackTrainingRewards are a little different, as we now
                    # have to display the gag track selection menu.
                    npc.presentTrackChoice(toonId, questId, quest.getChoices())
                    return
                # This function is pretty weird... not sure why it's even here...
                # But I'll include it just in case... (TMS says: "idk about this
                # one, maybe a single quest can have different rewards?")
                rewardId = Quests.getAvatarRewardId(toon, questId)
                npc.completeQuest(toonId, questId, rewardId)
                self.completeQuest(toon, questId)
                self.giveReward(toon, rewardId)
                return
            else:
                # We have another quest to go, sigh.
                self.completeQuest(toon, questId)
                nextQuestId = nextQuest[0]
                nextRewardId = Quests.getFinalRewardId(questId, 1)
                nextToNpcId = nextQuest[1]
                self.npcGiveQuest(npc, toon, nextQuestId, nextRewardId, nextToNpcId)
                return

        # We had no quests to hand in, maybe they want to take out a new ToonTask?
        if len(self.__toonQuestsList2Quests(toon.quests)) >= toon.getQuestCarryLimit():
            # Nope, they already have the maximum amount of concurring quests they
            # can carry. Reject them.
            self.notify.debug("Rejecting toonId %d because their quest inventory is full." % toonId)
            npc.rejectAvatar(toonId)
            return

        # Are we in the Toontorial?
        if toonId in self.air.tutorialManager.avId2fsm.keys():
            # Are we speaking to Tom?
            if toon.getRewardHistory()[0] == 0:
                self.npcGiveQuest(npc, toon, 101, Quests.findFinalRewardId(101)[0], Quests.getQuestToNpcId(101), storeReward=True) # FIXME please, i have no idea if this is correct
                self.air.tutorialManager.avId2fsm[toonId].demand('Battle')
                return

        # Are they eligible for a tier upgrade?
        tier = toon.getRewardHistory()[0]
        if Quests.avatarHasAllRequiredRewards(toon, tier):
            # They have all the rewards needed for the next tier.
            if not Quests.avatarWorkingOnRequiredRewards(toon):
                # Check to make sure they are not on the LOOPING_FINAL_TIER
                if tier != Quests.LOOPING_FINAL_TIER:
                    tier += 1

                # Set the tier
                toon.b_setRewardHistory(tier, [])
            else:
                # They're eligible for a tier upgrade, but haven't finished all
                # of their required ToonTasks yet.
                self.notify.debug("Rejecting toonId %d because they are still working on their current tier." % toonId)
                npc.rejectAvatarTierNotDone(toonId)
                return

        # Time to give them a list of "suitable" tasks!
        suitableQuests = Quests.chooseBestQuests(tier, npc, toon)
        if not suitableQuests:
            # Uh oh! There's no suitable quests for them at the moment... reject.
            self.notify.debug("Rejecting toonId %d because there are no quests available!" % toonId)
            npc.rejectAvatar(toonId)
            return

        # Tell the NPC to select some quests from the generated list.
        npc.presentQuestChoice(toonId, suitableQuests)
        return