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. 

Thursday, 2 February 2017

Creating the item database

Inventory Object Constructor Classes:

Firstly, I need to create a constructor class that will define the properties shared by all objects. A weapon would require stored data determining it's attack however potions would have no such requirement. A potion would require stored data to determine it's quantity; as would the weapon.

There are four data types I believe all objects would require; a name, icon, description and quantity. You may question that items require a value to transact with merchants however quest items wouldn't function in this fashion.

I start by creating an empty class that doesn't inherit from mono-develop. I add in the four data types and then add a public constructor method. This method contains the values required to define the class. It's called while creating a new class instance. I finish by adding multiple virtual methods, known as 'getter' methods, to allow other classes to read the class variables.


I need to create multiple sub-classes that inherit and expand from it to create unique inventory objects. I have created 'armour', 'consumable', 'merchant', 'quest', 'ring' and 'weapon' sub-classes. As all classes operate in the same manner I will explain one of these sub-classes which will provide insight towards how they all operate. I will used the 'consumable' class as the example.

A 'consumable' object is something which can be expended for personal gain. This encapsulates items such as potions, cuisine and drinkable liquids. In order to account for all the multiple usage of these items I need to implement multiple class constructor methods. 

Each constructor will inherit and expand upon the original constructor outlined within the base class. This means a consumable item will contain, minimum, a name, icon, quantity and description. 

If an item is consumed for instant player gains it would require a stat increase value. If an item is consumed for small gains over a period of time it would require a stat increase values and duration time. An item such as an antidote would require neither. It's for this reason I need to implement multiple class constructor methods.


Constructing a database:

This is actually fairly straight-forward therefore I won't explain in too much detail. The short explanation is that as all my methods extend from a base object class therefore I am able to add all sub-class items into the same list. 

This list will be loaded upon start up to store the in-game objects values eliminating the requirement to create items during run-time. I will be able to match the interacted item to an object within the database and store a copy of it to a localised list.