Skip to content

Handling Inventory & Items

Bryan Abrams edited this page Aug 5, 2013 · 3 revisions

engine::items::BaseItem represents information that EVERY item has. These properties can be applied to every item and can be set in the constructor of the inhereiting object (to be for example your own definition. See game::items::ArrowItem

String _name;        // The name of the item to be displayed in UI's, dialogues, etc.
String _description; // The description to be shown upon inspection of the item
double _value;       // How much is 1 unit of this item worth?
bool _stackable;     // Should this item stack with other items of the same name in an inventory?

These are the virtual functions avaliable to EVERY item derived from engine::items::BaseItem

// This function will be called when the item enters the inventory of an actor
virtual void onPickup( actor::ActorBase * aOwner ) = 0;

// This function will be called when the item leaves the inventory of an actor
virtual void onDrop( actor::ActorBase * aOwner ) = 0;

// When the players look at the item this function will be called.
virtual void onInspect( actor::ActorBase * aOwner ) = 0;

Features of Inventory

  • Items with the same name can be stacked in the inventory.
  • Items will have a weight unit of some sort.
  • Item weight will have an effect on players concerning possible actions.
  • Will the player have a limited number of slots to store items?
  • Will there be a max stackable amount of one item?

Discussion on Engine Level:

  • What should the interface of the virtual functions from above have? Assume the player has a health potion and uses it, it's his own item so it's easy. However if a player uses a "grenade" or a "bomb" that effects a range, how should this be considered? - (All items will have "onUpdate" event thats triggered every frame. This is good way to have a trigger for example, most items just ignore this)
  • Where should the action for each item be defined? via engine::item::BaseItem or engine::item::BaseItemContainer?
  • Which object should actually be calling the virtual functions, engine::item::BaseItem, engine::item::BaseItemContainer, engine::item::BaseActor, or etc etc. - virtual functions are called where they are needed. (onDrop is called from somewhere in the actor code for example)
  • I also remember hearing about giving engine::world::Room an inventory. Accessing inventory in a room logically will probably be different than via an actor (for example, multiple items on the same tile). Keep this in consideration. - Actor inventory is just a list of items for that. Room inventory is a list of all items in that room, with x/y coordinates. So for example when rendering, we only get items from the room we are in)

Clone this wiki locally