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>
This commit is contained in:
shenlei
2026-10-16 10:31:07 +09:00
co-authored by Claude Opus 5.5
parent cd395c73b7
commit 38b62cfdbd
10 changed files with 386 additions and 19 deletions
+52
View File
@@ -0,0 +1,52 @@
#!/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')
+10 -1
View File
@@ -12,6 +12,7 @@ points=sorted(set(re.findall(r'\bPOINT_[A-Z_]+', (SRC/'port_features.h').read_te
code=r'''
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdarg>
#include <cstdio>
#include <map>
@@ -28,7 +29,7 @@ GROUPS
#include "item_manager_private_types.h"
std::vector<CItemDropInfo> g_vec_pkCommonDropItem[MOB_RANK_MAX_NUM];
struct TItemTable{unsigned dwVnum;unsigned bType=0;};
struct MobTable{unsigned bType=0,bRank=0,dwPolymorphItemVnum=0,dwDropItemVnum=0;};
struct MobTable{unsigned bType=0,bRank=0,dwPolymorphItemVnum=0,dwDropItemVnum=0;unsigned char bLevel=0;};
struct CMob{MobTable m_table;};
class CMobManager {
public:std::map<DWORD,CMob*> mobs;
@@ -44,6 +45,7 @@ class ITEM_MANAGER {
std::map<DWORD,CLevelItemGroup*> m_map_pkLevelItemGroup;
std::map<DWORD,CBuyerThiefGlovesItemGroup*> m_map_pkGloveItemGroup;
std::map<DWORD,DWORD> m_map_dwEtcItemDropProb;
std::vector<CCommonDropNew*> m_vec_pkCommonNewItemGroup;
std::map<DWORD,CSpecialItemGroup*> special;
static ITEM_MANAGER& instance(){static ITEM_MANAGER m;return m;}
TItemTable* GetTable(unsigned id){for(auto& t:tables)if(t.dwVnum==id)return &t;return nullptr;}
@@ -100,6 +102,13 @@ int main(){
assert(items.PortWikiDrops(9001).empty() && items.PortWikiDrops(99999).empty());
drop.AddItem(30220,25,1);assert(items.PortWikiDrops(101).size()==8);
drop.AddItem(70104,1,1);assert(items.PortWikiDrops(101).size()==9); // Non-common groups retain configured polymorph candidates. // Sees active changes, not exported text.
// common_drop_new: player range clipped to the mob level +-20; groups out of reach are left out
mob.m_table.bLevel=10;CCommonDropNew low,high;low.minLevel=1;low.maxLevel=40;low.AddItem(30006,3,1200);high.minLevel=31;high.maxLevel=60;high.AddItem(19,1,1200);
items.m_vec_pkCommonNewItemGroup={&low,&high};rows=items.PortWikiDrops(101);assert(rows.size()==10);
assert(rows[1].item==30006 && rows[1].count==3 && rows[1].rule==WIKI_COMMON && rows[1].minimum==1 && rows[1].maximum==30 && rows[1].weight==1200);
high.minLevel=30;assert(items.PortWikiDrops(101).size()==11 && items.PortWikiDrops(101)[2].minimum==30);
assert(low.CanDropThisMap(41));low.m_vecMapIndex={1};assert(low.CanDropThisMap(1) && !low.CanDropThisMap(41));
items.m_vec_pkCommonNewItemGroup.clear();mob.m_table.bLevel=0;
CSpecialItemGroup chest(50011);chest.AddItem(19,1,80,0);chest.AddItem(1,500,20,0);items.special[50011]=&chest;
CSpecialItemGroup multi(50012,CSpecialItemGroup::PCT);multi.AddItem(19,2,20,0);multi.AddItem(3,101,150,0);items.special[50012]=&multi;
CSpecialItemGroup attr(50013,CSpecialItemGroup::SPECIAL);attr.AddItem(19,1,100,0);items.special[50013]=&attr;