#coding: utf-8
import workflow, ast, random
monster = workflow.get_variable('monster')
monster_dict = {}
monster_dict = ast.literal_eval(workflow.get_variable('monster_dict'))
def roll_em(dice,pips,mods):
total = 0
for die in range(1,dice+1):
total += random.randint(1,pips)
total += mods
if mods > 0:
text = '>Rolled {}d{}+{}. Your result is **{}**.'.format(dice,pips,mods,total)
elif mods < 0:
text = '>Rolled {}d{}{}. Your result is **{}**.'.format(dice,pips,mods,total)
else:
text = '>Rolled {}d{}. Your result is **{}**.'.format(dice,pips,total)
return total
# Basic encounter function called by the map.
def encounter(monster):
mon_dict = monster_dict[monster]
# Determining the number of creatures encountered, the distance (as per a wooded encounter) and surprise.
tot_enc = 0
if int(mon_dict['Enc Pips']) == 1:
tot_enc = 1
enc1 = "**Encounter: {} {}**.<br>".format(tot_enc,monster)
else:
tot_enc = roll_em(int(mon_dict['Enc Dice']),int(mon_dict['Enc Pips']),0)
enc1 = "**Encounter: {} {}**.<br>".format(tot_enc,mon_dict['Natural Spelling Plural'])
# Determining hit dice and hit points for creatures (NOTE: I screwed up some low hp creatures in the CSV file. Will need to fix.)
hd = 1
hp = []
x = 0
try:
int(mon_dict['HD'])
except ValueError:
raise
mon_dict['HD'] = 1
for i in range(1,100):
print '********************'+mon_dict[""]+'**********************'
num_beasties = 0
if tot_enc > 26:
num_beasties = 26
else:
num_beasties = tot_enc
if int(mon_dict['Pips']) == 0:
hd = str(mon_dict['HD'])
for beast in range(1,num_beasties+1):
x = roll_em(int(mon_dict['HD']),8,0)
hp.append(x)
elif mon_dict['HD'] in (0,'',""):
hd = str(mon_dict['Pips'])+'hp'
for beast in range(1,num_beasties+1):
x = mon_dict['Pips']
hp.append(x)
else:
hd = str(mon_dict['HD'])+'+'+str(mon_dict['Pips'])
for beast in range(1,num_beasties+1):
x = roll_em(int(mon_dict['HD']),8,int(mon_dict['Pips']))
hp.append(x)
if mon_dict['2nd Move Type'] == '':
two_move = 'None'
else:
two_move = mon_dict['2nd Move Type']+" "+mon_dict['2nd Move Spd']
# Final part of the stat block and returning the full script to the map.
enc3 = '**Al**: {}, **Move**: {}, **Alt**: {}, **AC**: {}, **HD**: {}<br>**HP**: {}<br>**Atk**: {}, **Dam**: {}<br>**Save**: {}, **Morale**: {}, **Treasure**: {}, **XP**: {} (total {}xp)<br> **Special**: {}.'.format(mon_dict['Align'],mon_dict['Move'],two_move,str(mon_dict['AC']),str(hd),str(hp).strip('[]'),mon_dict['Attacks'],mon_dict['Damage'],mon_dict['Save'],str(mon_dict['Morale']),str(mon_dict['Treasure Type']),str(mon_dict['XP']),int(mon_dict['XP'])*num_beasties,mon_dict['Special Attack'])
full_text = enc1+'\n'+enc3
#print(full_text)
#print('')
return full_text
workflow.set_output(encounter(monster))
There are no comments yet.