Hi All,
I'd like to have players be able to buy a booster packs of game items from a list of payVaultItems I've created. I'm having trouble finding an efficient and scalable way to do this. I'd like to hear your suggestions for how to most efficiently support the below scenario:
1) I have all of the items I'd like to select from created as PayVaultItems. Each item has a rarity and edition property. I have an index setup that sorts all items by rarity.
2) I'd like to be able to select a random set of these items based upon some breakdown in rarity (for example, a pack of 8 cards, 4 commons, 3 uncommons, and 1 rare).
3) Award them all to the user's collection once the set is selected.
What I've tried so far:
1) Brute Force: do a load range of my index organized by rarity. Pull down each set of cards by rarity separately. I then select randomly from the arrays that are returned to build my pack. This seems really bad for when I start getting 100's of items in my total collection.
2) I tried to develop a solution that fit what was suggested here (giving each card an id, then loading by that id after a random selection): post5697?hilit=random%20object#p5697 . The difference in my case is that ids for each card will not match their position within the index, because I want to select from only a subset of the collection in most cases. What I'd like to be able to do is: set my total count of known rare cards in some other object, generate a random number between o and that total, and then load an item at that position within the rarity index (ex: select card at index 3 of the returned set of 5 rare cards). I couldn't see a way to load by a particular position in an index, however.
Any suggestions for how to approach this would be appreciated!
-Scott