#!/usr/bin/env python3 """Temporary CH5-only NPC click fixture for a named QA character; remove after acceptance.""" import argparse,json,pathlib,re,shutil,subprocess BASE=pathlib.Path('/root/deploy-features/20261026-stack2000') QUEST=pathlib.Path('/usr/metin2/server/sbtest/share/locale/newcibn/quest') if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('action',choices=['install','remove']);p.add_argument('--private-file',required=True);p.add_argument('--extended',action='store_true');p.add_argument('--scope',choices=['test','production'],default='test');a=p.parse_args() if a.scope=='production': if a.extended:raise RuntimeError('extended fixtures are isolated-only') QUEST=pathlib.Path('/usr/metin2/server/share/locale/newcibn/quest') manifest=BASE/('warehouse-fixture-files.json' if a.scope=='test' else 'warehouse-fixture-production-files.json') if a.action=='remove': if manifest.exists(): for name in json.loads(manifest.read_text()): path=pathlib.Path(name) if not path.is_relative_to(QUEST/'object'):raise RuntimeError('unexpected fixture path') path.unlink(missing_ok=True) manifest.unlink() else: s=json.loads(pathlib.Path(a.private_file).read_text());name=s['name'] if not re.fullmatch('[A-Za-z0-9]+',name):raise ValueError('name') work=BASE/('warehouse-quest' if a.scope=='test' else 'warehouse-quest-production');work.mkdir(exist_ok=True) shutil.copy2(QUEST/'quest_functions',work/'quest_functions') source=work/'stack2000_acceptance.quest' actions={'STACK2000_QA':'game.open_safebox()'} if a.extended:actions.update(STACK2000_SHOP='npc.open_shop(65001)',STACK2000_MALL='game.open_mall()',STACK2000_GRANT='pc.give_item2(30007,4001)',STACK2000_CUBE='command("cube open")',STACK2000_CUBE_MATERIAL='pc.give_item2(30008,2000)',STACK2000_FULL='pc.give_item2(27003,2001)',STACK2000_REFINE='pc.give_item2(30053,2000) mob.spawn(20016,pc.get_local_x()+1,pc.get_local_y()+1,0,false,1)') clauses=['when 9005.chat."'+label+'" with pc.get_name()=="'+name+'" begin\n setskin(NOWINDOW)\n '+action+'\n end' for label,action in actions.items()] source.write_text('quest stack2000_acceptance begin\n state start begin\n'+'\n'.join(clauses)+'\n end\nend\n') shutil.rmtree(work/'object',ignore_errors=True) subprocess.run([str(QUEST/'qc'),str(source)],cwd=work,check=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) files=[] for path in (work/'object').rglob('*'): if not path.is_file():continue target=QUEST/'object'/path.relative_to(work/'object') if target.exists():raise RuntimeError('fixture path already exists') target.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(path,target);files.append(str(target)) manifest.write_text(json.dumps(files));print('fixture files',len(files))