Question about Items

Hello @pspeed !

I have a question about items. Could you guide me how to store them?

For example this screenshot from internet: http://images.mmosite.com/sro/images/content/2009-04-13/magic_items1_1.jpg

Right now I have a MainCharacter which has BagComponent. BagComponent stores Item.class objects.
But possibly i should store items as Component.class objects?
What will be your recomendation to store items? As Components or as Custom objects?

Thank you.

The way I did it is similar to how one would link items to a character in a database.

Take for example orders containing many articles.
Then you would have the Order grouping them together and storing core information about the order, for example which customer it belongs to.
Then you would have the OrderRow holds information about article and amount and points towards the order to denote that it belongs to a certain order.

In the ES perspective, the approach I took was:

Items are handled as entities (should be?), to allow for full customization.
An item can have an InventoryComponent which is shared between the Player and Item.
As such the InventoryComponent here works as the Order in the database example.

By letting items be entities, you can set/remove alot of properties, for example:
ItemSlotIndexComponent
ItemStackSizeComponent
ItemSlotTypeComponent (which slots can it be stored in?)

I don’t really understand the question, actually.

And is your bag component attached to the children and pointing to the parent? (That’s the usual/best way.)

If this were my game, each item would be an entity with some kind of ContainedBy component that pointed to its container.

if i understand question correctly:
we did it like this: Map<int slot, Map<int item_id, int count>>;
and in db it looks like this: (int 11)player_id (int 11)slot (int 11)item_id (int 11)cnt, uniq on player_id+slot

@eraslt said: if i understand question correctly: we did it like this: Map<int slot, Map<int item_id, int count>>; and in db it looks like this: (int 11)player_id (int 11)slot (int 11)item_id (int 11)cnt, uniq on player_id+slot

He’s asking specifically about an entity system solution.

In Mythruna, I have an InContainer component: InContainer( EntityId parentId )

…and a ContainerPosition component: ContainerPosition( int x, int y )

Stacks are also containers and so need no special handling other than limiting the stack size… which is a function of the UI and a component on the “object type” entity. There’s no reason the ContainerSize couldn’t be stored right on the stack entity but I don’t do it that way.

What’s confusing me about your question is what you mean by “store”, though. Do you mean in the data structure sense of storing on disk?

Hey guys thanks for answering.

@pspeed i meant how to store Items in Player’s inventory.

As i see you store Items as Entities. But is it ok if i will store items as Components?
For example, a player has BagComponent which has a list of ItemComponent objects.
Edited: Or represent an Item as an Entity is more powerful?

@pspeed another small question for you according the ES:
I cannot put EntityId class to spatial’s UserData. Should I use Long class instead of EntityId?
If i will use Long class then i have to create a new EntityID object every time. Is it ok for performance?

Entities are nouns. Components are adjectives.

Of course items are entities. The are things with a bunch of “adjectives”. Icon, location, container, bonuses, name, description… all components.

Yes, storing a long is fine for performance… but if you are retrieving it often then you might be doing something wrong. For example, I use it for finding the entity for a picked object but I don’t know that I’d do the conversion every frame on update… I’ve also never needed to. That would be a sign of something backwards.

1 Like
@pspeed said: Entities are nouns. Components are adjectives.

Of course items are entities. The are things with a bunch of “adjectives”. Icon, location, container, bonuses, name, description… all components.

Yes, storing a long is fine for performance… but if you are retrieving it often then you might be doing something wrong. For example, I use it for finding the entity for a picked object but I don’t know that I’d do the conversion every frame on update… I’ve also never needed to. That would be a sign of something backwards.

Thank you a lot! Now i get clear way to go!

I use collision checking for NPCs when they move. I think i’ll extend RigidBody and put EntityId there.