151 lines
7.8 KiB
Python
151 lines
7.8 KiB
Python
"""Build the Lua weapon catalog from locally decoded DT_WeaponData, weapon configs and input maps."""
|
|
import argparse
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
|
|
|
|
def load(path):
|
|
return json.loads(path.read_text(encoding="utf-8"))
|
|
|
|
|
|
def quote(value):
|
|
return json.dumps(value, ensure_ascii=False)
|
|
|
|
|
|
def strings(values):
|
|
return "{" + ",".join(map(quote, values)) + "}"
|
|
|
|
|
|
def asset_paths(props, key):
|
|
return [v[1] for v in props.get(key, []) if isinstance(v, list) and len(v) > 1 and v[1].startswith("/")]
|
|
|
|
|
|
def effects(row):
|
|
seen = set()
|
|
out = []
|
|
|
|
def add(effect, level, soul):
|
|
if not effect:
|
|
return
|
|
path = effect.get("SoftClassPtr") or effect.get("GameplayEffect")
|
|
if not path:
|
|
return
|
|
entry = (path, level, effect.get("GELevel", effect.get("Level", 1)),
|
|
bool(effect.get("bApplyOnCurrentEquipOnly", False)), soul)
|
|
if entry not in seen:
|
|
seen.add(entry)
|
|
out.append(entry)
|
|
|
|
add(row.get("DefaultGEData"), 1, False)
|
|
add(row.get("DefaultSnapSoulGEData"), 1, True)
|
|
for level, tier in enumerate(row["WeaponUpLevelDatas"], start=2):
|
|
for key in ("GEDatas", "PersistentGEDatas", "SnapSoulGEDatas"):
|
|
for effect in tier[key]:
|
|
add(effect, level, key == "SnapSoulGEDatas")
|
|
for key in ("GameplayEffectDatas", "PersistentGEDatas"):
|
|
for effect in row["WeaponSnapSoulData"].get(key, []):
|
|
add(effect, 1, True)
|
|
return out
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("items", type=Path)
|
|
parser.add_argument("weapon_table", type=Path)
|
|
parser.add_argument("configs", type=Path)
|
|
parser.add_argument("output", type=Path)
|
|
parser.add_argument("--grants", type=Path, required=True, help="Verified native reward nodes and their unique B-map groups")
|
|
parser.add_argument("input_maps", nargs="+", type=Path)
|
|
args = parser.parse_args()
|
|
grants = load(args.grants)
|
|
rows = load(args.weapon_table)["objects"][0]["rows"]
|
|
configs = {d["path"].casefold(): d["objects"][0]["properties"] for directory in [args.configs, *args.input_maps] for f in directory.glob("Weapon_Hun_*.json")
|
|
if (d := load(f))["objects"]}
|
|
maps = {d["path"]: d["objects"][0]["properties"] for directory in args.input_maps
|
|
for f in directory.glob("AIM*Attack*.json") if (d := load(f))["objects"]}
|
|
generic = next(key for key in maps if key.endswith("/AIM_Hun_LightAttack"))
|
|
catalog = load(args.items)["items"]
|
|
items = [item for item in catalog if item["kind"] == "main_weapon"]
|
|
variants = [item for item in catalog if item["kind"] == "resource_armament" and "/Temp_" in item["normal_config"]]
|
|
out = ["-- Generated by tools/generate_hun_weapons.py from DT_WeaponData and the game's input maps.",
|
|
"local data={rows={},variants={},configs={},chains={}}"]
|
|
generic_heavy = next(key for key in maps if key.endswith("/AIM_Hun_HeavyAttack"))
|
|
used_maps = {generic, generic_heavy}
|
|
for p in sorted({item[key] for item in items + variants for key in ("normal_config", "soul_config") if item[key]}):
|
|
props = configs[p.split(".")[0].casefold()]
|
|
abilities = asset_paths(props, "Equip Abilities")
|
|
# Select the ground A class, with its native naming (some families share the Tang or Double attacks).
|
|
ground = next((a.rsplit("/", 1)[-1] for a in abilities if a.endswith("_A") and "_Air" not in a), "")
|
|
prefix = ground.removesuffix("_A") + "_" if ground else "GA_Hun_"
|
|
m = next((v[1][1] for v in props.get("Weapon Combos", []) if v[1] and
|
|
v[0][1].endswith("/IA_AttackL_Press") and not v[1][1].endswith("_Hold")), generic)
|
|
heavy = next((v[1][1] for v in props.get("Weapon Combos", []) if v[1] and
|
|
v[0][1].endswith("/IA_AttackH_Press") and not v[1][1].endswith("_Hold")), generic_heavy)
|
|
if heavy not in maps:
|
|
raise ValueError(f"Missing decoded heavy input map {heavy}")
|
|
used_maps.add(heavy)
|
|
if m not in maps:
|
|
raise ValueError(f"Missing decoded input map {m}")
|
|
used_maps.add(m)
|
|
args_ = [f"prefix={quote(prefix)}", f"chain={quote(m.rsplit('/', 1)[-1])}",
|
|
f"heavyChain={quote(heavy.rsplit('/', 1)[-1])}",
|
|
"tags=" + strings(t for t in props.get("Weapon Equip Tags", []) if t.startswith("Weapon.Type."))]
|
|
art = next((a for a in abilities if re.search(r"/GA_Hun_\w+_(?:C|C1|C_Range|CA)$", a)), None)
|
|
if "/Temp_" in p:
|
|
art = next((a for a in abilities if a.endswith("_Ultimate")), None)
|
|
if art:
|
|
args_.append("art=" + quote(art + "." + art.rsplit("/", 1)[-1] + "_C"))
|
|
grab = next((a for a in abilities if a.endswith("/GA_Hun_DualHook_GEx") or a.endswith("/GA_Hun_ZhanMa_C")), None)
|
|
if grab:
|
|
args_.append("grab=" + quote(grab + "." + grab.rsplit("/", 1)[-1] + "_C"))
|
|
if grab.endswith("ZhanMa_C"):
|
|
args_.append("grabNeeds='CharacterType.Humanoid'")
|
|
out.append(f"data.configs[{quote(p)}]={{" + ",".join(args_) + "}")
|
|
for rank, item in enumerate(items, 1):
|
|
row = rows[item["row"]]
|
|
assert row["ItemId"] == item["native_id"]
|
|
out.append(f"data.rows[{rank}]={{id={quote(item['id'])},native_id={quote(item['native_id'])},"
|
|
f"label={quote(item['name'])},path={quote(item['normal_config'])},soulPath={quote(item['soul_config'])},"
|
|
f"soul={str(item['soul_option']).lower()},")
|
|
grant = grants.get(row["ItemId"])
|
|
if grant:
|
|
out.append(f" grantStage={grant['stage']},grantGroup={quote(grant['group'])},"
|
|
f"grantNode={quote(grant['node'])},grantMap={quote(grant['map'])},")
|
|
out.append(" multipliers={" + ",".join(["1"] + [f"{v['AttackMultipliers']:.5g}"
|
|
for v in row["WeaponUpLevelDatas"]]) + "},")
|
|
out.append(" effects={ -- class, unlock level, GE level, equipped only, requires soul")
|
|
for p, level, ge_level, equipped, soul in effects(row):
|
|
out.append(f" {{{quote(p)},{level},{ge_level},{str(equipped).lower()},{str(soul).lower()}}},")
|
|
out.append(" }}")
|
|
for item in variants:
|
|
p = item["normal_config"]
|
|
props = configs[p.split(".")[0].casefold()]
|
|
is_head = not asset_paths(props, "Equip Abilities")
|
|
assert is_head == ("_HouHouHouHead." in p)
|
|
out.append(f"data.variants[{quote(item['id'])}]={{id={quote(item['id'])},native_id={quote(p.split('.')[-1])},"
|
|
f"label={quote(item['name'])},path={quote(p)},soulPath='',rank=1,multipliers={{1}},"
|
|
f"effects={{}},temporary=true,poleOnly={str(is_head).lower()}" + "}")
|
|
for p in sorted(used_maps):
|
|
out.append(f"data.chains[{quote(p.rsplit('/', 1)[-1])}]={{")
|
|
for src, dest in (("Actions", "actions"), ("Combos", "combos")):
|
|
out.append(" " + dest + "={")
|
|
for b in maps[p]["Bindings"]:
|
|
if b.get("ActionPriority") != (2 if "HeavyAttack" in p else 1):
|
|
continue
|
|
for action in b.get("NormalData", {}).get(src) or []:
|
|
req = action["RequiredTags"]
|
|
tag = action["TriggerTag"]["TagName"]
|
|
if "CharacterState.Space.Ground" not in req or any(
|
|
token in t for t in req for token in ("Sprinting", "Jump", "Air")
|
|
) or ".Air." in tag or "ADash" in tag:
|
|
continue
|
|
out.append(f" {{tag={quote(tag)},req={strings(req)},ign={strings(action['IgnoredTags'])}}},")
|
|
out.append(" },")
|
|
out.append("}")
|
|
args.output.write_text("\n".join(out + ["return data", ""]), encoding="utf-8", newline="\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|