Skip to content

Abstract Item

mitsudz edited this page Aug 13, 2024 · 4 revisions

AbstractItem

The AbstractItem class represents the abstract super class from which all in-game items must inherit from. There is some important base functionality enabled for all items:

  • All items are given a name and (unique up to item name) item code. This will (in future) allow for identification, sorting and searching of items (particularly within the inventory) by item code or name. In particular, version 2 (in future) of abstract item will require that all item codes/names are added to a json file and a test will be added to ensure these are unique.
  • All items are given a stack limit and quantity. This allows multiple items to be represented by a single item (ie 5 apples do not require 5 apple items - just a single apple). The limit represents the maximum number of this item that can be held at once (e.g, in an inventory), and the quantity represents the number of the item currently held. Default behaviour if no limit or quantity is given is to assume there is exactly 1 of the item and it cannot be stacked. Note - this functionality can be used to implement items with durability, (e.g. a weapon with a maximum durability (limit) and remaining durability (quantity)).
  • Rendering of the item will be enabled (in future) for each item.
  • Other functionality includes helper functions to add more items to the current item (ie increase the quantity); to check how many items can be added; and also to check whether the item has been fully consumed (quantity is 0).
  • All sub-classes must override the useItem function - this is the function which allows an item to have an in-game effect (this class is useless if useItem is not implemented correctly). Using an item requires first defining an item usage context - this is a wrapper around the inputs to allow different items to take in different inputs - see page on ItemUsageContext before creating or using items.
Clone this wiki locally