Ideas on a loot system

Ok so I’m looking for criticism for a loot system I’m going to be implementing. How it works is I use one table to be used as the items to get.

Loot_pool id, title,probability

Each table has a decimal value called probabilty. I use my weighted random select class on an array of the weights and the sum of the weights from the database. I then query the rarity table.

item_rarity id,title,color,probability

and do the random roll there. Then with the two numbers(pool to pick from, and rarity) I do my final query and get a random item from that pool with that rarity. That involves getting the total number of items that match the criteria and do a random number roll between 1 and item count.

What I’m looking for is a better way to structure the data so selecting an item is easier and less of a mess.

The weighted random selection is here

It was a quick write up I need to upload the fixed version. Any ideas would be appreciated.

To be fair, what you’re describing is weighted selection, but not weighted random. It’s a ‘true’ random across a spread range, which then identifies the table based on weighted value.

Databases dont like random, in general. It’s usually a pretty slow operation (by database standards) for a database to retrieve a random record.

That said, i’m not sure why you’d be rolling a random loot pool at all. Surely a pool is fixed to whatever it is you’re looting.

Also, PHP’s rand() takes optional min/max parameters, so you dont need to do all the additional function/math involved.

mt_rand() performs better, thats why I used it. It’s supposed to be dynamic. It’s part of a gamification platform I’m working on that would include a more robust feature set. This would tie into mission/quests to award a prize and certain items like a treasure chest would need to be able to award loot when opened. Certain loot would be unique and be quest specific i.e. can only be awarded by doing a certain quest.

Get loot tables and rarity

Do weighted selection on loot table to pick loot to drop.

Do weighted selection on rarity to pick rarity.

Get items that match loot table and rarity.

Select random item and award it.

The code is ported from a python and javascript implementation. I took out the exception in the constructors. In the js port the author created the random method based on something he/she found. I wrote the ports myself and I admit it was rushed. It was date night for me and the mrs.

My intial idea was to store the loot table and rarity as json files and only query the db for the items.
What would you suggest there?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.