Files
shenleiandClaude Opus 5.5 38b62cfdbd Port AVA2 drop tables and drop code
make_drops.py builds 203's mob_drop_item / common_drop_new / special_item_group
from AVA2's (unknown items removed and renumbered, AVA2 boxes replace the same
vnum except 50035). The game loads common_drop_new.txt (level-range common
drops), GetDropPct follows AVA2 (premium/glove rates, fixed precedence bug),
a mob's second drop group no longer uses an uninitialised pointer, special
groups allow 1023 entries, and the wiki lists common_drop_new rows as rule 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 10:31:07 +09:00

53 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""AVA2 drop tables: the table builder on fixtures, then the wiring of the ported drop code."""
from pathlib import Path
import importlib.util
import json
import tempfile
ROOT=Path(__file__).resolve().parents[2]
SRC=ROOT/'src/server/game/src'
spec=importlib.util.spec_from_file_location('make_drops',ROOT/'tools/ava2-drops/make_drops.py')
make_drops=importlib.util.module_from_spec(spec);spec.loader.exec_module(make_drops)
with tempfile.TemporaryDirectory(prefix='mt-drops-') as folder:
base=Path(folder);ava=base/'ava';live=base/'live';out=base/'out';ava.mkdir();live.mkdir()
(ava/'mob_drop_item.txt').write_bytes(b'Group\tA\n{\n\tMob\t101\n\tType\tdrop\n\t1\t19\t1\t100\n\t2\t99999\t1\t100\n\t3\t110005\t1\t50\n}\n'
b'Group\tB\n{\n\tMob\t102\n\tType\tdrop\n\t1\t99999\t1\t100\n}\n')
(ava/'common_drop_new.txt').write_bytes(b'Group\tW\n{\n\tmap_index\t0\n\tlevel_range\t1\t12\n\t1\t19\t1\t0.03\n}\n')
(ava/'special_item_group.txt').write_bytes(b'Group\tX\r\n{\r\n\tVnum\t50011\r\n\t1\t19\t5\t2\r\n}\r\n'
b'Group\tGM\n{\n\tVnum\t50035\n\tType\tPct\n\t1\t19\t2000\t100\n}\n'
b'Group\tNew\n{\n\tVnum\t77900\n\t1\t99999\t1\t30\n\t2\t19\t1\t30\n}\n')
(live/'special_item_group.txt').write_bytes(b'Group\t\xc0\xcc\n{\n\tVnum\t50011\n\t1\t\xb0\xe6 \xc7\xe8\t1\t1\n}\n'
b'Group\tKid\n{\n\tVnum\t50035\n\t1\t19\t1\t1\n}\n'
b'Group\tOld\n{\n\tVnum\t10000\n\t1\t19\t1\t1\n}\n')
(base/'proto.txt').write_bytes(b'VNUM\tNAME\n19\tsword\n110000~110099\tds\n')
report=make_drops.build(ava,live,out,[base/'proto.txt'])
mob=(out/'mob_drop_item.txt').read_bytes()
# unknown items removed, entries renumbered (the reader stops at the first gap), empty groups skipped, ranges known
assert mob==b'Group\tA\n{\n\tMob\t101\n\tType\tdrop\n\t1\t19\t1\t100\n\t2\t110005\t1\t50\n}\n',mob
assert report['mob_dropped']=={'99999':2}
assert b'level_range\t1\t12' in (out/'common_drop_new.txt').read_bytes()
special=(out/'special_item_group.txt').read_bytes()
assert b'Vnum\t50011\n\t1\t19\t5\t2' in special and b'\xb0\xe6' not in special # AVA2 replaces the same vnum
assert b'Kid' in special and b'2000' not in special # 50035 is a different box on 203
assert b'Old' in special and b'Vnum\t77900\n\t1\t19\t1\t30' in special
assert (out/'common_drop_item.txt').read_bytes()==b''==(out/'etc_drop_item.txt').read_bytes()
assert json.loads((out/'report.json').read_text())['special_replaced']==[50011]
def source(name):return (SRC/name).read_bytes().decode('latin1')
manager=source('item_manager.cpp')
pct=manager[manager.index('bool ITEM_MANAGER::GetDropPct('):manager.index('bool ITEM_MANAGER::CreateDropItem(')]
assert '?100:0' not in pct.replace(' ','') # the precedence bug that pinned the denominator to 100
assert 'else\n\t\tiDeltaPercent += iDeltaPercent / 2;' in pct
assert '(100 + CPrivManager::instance().GetPriv(pkKiller, PRIV_ITEM_DROP) + bonus)' in pct
drop=manager[manager.index('bool ITEM_MANAGER::CreateDropItem('):]
assert drop.index('// Drop Item Group')<drop.index('m_vec_pkCommonNewItemGroup')<drop.index('// MobDropItem Group')
assert 'abs(pkChr->GetLevel() - iLevel) <= 20' in drop
tables=source('item_manager_read_tables.cpp')
assert 'CDropItemGroup* pkGroup = it->second;' not in tables # second group of a mob used an uninitialised pointer
special=tables[tables.index('bool ITEM_MANAGER::ReadSpecialDropItemFile('):tables.index('bool ITEM_MANAGER::ReadCommonDropNewItemFile(')]
assert special.count('k < 1024')==2 and 'char buf[4]' not in special.split('ConvSpecialDropItemFile')[0]
db=source('input_db.cpp')
assert db.index('ReadCommonDropItemFile(')<db.index('ReadCommonDropNewItemFile(')<db.index('ReadEtcDropItemFile(')
print('PASS: drop table builder (filter, renumber, ranges, merge, kept 203 box) and AVA2 drop code wiring')