Items Package#
Submodules#
Item Class#
- class game.common.items.item.Item(value: int = 1, durability: int | None = None, quantity: int = 1, stack_size: int = 1)[source]#
Bases:
GameObjectItem Class Notes:
Items have 4 different attributes: value, durability, quantity, stack-size.
- Value:
The value of an item can be anything depending on the purpose of the game. For example, if a player can sell an item to a shop for monetary value, the value attribute would be used. However, this value may be used for anything to better fit the purpose of the game being created.
- Durability:
The value of an item’s durability can be either None or an integer. If durability is an integer, the stack size must be 1. Think of Minecraft and the mechanics of tools. You can only have one sword with a durability (they don’t stack).
If the durability is equal to None, it represents the item having infinite durability. The item can now be stacked with others of the same type. In the case the game being created needs items without durability, set this attribute to None to prevent any difficulties.
- Quantity and Stack Size:
These two work in tandem. Fractions (x/y) will be used to better explain the concept.
Quantity simply refers to the amount of the current item the player has. For example, having 5 gold, 10 gold, or 0 gold all work for representing the quantity.
The stack_size represents how much of an item can be in a stack. Think of this like the Minecraft inventory system. For example, you can have 64 blocks of dirt, and if you were to gain one more, you would have a new stack starting at 1.
In the case of items here, it works with the avatar.py file’s inventory system (refer to those notes on how the inventory works in depth). The Minecraft analogy should help understand the concept.
To better show this, quantity and stack size work like the following fraction model: quantity/stack_size.
The quantity can never be 0 and must always be a minimum of 1. Furthermore, quantity cannot be greater than the stack_size. So 65/64 will not be possible.
- Pick Up Method:
When picking up an item, it will first check the item’s ObjectType. If the Object interacted with is not of the ObjectType ITEM enum, an error will be thrown.
Otherwise, the method will check if the picked up item will be able to fit in the inventory. If some of the item’s quantity can be picked up and a surplus will be left over, the player will be pick up what they can.
Then, the same item they picked up will have its quantity modified to be what is left over. That surplus of the item is then returned to allow for it to be placed back where it was found on the map.
If the player can pick up an item without any inventory issues, the entire item and its quantity will be added.
Refer to avatar.py for a more in-depth explanation of how picking up items work with examples.
- property durability: int | None#
- property quantity: int#
- property stack_size: int#
- property value: int#