wynnbuilder-forked-for-changes/py_script/atree-generateID.py

109 lines
5.2 KiB
Python
Raw Normal View History

"""
Generate a minified JSON Ability Tree [atree_constants_min.json] AND a minified .js form [atree_constants_min.js] of the Ability Tree with:
- All references replaced by numerical IDs
2022-06-27 09:23:22 +00:00
- Extra JSON File with Class: [Original name as key and Assigned IDs as value].
given [atree_constants.js] .js form of the Ability Tree with reference as string.
"""
import json
def translate_id(id_data, atree_data):
for _class, info in atree_data.items():
def translate(path, ref):
ref_dict = info
for x in path:
ref_dict = ref_dict[x]
ref_dict[ref] = id_data[_class][ref_dict[ref]]
for abil in range(len(info)):
info[abil]["id"] = id_data[_class][info[abil]["display_name"]]
for ref in range(len(info[abil]["parents"])):
translate([abil, "parents"], ref)
for ref in range(len(info[abil]["dependencies"])):
translate([abil, "dependencies"], ref)
for ref in range(len(info[abil]["blockers"])):
translate([abil, "blockers"], ref)
if "base_abil" in info[abil]:
base_abil_name = info[abil]["base_abil"]
if base_abil_name in id_data[_class]:
translate([abil], "base_abil")
if "effects" not in info[abil]:
print("WARNING: abil missing 'effects' tag")
print(info[abil])
info[abil]["effects"] = []
for effect in info[abil]["effects"]:
if effect["type"] == "raw_stat":
for bonus in effect["bonuses"]:
if "abil" in bonus and bonus["abil"] in id_data[_class]:
bonus["abil"] = id_data[_class][bonus["abil"]]
elif effect["type"] == "replace_spell":
for part in effect['parts']:
if 'hits' in part: # Translate parametrized hits...
hits_mapping = part['hits']
keys = list(hits_mapping.keys())
for k in keys:
v = hits_mapping[k]
if isinstance(v, str):
abil_id, propname = v.split('.')
hits_mapping[k] = str(id_data[_class][abil_id])+'.'+propname
elif effect["type"] == "add_spell_prop":
if 'hits' in effect: # Translate parametrized hits...
hits_mapping = effect['hits']
keys = list(hits_mapping.keys())
for k in keys:
v = hits_mapping[k]
if isinstance(v, str):
abil_id, propname = v.split('.')
hits_mapping[k] = str(id_data[_class][abil_id])+'.'+propname
elif effect["type"] == "stat_scaling":
if "inputs" in effect: # Might not exist for sliders
for _input in effect["inputs"]:
if "abil" in _input and _input["abil"] in id_data[_class]:
_input["abil"] = id_data[_class][_input["abil"]]
if "output" in effect:
if isinstance(effect["output"], list):
for output in effect["output"]:
if "abil" in output and output["abil"] in id_data[_class]:
output["abil"] = id_data[_class][output["abil"]]
else:
if "abil" in effect["output"] and effect["output"]["abil"] in id_data[_class]:
effect["output"]["abil"] = id_data[_class][effect["output"]["abil"]]
abilDict = {}
with open("atree_constants.js") as f:
data = f.read()
data = data.replace("const atrees = ", "")
data = json.loads(data)
for classType, info in data.items():
2022-06-27 09:23:22 +00:00
_id = 0
abilDict[classType] = {}
for abil in info:
2022-06-27 09:23:22 +00:00
abilDict[classType][abil["display_name"]] = _id
_id += 1
2022-06-27 09:23:22 +00:00
with open("atree_ids.json", "w", encoding='utf-8') as id_dest:
json.dump(abilDict, id_dest, ensure_ascii=False, indent=4)
translate_id(abilDict, data)
2.0.3 update (#260) * Mage atree changes * Bump version to 2.0.3.1 just tree for now * Warrior tree :pray: * Shaman tree WIP some things are too jank to stay * Fixes to bamboozle behavior also echo was -60% instead of -65% in the file??? wtf * Shurikens damage boost by echo meme * Fix description text in echo, update old version atree file * Fix shaman tree thanks spegg! * Spegg atree changes assassin tree fixed many of my shaman mistakes and other changes we missed over the months somehow? * Updated archer ability tree Thanks @mr_me! All credit to them. * Fixes to spegg's fixes implement beast lore * Change how Chant of the Lunatic is calculated coursing restraints ingame is 15% damage bonus * Updated ingredients manually thanks @watermelon (snownlite)! * Forgor to bump ing db version * Fix ingredient display jank * 2.0.3 items (#259) * API update also add new IDs to a bunch of places... tech debt whyyy * Forgot to update ingreds... * Change heal power ID name to stack with tree abils, fix multi totem effect on totemic shatter and req for mana traps * Forgot to bump item db version * Implement major IDs not implemented: Gentle Glow, and Forest's Blessing damage increase (since I don't know the exact numbers) and radiance boost is not implemented (radiance is currently handled way too jank) might wait for buffs rework to handle radiance. * patch item searcher TODO: make this not disgusting... build_encode_decode file has gotten too big --------- Co-authored-by: hppeng <hppeng> Co-authored-by: RawFish69 <108964215+RawFish69@users.noreply.github.com>
2023-07-15 01:34:30 +00:00
with open("major_ids_clean.json") as maj_id_file:
maj_id_dat = json.load(maj_id_file)
for k, v in maj_id_dat.items():
for abil in v['abilities']:
clazz = abil['class']
base_abil = abil['base_abil']
abil['base_abil'] = abilDict[clazz][base_abil]
with open("major_ids_min.json", "w", encoding='utf-8') as maj_id_out:
json.dump(maj_id_dat, maj_id_out, ensure_ascii=False, separators=(',', ':'))
data_str = json.dumps(data, ensure_ascii=False, separators=(',', ':'))
data_str = "const atrees=" + data_str
with open('atree_constants_min.js', 'w', encoding='utf-8') as abil_dest:
abil_dest.write(data_str)
with open('atree_constants_min.json', 'w', encoding='utf-8') as json_dest:
json.dump(data, json_dest, ensure_ascii=False, separators=(',', ':'))