Files
metin2-client/tools/server/ava2-stones/prepare.py
T

34 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Generate a stone-only patch from AVA2; the shared locale builder packages the same rows."""
import argparse,hashlib,importlib.util,json
from pathlib import Path
HERE=Path(__file__).resolve().parent
spec=importlib.util.spec_from_file_location('ava2_items',HERE.parent/'ava2-items/make_items.py')
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
def prepare(ava,reader,out):
raw=m.server_proto(ava,'item_proto.txt')
source={int(c[0]):[x.decode('latin1') for x in c] for l in raw.splitlines()
if len(c:=l.split(b'\t'))>=33 and c[0].isdigit() and c[2]==b'ITEM_METIN'}
if set(source)!=m.STONE_IDS:raise ValueError('AVA2 stone IDs changed; audit the catalogue before importing')
E=m.enums(reader);out.mkdir(parents=True,exist_ok=True);server=[];client=[];items=[]
for v,c in sorted(source.items()):
s,n,kept=m.convert(c,E,set(source));s[1]=m.stone_name(v)
server.append('\t'.join(s).encode('gbk'))
client.append(('\t'.join(map(str,n))+'\t'+s[1]).encode('gbk'))
items.append(dict(vnum=v,name=s[1],locked=m.stone_lock_reason(c,E),source_type=c[2:4],
source_applies=c[18:24],source_values=c[24:30],source_wear=c[7]))
(out/'stones-server.tsv').write_bytes(b'\n'.join(server)+b'\n')
(out/'stones-client.tsv').write_bytes(b'\n'.join(client)+b'\n')
report=dict(source_sha256=hashlib.sha256(raw).hexdigest(),items=items,
legacy_plus6_policy='preserve existing items and sockets; no new distribution in this patch')
(out/'stones.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
return report
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('--ava',type=Path,required=True);p.add_argument('--reader',type=Path,required=True)
p.add_argument('--output',type=Path,required=True);a=p.parse_args()
r=prepare(a.ava,a.reader,a.output)
print('stones=%d locked=%d (broken-stone marker is retained)'%(len(r['items']),sum(bool(x['locked']) for x in r['items'])))