I’ve been theorizing for a while. I want the diablo like random loot stuff without spending 10 hours a day grinding. So i’m thinking of a game where you log in, open some chests, fight a few bosses and leave. Basically to satisfy my thirst for loot without spending ALL my time. Others could also like the game, so i wanted to give it some backend too.
Basically because items will be random, which means i’d do something like this:
Math.random > pick a stat > Math.random > pick a number and get an item like this:
Epic boots: +1 str, +50int, + 200hp
That item is unique and that means I have to store it on the server. But i also have to delete it after it was deleted right?
Either that or I could generate every possible item (millions or billions of items?!), store it on the server and use Math.random to pick one of them
Which approach is the best?
Also, if I mark every item with a number starting from 0, that means that if a few thousand players are playing, after a few months, the number can go up to a few million. So item id would be like 20801258, would this affect performance?
So to fix it, i’m thinking of making a server maintenenance to clear up the ID numbers, because they’d be like this: 100 deleted 102 deleted deleted 105 106… So because most items will be deleted after a while, the maintenance could re-order the millions of items by removing the deleted and giving them new number names, so they don’t become too big.
But i don’t know if this method is any good, probably not because it’s the first think I thought of, doesn’t it create lag if 50 people are all getting items at once because that means the server must schedule each item to get an ID, random stats etc, one by one? Because if 2 people create an item at the same time, those 2 items would have the same ID and bug the game? Or are numbers and letters so fast to process that this isn’t a worry?
Sorry for the rant, I just had an idea and I woke up still thinking of how to do it, and I didn’t even delve into back end yet lol.
EDIT: I think I have an idea to fix the items at same time! What if I used player ID + number to generate IDs? That means every one will be unique even if 2 players are making item at same time!
EDIT2, even with player + number, the items object or array would still be millions long, maybe I should create a new array/object for every player to store items in?