Ejemplo n.º 1
0
    def parseResponse(self):
        # First parse for errors
        notEnoughPattern = PatternManager.getOrCompilePattern("notEnoughToUse")
        if notEnoughPattern.search(self.responseText):
            raise Error.Error("You don't have that many of that item.",
                              Error.ITEM_NOT_FOUND)

        notMultiPattern = PatternManager.getOrCompilePattern("notMultiUse")
        if notMultiPattern.search(self.responseText):
            raise Error.Error("You cannot multi-use that item.",
                              Error.WRONG_KIND_OF_ITEM)

        # Find out what happened
        items = ParseResponseUtils.parseItemsReceived(self.responseText,
                                                      self.session)
        if len(items) > 0:
            self.responseData["items"] = items

        meat = ParseResponseUtils.parseMeatGainedLost(self.responseText)
        if meat != 0:
            self.responseData["meat"] = meat

        hp = ParseResponseUtils.parseHPGainedLost(self.responseText)
        if hp != 0:
            self.responseData["hp"] = hp

        mp = ParseResponseUtils.parseMPGainedLost(self.responseText)
        if mp != 0:
            self.responseData["mp"] = mp

        drunk = ParseResponseUtils.parseDrunkGained(self.responseText)
        if drunk != 0:
            self.responseData["drunk"] = drunk

        adventures = ParseResponseUtils.parseAdventuresGained(
            self.responseText)
        if adventures != 0:
            self.responseData["adventures"] = adventures

        effects = ParseResponseUtils.parseEffectsGained(self.responseText)
        if len(effects) > 0:
            self.responseData["effects"] = effects
Ejemplo n.º 2
0
    def parseResponse(self):
        notBarrelPattern = PatternManager.getOrCompilePattern('usedBarrel')
        noAdventuresPattern = PatternManager.getOrCompilePattern('noAdventures')
        if notBarrelPattern.match(self.responseText):
            raise Error.Error("Barrel already opened or doesn't exist. (#%s)" % self.requestData['smash'], Error.INVALID_ACTION)
        if noAdventuresPattern.match(self.responseText):
            raise Error.Error("You don't have enough adventures to smash that", Error.NOT_ENOUGH_ADVENTURES)

        url = self.response.url
        if url.find("/fight.php") >= 0:
            # Get the monster's name.
            self.responseData["adventureType"] = "combat"
            monsterNamePattern = PatternManager.getOrCompilePattern('monsterName')
            monsterNameMatch = monsterNamePattern.search(self.responseText)
            self.responseData["monsterName"] = monsterNameMatch.group(1)

            # Check to see if the fight was won or lost.
            fightWonPattern = PatternManager.getOrCompilePattern('fightWon')
            if fightWonPattern.search(self.responseText):
                self.responseData["fightWon"] = True
            else:
                fightLostPattern = PatternManager.getOrCompilePattern('fightLost')
                if fightLostPattern.search(self.responseText):
                    self.responseData["fightLost"] = True

            # Get items, meat, and substats gained. We always need to check these since they can
            # happen at any point during the fight.
            self.responseData["items"] = ParseResponseUtils.parseItemsReceived(self.responseText, self.session)
            self.responseData["meat"] = ParseResponseUtils.parseMeatGainedLost(self.responseText)
            self.responseData["substats"] = ParseResponseUtils.parseSubstatsGainedLost(self.responseText)

        item = ParseResponseUtils.parseItemsReceived(self.responseText, self.session)
        if len(item) > 0:
            self.responseData["items"] = item

        hp = ParseResponseUtils.parseHPGainedLost(self.responseText)
        if hp != 0:
            self.responseData["hp"] = hp
Ejemplo n.º 3
0
 def parseResponse(self):
     self.responseData["meat"] = ParseResponseUtils.parseMeatGainedLost(
         self.responseText)
Ejemplo n.º 4
0
    def parseResponse(self):
        response = {}
        response["meat"] = ParseResponseUtils.parseMeatGainedLost(self.responseText)

        self.responseData = response
    def parseResponse(self):
        """
        Default response method for adventuring.
        """

        shouldNotBeHerePattern = PatternManager.getOrCompilePattern(
            'userShouldNotBeHere')
        if shouldNotBeHerePattern.search(self.responseText):
            raise Error.Error("Unable to adventure. You should not be here.",
                              Error.INVALID_LOCATION)

        url = self.response.url
        if url.find("/fight.php") >= 0:
            # See if the user tried to perform an invalid action.
            twiddlingThumbsPattern = PatternManager.getOrCompilePattern(
                'twiddlingThumbs')
            if twiddlingThumbsPattern.search(self.responseText):
                raise Error.Error(
                    "Could not perform action. Thumbs were twiddled.",
                    Error.INVALID_ACTION)

            # Get the monster's name.
            self.responseData["adventureType"] = "combat"
            monsterNamePattern = PatternManager.getOrCompilePattern(
                'monsterName')
            monsterNameMatch = monsterNamePattern.search(self.responseText)
            self.responseData["monsterName"] = monsterNameMatch.group(1)

            # Check to see if the fight was won or lost.
            fightWonPattern = PatternManager.getOrCompilePattern('fightWon')
            if fightWonPattern.search(self.responseText):
                self.responseData["fightWon"] = True
            else:
                fightLostPattern = PatternManager.getOrCompilePattern(
                    'fightLost')
                if fightLostPattern.search(self.responseText):
                    self.responseData["fightLost"] = True

            # Get items, meat, and substats gained. We always need to check these since they can
            # happen at any point during the fight.
            self.responseData["items"] = ParseResponseUtils.parseItemsReceived(
                self.responseText, self.session)
            self.responseData["meat"] = ParseResponseUtils.parseMeatGainedLost(
                self.responseText)
            self.responseData[
                "substats"] = ParseResponseUtils.parseSubstatsGainedLost(
                    self.responseText)

            # The same goes for HP and MP
            self.responseData["hp"] = ParseResponseUtils.parseHPGainedLost(
                self.responseText)
            self.responseData["mp"] = ParseResponseUtils.parseMPGainedLost(
                self.responseText)

        elif url.find("/choice.php") >= 0:
            self.responseData["adventureType"] = "choice"
            choiceIdentifierPattern = PatternManager.getOrCompilePattern(
                'choiceIdentifier')
            choiceIdentifierMatch = choiceIdentifierPattern.search(
                self.responseText)
            if choiceIdentifierMatch:
                choiceNamePattern = PatternManager.getOrCompilePattern(
                    'choiceName')
                self.responseData["choiceId"] = choiceIdentifierMatch.group(1)
                self.responseData["choiceName"] = choiceNamePattern.search(
                    self.responseText).group(1)
            else:
                self.responseData[
                    "items"] = ParseResponseUtils.parseItemsReceived(
                        self.responseText, self.session)
                self.responseData[
                    "meat"] = ParseResponseUtils.parseMeatGainedLost(
                        self.responseText)
                self.responseData[
                    "substats"] = ParseResponseUtils.parseSubstatsGainedLost(
                        self.responseText)

        elif url.find("/adventure.php") >= 0:
            self.responseData["adventureType"] = "noncombat"
            noncombatNamePattern = PatternManager.getOrCompilePattern(
                'noncombatName')
            noncombatNameMatch = noncombatNamePattern.search(self.responseText)
            if noncombatNameMatch:
                self.responseData["noncombatName"] = noncombatNameMatch.group(
                    1)
            self.responseData["items"] = ParseResponseUtils.parseItemsReceived(
                self.responseText, self.session)
            self.responseData["meat"] = ParseResponseUtils.parseMeatGainedLost(
                self.responseText)
            self.responseData[
                "substats"] = ParseResponseUtils.parseSubstatsGainedLost(
                    self.responseText)
        else:
            raise Error.Error("Adventure URL not recognized: %s" % url,
                              Error.REQUEST_GENERIC)