So I have this bit of code that takes 5 weighted rarity levels and randomly selects one. These rarity levels all have 10 corresponding image files, when a rarity is selected, the code then randomly selects an image file of that rarity.
What I would like to do is over the course of X amount of rolls, guarantee 1 specific image file of the Epic rarity is always selected, but only once. I'm assuming this would need a check of some kind.
I'm sure this can be done, but I am just having a hard time wrapping my head around how to approach it. Any help is greatly appreciated.
# randomly selects a weighted level of rarity
def quality():
A = 'Common'
B = "Uncommon"
C = "Rare"
D = "Legendary"
E = "Epic"
loot = [ (A,50), (B,30), (C,14), (D,5), (E,1) ]
choices = []
for item, weight in loot:
choices.extend( [item]*weight )
roll = random.choice(choices)
return roll
# randomly adds Aura from the selected rarity
def Aura():
#print(random.choice(os.listdir(os.path.join('/PNG/Aura/', q ))))
layQ = os.path.join('/PNG/Test/Aura/', quality() )
qLen = len(fnmatch.filter(os.listdir(layQ), '*.png'))
if qLen > 0:
png = random.choice(os.listdir(layQ))
roll = os.path.join('PNG/Test/Aura/', layQ, png)
return roll
Aucun commentaire:
Enregistrer un commentaire