Difference between revisions of "Talk:Monster stats"

From Wildermyth Wiki
(Created page with "== Generation script == This is a [https://www.python.org/downloads/ Python] script to generate the monster stat tables. Copy the code in the box below into a text file n...")
 
(Blanked the page)
Tag: Blanking
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== Generation script ==


This is a [https://www.python.org/downloads/ Python] script to generate the [[monster stat]] tables. Copy the code in the box below into a text file named '''<nowiki>tables.py</nowiki>''' (or whatever you want) inside the '''<nowiki>Wildermyth</nowiki>''' directory. Then run it by calling '''<nowiki>python tables.py</nowiki>''' from the command line. It will create a text file for each difficulty named '''<nowiki>tables_<difficulty>.txt</nowiki>''', full of wiki-formatted tables that can be pasted into the appropriate wiki pages.
{| role="presentation" class="wikitable mw-collapsible mw-collapsed"
| '''<nowiki>tables.py</nowiki>'''
|-
|
<nowiki>import json
from glob import glob
name_path_base = ''
type_paths = {
  'Deepist':['assets/data/monsters/cultist'],
  'Drauven':['assets/data/monsters/drauven'],
  'Gorgon':['assets/data/monsters/gorgon'],
  'Morthagi':['assets/data/monsters/morthagi'],
  'Thrixl':['assets/data/monsters/thrixl'],
  'Miscellaneous':['./assets/data/monsters/misc'],
  'Age of Ulstryx':['mods/builtIn/villain_ulstryx/assets/data/monsters/misc'],
  'The Enduring War':['mods/builtIn/villain_enduringWar/assets/data/monsters/morthagi','mods/builtIn/villain_enduringWar/assets/data/monsters/misc'],
  'Monarchs Under the Mountain':['mods/builtIn/villain_monarchs/assets/data/monsters/cultist'],
  'Eluna and the Moth':['mods/builtIn/villain_ecthis/assets/data/monsters/thrixl'],
  'All the Bones of Summer':['mods/builtIn/villain_cvawn/assets/data/monsters/drauven'],
  'The Sunswallower\'s Wake':['mods/builtIn/villain_vulture_lord/assets/data/monsters/misc'],
  }
 
names = {}
for m in (['.'] + glob('mods/builtIn/*')):
  name_file = m + '/assets/text/dynamic/dynamic.properties'
  try:
    with open(name_file,'r',encoding='utf8') as f:
      lines = f.readlines()
      for line in lines:
        if line[0] == '#':
          continue
        try:
          key,val = line.split('=')
        except:
          continue
        try:
          key_split = key.split('.')
        except:
          continue
        if len(key_split) != 2 or key_split[-1] != 'name':
          continue
        names[key_split[0]] = val[:-1]
  except:
    continue
 
diffs = {
  'Storyteller':'combatDifficulty_1',
  'Adventurer':'combatDifficulty_10',
  'Tragic Hero':'combatDifficulty_20',
  'Walking Lunch':'combatDifficulty_30',
  }
def read_stat(data,stat,diff):
  out = data['stats'][stat]
  try:
    out = data[diff]['stats'][stat]
  except:
    pass
  return out
for diff in list(diffs):
 
  d = diffs[diff]
  string = '[[Monster]] [[stat]]s at %s [[difficulty]] level:\n\n'%diff
  for faction in list(type_paths):
    string += '{| role="presentation" class="wikitable sortable mw-collapsible mw-collapsed" style="text-align: center"\n'
    string += '| style="width:880px" | ' + "'''%s'''\n"%faction
    string += '|-\n'
    string += '|\n\n'
    string += '{| class="wikitable sortable" style="text-align: center"\n'
    string += '! ID !! Name !! Health !! Armor !! Warding !! Block + Dodge !! Speed !! Melee Accuracy !! Ranged Accuracy\n'
    for l in type_paths[faction]:
      for m in glob(l + '/*.json'):
        with open(m) as f:
          data = json.load(f)
          id = data['id']
          name = names[id]
          health = read_stat(data,'HEALTH',d)
          speed = read_stat(data,'SPEED',d)
          armor = read_stat(data,'ARMOR',d)
          warding = read_stat(data,'WARDING',d)
          block = read_stat(data,'BLOCK',d)
          dodge = read_stat(data,'DODGE',d)
          macc = read_stat(data,'MELEE_ACCURACY',d)
          racc = read_stat(data,'RANGE_ACCURACY',d)
         
          avoid = str(int(block)+int(dodge))
          string += '|-\n'
          string += '| <small>' + id + '</small> || ' + name + ' || ' + health + ' || ' + armor + ' || ' + warding + ' || ' + avoid + ' || ' + speed + ' || ' + macc + ' || ' + racc + '\n'
     
    string += '|}\n\n'
    string += '|}\n\n'
 
  with open('tables_%s.txt'%diff, 'w') as f:
    f.write(string)</nowiki>
|}

Latest revision as of 12:43, 16 February 2022