afonsolage / skyon

Sandbox MMORPG
0 stars 0 forks source link

Add inventory to item system #48

Open afonsolage opened 2 years ago

afonsolage commented 2 years ago

Concept

Item system should be a one-system-rule-them-all for items. It should handle the loading of item resources and creation and management of item instances (check #13 for more details).

Inventory

All item instance will exists in a single inventory at any given time. No item instance can live in two or more inventories at the same time, this is to avoid items duplication issues.

In Skyon an item should be available to a player on the following conditions:

Also, Item system should handle inventory, which will be a single container to all inventory related things.

afonsolage commented 2 years ago

Inventory should be persisted on db, since multiples game servers may access the same inventory at a single time, so all inventory operations should be done on db first and replicated to game server.

Inventory table should have the following structure:

CREATE TABLE inventory(
  id bigint primary key generated always as identity,
  owner_id bigint not null,
  owner_type smallint not null,
  slot_count smallint not null default 0,
)

owner_id is who owns the inventory, it can be a NPC, resource node, mob or just a loot_bag owner_type indicates what is the type of the owner

ALTER TABLE item_instance ADD COLUMN inventory_id bigint NOT NULL;
ALTER TABLE item_instance ADD COLUMN inventory_slot smallint NOT NULL;

By adding those two columns on item_instance table we can ensure no duplicated item will ever exists in two inventory at any time.

Also, in order to get items from an given inventory, it's easier to just query by using inventory_id.