Files
2026-11-23 03:28:32 +02:00

57 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Extend the installed weapon presentation profile with Turtle weapons added after its (lost) 2026-10-17 snapshot.
Base: the profile behind the installed SourceWeaponDamageData.lua (lua_payload(base) must equal the installed file).
New records come from the current Tortoise templates (missing-sparse-public-templates.json) with the same
weapon_record() rules and the same primary-tooltip selection as compile_inventory (melee physical, bow/gun/crossbow
physical, wands, thrown physical). Existing records are never changed.
"""
import argparse, hashlib, json, sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
import item_damage_profile as D
sys.path.insert(0, str(Path(__file__).resolve().parent))
import source_fixes
def primary(source, record):
band = record['bands'][0]
if band['maximum'] <= 0: return False
inv, sub = source['inventory_type'], source['subclass']
# New records only: any primary school (Grungy Firestick fire, Diathorus' Claw shadow); the tooltip renders schools.
if inv in (13, 17, 21, 22): return True
if inv in (15, 26) and sub in (2, 3, 18): return True
if inv == 26 and sub == 19: return True
if inv == 25 and sub == 16: return band['school'] == 0
return False
def main():
a = argparse.ArgumentParser(description=__doc__)
a.add_argument('--base', type=Path, required=True); a.add_argument('--installed-lua', type=Path, required=True)
a.add_argument('--templates', type=Path, required=True); a.add_argument('--out', type=Path, required=True)
o = a.parse_args()
base = json.loads(o.base.read_text())
if D.lua_payload(base) != o.installed_lua.read_bytes(): raise SystemExit('base profile does not regenerate the installed Lua')
have = {r['item_id'] for r in base['records']}
added, blocked = [], []
for s in source_fixes.apply(json.loads(o.templates.read_text())):
if s['class'] != 2 or s['entry'] in have: continue
try: rec = D.weapon_record(s)
except ValueError as e: blocked.append(dict(item_id=s['entry'], reason=str(e))); continue
added.append((s, rec))
prof = json.loads(json.dumps(base))
prof['records'] = sorted(prof['records'] + [r for _, r in added], key=lambda r: r['item_id'])
# Reviewed: wands with non-wand slot types (one-hand / ranged); primary() cannot classify them by slot.
WAND_SLOT_EXCEPTIONS = {61374, 70013, 910097} # Grungy Firestick (Fire), Diathorus' Claw, Emissary Shooter (Shadow)
assert WAND_SLOT_EXCEPTIONS <= {r['item_id'] for r in prof['records']}
prof['primary_item_ids'] = sorted(set(prof['primary_item_ids']) | {r['item_id'] for s, r in added if primary(s, r)} | WAND_SLOT_EXCEPTIONS)
prof['blocked'] = sorted(prof['blocked'] + blocked, key=lambda r: r['item_id'])
prof['extension'] = dict(kind='claude-post-snapshot-weapon-extension-20261122',
base_profile_sha256=hashlib.sha256(o.base.read_bytes()).hexdigest(),
templates_sha256=hashlib.sha256(o.templates.read_bytes()).hexdigest(), added_item_ids=sorted(r['item_id'] for _, r in added))
o.out.mkdir(parents=True, exist_ok=True)
(o.out / 'profile.json').write_text(json.dumps(prof, sort_keys=True, indent=1) + '\n')
(o.out / 'SourceWeaponDamageData.lua').write_bytes(D.lua_payload(prof))
print('added', len(added), 'primary', sum(primary(s, r) for s, r in added), 'blocked', len(blocked))
if __name__ == '__main__': main()