Files
metin2-client/tools/server/ava2-dungeons/make_quests.py
T
shenleiandClaude Opus 5.5 a1e7da68a4 Level 120 (L1-L5): AVA2 maps, drops, dungeons, dungeon timer UI
- tools/server/level-120: sbtest install of the 120 exp table and the
  unsigned exp column.
- tools/server/ava2-maps: the 10 AVA2 maps (pack, map data, regen, designed
  drops) for sbtest; Ava2MapsScript.inc, gr2 texture and mob_proto tests.
- tools/server/ava2-dungeons: snow / ship defence / Meley quests ported from
  AVA2 (make_quests.py + install.sh).
- mt_dungeon_timer (DungeonTimerScript.inc): AVA2 dungeon timer in place of
  the minimap (RefreshDungeonTimer) and the hydra mast HP bar (gethydrahp).
- Autohunt skips a target that is hit but takes no damage for 4 s (blocked
  Meley statues) and keeps it skipped for 60 s; FindCloseTarget now honours
  the skip list.

Meley full run passed on sbtest with the Mac client. Not deployed live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 08:13:32 +09:00

149 lines
9.8 KiB
Python

#!/usr/bin/env python3
"""Stage AVA2's three new dungeons for the 203 server: quests, regen data, monster groups and entrance NPCs.
The quests are AVA2's quest/Mazmorras/{snow,shipdefense,meleylair}.lua with asserted patches (every patch must
match, so a changed source fails loudly):
- lc_quest("KEY") and the mission notice numbers become zh text (the 203 quests carry their strings inline);
- GetMissionInfo(level, seconds) becomes d.command("RefreshDungeonTimer ...") (the client ignores it for now);
- the battle pass / dungeon tracker calls and the DUNGEON_COOLDOWN_EVENT branch go (203 has neither; the normal
cooldown stays: snow 60 min, ship and Meley 3 h);
- time_str, which 203 lacks, becomes seconds;
- the hydra map entry moves with the map (AVA2 972800,153600 -> 203 3276800,0: entry 10049,1652 -> 33089,116);
- two AVA2 bugs: an undefined `index` in snow's nemere_full_timer / nemere_dead_timer warps and in Meley's
6230.attack set_meley_hp.
Output (UTF-8; install.sh converts the quests to GBK):
<stage>/quest/<name>.quest snow_dungeon, ShipDefense, MeleyDungeon
<stage>/data/dungeon/{ice_dungeon,hydra,meley}/ AVA2 regen files (local coordinates, unchanged)
<stage>/group.txt AVA2 Meley groups 6220/6223-6225 (install.sh appends the ones 203 lacks)
<stage>/npc.tsv entrance NPC rows: <map dir> <npc.txt row>
<stage>/quest_functions new quest function names (port_ava2_dungeon.cpp)
Usage: make_quests.py <stage dir> [<AVA2 srv1 dir>]
"""
import re,shutil,sys
from pathlib import Path
HERE=Path(__file__).resolve().parent
SRV1=Path(sys.argv[2]) if len(sys.argv)>2 else HERE.parents[3]/'AVA2/TEST/2. Backup SF+SRC and SQL/home/srv1'
stage=Path(sys.argv[1])
MAZ=SRV1/'share/locale/germany/quest/Mazmorras'
QUESTS={'snow_dungeon':'snow.lua','ShipDefense':'shipdefense.lua','MeleyDungeon':'meleylair.lua'}
LC={'10':'剩余时间:','11':'秒','12':'确定要开始吗?','29':'顺序不正确!','30':'奈梅尔瞭望塔','31':'开始副本',
'32':'确定要开始副本吗?','33':'冰块消失了。','50':'船只防御战','50_1':'需要等待:','51':'守住桅杆,别让它们摧毁!',
'71':'赤龙巢穴','BACK_DUNGEON':'返回副本','BACK_QUESTION':'要回到之前所在的副本吗?',
'CANT_BACK':'只能在5分钟内重新进入,已超时!','COOLDOWN':'以下玩家仍需等待:','DUNGEON_REMOVE':'副本已关闭,请从头开始。',
'ENTER_DUNGEON':'要进入副本吗?','GROUP':'要组队进入吗?','INDIVIDUAL':'单人进入','LEVEL_ERROR':'你的等级不足,无法进入此副本!',
'LOW_LEVEL':'以下玩家等级不足:','NO_CH':'副本不在本频道开启。','NO_KEY':'你没有进入副本的钥匙!',
'NO_MEMBER_KEY':'以下玩家没有钥匙:','NO_PARTY':'你不在队伍中!','NO_PARTY_MEMBER':'附近的队员不足!','PARTY':'组队进入',
'YES':'是','CANCEL':'取消'}
NOTICE={'1003':'副本完成!即将传送出去。','1019':'消灭所有怪物。','1020':'任务完成!','1021':'摧毁寒冰之石。',
'1022':'找出正确的钥匙。','1023':'钥匙不对。','1024':'按正确的顺序解开冰块。','1025':'摧毁北方龙柱。','1026':'击败奈梅尔!',
'1027':'击败艾斯特尔继续前进。','1047':'你登上了被九头蛇和它的爪牙占领的船!','1048':'准备迎接海战!','1049':'守卫船只!',
'1050':'你成功守住了桅杆!准备迎接下一波。','1051':'……但战斗还没有结束','1052':'……去领取你的宝箱奖励!',
'1053':'九头蛇和它的军队有备而来,保护船只!','1054':'它们不知疲倦地进攻,继续守卫船只!','1102':'摧毁龙之雕像!',
'1103':'摧毁所有龙蛋!','1104':'击败变异怪物!'}
# (quest, old, new, expected count)
FIXES=[
('snow_dungeon','1647*100,index,60)','1647*100,get_server_timer_arg(),60)',2),
('ShipDefense','time_str(r_cooldown)','r_cooldown.."秒"',1),
('ShipDefense','d.new_jump(355, 10049*100,1652*100)','d.new_jump(355, 33089*100,116*100)',1),
('ShipDefense','d.new_jump_party(355, 10049, 1652)','d.new_jump_party(355, 33089, 116)',1),
('ShipDefense','d.jump_all(10049,1652)','d.jump_all(33089,116)',1),
('ShipDefense','pc.warp(10049*100,1652*100, dungeonMapIndex)','pc.warp(33089*100,116*100, dungeonMapIndex)',1),
('MeleyDungeon','npc.set_meley_hp(index,6230,','npc.set_meley_hp(d.get_map_index(),6230,',8),
('MeleyDungeon','say("Bileti olmayan \xfcyeler: ")','say("以下玩家没有钥匙:")',1),
]
NEW_FUNCTIONS=['d.mission_notice','d.global_warp_all_to_base','d.new_kill_all','d.command','d.dungeon_remove_all',
'd.kill_area','d.spawn_mob_new','npc.get_protect_time','npc.set_protect_time','npc.set_statu_affect',
'npc.set_statu_clear_aff','npc.show_statu','npc.set_meley_hp','npc.show_end_statu','npc.set_protect_flag2',
'npc.dead_by_vnum','npc.set_hp','npc.get_hp',
'table.remove'] # a Lua 5.0 builtin the 203 list lacks
# Entrance NPCs AVA2 places on the 203 maps (snow: 冰原守卫 on map 61; Meley: 守望者多纳尔 on map 62).
# ShipDefense's fisherman 9009 already stands on 301 (838,1187).
NPCS=[('map_n_snowm_01','m\t735\t105\t0\t0\t0\t5\t1m\t100\t1\t20395'),
('metin2_map_n_flame_01','m\t1476\t95\t0\t0\t0\t5\t1m\t100\t1\t20441')]
GROUPS=(6220,6223,6224,6225)
def sub(text,pattern,repl,where,flags=0,min_count=1):
out,n=re.subn(pattern,repl,text,flags=flags)
if n<min_count:raise SystemExit('%s: no match for %r'%(where,pattern))
return out
def mission_info(text,where):
"""GetMissionInfo(a,b) -> d.command(string.format("RefreshDungeonTimer %d %d",a,b)); args may nest calls."""
out=[];i=0;n=0
while True:
j=text.find('GetMissionInfo(',i)
if j<0:break
k=j+len('GetMissionInfo(');depth=1;args=k
while depth:
depth+={'(':1,')':-1}.get(text[k],0);k+=1
line_start=text.rfind('\n',0,j)+1
commented=text[line_start:j].lstrip().startswith('--')
out.append(text[i:j])
out.append(text[j:k] if commented else 'd.command(string.format("RefreshDungeonTimer %%d %%d",%s))'%text[args:k-1])
n+=not commented;i=k
if not n:raise SystemExit(where+': no GetMissionInfo')
return ''.join(out)+text[i:]
def convert(name,src):
# AVA2's Turkish comments (latin1-decoded) have no GBK form
t=''.join(l for l in src.splitlines(True) if not (l.lstrip().startswith('--') and not l.isascii()))
for q,old,new,count in FIXES:
if q!=name:continue
if t.count(old)!=count:raise SystemExit('%s: %r found %d times, expected %d'%(name,old,t.count(old),count))
t=t.replace(old,new)
t=re.sub(r'lc_quest\(string\.format\("NO_CH2 %d ?",(\w+)\)\)',r'string.format("请切换到 %d 频道。",\1)',t)
def lc(m):
k=m.group(1).strip()
if k not in LC:raise SystemExit('%s: lc_quest key %r has no zh text'%(name,k))
return '"%s"'%LC[k]
t=re.sub(r'lc_quest\("([^"]*)"\)',lc,t)
def notice(m):
k=m.group(2).strip()
if k not in NOTICE:raise SystemExit('%s: notice %r has no zh text'%(name,k))
return '%s"%s")'%(m.group(1),NOTICE[k])
t=re.sub(r'(d\.mission_notice\([^,()]+(?:\(\))?,)"(\d+ ?)"\)',notice,t)
t=re.sub(r'(d\.notice\()"(\d+)"\)',notice,t)
t=mission_info(t,name)
# AVA2 systems 203 does not have: battle pass missions, the dungeon tracker, DUNGEON_COOLDOWN_EVENT.
t=re.sub(r'[ \t]*do_battlepass_mission\([^\n]*\n','',t)
t=re.sub(r'[ \t]*d\.track_update\([^\n]*\n','',t)
t=re.sub(r'[ \t]*if game\.check_event\([^\n]*\n[^\n]*\n[ \t]*else[ \t]*\n([^\n]*\n)[ \t]*end[ \t]*\n',r'\1',t)
for bad in ('lc_quest','GetMissionInfo(','do_battlepass_mission','track_update','check_event','time_str'):
if bad in t.replace('--GetMissionInfo(','').replace('-- GetMissionInfo(',''):
raise SystemExit('%s: %s left'%(name,bad))
if not re.search(r'^quest %s begin'%re.escape(name),t,re.M):raise SystemExit(name+': quest name changed')
return t
def main():
(stage/'quest').mkdir(parents=True,exist_ok=True)
for name,lua in QUESTS.items():
src=(MAZ/lua).read_bytes().decode('latin1').replace('\r\n','\n')
text=convert(name,src)
text='-- AVA2 quest/Mazmorras/%s for 203, generated by tools/server/ava2-dungeons/make_quests.py\n%s'%(lua,text)
(stage/'quest'/(name+'.quest')).write_text(text,encoding='utf-8')
text.encode('gbk') # every string must have a GBK form
data=stage/'data/dungeon'
for d in ('ice_dungeon','hydra','meley'):
if (data/d).exists():shutil.rmtree(data/d)
(data/d).mkdir(parents=True)
for f in sorted((SRV1/'share/data/dungeon'/d).glob('*.txt')):shutil.copy2(f,data/d/f.name)
blocks={}
for b in re.finditer(r'Group[ \t]+(\S+)\s*\{(.*?)\}',(SRV1/'share/locale/germany/group.txt').read_bytes().decode('latin1'),re.S):
v=re.search(r'Vnum\s+(\d+)',b.group(2))
if v and int(v.group(1)) in GROUPS:blocks[int(v.group(1))]=b.group(2)
if sorted(blocks)!=sorted(GROUPS):raise SystemExit('group.txt: missing '+str(set(GROUPS)-set(blocks)))
out=[]
for v in GROUPS:
body=[l.strip() for l in blocks[v].replace('\r','').split('\n') if l.strip()]
rows=[re.findall(r'"[^"]*"|\S+',l) for l in body]
# member names are only labels; AVA2's quoted English ones contain spaces
out+=['Group\tAVA2Meley_%d'%v,'{']+['\t'+'\t'.join(r if r[0]=='Vnum' else [r[0],'mob%s'%r[-1],r[-1]]) for r in rows]+['}']
(stage/'group.txt').write_bytes(('\r\n'.join(out)+'\r\n').encode('latin1'))
(stage/'npc.tsv').write_text(''.join('%s\t%s\n'%r for r in NPCS))
(stage/'quest_functions').write_text('\n'.join(NEW_FUNCTIONS)+'\n')
print('staged %d quests, %d data files, %d groups, %d npcs -> %s'%(len(QUESTS),sum(1 for _ in data.rglob('*.txt')),len(GROUPS),len(NPCS),stage))
if __name__=='__main__':main()