Let's say I have the following Dictionary (name, rarity)
var characters = { ["Foo", "common"], ["Bar", "common"], ["Baz", "rare"], ["Quux", "epic"], ["Quuz", "legendary"] }
And I want to randomly spawn an enemy based on rarity:
I define a random value between 0 and 1:
var roll = randf()
And then I limitate the probability
if roll < 0.8: return "Any Common monster" elif roll < 0.90: return "Any Rare Monster" elif roll < 0.99: return "Any Epic Monster" else: return "Any Legendary Monster"
What I want to do is replace return "Common" for a code that searches in my dictionary, filters all possible monsters by that rarity, and then randomly select one of them:
Example:
- Randf() returns 0.5 --> Common
- Filter Dictionary by Common = Foo, Bar
- Randomly choose between all options (1 or 2) --> 1
- Add Foo to a new dictionary
Hope I have been clear enough, as I am failing to understand how to do this from the documentation 😦