Items - mganzarcik/fabulae GitHub Wiki
UsableItems are items that are not equipped, but can instead be used by the PC to achieve some effect. Each usable has a number of uses defined before the item gets destroyed – the number is considered infinite if it is negative.
UsableItem have a list of Effects associated which describe what happens when the usable is consumed. The Effects are executed all at the same time at the time of use. UsableItem also define the target type for their effects and a projectile that should be rendered (if any).
When using a UsableItem , the player has to define the user of the usable and the target of the usable. These can be the same GameObject. For example, when a PC drinks a potion, she is both the user and the target. If a PC throws a fire potion on a goblin, he is a user, while the goblin is the target.
UsableItem by default do not require any skill level to be used, however, the individual Effects might have different results based on skill levels of the user or target.
Examples:
https://github.com/mganzarcik/fabulae-showcase/blob/master/showcase/items/Apple.xml
https://github.com/mganzarcik/fabulae-showcase/blob/master/showcase/items/RodOfStopMotion.xml
Item groups are used in random tables to tell the table from which pool to pick the item.
One item usually belongs to several ItemGroups, since groups can semantically mean different things – rarity, item type, some item property, etc. For example, the Magical Sword of Really, Really Hot Flames can belong to RareItems, Weapons and MagicalItems.
For example, basic item groups might include:
- CommonItems
- UncommonItems
- RareItems
- UniqueItems
- Armors
- Weapons
- Potions
- SimpleItems
Item groups are technically just named lists of InventoryItem ids. They are all loaded during game startup. They can be defined both in their own files, or on the items themselves. In both cases, the engine will gather all the item group data during the module load.
Random tables can be assigned to inventories to describe what kind of content the inventory might include. Inventories use these tables to calculate what exactly is inside the first time the area containing the inventory is loaded. After that, the inventory is persisted and never gets recalculated again.
Random tables use item groups to define the possible content.
Example random table in an inventory:
<usable>
<inventory>
<backPack>
<item groups="CommonItems, Potions" stackSize="2" />
<item groups="CommonItems, Potions" maxStackSize="3" />
<item groups="SimpleItems" />
<item groups="SimpleItems" />
<item groups="SimpleItems" />
<item groups="CommonItems, Weapons" />
<item id="Apple" />
</backPack>
</inventory>
</usable>
This inventory will contain two common potions in slot 1, one to three common potions in slot 2, 1 simple item in slots 3, 4 and 5 and one common weapon in slot 6. It will also always contain an Apple in slot 7.
When the inventory with this RandomTable becomes loaded, the logic will go through the table and for each item in it, it will make an intersection on all specified item groups and then take a random item from the result. If maxStackSize is defined, is more than 1 and the item is stackable, it will then compute another random number between 1 and the maxStackSize and set the stack size of the selected item to that value. If instead stackSize is defined, it will just set the stack size to that number.