Esempio n. 1
0
    def autoPopulateInventory(self):
        """ create creature inventory
           * randomly pick the number of items from the numOfItemsDropped list
           * for each of those, randomly pick an objNum from the itemCatalog
           * for each of those, load the object and add it to the inventory
           * typically run at creature load time
        """
        if not self._permanent:
            self.clearInventory()

        # Randomly select the itemCount
        itemCount = int(getRandomItemFromList(self._numOfItemsCarried))

        if not itemCount:  # 0 items carried
            return True

        for itemNum in range(1, itemCount + 1):  # +1 due to exclusive ranges
            itemId = getRandomItemFromList(self._itemCatalog)
            if not itemId:
                continue
            if "/" not in itemId:
                continue

            dLog("creature.autoPopulateInventory: obj = " + itemId)
            oType, oNum = itemId.split("/")
            obj1 = ObjectFactory(oType, oNum)
            obj1.load()
            self.addToInventory(obj1)
        return True
Esempio n. 2
0
    def run(self, charObj):
        """ Drop weapon and escape to an adjoining room """
        roomNumList = []
        roomNumList += list(charObj.getRoom().getAllAdjacentRooms())

        if len(roomNumList) == 0:
            self.charMsg(
                charObj,
                "You try to run, but " + "there are no escape routes.\n")
            return False

        escapeRoom = getRandomItemFromList(roomNumList)

        # drop weapon
        if not charObj.isAttackingWithFist():
            charObj.discardsEquippedWeapon()
            cMsg = "You drop your weapon and run!"
            (article, possessive, predicate) = charObj.getArticle("self")
            oMsg = charObj.getName(
            ) + " drops " + possessive + " weapon and runs away!"
        else:
            cMsg = "You run away!"
            oMsg = charObj.getName() + " runs away!"

        self.charMsg(charObj, cMsg + "\n")
        self.othersInRoomMsg(charObj, charObj.getRoom(), oMsg + "\n")

        self.joinRoom(escapeRoom, charObj)
        self.charMsg(charObj, charObj.getRoom().display(charObj))
Esempio n. 3
0
    def getParleyTxt(self):
        """ Returns a string containing the creatures response to a parley """
        buf = ""

        msg = getRandomItemFromList(self._parleyTxt)
        if not msg:
            buf += self.describe(article="The") + " does not respond"
        elif self._parleyAction.lower() == "none":
            # None is special, because it doesn't add "says".  This is useful
            # for some responses where a different verb is desired.
            buf += self.describe(article="The") + " " + msg
        else:
            buf += self.describe(article="The") + " says, " + msg.capitalize()

        if re.search("/W$", buf):
            # Add punctuation if it's not already included
            buf += "."
        return buf
Esempio n. 4
0
 def getRandomInventoryItem(self):
     if not self.getInventory():
         return None
     return getRandomItemFromList(self.getInventory())
Esempio n. 5
0
 def getParleyTeleportRoomNum(self):
     if len(self._parleyTeleportRooms) == 0:
         return random.randint(1, 300)
     return getRandomItemFromList(self._parleyTeleportRooms)