- Home /
Seed-based loot generation... what if I WANT a specific item?
I've developed a simple test loot generation system for my network game. My goal is to have every item reducible to the seed it was generated with so I can easily send items over the network with nothing but an integer, which I've managed to accomplish.
My issue is, there are a few cases, like monsters with specific loot tables, or vendors, where I want to be able to specify a particular item without knowing a seed that will generate it, but still be able to randomly roll the item's values, and still have it be reducible to an integer for network purposes.
I entertained the idea of using negative seeds to trigger a conditional for an array lookup instead of random generation, but I'm not sure how to roll the values the same after that?
What is the advantage of sending the item seed over sending a copy of the item? It sounds like you've tried to be clever with your optimization and now you need to extend it you can't.
Answer by orb · Sep 10, 2014 at 01:25 PM
If you have to use an integer, implementing the loot list as a custom asset list of fixed items might work. Then the integer is simply an index in the list, and lookup should be easy. If you can look up the index from the item's name, that is.
The way I'd prefer to implement it would be by generating code strings. One- or two-letter codes followed by either an index or value, combined to create an item description. There wouldn't be much need of storage for unique items, only a code that creates the object, its properties and holds its model.
Example: Let B be the base model asset (a class that holds a pointer to a model and a texture for the inventory symbol), D damage bonus, Rf fire resistance. A sword (index 8 in the model list) with +2 damage and 5% fire resistance could be coded as B8D2Rf5. More complicated use would be individual loot table scripts for different monsters that create items with attributes within ranges, trending towards certain resistances etc. The models and images would be simple custom assets.
On networking: You're best off using an authoritative server, which means the actual object is created server-side and copied to the players, and the string is shorthand for displaying the stats. Yes, there could be some hairy programming involved to implement this :)
See this blog post for a starting point with custom assets. They can make item generation a lot handier.
I already have the authoritative networking and my current, rudimentary seed based item system working. I was hoping to avoid strings just because in uLink they are kind of expensive, bandwidth-wise (1 byte per character per string). Currently I'm only using half precision seeds, so I can send an entire character inventory in 72 bytes (30 items +6 pieces of equipment).
When someone changes a piece of a equipment, its nice that the server only has to send proxies a 2 byte integer vs. a potentially much larger string.