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 testEquip(self):
        equipmentList = ["Armor/1", "Weapon/1"]

        gameCmdObj = self.getGameCmdObj()

        for itemId in equipmentList:
            objType, objId = itemId.split("/")
            obj = ObjectFactory(objType, objId)
            name = obj.getName()
            self.getCharObj().addToInventory(obj)
            logger.info("Command: use " + name)
            assert not gameCmdObj.runcmd("use " + name)
Esempio n. 3
0
 def createObject(self, num=99999, type="Portal", name="portal"):
     obj = ObjectFactory(type, num)
     if not obj:
         logger.error("Could not instanciate object type " + type)
     obj._name = name
     obj._article = "a"
     obj._singledesc = name
     obj._pluraldesc = name + "s"
     obj._longdesc = "A long " + name
     obj._weight = 5
     obj._value = 100
     return obj
Esempio n. 4
0
    def getPermanent(self, permId):
        """ Returns an object, given the objectID """
        itemObj = None
        (objType, objId) = permId.split("/")

        if objType.lower() == "creature":
            itemObj = Creature(objId)
        elif isObjectFactoryType(objType.lower()):
            itemObj = ObjectFactory(objType, objId)
        else:
            logger.error("Can not determine object type.")
            return None

        if itemObj:
            if itemObj.load():
                return itemObj
            else:
                logger.error(
                    "Could not load object "
                    + permId
                    + " with type "
                    + itemObj.getType()
                )
        else:
            logger.error(
                "Could not instanciate object "
                + permId
                + " with type="
                + objType
                + "and id="
                + str(objId)
            )

        return None
Esempio n. 5
0
    def getItemObj(self, itemStr, id1, id2=""):
        """ given return an existing object, or None if it doesn't exist """
        if isRoomFactoryType(itemStr.lower()):
            itemObj = RoomFactory(itemStr, id1)
        elif itemStr.lower() == "character":
            itemObj = Character(None, id2)
            itemObj.setName(id1)
        elif itemStr.lower() == "creature":
            itemObj = Creature(id1)
        elif isObjectFactoryType(itemStr.lower()):
            itemObj = ObjectFactory(itemStr, id1)
        elif itemStr.lower() == "account":
            itemObj = Account()
            itemObj.email = id1
        else:
            print("Can not determine object type.")
            return None

        if not itemObj:
            msg = "Object doesn't exist.  Aborting..."
            print(msg + "\n")
            logger.warning(msg)
            return None
        if not itemObj.load():
            if itemObj.getId() == 0:
                msg = "Couldn't load object and ID is 0.  Aborting..."
                print(msg + "\n")
                logger.warning(msg)
                return None
            else:
                itemObj._isNew = True
        return itemObj
Esempio n. 6
0
 def object_init():
     obj = ObjectFactory.createPlain(0, len(nodes) + 2)
     return obj.pointer
Esempio n. 7
0
 def array_init(length):
     array = ObjectFactory.createArray(length)
     return array.pointer
Esempio n. 8
0
 def object_init():
     obj = ObjectFactory.createPlain(0, len(nodes) + 2)
     return obj.pointer
Esempio n. 9
0
 def array_init(length):
     array = ObjectFactory.createArray(length)
     return array.pointer