osx11

change damage with respect to element

Sep 17th, 2021 (edited)
882
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from yaml import safe_load
  2. from re import sub
  3.  
  4. reflist = {}
  5.  
  6. with open('distr.txt', 'rb') as f:
  7.     for l in f:
  8.         l = l.decode('utf-8')
  9.  
  10.         if '"' not in l:
  11.             l = l.strip()
  12.  
  13.             if not l:
  14.                 continue
  15.  
  16.             split = l.split(" - ")
  17.             name = split[0]
  18.             ref = split[1].replace('стихия ', '')
  19.  
  20.             reflist[name] = ref
  21.  
  22. with open('messages.yml', 'rb') as f:
  23.     spellnames = safe_load(f)
  24.  
  25. with open('spells.yml', 'rb') as fi:
  26.     with open('spells_mod.yml', 'wb') as fo:
  27.         current_spell = ''
  28.  
  29.         for l in fi:
  30.             l = l.decode('utf-8')
  31.  
  32.             if not l.startswith(' ') and not l.startswith('#') and l != '' and l != '\r\n':
  33.                 current_spell = l.replace(':\r\n', '')
  34.                 write = l.encode('utf-8')
  35.             else:
  36.                 if 'damage: "' in l:
  37.                     l = l.replace(':\r\n', '')
  38.                     original_damage = l.split(' + ')[-1]
  39.  
  40.                     if 'intelligence' in original_damage:
  41.                         original_damage = l.split(' + ')[-2]
  42.  
  43.                     original_damage = original_damage.replace('"', '').replace('\r\n', '')
  44.  
  45.                     if ')' or '(' in original_damage:
  46.                         original_damage = sub(r'\).+|\)|.+\(|\(', '', original_damage)
  47.  
  48.                     if current_spell not in spellnames['spells']:
  49.                         continue
  50.  
  51.                     if 'name' not in spellnames['spells'][current_spell]:
  52.                         continue
  53.  
  54.                     spellname = sub(r'&.', '', spellnames['spells'][current_spell]['name'])
  55.  
  56.                     if spellname not in reflist:
  57.                         print(f'WARNING: ref for {current_spell} is not defined')
  58.                         continue
  59.  
  60.                     ref = reflist[spellname]
  61.  
  62.                     if ref == 'Аркана':
  63.                         damage = f'arcana/{"{0:.1f}".format(33/float(original_damage))} + {original_damage}'
  64.                     elif ref == 'Хаос':
  65.                         damage = f'chaos/{"{0:.1f}".format(50/float(original_damage))} + {original_damage}'
  66.                     elif ref == 'Свет':
  67.                         damage = f'light/{"{0:.1f}".format(50/float(original_damage))} + {original_damage}'
  68.                     elif ref == 'Тьма':
  69.                         damage = f'dark/{"{0:.1f}".format(50/float(original_damage))} + {original_damage}'
  70.  
  71.                     write = sub(r'".+"', f'"{damage}"', l).encode('utf-8')
  72.                 else:
  73.                     write = l.encode('utf-8')
  74.  
  75.             fo.write(write)
  76.  
RAW Paste Data