Editorial Workflows

Wandering Monsters (Dungeon)

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: A random encounter workflow for the Adventure Conqueror King system.

Shared by: Chris Allison

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Get File Contents ?
File Name
ACKS data/Monsters.txt
In Dropbox
OFF
If File Does Not Exist
  • Empty Output
  • Stop Workflow
Set Variable ?
Variable Name
monster_dict
Value
Input
Select from List ?
Title
Select the dungeon level:
List (Lines)
1 2 3 4 5 6
Multiple Selection
OFF
Show in Popover
OFF
Run Python Script ?
Source Code
#coding: utf-8
import workflow,random, ast

monster_dict = ast.literal_eval(workflow.get_variable('monster_dict'))
level = int(workflow.get_input())

wandering_m = {1: [['Beetle, Giant Fire',1,8,0],['Centipede, Giant',2,4,0],['Ferret, Giant',1,8,0],['Goblin',2,4,0], ['Kobold',4,4,0], ['Brigand',2,4,0],['Goblin',1,12,0], ['NPC Party',1,4,2],['Orc',2,4,0], ['Rat, Giant',3,6,0],['Skeleton',3,4,0],['Stirge',1,10,0]], 
               2: [['Bat, Giant',1,10,0],['Fly, Giant Carnivorous',1,8,0],['Ghoul',1,6,0],['Gnoll',1,6,0],['Hobgoblin',1,6,0],['Lizardman',2,4,0],['Insect Swarm, 2HD',1,10,0], ['Berserker',1,6,0],['NPC Party',1,4,2],['Snake, Pit Viper',1,8,0],['Troglodyte',1,8,0],['Zombie',2,4,0]], 
               3: [['Ant, Giant',2,4,0],['Bugbear',2,4,0],['Carcass Scavenger',1,3,0],['Gargoyle',1,6,0],['Lizard, Giant Draco',1,3,0],['Werewolf',1,6,0],['NPC Party',1,4,2],['Ogre',1,6,0], 	['Scorpion, Giant',1,6,0],['Throghrin',1,6,0],['Wight',1,6,0],['Wolf, Dire',1,4,0]], 
               4: [['Boar, Giant',1,4,0],['Cockatrice',1,3,0],['Wereboar',1,4,0],['Weretiger',1,4,0],['Medusa',1,3,0],['Minotaur',1,6,0],['NPC Party',1,4,2],['Owl Bear',1,4,0],['Phase Tiger',1,4,0],['Rhagodessa, Giant',1,4,0],['Snake, Giant Python',1,3,0],['Wraith',1,4,0]], 
               5: [['Ankheg',1,6,0],['Basilisk',1,6,0],['Caecilian',1,3,0],['Ettin',1,2,0],['Giant, Hill',1,4,0],['Giant, Stone',1,2,0],['Hell Hound, Greater',2,4,0],['NPC Party',1,4,3],['Salamander, Flame',1,4,1],['Spectre',1,4,0],['Troll',1,8,0],['Wyvern',1,2,0]], 
               6: [['Cyclops',1,1,0],['Demon Boar',1,4,0],['Dragon, 20HD',1,1,0],['Giant, Cloud',1,2,0],['Gorgon',1,2,0],['Hydra, 12HD',1,1,0],['Lamia',1,1,0],['NPC Party',1,4,3],['Purple Worm',1,2,0],['Remorhaz, 15HD',1,1,0],['Skittering Maw',1,1,0],['Vampire, 9HD',1,4,0]]}

wm_level = {1:[0,0,10,11,13],2:[0,4,10,12,13],3:[2,4,10,12,13],4:[2,4,10,12,13],5:[2,4,10,13,14],6:[2,4,13,14,15]}

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 encounter(monster,dice,pips,mod):
		try:
			mon_dict = monster_dict[monster.title()]
		except KeyError:
			mon_dict = monster_dict['Goblin']
			print monster

		# Determining the number of creatures encountered, the distance (as per a wooded encounter) and surprise.
		tot_enc = 0
		if int(pips) == 1:
			tot_enc = 1
			enc1 = "Encounter: {} {}.".format(tot_enc,monster)
		else:
			tot_enc = roll_em(int(dice),int(pips),mod)
			
			enc1 = "Encounter: {} {}.".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

wm_mod = roll_em(1,12,0)
mod_level = 0
if wm_mod < wm_level[level][0]:
	mod_level = level -2
elif wm_mod < wm_level[level][1]:
	mod_level = level -1
elif wm_mod < wm_level[level][2]:
	mod_level = level
elif wm_mod < wm_level[level][3]:
	mod_level = level +1
elif wm_mod < wm_level[level][4]:
	mod_level = level +2
					
if mod_level < 1:
	mod_level = 1
					
rm_monster = random.choice(wandering_m[mod_level])
monster_name = rm_monster[0]
monster_die = int(rm_monster[1])
monster_pips = int(rm_monster[2])
monster_mod = int(rm_monster[3])

random_enc = roll_em(1,6,0)

if random_enc < 3:
	result = 'Encounter roll {} for dungeon level {}: {}<br>'.format(random_enc,level,encounter(rm_monster[0],rm_monster[1],rm_monster[2],rm_monster[3])).translate(None,'"').lstrip(',')
else:
	result = 'Encounter roll {} for dungeon level {}: No encounter.<br>'.format(random_enc,level)

workflow.set_output(result)
Replace Selected Text ?
Replacement Text
Input