Tuesday, 7 February 2017

Player Inventory

Initiating the Player's Inventory
The 'PlayerInventory' class will be attached to the player's character game object and will store a list of objects the player has collected.

The list will be read-only meaning I will need to create multiple methods to manipulate the list. The class will require a method to add an item, merge an item, remove an item and retrieve read-only copies of the items.

Add Item:
The 'add item' method is fairly straight-forward. It is a method called whenever the player collects an item. The method requires an item variable within it's parameters. The collected item will contain a database index useful for retrieving an item from the database and adding it into the parameters.

The 'add item' and 'merge item' methods are combined into the same method therefore I need to do some exception handling before I can add an item to the inventory. I need to ensure no copy of the item exists within the database. If the item already exists I need to simply merge the quantities assuming the combined quantities do not exceed the limit.



Sort Items:
I have created four methods used to differentiate the items into the four item sub-groups. The four methods return all items, weapons, gear and quest items. This is useful when I need to draw the items into the inventory. I can just call the appropriate method and retrieve all the objects I require. 


The class checks all the items in the inventory for a certain class type. As I created multiple classes that inherit from the same parent class I was able to add all inheritance classes to the same list. This design pays off now as it's simple to search and retrieve specific class types. 

No comments:

Post a Comment