Files
metin2-server/tools/ava2-itemshop/audit_completion.py
T

69 lines
5.1 KiB
Python

#!/usr/bin/env python3
"""Check the exact remaining original offers and their staged dependencies. Never enables offers."""
import argparse,collections,hashlib,json
from pathlib import Path
ROOT=Path(__file__).resolve().parents[2]
CLIENT=ROOT.parent/'metin2-client'
def feature(row):
v=row['vnum'];t=row['source_type'];sub=row['source_subtype']
if v in (53998,53999):return 'costume_attribute_removal'
if v in (100001,100002):return 'dragon_soul_charge'
if v in (39063,39064):return 'gaya_consumables'
if v==71097:return 'dragon_soul_attribute_change'
if v==85009:return 'sash_detachment'
if v==6884:return 'rarity_conversion'
if v==72319:return 'offline_shop_key'
if v==72320:return 'storage_unlock'
if v==25159:return 'monthly_battlepass_ticket'
if v in (72067,72068):return 'rare_attribute_support'
if v in range(25163,25170):return 'dungeon_tickets'
if v==20059:return 'appearance_exchange_ticket'
if t=='ITEM_COSTUME':return sub.lower()
if t=='ITEM_PET':return 'growing_pet_'+sub.removeprefix('PET_').lower()
if t=='ITEM_GIFTBOX':return 'giftbox_reward_chain'
if t=='ITEM_TREASURE_KEY':return 'treasure_key_reward_chain'
if t=='ITEM_MATERIAL':return 'dragon_soul_refine_material'
if t=='ITEM_USE' and sub=='USE_CHANGE_ATTRIBUTE':return 'costume_fixed_attribute'
if t=='ITEM_UNIQUE':return 'unique_item_'+str(v)
if t=='ITEM_USE' and sub=='USE_AFFECT':return 'affect_consumable'
return 'quest_item_'+str(v)
def audit(staged=None,assets=None):
data=ROOT/'data/ava2-itemshop'
ledger=json.loads((data/'completion-168.json').read_text());remaining=ledger['products']
baseline=json.loads((data/'verified-products.json').read_text())['products']
originals={}
for line in (data/'original-products.tsv').read_text().splitlines():
c=line.split('\t');key=int(c[0]);assert key not in originals,'duplicate original id';originals[key]=(int(c[3]),int(c[4]))
ids=[r['id'] for r in remaining];assert len(ids)==len(set(ids))==ledger['count']==168,'remaining identity/count changed'
baseids={r['id'] for r in baseline};assert len(baseids)==49 and not baseids.intersection(ids)
assert baseids.union(ids)==set(originals),'original catalogue not partitioned exactly'
rows={}
if staged:
for line in Path(staged).read_bytes().splitlines():
c=line.split(b'\t')
if c[0].isdigit():
v=int(c[0]);assert v not in rows,'duplicate staged vnum';rows[v]=[x.decode('gbk') for x in c]
# Resolve the exact original icon/model mapping; a missing explicit mapping is
# shown as missing rather than guessed to be a working model.
items={}
for line in (ROOT.parent/'AVA2/1. Client DEV/pack_maker/locale/locale/es/item_list.txt').read_text(encoding='latin1').splitlines():
c=[x.strip().lower().replace('\\','/') for x in line.split('\t') if x.strip()]
if c and c[0].isdigit():items[int(c[0])]=c
result=[]
for r in remaining:
assert (r['vnum'],r['original_price'])==originals[r['id']],'offer identity or original price changed'
evidence=r.get('evidence',[])
for name in evidence:
p=Path(name);p=p if p.is_absolute() else ROOT.parent/p
assert p.is_file(),'missing evidence source: '+name
v=r['vnum'];proto=rows.get(v);entry=items.get(v,[str(v),'etc','icon/item/%05d.tga'%v]);paths=entry[2:4]
ready=bool(proto and proto[2]!='ITEM_NONE' and proto[2:4]==[r['source_type'],r['source_subtype']])
# QUEST_NONE/NONE are aliases for the zero subtype, not distinct handlers.
if proto and r['source_type']=='ITEM_QUEST':ready=proto[2]=='ITEM_QUEST' and proto[3] in ('0','NONE','QUEST_NONE')
result.append({'id':r['id'],'vnum':v,'original_price':r['original_price'],'feature':feature(r),'status':r['status'],'prototype_staged':ready if staged else None,'staged_type':proto[2:4] if proto else None,'direct_asset_paths':paths,'missing_direct_assets':[p for p in paths if not (Path(assets)/p).is_file()] if assets else None,'live_acceptance':'NOT_VERIFIED','evidence_sources':evidence})
return {'count':168,'baseline_count':49,'original_count':len(originals),'scope':'dependency inventory; source paths and direct assets do not prove working gameplay, full resource closure or live acceptance','ledger_sha256':hashlib.sha256((data/'completion-168.json').read_bytes()).hexdigest(),'groups':dict(sorted(collections.Counter(r['feature'] for r in result).items())),'statuses':dict(collections.Counter(r['status'] for r in result)),'prototype_staged_count':sum(r['prototype_staged'] is True for r in result) if staged else None,'products':result}
def main():
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--staged-server-tsv',type=Path);p.add_argument('--assets',type=Path);p.add_argument('--output',type=Path,required=True);a=p.parse_args()
report=audit(a.staged_server_tsv,a.assets);a.output.parent.mkdir(parents=True,exist_ok=True);a.output.write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n');print(json.dumps({k:report[k] for k in ('count','groups','statuses','prototype_staged_count')},ensure_ascii=False))
if __name__=='__main__':main()