Inventory Schema
Database tabellen voor het inventory systeem.
Overzicht
Het inventory systeem gebruikt een container-gebaseerde aanpak:
- Spelers hebben containers (rugzakken, pouches)
- Containers bevatten items in slots
- Daarnaast zijn er resources (valuta, grondstoffen) zonder slots
Player
│
├── PlayerContainer (max 5)
│ └── ContainerItem (per slot)
│ └── ItemDefinition (referentie)
│
├── PlayerResource (geen limiet)
│
└── StorageItem (bank/chest)
└── StorageLocation
Tabellen
item_definition
Master tabel met alle item definities.
#[table(name = item_definition, public)]
pub struct ItemDefinition {
#[primary_key]
pub item_id: String, // "honey_jar", "oak_seed"
pub category: String, // "food", "seed", "tool", "container"
pub display_name: String, // "Honingpot"
pub description: String, // "Zoete honing van de bijen"
pub icon_path: String, // "items/honey_jar.png"
pub max_stack: u32, // 1 voor tools, 99 voor seeds
pub is_tradeable: bool,
pub rarity: u8, // 0=common, 1=uncommon, 2=rare, 3=legendary
}
| Veld | Type | Beschrijving |
|---|---|---|
item_id | String (PK) | Unieke identifier |
category | String | Item categorie |
max_stack | u32 | Maximale stack grootte |
rarity | u8 | 0-3 zeldzaamheid |
container_type
Types containers die spelers kunnen hebben.
#[table(name = container_type, public)]
pub struct ContainerType {
#[primary_key]
pub type_id: String, // "starter_bag", "large_backpack"
pub display_name: String, // "Starter Rugzak"
pub slot_count: u8, // 6, 8, 12, 16, 20, 24, 32
pub icon_path: String,
}
Voorbeelden:
| type_id | display_name | slot_count |
|---|---|---|
| starter_bag | Starter Rugzak | 8 |
| leather_backpack | Leren Rugzak | 12 |
| adventure_pack | Avonturen Rugzak | 16 |
| pouch_small | Kleine Buidel | 4 |
player_container
Containers die een speler bezit (max 5).
#[table(name = player_container, public)]
pub struct PlayerContainer {
#[primary_key]
#[auto_inc]
pub id: u64,
pub owner: Identity,
pub container_type: String, // FK naar container_type
pub slot_index: u8, // 0-4 positie in UI
pub is_equipped: bool, // Primary backpack?
}
container_item
Items in een container slot.
#[table(name = container_item, public)]
pub struct ContainerItem {
#[primary_key]
#[auto_inc]
pub id: u64,
pub container_id: u64, // FK naar player_container
pub slot: u8, // 0 tot slot_count-1
pub item_id: String, // FK naar item_definition
pub quantity: u32,
}
player_resource
Resources en valuta (geen slots, alleen hoeveelheden).
#[table(name = player_resource, public)]
pub struct PlayerResource {
#[primary_key]
#[auto_inc]
pub id: u64,
pub owner: Identity,
pub resource_type: String, // "eikels", "beukenootjes", "hout"
pub amount: u64, // Geen limiet
}
Resource Types:
| Type | Beschrijving | Gebruik |
|---|---|---|
| eikels | Premium valuta | Zeldzame items kopen |
| beukenootjes | Basis valuta | Algemene aankopen |
| hout | Bouwmateriaal | Crafting, bouwen |
| steen | Bouwmateriaal | Crafting, bouwen |
| mest | Farming materiaal | Gewassen voeden |
| potgrond | Farming materiaal | Planten |
storage_location
Opslag locaties (bank, chest).
#[table(name = storage_location, public)]
pub struct StorageLocation {
#[primary_key]
pub location_id: String, // "bank", "home_chest"
pub display_name: String,
pub slot_count: u16, // Bank kan groot zijn
pub requires_unlock: bool,
}
storage_item
Items in opslag.
#[table(name = storage_item, public)]
pub struct StorageItem {
#[primary_key]
#[auto_inc]
pub id: u64,
pub owner: Identity,
pub location_id: String, // FK naar storage_location
pub slot: u16,
pub item_id: String,
pub quantity: u32,
}
Relaties
┌─────────────────┐ ┌─────────────────┐
│ ContainerType │ │ ItemDefinition │
│─────────────────│ │─────────────────│
│ type_id (PK) │ │ item_id (PK) │
│ slot_count │ │ max_stack │
└────────┬────────┘ └────────┬────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ PlayerContainer │ │ ContainerItem │
│─────────────────│ │─────────────────│
│ id (PK) │──────▶│ container_id │
│ owner │ │ slot │
│ container_type │ │ item_id ────────┘
│ is_equipped │ │ quantity │
└─────────────────┘ └─────────────────┘
Queries
Speler's inventory laden
-- Containers
SELECT * FROM player_container WHERE owner = :identity ORDER BY slot_index
-- Items per container
SELECT * FROM container_item WHERE container_id IN (
SELECT id FROM player_container WHERE owner = :identity
)
Resources laden
SELECT * FROM player_resource WHERE owner = :identity
Reducers
Zie Inventory Reducers voor:
add_item_to_container- Item toevoegenmove_item- Item verplaatsenadd_resource- Resource toevoegenspend_resource- Resource uitgeven