Editorial Workflows

Treasure

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: Random treasure generation for ACKS.

Shared by: Chris Allison

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Get File Contents ?
File Name
ACKS data/treasure.txt
In Dropbox
OFF
If File Does Not Exist
  • Empty Output
  • Stop Workflow
Set Variable ?
Variable Name
treasure
Value
Input
Create List ?
Source Code
#coding: utf-8
import workflow, ast

action_in = {}
action_in = ast.literal_eval(workflow.get_variable('treasure'))

action_out = ''

for item in action_in:
	action_out += action_in[item]['Class']+" - "+action_in[item]['Type']+'\n'

workflow.set_output(action_out)
Sort Lines ?
Sort Order
  • Ascending (A → Z)
  • Descending (Z → A)
Select from List ?
Title
Select treasure type:
List (Lines)
Input
Multiple Selection
OFF
Show in Popover
OFF
Shorten List for Script ?
Source Code
#coding: utf-8
import workflow

action_in = workflow.get_input()

#TODO: Generate the output...
action_out = action_in[0]

workflow.set_output(action_out)
Generate Treasure ?
Source Code
#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))
Replace Selected Text ?
Replacement Text
Input