From 16f5934daa2eb1d2a3cbb7feb9b3366dd5466973 Mon Sep 17 00:00:00 2001 From: James Miller Date: Tue, 18 Feb 2020 23:30:31 -0600 Subject: [PATCH] still cleaning up monsters --- data/yaml/clean-up-monsters.py | 99 ++++++++++++++++++++++++++++++++-- data/yaml/monsters.yaml | 18 +++---- 2 files changed, 105 insertions(+), 12 deletions(-) diff --git a/data/yaml/clean-up-monsters.py b/data/yaml/clean-up-monsters.py index 606707a..c4d0551 100644 --- a/data/yaml/clean-up-monsters.py +++ b/data/yaml/clean-up-monsters.py @@ -1,4 +1,5 @@ import yaml +import re def main(): @@ -37,8 +38,8 @@ def main(): i['saves_special'][k] = a[1] i['saves'][k] = a[0] elif '(' in v: - print("we got a parentheses") - print(v) + #print("we got a parentheses") + #print(v) a = v.split(' (') # print(a) i['saves_special'][k] = a[1] @@ -57,7 +58,72 @@ def main(): res.append(z.strip()) i['immunities'] = res - print(i['immunities']) + # clean up traits with trailing or leading whitespace + traitslist = [] + print(i['traits']) + for x in i['traits']: + traitslist.append(x.strip()) + print(x.strip()) + print(traitslist) + i['traits'] = traitslist + + # clean up traits underneath proactive actions with trailing or leading whitespace + print(i['proactive_abilities']) + for x in i['proactive_abilities']: + traitslist = [] + if x['traits'] != None: + if len(x['traits']) == 0: + x['traits'] = None + else: + for y in x['traits']: + traitslist.append(y.strip()) + print(y.strip()) + x['traits'] = traitslist + + # clean up senses + + senseslist = [] + if i['senses'] != None: + if len(i['senses']) == 0: + i['senses'] = None + else: + for x in i['senses']: + senseslist.append(x.strip()) + i['senses'] = senseslist + + # clean up spell DC + if i['spell_dc'] == "None": + i['spell_dc'] = None + else: + i['spell_dc'] = int(i['spell_dc']) + + # clean up innate_spell levels + if 'innate_spells' not in i: + i['innate_spells'] = None + elif i['innate_spells'] == "None": + i['innate_spells'] = None + else: + for x in i['innate_spells']: + x['level'] = int(x['level']) + + + # clean up resistances + + # set Nones to null + if i['resistances'] == "None": + i['resistances'] = None + + # remove trailing ; + elif i['resistances'].endswith(";"): + i['resistances'] = i['resistances'][:-1] + #print("\t{}".format(i['resistances'])) + + if i['resistances'] != None: + #print("{}\t{}".format(counter, i['name'])) + #print("\t{}".format(i['resistances'])) + res = processResistances(i['resistances']) + i['resistances'] = res + #print(res) final = yaml.safe_dump(data, allow_unicode=True) @@ -65,6 +131,33 @@ def main(): with open("tmp-monsters.yaml", 'w') as f: f.write(final) +def processResistances(r): + if '(' in r: + # TODO This is what needs to be done + #print("\t\tTODO: Need to process with parentheses") + return r + else: + #print("\t\tNo parentheses") + # split on commas + res = r.split(',') + #print(r.split(',')) + #print(res) + results_list = [] + for i in res: + #print(i) + #tmp = re.search('(\d+)', i) + #print(tmp.groups()) + tmp = re.split('(\d+)', i) + #print(tmp) + tmpres = {"type": tmp[0].strip(), "amount": int(tmp[1])} + results_list.append(tmpres) + + return results_list + + + return "Something went wrong" + + if __name__ == "__main__": main() diff --git a/data/yaml/monsters.yaml b/data/yaml/monsters.yaml index b438379..62fa33c 100644 --- a/data/yaml/monsters.yaml +++ b/data/yaml/monsters.yaml @@ -2988,7 +2988,7 @@ fort: "+25," hp: "250 (negative healing);" immunities: "disease, paralyzed, poison, precision, unconscious" - resistances: "all damage 12 (except force," + resistances: "all damage 12 (except force, ghost touch, or positive; double resistance vs. non-magical)" proactive_abilities: - name: "Spectral Ripple" @@ -17935,7 +17935,7 @@ fort: "+8," hp: "30 (negative healing, rejuvenation);" immunities: "death effects, disease, paralyzed, poison, precision, unconscious" - resistances: "all damage 5 (except force," + resistances: "all damage 5 (except force, ghost touch, or positive; double resistance vs. non-magical)" proactive_abilities: - name: "Frightful Moan" @@ -18006,7 +18006,7 @@ fort: "+16," hp: "135 (negative healing, rejuvenation);" immunities: "death effects, disease, paralyzed, poison, precision, unconscious" - resistances: "all damage 10 (except force," + resistances: "all damage 10 (except force, ghost touch, or positive; double resistance vs. non-magical)" proactive_abilities: - name: "Frightful Moan" @@ -20131,7 +20131,7 @@ fort: "+33," hp: "255 (repair mode);" immunities: "bleed, death effects, disease, doomed, drained, fatigued, fire, healing, magic (see below), mental, necromancy, nonlethal attacks, paralyzed, poison, sickened, unconscious" - resistances: "physical 20 (except" + resistances: "physical 20 (except vorpal adamantine)" proactive_abilities: - name: "Destructive Strike" @@ -27598,7 +27598,7 @@ fort: "+9," hp: "55 (rejuvenation);" immunities: "death effects, disease, paralyzed, poison, precision, unconscious" - resistances: "all damage 5 (except force," + resistances: "all damage 5 (except force, ghost touch, or positive; double resistance against non-magical)" proactive_abilities: - name: "Frighten" @@ -30125,7 +30125,7 @@ fort: "+8," hp: "40;" immunities: "death effects, disease, paralyzed, poison, precision, unconscious" - resistances: "all 5 (except force," + resistances: "all 5 (except force, ghost touch, or positive; double resistance against non-magical)" proactive_abilities: - name: "Shadow Spawn" @@ -30189,7 +30189,7 @@ fort: "+11," hp: "75;" immunities: "death effects, disease, paralyzed, poison, precision, unconscious" - resistances: "all 10 (except force," + resistances: "all 10 (except force, ghost touch, or positive; double resistance against non-magical)" proactive_abilities: - name: "Shadow Spawn" @@ -34611,7 +34611,7 @@ fort: "+8," hp: "80 (negative healing);" immunities: "death effects, disease, paralyzed, poison, precision, unconscious" - resistances: "all 5 (except force," + resistances: "all 5 (except force, ghost touch, or positive; double resistance against non-magical)" proactive_abilities: - name: "Drain Life" @@ -38017,7 +38017,7 @@ fort: "+14," hp: "135;" immunities: "death effects, disease, paralyzed, poison, precision, unconscious" - resistances: "all damage 8 (except force," + resistances: "all 8 (except force, ghost touch, or positive; double resistance against non-magical), haunted form" proactive_abilities: - name: "Create Haunt"