Items are a generic representation on anything which can be stored inside an Inventory (Weapons, Armor, Consumables,...).
Items are managed inside an Inventory Component, or an EquipedItems Component. EquipedItems Component inherits from the Inventory Component and lets the Player equip weapons and armors.
To represent an Item in the World you have different possibilities :
The ItemDisplayer Component lets you visualize ItemInWorlds' labels in the player HUD. You can toggle the visibility by pressing Alt.
Items are data driven. Which means that if you want to add a specific item to your game, you can just modify infos in Data Tables.
because items are data driven, there is a specific way to reference an Item : The ItemKey.
The ItemKey is a struct composed of a Item Class, Name and Seed :
The class represents the class of the Item, the name represents the name of the row corresponding to this item in the item data table.
The seed has been added in V2. It gathers a seed (an integer used to create unique datas for an item) and a "level" for the item. Thoses two infos are used to create unique datas for the item if you want to create procedural items.
An example of itemKey, if you want to access a non-procedural item which is a "basic sword" :
ItemKey {
Class : ItemWeapon,
Name : "BasicSword",
Seed : {Seed : -1, Level : 0} // Not used because here
}
Each time you want informations about this specific item, you can use the functions from the ItemUtilities Function Library (They take an ItemKey as input).
Here is a diagram showing you all the classes which participate to the item system :
The ItemKey allows you to access item static datas. All these datas are gathered from the data tables by the functions of the ItemUtilities function lib. The Data Tables are stored in the ItemGlobalDatas Object which is itself stored inside the GameInstance of the game.
If you want to put an item inside a slot, the item SlotTypes variable needs to match with the filters of the slot.
If all the filters in the SlotTypes array of the item are contained inside the filters of the slot, then the item is accepted.
For example, the EquipedItem Component uses different filters so that you can only drop items with filters : "Equipment, Head" for the head, "Equipment, Body" for the body and so on.
If you set the boolean value "IsUsable" of the Item, then you'll have the Use option showed when you right click an item inside the inventory.
It's the UseItem() function of the Item which will handle the action to be performed when you click the Use option. If you made a custom Item, don't forget to override this function if you want your Item to be usable.
Here is the UseItem() function of the ItemWeapon :
Since the V2, you can proceduraly create new items ! The procedural generation randomly pick the type of item to spawn and fill its stats, taking into account the player level. This gives you a way to add inifite variations of items for things like weapons, armors.
The main table which setup rules for the procedural generation is the [Weapon/Armor]ProceduralSettings. Here is the diagram of all the tables which are used to provide settings for the procedural generation.
As you can see, the normal "[Weapon]ItemDatas" table is also used in the procedural generation. This means that you can fill this table with all the items you want to use and then create a [weapon]ProceduralSettings to setup rules to procedurally create items from several rows of the [Weapon]ItemDatas table.