#coding: utf-8
import workflow, random, ast
treasure_class = workflow.get_input()
treasure_dict = ast.literal_eval(workflow.get_variable('treasure'))
treasure_list = ['Copper',"Silver",'Electrum','Gold','Platinum']
gem_list = ['Gem','Jewelry']
gem_value = {'ornamental': 50, 'gems': 200, 'brilliants':4000, 'trinkets': 225, 'jewelry': 1000, 'regalia': 11000}
coin_value = {'Copper': .01, 'Silver': .1, 'Electrum': .5, 'Gold': 1, 'Platinum': 5}
def roll_em(dice,pips,mod):
total = 0
for i in range(1,dice+1):
total += random.randint(1,pips)
total += mod
return total
def generate_treasure(t_type):
total = 0
treasure = ''
treasure = '**Treasure Type {}**<br> '.format(t_type)
for item in treasure_list:
amount = 0
prob = int(treasure_dict[t_type][item])
x = roll_em(1,100,0)
if x <= prob:
amount = roll_em(int(treasure_dict[t_type][item+'_amount'][1]),int(treasure_dict[t_type][item+'_amount'][3]),int(treasure_dict[t_type][item+'_amount'][5]))
amount *= 1000
treasure += '* {}: {} coins <br> '.format(item,amount)
total += (amount * float(coin_value[item]))
for item in gem_list:
amount = 0
prob = int(treasure_dict[t_type][item])
x = roll_em(1,100,0)
if x <= prob:
amount = int(roll_em(int(treasure_dict[t_type][item+'_amount'][1]),int(treasure_dict[t_type][item+'_amount'][3]),int(treasure_dict[t_type][item+'_amount'][5])))
treasure += '* {}: {} {} (value {} each) <br> '.format(item,amount,treasure_dict[t_type][item+'_type'],gem_value[treasure_dict[t_type][item+'_type']])
total += (amount * gem_value[treasure_dict[t_type][item+'_type']])
treasure += '* Magic {} <br> '.format(treasure_dict[t_type]['Magic '])
treasure += 'The total value of this hoard is {}gp <br>'.format(int(total))
return treasure
workflow.set_output(generate_treasure(treasure_class))
There are no comments yet.