Inventories, or a stash of items, exist in many game designs. It may be items that a character carries, or a shop’s items available to buy1.
How to implement items, item pickup, and inventory in a game is a complicated process - here’s some things I’m thinking through.
Items
- similar attributes:
- name: as displayed in game.
- description: as displayed in game - probably tooltip-like.
- texture: for rendering in the game and/or UI
- id: is this strictly necessary? A unique identifier requires an identifier-creation scheme. Maybe a three or four alpha code followed by a number? SWRD001. Should there be metadata here? WEAP or HEAL? Is a pitchfork only a TOOL that a character can use for a job animation or can it inflict damage? “In a bar, I once saw him kill three men… with a pencil.”2
- quantity: I think this is a different type of attribute - part of the inventory itself (stacks) but what about an in-game item on a table - is it a single coin or 12?
- unique attributes:
- healing items: these can inherit from inventory item with the additional field of healing amount3
- any: it would be easy to get too granular when it is probably unnecessary. Maybe it is better to have stat and effect attributes as key: value pairs - then it could be item > effect_item as the hierarchy and anything without an effect is just economic or decorative.
- world item vs inventory item: is the same resource or representation of the item used to display it in the game world and to store it in the inventory?
- item pickup:
- is it automatic: player running into or near it (an area2D interaction in Godot). If not automatic is it a raycast and the player does some input to activate the interaction?
- what if the inventory is full? does the inventory remove the item from the world or does the item remove itself when picked up?
- can the player drop items in the world? How is this handled - right in front of them or can they be placed? Do they persist on level change?
Inventory
- internal model
- represented model - UI
- can items be rearranged? Do they take up a set area of the inventory? Weight limits? Is inventory infinite or limited - how does this affect item pickup?
- multiple inventories for a party or one?
- stacks, max stack size, splitting?
My initial idea is to have a single inventory with limited space and reject items when it is full by not picking them up. Items will be Godot resources inheriting from a common base. I may have a flag if an item can be interacted with, otherwise it is just set dressing. I want the player to decide if they are picking something up so I’ll have an interaction input and maybe I should have an outline shader on objects for when they are “targeted”? (or another interaction UI indicator)
-
In Bethesda’s Creation Engine (Skyrim), shop inventory is held in a hidden chest that the player accesses through the shopping UI. Player inventory and shop inventory are presented side-by-side, and, instead of a different model, someone said, ‘let’s just hide a chest full of goods’. A player can access this chest by clipping through the level with a cheat code and finding the chest, usually below the ground of the shop area. ↩
-
John Wick, 2014 ↩
-
Healing and damaging items can use the same mechanic, with a poison sending a negative amount:
func change_stat(amount: float, stat: String = "Health") -> void: AutoloadStats.stat += amount
↩