fix: import complete sash combine chains and sync isolated db prototypes
This commit is contained in:
@@ -19,6 +19,12 @@ def install(proto,names,rows):
|
||||
newline=b'\r\n' if b'\r\n' in raw else b'\n'
|
||||
kept=[l for l in raw.replace(b'\r\n',b'\n').split(b'\n') if l and not (l.split(b'\t',1)[0].isdigit() and int(l.split(b'\t',1)[0]) in rows)]
|
||||
tmp=path.with_name(filename+'.tmp');tmp.write_bytes(newline.join(kept+[row(v) for v in sorted(rows)])+newline);tmp.replace(path)
|
||||
# Isolated clusters may use copies rather than links to share/conf.
|
||||
dbpath=server/'db'/filename
|
||||
if dbpath.is_file() and dbpath.resolve()!=path.resolve():
|
||||
dbbackup=backup/'db'/filename;dbbackup.parent.mkdir(parents=True,exist_ok=True)
|
||||
shutil.copy2(dbpath,dbbackup)
|
||||
dbtmp=dbpath.with_name(filename+'.tmp');shutil.copy2(path,dbtmp);dbtmp.replace(dbpath)
|
||||
|
||||
items=load(rows);install('item_proto.txt','item_names.txt',items)
|
||||
print('AVA2 items installed:',len(items),'backup:',backup)
|
||||
|
||||
@@ -82,6 +82,10 @@ def names():
|
||||
for k in range(PENDANT_STEPS):result[base+k]='%s+%d'%(n,k)
|
||||
for base,n in RINGS.items():
|
||||
for k in range(10):result[base+k]='%s+%d'%(n,k)
|
||||
# Combine consumes two sashes and advances to the next grade; import every step.
|
||||
for base,label in ((85001,'领主'),(85005,'大师'),(85011,'王朝'),(85015,'皇家')):
|
||||
for grade,suffix in enumerate(('普通','精致','高级','个人')):
|
||||
result[base+grade]=label+'披风('+suffix+')'
|
||||
result.update({50348:'属性锁定符',50349:'属性解锁符'})
|
||||
for month in range(1,13):result[25149+month]='%d月战令票'%month
|
||||
return result
|
||||
@@ -154,31 +158,32 @@ def pack_index(pack_maker):
|
||||
index.setdefault(archived.lower().replace('\\','/'),pack_maker.parent/source)
|
||||
return index
|
||||
|
||||
def server_proto(ava,filename):
|
||||
path=ava/'2. Backup SF+SRC and SQL/home/srv1/db'/filename
|
||||
if path.is_file():return path.read_bytes()
|
||||
with tarfile.open(ava/'2. Backup SF+SRC and SQL/FILES+SRC.tgz','r:gz') as source:
|
||||
member=source.extractfile('home/srv1/db/'+filename)
|
||||
if member is None:raise ValueError('AVA2 archive has no '+filename)
|
||||
return member.read()
|
||||
|
||||
def prepare(ava,proto_reader,locale,output,tool,packer,wrap=lambda text:text):
|
||||
"""wrap: the locale's itemdesc line wrapping (build_zh_locale.wrap_description)."""
|
||||
E=enums(proto_reader);zh=names();wanted=set(zh)
|
||||
db=ava/'2. Backup SF+SRC and SQL/home/srv1/db';pack_maker=ava/'1. Client DEV/pack_maker'
|
||||
rows={}
|
||||
proto=db/'item_proto.txt'
|
||||
if proto.is_file():raw=proto.read_bytes()
|
||||
else:
|
||||
# The checked-out reference normally contains the original archive,
|
||||
# not somebody else's AVA2/TEST extraction directory.
|
||||
with tarfile.open(ava/'2. Backup SF+SRC and SQL/FILES+SRC.tgz','r:gz') as source:
|
||||
member=source.extractfile('home/srv1/db/item_proto.txt')
|
||||
if member is None:raise ValueError('AVA2 archive has no item_proto.txt')
|
||||
raw=member.read()
|
||||
raw=server_proto(ava,'item_proto.txt')
|
||||
for line in raw.splitlines():
|
||||
cols=line.split(b'\t')
|
||||
if cols[0].strip().isdigit() and int(cols[0]) in wanted:rows[int(cols[0])]=[x.decode('latin1') for x in cols]
|
||||
# The archived server DB omits the lock materials even though its gameplay
|
||||
# code registers them. AVA2's client DumpProto ships their actual definitions.
|
||||
if not {50348,50349}<=rows.keys():
|
||||
# The archived server DB omits lock materials and lower sash grades.
|
||||
# Fill missing requested rows from AVA2's original client definitions.
|
||||
if wanted-rows.keys():
|
||||
dump=ava/'3. Source BIN/Tools/DumpProto/Release/item_proto.txt'
|
||||
if not dump.is_file():dump=ava.parent/'3. Source BIN/Tools/DumpProto/Release/item_proto.txt'
|
||||
for line in dump.read_bytes().splitlines():
|
||||
cols=line.split(b'\t')
|
||||
if cols[0] in (b'50348',b'50349'):rows[int(cols[0])]=[x.decode('latin1') for x in cols]
|
||||
if cols[0].strip().isdigit() and int(cols[0]) in wanted-rows.keys():
|
||||
rows[int(cols[0])]=[x.decode('latin1') for x in cols]
|
||||
assert rows.keys()==wanted,sorted(wanted-rows.keys())
|
||||
listrows={}
|
||||
for line in (pack_maker/'locale/locale/es/item_list.txt').read_bytes().splitlines():
|
||||
@@ -218,7 +223,7 @@ def prepare(ava,proto_reader,locale,output,tool,packer,wrap=lambda text:text):
|
||||
(output/'items-server.tsv').write_bytes(b'\n'.join(server)+b'\n')
|
||||
(output/'items-client.tsv').write_bytes(b'\n'.join(client)+b'\n')
|
||||
mobs={}
|
||||
for line in (db/'mob_proto.txt').read_bytes().splitlines():
|
||||
for line in server_proto(ava,'mob_proto.txt').splitlines():
|
||||
cols=line.split(b'\t')
|
||||
if cols[0].strip().isdigit() and int(cols[0]) in MOUNT_MOBS:
|
||||
v=int(cols[0]);cols[1]=MOUNT_MOBS[v][0].encode('gbk');mobs[v]=b'\t'.join(cols)
|
||||
|
||||
@@ -55,6 +55,17 @@ class ConvertTests(unittest.TestCase):
|
||||
values=('4','0','0','0','0','0')),self.E,{85004})
|
||||
self.assertTrue(kept);self.assertEqual(s[2:4],['ITEM_COSTUME','COSTUME_SASH']);self.assertEqual(s[24],'4') # value0 = grade
|
||||
self.assertEqual(c[2],3) # COSTUME_SASH, after BODY/HAIR/MOUNT
|
||||
def test_sash_complete_chains(self):
|
||||
n=m.names()
|
||||
for base in (85001,85005,85011,85015):
|
||||
for grade in range(1,5):
|
||||
v=base+grade-1
|
||||
self.assertIn(v,n)
|
||||
s,c,kept=m.convert(row(v,'ITEM_COSTUME','COSTUME_SASH',
|
||||
values=(str(grade),'0','0','0','0','0')),self.E,set(n))
|
||||
self.assertTrue(kept)
|
||||
self.assertEqual(s[24],str(grade))
|
||||
self.assertEqual(c[23],grade)
|
||||
def test_mount_and_skin_kept(self):
|
||||
s,c,kept=m.convert(row(71502,'ITEM_COSTUME','COSTUME_MOUNT','ANTI_STACK',applies=('APPLY_ATTBONUS_MONSTER','30','APPLY_NONE','0','APPLY_NONE','0'),
|
||||
values=('20113','0','0','0','0','0')),self.E,{71502})
|
||||
@@ -86,12 +97,15 @@ class ConvertTests(unittest.TestCase):
|
||||
d=Path(d);conf=d/'share/conf';conf.mkdir(parents=True)
|
||||
(conf/'item_proto.txt').write_bytes(b'VNUM\tNAME\r\n71502\told\r\n');(conf/'item_names.txt').write_bytes(b'VNUM\tNAME\r\n')
|
||||
(conf/'mob_proto.txt').write_bytes(b'VNUM\tNAME\n20110\tboar\n');(conf/'mob_names.txt').write_bytes(b'20110\tboar\n')
|
||||
(d/'db').mkdir();(d/'db/item_proto.txt').write_bytes(b'old db copy\n')
|
||||
(d/'i.tsv').write_bytes(b'71502\tnew\n');(d/'m.tsv').write_bytes(b'32012\tbari\tKING\n')
|
||||
subprocess.run([sys.executable,str(HERE/'install_items.py'),str(d),str(d/'i.tsv'),str(d/'bk'),str(d/'m.tsv')],check=True,capture_output=True)
|
||||
self.assertEqual((conf/'item_proto.txt').read_bytes(),b'VNUM\tNAME\r\n71502\tnew\r\n')
|
||||
self.assertEqual((conf/'mob_proto.txt').read_bytes(),b'VNUM\tNAME\n20110\tboar\n32012\tbari\tKING\n')
|
||||
self.assertEqual((conf/'mob_names.txt').read_bytes(),b'20110\tboar\n32012\tbari\n')
|
||||
self.assertTrue((d/'bk/mob_proto.txt').is_file())
|
||||
self.assertEqual((d/'db/item_proto.txt').read_bytes(),(conf/'item_proto.txt').read_bytes())
|
||||
self.assertEqual((d/'bk/db/item_proto.txt').read_bytes(),b'old db copy\n')
|
||||
def test_sash_effect_closure(self):
|
||||
import tempfile
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
@@ -117,7 +131,7 @@ class ConvertTests(unittest.TestCase):
|
||||
|
||||
|
||||
def test_names_cover_ranges(self):
|
||||
n=m.names();self.assertEqual(len(n),518+6*200+4*9+14);self.assertEqual(n[54100],'武器外观强化石')
|
||||
n=m.names();self.assertEqual(len(n),518+6*200+4*9+14+12);self.assertEqual(n[54100],'武器外观强化石')
|
||||
self.assertEqual([n[v] for v in (21210,21219,21279)],['暗龙铠甲+0','暗龙铠甲+9','神龙铠甲+9'])
|
||||
self.assertTrue(all(len(v.encode('gbk'))<=24 for v in n.values()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user