def addItemToIndex(self, id, index, count=1):
		# Check parameters before initiation
		if self.countIsValid(items.getItemByID(id), count) is GlobalConstants.INVENTORY_OPERATION_INVALID_COUNT:
			return GlobalConstants.INVENTORY_OPERATION_INVALID_COUNT, None
		# Item exists in the space requested
		if not self.isSpaceEmpty(index):
			# item requested to be added is the same as the slot it is going in
			if self.inventory[index].getID() == id:
				# item is stackable (CHANGE THIS WHEN REAL ITEMS IMPLEMENTED)
				if self.inventory[index].getMaxStack() > 0:
					newCount = count
					# Do not let the count overflow
					if count > self.inventory[index].getMaxStack():
						newCount = self.inventory[index].getMaxStack()
					updateResult, updatedItem = self.updateItem(self.inventory[index], index, newCount)
					self.inventory[index] = updatedItem
					return updateResult, updatedItem

		item = items.getNewItemByID(id)

		if item is None:
			return GlobalConstants.INVENTORY_OPERATION_ITEM_NONEXISTENT, None

		if self.indexIsValid(index) is GlobalConstants.INVENTORY_OPERATION_INVALID_INDEX:
			return GlobalConstants.INVENTORY_OPERATION_INVALID_INDEX, None
		setupResult, setupItem = self.setupItem(item, index, count)
		self.inventory[index] = setupItem
		return setupResult, setupItem
예제 #2
0
 def removeItem(self, itemID, itemIndex=-1, count=1):
     if itemIndex != -1:
         result = self.inventoryManagement.removeItemAtIndex(
             itemIndex, count)
     else:
         result = self.inventoryManagement.removeItem(itemID, count)
     if result is GlobalConst.INVENTORY_OPERATION_OK:
         if self.client:
             self.client.onReqItemList(self.itemList, self.equipItemList)
             DEBUG_MSG('Removed %i %s to %s inventory.' %
                       (count, items.getItemByID(itemID).getName(),
                        self.playerName))
     else:
         DEBUG_MSG('Failed to remove %i %i to %s inventory' %
                   (count, itemID, self.playerName))
         DEBUG_MSG('Result: ', result)
	def addItem(self, id, count=1):
		remainingCount = count
		itemAdded = False
		for i in range(len(self.inventory)):
			item = self.inventory[i]
			# Blank space
			blankSpaceResult = self.isSpaceEmpty(i)
			# Operations are finished, No items left to add
			if remainingCount == 0:
				break
			# Blank Space
			if blankSpaceResult is GlobalConstants.INVENTORY_OPERATION_OK:
				# Create new item in blank space
				newItem = items.getItemByID(id)
				amountToAdd = remainingCount
				if remainingCount > newItem.getMaxStack():
					amountToAdd = newItem.getMaxStack()
				addItemResult, updatedBlankItem = self.addItemToIndex(id, i, amountToAdd)
				self.inventory[i] = updatedBlankItem
				remainingCount -= amountToAdd
				if addItemResult is GlobalConstants.INVENTORY_OPERATION_OK:
					itemAdded = True
			# Non-Blank Space
			elif blankSpaceResult is not GlobalConstants.INVENTORY_OPERATION_OK and item.getID() is id and remainingCount > 0:
				amountCanAdd = item.getMaxStack() - item.getCount()
				amountToAdd = remainingCount
				if remainingCount > amountCanAdd:
					amountToAdd = amountCanAdd
				finalAmountToAdd = amountToAdd + item.getCount()
				# Get updated item
				addItemResult, updatedItem = self.updateItem(item, i, finalAmountToAdd)
				# Update failed, discontinue add item procedure
				if addItemResult is not GlobalConstants.INVENTORY_OPERATION_OK:
					break
				# Set updated item
				self.inventory[i] = updatedItem
				remainingCount -= amountToAdd
				if addItemResult is GlobalConstants.INVENTORY_OPERATION_OK:
					itemAdded = True
			else:
				continue
		if itemAdded is True:
			return GlobalConstants.INVENTORY_OPERATION_OK
		return addItemResult
예제 #4
0
    def addItemToIndex(self, id, index, count=1):
        overflowed = False
        # Check parameters before initiation
        if self.countIsValid(
                items.getItemByID(id),
                count) is GlobalConst.INVENTORY_OPERATION_INVALID_COUNT:
            return GlobalConst.INVENTORY_OPERATION_INVALID_COUNT, None
        # Item exists in the space requested
        if not self.isSpaceEmpty(index):
            # item requested to be added is the same as the slot it is going in
            if self.inventory[index].getID() == id:
                # item is stackable
                if self.inventory[index].getStackable(
                ) or self.inventory[index].getMaxStack() > 0:
                    newCount = count
                    # Do not let the count overflow
                    if count > self.inventory[index].getMaxStack():
                        newCount = self.inventory[index].getMaxStack()
                        overflowed = True
                    updateResult, updatedItem = self.updateItem(
                        self.inventory[index], index, newCount)
                    self.inventory[index] = updatedItem
                    self.setItemInOuroItemList(updatedItem, index)
                    return updateResult, updatedItem

        item = items.getNewItemByID(id)

        if item is None:
            return GlobalConst.INVENTORY_OPERATION_ITEM_NONEXISTENT, None

        if self.indexIsValid(
                index) is GlobalConst.INVENTORY_OPERATION_INVALID_INDEX:
            return GlobalConst.INVENTORY_OPERATION_INVALID_INDEX, None
        setupResult, setupItem = self.setupItem(item, index, count)
        if overflowed:
            setupResult = GlobalConst.INVENTORY_OPERATION_OVERFLOWED
        self.inventory[index] = setupItem
        self.setItemInOuroItemList(setupItem, index)
        return setupResult, setupItem
예제 #5
0
def InventoryTest6():
    inv = ItemManagement()
    item = items.getItemByID(2)
    item.use(1)
예제 #6
0
 def addItem(self, id, count=1):
     remainingCount = count
     itemAdded = False
     addItemResult = None
     if items.getItemByID(id) is None:
         return GlobalConst.INVENTORY_OPERATION_ITEM_NONEXISTENT
     completelyFull = self.isInventoryCompletelyFull()
     if completelyFull is GlobalConst.INVENTORY_OPERATION_COMPLETELY_FULL:
         return completelyFull
     for i in range(len(self.inventory)):
         item = self.inventory[i]
         # Blank space
         blankSpaceResult = self.isSpaceEmpty(i)
         # Operations are finished, No items left to add
         if remainingCount == 0:
             break
         # Blank Space
         if blankSpaceResult is GlobalConst.INVENTORY_OPERATION_OK:
             # Create new item in blank space
             newItem = items.getItemByID(id)
             amountToAdd = remainingCount
             if remainingCount > newItem.getMaxStack():
                 amountToAdd = newItem.getMaxStack()
             addItemResult, updatedBlankItem = self.addItemToIndex(
                 id, i, amountToAdd)
             # Catch any errors occuring in this procedure
             if addItemResult is not GlobalConst.INVENTORY_OPERATION_OK:
                 return addItemResult
             self.inventory[i] = updatedBlankItem
             self.setItemInOuroItemList(updatedBlankItem, i)
             remainingCount -= amountToAdd
             if addItemResult is GlobalConst.INVENTORY_OPERATION_OK:
                 itemAdded = True
         # Non-Blank Space
         elif blankSpaceResult is not GlobalConst.INVENTORY_OPERATION_OK and item.getID(
         ) is id and remainingCount > 0:
             amountCanAdd = item.getMaxStack() - item.getCount()
             amountToAdd = remainingCount
             if remainingCount > amountCanAdd:
                 amountToAdd = amountCanAdd
             finalAmountToAdd = amountToAdd + item.getCount()
             # Get updated item
             addItemResult, updatedItem = self.updateItem(
                 item, i, finalAmountToAdd)
             # Update failed, discontinue add item procedure
             if addItemResult is not GlobalConst.INVENTORY_OPERATION_OK:
                 break
             # Set updated item
             self.inventory[i] = updatedItem
             self.setItemInOuroItemList(updatedItem, i)
             remainingCount -= amountToAdd
             if addItemResult is GlobalConst.INVENTORY_OPERATION_OK:
                 itemAdded = True
         else:
             continue
     if itemAdded is True:
         return GlobalConst.INVENTORY_OPERATION_OK
     else:
         full = self.isInventoryFull()
         if full is GlobalConst.INVENTORY_OPERATION_FULL:
             return full
     return addItemResult