0
\$\begingroup\$

Recently I started developing my tiny html5 multiplayer game made in Node.js, Express.js, MongoDB(Mongoose), Socket.io and using Phaser.js.

I am quite new to these frameworks and especially new to database structuring/management.

My struggle comes when I think about how can I structure the database to store things as player username, password and general preferences (basic user info); and then things as player equipment such as items and currency.

I can figure out how to do the code part but what I do not know how to handle is the process I should follow.

I thought of the structure like so:

//Users Document
{
    "_id": "randId",
    "username": "ArthurConan",
    "password": "aquamarine12345",
    "credits": 20,
    "equipment": [
        {
            "name": "Sword of the Forsaken",
            "equiped": true,
            "slot": "weapon",
            "id": "itemId",
        },
        {
            "name": "Meteor Katana",
            "equiped": false,
            "id": "itemId"
        }
    ]
}

//Items Document
{
    "_id": "itemId",
    "name": "Sword of the Forsaken",
    "atk": 1400,
    "value": 500
},
{
    "_id": "itemId",
    "name": "Meteor Katana",
    "atk": 200,
    "value": 50
}

As I am using MongoDB the structure would be more or less similar to that.

With the code above then I would do the following: - Player Registers and his basic info(username, password, ...) is added to the database and he will also get one weapon to start with. - Player adventures into my world and gathers credits and equipment. Those items are stored in his inventory. - Player can equip/use/sell/destroy/upgrade some of those items. Upgraded items will have its stats upgraded based on preset stats.

As a side-note I would like you to know I am not the best at explaining myself, I hope you understand what I am trying to achieve. Also any suggestions are appreciated, have a good day :)

\$\endgroup\$
  • \$\begingroup\$ This looks like a reasonable starting point to my eye (though I'm not sure why you'd store the item name in two places?) What's your next step that you need help with? Have you run into trouble implementing the structure above? Or implemented it and found it fails to meet your expectations in some way? Or are you just looking to validate your approach? That latter question may be better suited to the code review StackExchange site. \$\endgroup\$ – DMGregory Nov 9 '16 at 0:08
  • \$\begingroup\$ @DMGregory right now I am still coding the registration process but I wanted to know if my approach was any good. I am storing them in two places so I can get the name, search its stats and send them to the client where the player will play the actual game. As I am saying this I am realising that I could just use the item ID......... I thought about posting it on StackOverflow but I did not know if this question was suitable to be asked there. Anyway, thank you :') \$\endgroup\$ – UzendayoNE Nov 9 '16 at 0:47
  • \$\begingroup\$ Is the user stuck to use a single character? Why not separate them so user can log other avatars when they like? For equipment, you can have identical storage tied to user but accessible to all character. This is different from character equipment which is located at characters container. \$\endgroup\$ – Ace Caserya Nov 9 '16 at 1:12
  • \$\begingroup\$ @AlvinCaseria there will be various playable characters and they will share storage but not all items can be equipped by different characters because I'm planing to make different classes which will use different types of weapons like Bows, Swords, Assault Rifles, ... \$\endgroup\$ – UzendayoNE Nov 9 '16 at 1:20
  • \$\begingroup\$ Suggested structure below, it worked for me before. \$\endgroup\$ – Ace Caserya Nov 9 '16 at 1:41
1
\$\begingroup\$

A suggestion: Data storage structure

User
|  |-- id
|  |-- password
|  |-- storage password
|  |-- etc
|
Characters
|  |-- name
|  |-- id (User)
|  |-- Equipment1 on head //store item by equipping
|  |-- Equipment2 as armor
|  |-- etc
|
Storage
|  |--id_storage
|  |--id (User)
|  |--id_item (Item) //store item by storage
|  |--etc
|
Item
   |--id_item
   |--item name
   |--item description
   |--etc
\$\endgroup\$
  • \$\begingroup\$ Looks like a nice organised way of doing it. Thanks for the suggestion, I will try it :') \$\endgroup\$ – UzendayoNE Nov 9 '16 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.