Jump to content
  • Advertisement
Sign in to follow this  
WombatTurkey

Is using a GUID (Globally Unique Identifier), a good idea for storing rpg items in the buffer?

This topic is 1082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using nodejs btw. For example, if a player kills a boss and he drops like 10 different items, they all must have a unique key so the player can loot an item if he wants later. Just curious if a GUID is how it's done, or is there another way?

 

Think of POE for example and all their items that are dropped. They all must have a unique key, right? 

Edited by WombatTurkey

Share this post


Link to post
Share on other sites
Advertisement

It might be overkill; if each item really needs to be distinct (because it can be individually modified in some fashion, for example), than a GUID is a simple way to do it. It takes up more space -- almost certainly more than you'll need -- but it does have the nice property of being locally-generatable, without requiring any sort of authoritative source for IDs that other, smaller ID forms may require if they need to be unique.

 

However if items are not distinct -- if you can't modify them, so that once instance of the Shovel of Demonslaying + 2 is always exactly the same as another, then you don't need a GUID. You only need to store the item template that this particular item is derived from. Seven instances of the Shovel are just seven handles referring to the one Shovel template in memory elsewhere.

 

 

 

My game basically has the same feel of POE/D2. You can pick up any item and do whatever you wish to it (yeah, the base ID's are there ofcourse), and once you loot that item, it get inserted into your inventory and saved (then it has it's own auto incremented id), but the buffer part in nodejs memory where all the items are floating around at is very confusing because there is no way to identify each one (if a user decides to loot one). I think your post confirms it basically, I'll move to a GUID for the buffer and then once the item gets inserted to database, it'll have it's own incremental unique id, so that should be fine.

 

I was going to use Date.now() within nodejs, but one problem.. Players (hundreds) will be slashing and killing bosses and loot will be popping in an out like a wild billy goat in the buffer.  There would be a ton of collisions with that. I honestly think GUID is the only way, I wonder how POE and others do it.

 

Thanks for the fast response though, love talking about this on an open forum!

 

Edit: Incremental ID to the rpg_user_items table, not the player.. That would be bad :P.

Edited by WombatTurkey

Share this post


Link to post
Share on other sites

I'm not convinced at all you need GUIDs for this; I know that Guild Wars 2 certainly doesn't. 

 

I feel like the real problem here is with "the buffer part in nodejs memory," which I feel like you don't properly understand. The reason for this is because NodeJS would be basically impossible to use if there was no way to look a thing back up once you have stored it in memory. So unless I'm missing some aspect of this "buffer part" you're talking about, you don't need GUIDs for this. Alternatively, if you're basically referring to not being able to tell which item (on the ground) a user clicks on to loot, that is also not a problem that requires the unique identification of every item using a GUID, as you already have a unique identification of every item (the item itself).

 

I think you should explain your scenario in more detail as it sounds like you're about to go off and make some very poor implementation decisions.

Share this post


Link to post
Share on other sites

I'm not convinced at all you need GUIDs for this; I know that Guild Wars 2 certainly doesn't. 

 

I feel like the real problem here is with "the buffer part in nodejs memory," which I feel like you don't properly understand. The reason for this is because NodeJS would be basically impossible to use if there was no way to look a thing back up once you have stored it in memory. So unless I'm missing some aspect of this "buffer part" you're talking about, you don't need GUIDs for this. Alternatively, if you're basically referring to not being able to tell which item (on the ground) a user clicks on to loot, that is also not a problem that requires the unique identification of every item using a GUID, as you already have a unique identification of every item (the item itself).

 

I think you should explain your scenario in more detail as it sounds like you're about to go off and make some very poor implementation decisions.

 

Aww I understand.

 

For example from my understanding..

 

I have an item_data property in my GAMES object. that item_data property is an object as well.

 

I fill that item_data property up (in the buffer) with all the loot that is being generated from players killing mobs.  I do this because when a player joins a game, the items are sent to them via websockets so the new player see's what items are on the ground.

 

For example, a player kills a boss and it drops 15 items. 7 random white gear, 7 rares and 1 unique.   These items are all fair game to anyone who joins the game as well. So there has to be a way to identify them with a number. I could create them all by doing a insert query with mysql and get the auto increment value which would work, but that would would go against using nodejs in the first place I think. I would use thousands of inserts instead of just storing them in memory until a player clicks on them, I think that's much better performance wise. Finally, if the player loots an item, I insert it to their inventory via mysql and update their buffer.  There just is not a way to identify all of them? Maybe I'm missing something here. But that's the jist of it so far.  

Edited by WombatTurkey

Share this post


Link to post
Share on other sites

I would most definitively not use a GUID for that. Why, to what avail?

 

A GUID has 128 bits and yet is not guaranteed to be unique (the likelihood is compelling, but there is no strict guarantee). Sequential integers take anywhere from 32 to 64 bits and are guaranteed to be unique (until overflow happens). But that's not an issue.

 

Even if a thousand bosses die every second, and each drops 10 lootable items, that's almost 5 days before a puny 32-bit counter overflows. Loot doesn't stay on the ground for 5 days, and you couldn't store 4 giga-items in memory anyway. You won't live to see a 64-bit integer overflow at that rate.

 

Further, do you even need the loot to be individual? I say no.

 

Given your description of being able to pick up an item and do "anything" with it, it's perfectly adaequate to e.g. pick up a "generic template" item and convert that to a unique item as soon as it enters the inventory (or maybe even when it's actually modified!). You can have several different but similar templates with the same human readable name or you can attach both a template plus a modifier to each item if you want some variation (so there exist goblin killing swords +17 and goblin killing swords +18 that you can pick up).

 

But even if you want every single item to be a fully fledged individual item from the start, using a 64-bit sequentially increasing integer will do. Unless you plan to generate more than 10,000 of them every second for the next 5 million years. Mind you, it might be troublesome having a 5 million year uptime on the server.

 

Of course, a GUID will "work fine", but whenever the words "many thousands" appear, you usually want to keep stuff as small as possible.

Edited by samoth

Share this post


Link to post
Share on other sites

I would most definitively not use a GUID for that. Why, to what avail?

 

A GUID has 128 bits and yet is not guaranteed to be unique (the likelihood is compelling, but there is no strict guarantee). Sequential integers take anywhere from 32 to 64 bits and are guaranteed to be unique (until overflow happens). But that's not an issue.

 

Even if a thousand bosses die every second, and each drops 10 lootable items, that's almost 5 days before a puny 32-bit counter overflows. Loot doesn't stay on the ground for 5 days, and you couldn't store 4 giga-items in memory anyway. You won't live to see a 64-bit integer overflow at that rate.

 

Further, do you even need the loot to be individual? I say no.

 

Given your description of being able to pick up an item and do "anything" with it, it's perfectly adaequate to e.g. pick up a "generic template" item and convert that to a unique item as soon as it enters the inventory (or maybe even when it's actually modified!). You can have several different but similar templates with the same human readable name or you can attach both a template plus a modifier to each item if you want some variation (so there exist goblin killing swords +17 and goblin killing swords +18 that you can pick up).

 

But even if you want every single item to be a fully fledged individual item from the start, using a 64-bit sequentially increasing integer will do. Unless you plan to generate more than 10,000 of them every second for the next 5 million years. Mind you, it might be troublesome having a 5 million year uptime on the server.

 

Of course, a GUID will "work fine", but whenever the words "many thousands" appear, you usually want to keep stuff as small as possible.

 

 

I'm a retard.

 

Appreciate  your post and thoughts. I overthought everything I said here.

 

What I basically did was when the game server starts, there is a global GAME_LOOT variable set to 1.  And each time that is generated from a mob to the buffer (not by player loot, they have their own id from the database to differentiate between them), I use something like this:

 

var nitem_id = 'L'+LOOT_COUNTER++;

 

and then I use that nitem_id variable for the items unique identifier. (I personally use it inside an objects key for simplicity), but others to each their own. It's basically a simple counter. And it will work perfect over websockets because it will be small and not long like most GUID's. (less bandwidth over the pipe). 

 

If anyone see's anything wrong with this way, let me know. For example, here are some screens using this method in my game:

09a3964404c6f78b2f94caf00b2f373f.gif

 

As we can see, there will never be a collision. And if the game server restarts or crashes. All the loot in the buffer will be deleted (obviously), so it would be OKAY to have the GAME_LOOT counter back to 1 upon a restart. I don't think collisions will ever happen.

Edited by WombatTurkey

Share this post


Link to post
Share on other sites
Well yeah, the items obviously have to be stored somewhere in your node.js, and the storage container has to have some sort of keys for those items. I.e. if its a plain array, you could just use array indices I suppose. It doesn't even matter if the indices get reused eventually, as long as your code is safe against packet manipulation in general, the worst thing that could happen is someone will pick up a different item because the one they wanted is already gone.

Share this post


Link to post
Share on other sites

the worst thing that could happen is someone will pick up a different item because the one they wanted is already gone
That would truly suck and would almost inevitably end with a huge shit storm on your user forums: I picked up the Pwn Sword and it turned out being a carrot later.

 

But luckily, this is not going to happen. Integers will not overflow (well, they will... but not soon enough).

 

No game can afford to have loot on the ground for that long (almost a week in the most contrieved case!). Not only would that eat up huge amounts of server memory, but it would also cause a bandwidth explosion (need to transmit info about everything on the floor, after all -- so if there's 300 million items on the floor in that dungeon... holy cow!).

But even if you could afford it otherwise, it would be unwise from a gameplay perspective. Nobody wants to dig through piles of junk that they didn't pick up last time (they might want to pick up a heal buff even if it's a cheap one before dying, but then again where's the challenge when all you need to do to prevent death is pick up something from one of the countless  junk piles quick!).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!