gammatools/app/functions/roll_dices.py

33 lines
896 B
Python

import random
def roll_dices(dice_count, dice_sides, discard_lowest):
roll_results = []
discarded = []
for _ in range(dice_count):
roll_results.append(random.randint(1, dice_sides))
if discard_lowest and len(roll_results) > 0:
discarded.append(min(roll_results))
roll_results.remove(min(roll_results))
if discarded:
net_dice_count = dice_count - 1
mnemonic = str(dice_count) + "(-1)d" + str(dice_sides)
else:
mnemonic = str(dice_count) + 'd' + str(dice_sides)
net_dice_count = dice_count
result = {
'dice-set': {
'mnemonic': mnemonic,
'min-roll': net_dice_count,
'max-roll': dice_sides * net_dice_count
},
'rolls': roll_results,
'result': sum(roll_results)
}
if discarded:
result['discarded'] = discarded
return result