From 38b62cfdbdd25c9b3a79af70000396781c84d1f3 Mon Sep 17 00:00:00 2001 From: shenlei Date: Fri, 16 Oct 2026 10:31:07 +0900 Subject: [PATCH] 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 --- docs/FEATURE-AVA2-DROPS.md | 38 +++++++ docs/FEATURE-QUERY-PROTOCOL.md | 2 +- src/server/game/src/input_db.cpp | 16 +++ src/server/game/src/item_manager.cpp | 45 ++++++-- src/server/game/src/item_manager.h | 28 +++++ .../game/src/item_manager_read_tables.cpp | 100 ++++++++++++++++- src/server/game/src/port_wiki_queries.inc | 7 ++ tests/features/test_drops.py | 52 +++++++++ tests/features/test_queries.py | 11 +- tools/ava2-drops/make_drops.py | 106 ++++++++++++++++++ 10 files changed, 386 insertions(+), 19 deletions(-) create mode 100644 docs/FEATURE-AVA2-DROPS.md create mode 100644 tests/features/test_drops.py create mode 100644 tools/ava2-drops/make_drops.py diff --git a/docs/FEATURE-AVA2-DROPS.md b/docs/FEATURE-AVA2-DROPS.md new file mode 100644 index 00000000..521320d0 --- /dev/null +++ b/docs/FEATURE-AVA2-DROPS.md @@ -0,0 +1,38 @@ +# AVA2 drop tables + +203 drops what AVA2 drops. Tables: `tools/ava2-drops/make_drops.py`. Code: `ITEM_MANAGER::ReadCommonDropNewItemFile` (item_manager_read_tables.cpp), the common-drop block and `GetDropPct` in item_manager.cpp, the load in input_db.cpp. The items AVA2 drops that 40250 lacks come from metin2-client `tools/server/ava2-items` and must be installed in the same deploy (the readers fail on an unknown item vnum and the core stops). + +## Tables + +Built by `make_drops.py <203 locale dir> ...`, the protos being every row the db will load (live item_proto.txt + ava2-items' items-server.tsv). + +| File | Content | +|---|---| +| mob_drop_item.txt | AVA2's 247 `drop` groups. Entries with an unknown item are removed and the rest renumbered: the reader stops at the first missing index. | +| common_drop_new.txt | AVA2's 26 level-range common groups (new file, see below). | +| special_item_group.txt | 203's groups; AVA2's groups replace those of the same box vnum (50011, 50082, 50186, 50255) and AVA2-only boxes are added. 50035 keeps 203's group: it is the children's day box on 203 but a GM box on AVA2. | +| common_drop_item.txt, etc_drop_item.txt | empty, as on AVA2. | + +`report.json` lists group counts, removed items and replaced boxes. + +## common_drop_new.txt + +``` +Group +{ + map_index 0 # 0 = every map, otherwise the maps listed + level_range # killer level + # pct as a float, chance = pct / 100 +} +``` + +A group drops when the monster level is within 20 of the killer, the killer level is in `level_range` and the map matches. Each entry is rolled against `GetDropPct`'s range (base 4,000,000) with probability `pct × 40000`. A missing file is logged and skipped; a parse error or unknown item fails the boot like the other drop files. + +## Changes to the drop code (from AVA2) + +- `GetDropPct`: premium item or glove doubles the drop rate, otherwise +50%; the permanent glove adds 100 (50 with premium) to the denominator bonus. `iRandRange = 4000000 * 100 / (100 + priv + bonus)`; 203 had an operator-precedence bug that fixed the divisor at 100. +- PC-bang bonus removed. The event-manager bonus is not ported (203 has no ENABLE_EVENT_MANAGER). +- A mob with two `drop` groups no longer reads an uninitialised group pointer. +- special_item_group.txt groups may have up to 1023 entries (AVA2's cofreskindop boxes have 267). + +The wiki (`/mt_features ... mob`) lists common_drop_new rows as rule 0 (FEATURE-QUERY-PROTOCOL.md). Not ported: AVA2's `/reload y`; quest-script and hardcoded drops are not compared. diff --git a/docs/FEATURE-QUERY-PROTOCOL.md b/docs/FEATURE-QUERY-PROTOCOL.md index ffff937f..d53deafd 100644 --- a/docs/FEATURE-QUERY-PROTOCOL.md +++ b/docs/FEATURE-QUERY-PROTOCOL.md @@ -39,7 +39,7 @@ Rules: | RULE | Meaning of MIN/MAX and weights | |---|---| -| 0 | rank common drop; MIN/MAX = eligible player levels | +| 0 | rank common drop (common_drop_item.txt) or level-range common drop (common_drop_new.txt, MIN/MAX clipped to monster level ±20); MIN/MAX = eligible player levels | | 1 | independent monster drop group; weight is original configured threshold, not final probability | | 2 | weighted kill group; MIN = original kill-per-drop parameter; weight/group total describe the conditional selection | | 3 | level group; MIN = player minimum level; original denominator 1,000,000 | diff --git a/src/server/game/src/input_db.cpp b/src/server/game/src/input_db.cpp index 9c272cb2..32688f90 100755 --- a/src/server/game/src/input_db.cpp +++ b/src/server/game/src/input_db.cpp @@ -963,6 +963,22 @@ void CInputDB::Boot(const char* data) return; } + // AVA2 NEW_COMMON_DROP; optional so the binary still runs on a locale without the file + char szCommonDropNewFileName[FILE_NAME_LEN]; + snprintf(szCommonDropNewFileName, sizeof(szCommonDropNewFileName), "%s/common_drop_new.txt", LocaleService_GetBasePath().c_str()); + if (access(szCommonDropNewFileName, R_OK) != 0) + sys_log(0, "LoadLocaleFile: CommonDropNew: %s absent", szCommonDropNewFileName); + else + { + sys_log(0, "LoadLocaleFile: CommonDropNew: %s", szCommonDropNewFileName); + if (!ITEM_MANAGER::instance().ReadCommonDropNewItemFile(szCommonDropNewFileName)) + { + sys_err("cannot load CommonDropNew: %s", szCommonDropNewFileName); + thecore_shutdown(); + return; + } + } + sys_log(0, "LoadLocaleFile: ETCDropItem: %s", szETCDropItemFileName); if (!ITEM_MANAGER::instance().ReadEtcDropItemFile(szETCDropItemFileName)) { diff --git a/src/server/game/src/item_manager.cpp b/src/server/game/src/item_manager.cpp index 149608d4..3288ccca 100755 --- a/src/server/game/src/item_manager.cpp +++ b/src/server/game/src/item_manager.cpp @@ -817,25 +817,26 @@ bool ITEM_MANAGER::GetDropPct(LPCHARACTER pkChr, LPCHARACTER pkKiller, OUT int& //if (pkKiller->GetPoint(POINT_MALL_ITEMBONUS) > 0) //iDeltaPercent += iDeltaPercent * pkKiller->GetPoint(POINT_MALL_ITEMBONUS) / 100; - // ADD_PREMIUM + // ADD_PREMIUM (AVA2 rates: premium or a thief glove doubles, everyone else gets +50%) if (pkKiller->GetPremiumRemainSeconds(PREMIUM_ITEM) > 0 || pkKiller->IsEquipUniqueGroup(UNIQUE_GROUP_DOUBLE_ITEM)) iDeltaPercent += iDeltaPercent; + else + iDeltaPercent += iDeltaPercent / 2; // END_OF_ADD_PREMIUM - // PC_BANG_ITEM_ADD - if (pkKiller->GetPoint(POINT_PC_BANG_DROP_BONUS) > 0) - { - if (pkKiller->IsPCBang() == true) - iDeltaPercent += iDeltaPercent * pkKiller->GetPoint(POINT_PC_BANG_DROP_BONUS)/100; - } - // END_PC_BANG_ITEM_ADD + // AVA2: the permanent glove adds 100 with premium and 50 alone (or a removable glove with premium). This also + // fixes the original ternary without parentheses, which always made the divisor 100 and ignored PRIV_ITEM_DROP. + int bonus = 0; + if (pkKiller->IsEquipUniqueItem(UNIQUE_ITEM_DOUBLE_ITEM) && pkKiller->GetPremiumRemainSeconds(PREMIUM_ITEM) > 0) + bonus = 100; + else if (pkKiller->IsEquipUniqueItem(UNIQUE_ITEM_DOUBLE_ITEM) || + (pkKiller->IsEquipUniqueGroup(UNIQUE_GROUP_DOUBLE_ITEM) && pkKiller->GetPremiumRemainSeconds(PREMIUM_ITEM) > 0)) + bonus = 50; iRandRange = 4000000; - iRandRange = iRandRange * 100 / - (100 + - CPrivManager::instance().GetPriv(pkKiller, PRIV_ITEM_DROP) + - pkKiller->IsEquipUniqueItem(UNIQUE_ITEM_DOUBLE_ITEM)?100:0); + iRandRange = iRandRange * 100 / + (100 + CPrivManager::instance().GetPriv(pkKiller, PRIV_ITEM_DROP) + bonus); if (distribution_test_server) iRandRange /= 3; @@ -926,6 +927,26 @@ bool ITEM_MANAGER::CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std:: } } + // AVA2 NEW_COMMON_DROP: killer level within a group's range and within 20 levels of the victim + if (abs(pkChr->GetLevel() - iLevel) <= 20) + { + for (size_t g = 0; g < m_vec_pkCommonNewItemGroup.size(); ++g) + { + const CCommonDropNew* commonNew = m_vec_pkCommonNewItemGroup[g]; + if (iLevel < commonNew->minLevel || iLevel > commonNew->maxLevel || !commonNew->CanDropThisMap(pkKiller->GetMapIndex())) + continue; + for (size_t i = 0; i < commonNew->m_vecProbs.size(); ++i) + { + int iPercent = (commonNew->m_vecProbs[i] * iDeltaPercent) / 100; + if (iPercent >= number(1, iRandRange)) + { + item = CreateItem(commonNew->m_vecItems[i].first, commonNew->m_vecItems[i].second, 0, true); + if (item) vec_item.push_back(item); + } + } + } + } + // MobDropItem Group { itertype(m_map_pkMobItemGroup) it; diff --git a/src/server/game/src/item_manager.h b/src/server/game/src/item_manager.h index 01aa3060..5e5e263e 100755 --- a/src/server/game/src/item_manager.h +++ b/src/server/game/src/item_manager.h @@ -1,6 +1,7 @@ #ifndef __INC_ITEM_MANAGER__ #define __INC_ITEM_MANAGER__ #include "port_feature_types.h" +#include #ifdef M2_USE_POOL #include "pool.h" @@ -273,6 +274,31 @@ class CDropItemGroup std::vector m_vec_items; }; +// AVA2 NEW_COMMON_DROP (common_drop_new.txt): level-ranged, optionally map-restricted groups replacing the +// rank-based common_drop_item.txt. Probabilities are stored on the 40000-per-percent scale of the other drop tables. +class CCommonDropNew +{ + public: + CCommonDropNew() : minLevel(0), maxLevel(INT_MAX) {} + + bool CanDropThisMap(DWORD mapIndex) const + { + return m_vecMapIndex.empty() || std::find(m_vecMapIndex.begin(), m_vecMapIndex.end(), mapIndex) != m_vecMapIndex.end(); + } + + void AddItem(DWORD dwItemVnum, DWORD iCount, DWORD iPartPct) + { + m_vecProbs.push_back(iPartPct); + m_vecItems.push_back(std::make_pair(dwItemVnum, iCount)); + } + + int minLevel; + int maxLevel; + std::vector m_vecMapIndex; + std::vector m_vecProbs; + std::vector > m_vecItems; +}; + class CLevelItemGroup { struct SLevelItemGroupInfo @@ -393,6 +419,7 @@ class ITEM_MANAGER : public singleton bool CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::vector & vec_item); bool ReadCommonDropItemFile(const char * c_pszFileName); + bool ReadCommonDropNewItemFile(const char * c_pszFileName); bool ReadEtcDropItemFile(const char * c_pszFileName); bool ReadDropItemGroup(const char * c_pszFileName); bool ReadMonsterDropItemGroup(const char * c_pszFileName); @@ -444,6 +471,7 @@ class ITEM_MANAGER : public singleton std::map m_map_pkMobItemGroup; std::map m_map_pkLevelItemGroup; std::map m_map_pkGloveItemGroup; + std::vector m_vec_pkCommonNewItemGroup; // CHECK_UNIQUE_GROUP std::map m_ItemToSpecialGroup; diff --git a/src/server/game/src/item_manager_read_tables.cpp b/src/server/game/src/item_manager_read_tables.cpp index 364bc192..a11f5b4e 100755 --- a/src/server/game/src/item_manager_read_tables.cpp +++ b/src/server/game/src/item_manager_read_tables.cpp @@ -169,9 +169,9 @@ bool ITEM_MANAGER::ReadSpecialDropItemFile(const char * c_pszFileName) if ("attr" == stType) { CSpecialAttrGroup * pkGroup = M2_NEW CSpecialAttrGroup(iVnum); - for (int k = 1; k < 256; ++k) + for (int k = 1; k < 1024; ++k) // AVA2 @fixme148: groups up to 1023 entries { - char buf[4]; + char buf[8]; snprintf(buf, sizeof(buf), "%d", k); if (loader.GetTokenVector(buf, &pTok)) @@ -212,9 +212,9 @@ bool ITEM_MANAGER::ReadSpecialDropItemFile(const char * c_pszFileName) else { CSpecialItemGroup * pkGroup = M2_NEW CSpecialItemGroup(iVnum, type); - for (int k = 1; k < 256; ++k) + for (int k = 1; k < 1024; ++k) // AVA2 @fixme148: groups up to 1023 entries { - char buf[4]; + char buf[8]; snprintf(buf, sizeof(buf), "%d", k); if (loader.GetTokenVector(buf, &pTok)) @@ -427,6 +427,96 @@ bool ITEM_MANAGER::ConvSpecialDropItemFile() return true; } +// AVA2 NEW_COMMON_DROP. Each group: optional "map_index" list (0 = every map), optional "level_range MIN MAX" of the +// killer, entries "N vnum count percent". A malformed group fails the whole file like the other drop tables. +bool ITEM_MANAGER::ReadCommonDropNewItemFile(const char * c_pszFileName) +{ + CTextFileLoader loader; + if (!loader.Load(c_pszFileName)) + return false; + + std::vector groups; + std::string stName; + bool ok = true; + + for (DWORD i = 0; i < loader.GetChildNodeCount() && ok; ++i) + { + CCommonDropNew* dropPtr = M2_NEW CCommonDropNew; + TTokenVector* pTok = NULL; + loader.SetChildNode(i); + loader.GetCurrentNodeName(&stName); + + if (loader.GetTokenVector("map_index", &pTok)) + { + if (pTok->empty()) + ok = false; + for (DWORD j = 0; ok && j < pTok->size(); ++j) + { + DWORD mapIndex = 0; + str_to_number(mapIndex, pTok->at(j).c_str()); + if (mapIndex) + dropPtr->m_vecMapIndex.push_back(mapIndex); + } + } + if (ok && loader.GetTokenVector("level_range", &pTok)) + { + if (pTok->size() != 2) + ok = false; + else + { + str_to_number(dropPtr->minLevel, pTok->at(0).c_str()); + str_to_number(dropPtr->maxLevel, pTok->at(1).c_str()); + } + } + for (int k = 1; ok && k < 256; ++k) + { + char buf[4]; + snprintf(buf, sizeof(buf), "%d", k); + if (!loader.GetTokenVector(buf, &pTok)) + continue; + DWORD itemVnum = 0, itemCount = 0; + float itemPct = 0.0f; + if (pTok->size() != 3) + { + ok = false; + break; + } + str_to_number(itemVnum, pTok->at(0).c_str()); + str_to_number(itemCount, pTok->at(1).c_str()); + str_to_number(itemPct, pTok->at(2).c_str()); + if (!GetTable(itemVnum) || !itemCount) + { + sys_err("ReadCommonDropNewItemFile : no item %u (count %u) : node %s", itemVnum, itemCount, stName.c_str()); + ok = false; + break; + } + dropPtr->AddItem(itemVnum, itemCount, (DWORD)(40000.0f * itemPct)); + } + loader.SetParentNode(); + + if (!ok) + sys_err("ReadCommonDropNewItemFile : Syntax error %s : node %s", c_pszFileName, stName.c_str()); + if (!ok || dropPtr->m_vecItems.empty()) + { + M2_DELETE(dropPtr); + continue; + } + groups.push_back(dropPtr); + } + + if (!ok) + { + for (size_t i = 0; i < groups.size(); ++i) + M2_DELETE(groups[i]); + return false; + } + + for (size_t i = 0; i < m_vec_pkCommonNewItemGroup.size(); ++i) + M2_DELETE(m_vec_pkCommonNewItemGroup[i]); + m_vec_pkCommonNewItemGroup.swap(groups); + return true; +} + bool ITEM_MANAGER::ReadEtcDropItemFile(const char * c_pszFileName) { FILE * fp = fopen(c_pszFileName, "r"); @@ -634,7 +724,7 @@ bool ITEM_MANAGER::ReadMonsterDropItemGroup(const char * c_pszFileName) else { bNew = false; - CDropItemGroup* pkGroup = it->second; + pkGroup = it->second; } for (int k = 1; k < 256; ++k) diff --git a/src/server/game/src/port_wiki_queries.inc b/src/server/game/src/port_wiki_queries.inc index c47e14cb..e36a945f 100644 --- a/src/server/game/src/port_wiki_queries.inc +++ b/src/server/game/src/port_wiki_queries.inc @@ -13,6 +13,13 @@ std::vector ITEM_MANAGER::PortWikiDrops(DWORD race) { if (mob->m_table.bRankm_table.bRank]) add(row.m_dwVnum,1,WIKI_COMMON,row.m_iLevelStart,row.m_iLevelEnd,row.m_iPercent,0); + // common_drop_new.txt: the player range narrowed to the killers within 20 levels of this mob; map lists are not shown + for (const CCommonDropNew* group:m_vec_pkCommonNewItemGroup) { + int low=std::max(group->minLevel,int(mob->m_table.bLevel)-20),high=std::min(group->maxLevel,int(mob->m_table.bLevel)+20); + if (low>high) continue; + for (size_t i=0;im_vecItems.size() && im_vecProbs.size();++i) + add(group->m_vecItems[i].first,group->m_vecItems[i].second,WIKI_COMMON,unsigned(std::max(low,0)),unsigned(high),group->m_vecProbs[i],0); + } auto drop=m_map_pkDropItemGroup.find(race); if (drop!=m_map_pkDropItemGroup.end() && drop->second) for (const auto& row:drop->second->GetVector()) add(row.dwVnum,row.iCount,WIKI_DROP,0,0,row.dwPct,0); diff --git a/tests/features/test_drops.py b/tests/features/test_drops.py new file mode 100644 index 00000000..93fa9110 --- /dev/null +++ b/tests/features/test_drops.py @@ -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')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(') #include +#include #include #include #include @@ -28,7 +29,7 @@ GROUPS #include "item_manager_private_types.h" std::vector 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 mobs; @@ -44,6 +45,7 @@ class ITEM_MANAGER { std::map m_map_pkLevelItemGroup; std::map m_map_pkGloveItemGroup; std::map m_map_dwEtcItemDropProb; + std::vector m_vec_pkCommonNewItemGroup; std::map 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; diff --git a/tools/ava2-drops/make_drops.py b/tools/ava2-drops/make_drops.py new file mode 100644 index 00000000..f63e1a0c --- /dev/null +++ b/tools/ava2-drops/make_drops.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Build the 203 drop tables from AVA2's (docs/FEATURE-AVA2-DROPS.md). + + mob_drop_item.txt AVA2's, entries whose item 203 lacks are dropped and the rest renumbered + (the reader stops at the first missing index and fails on an unknown item) + common_drop_new.txt AVA2's NEW_COMMON_DROP groups, filtered the same way + special_item_group.txt 203's groups with AVA2's groups replacing those of the same vnum; AVA2-only groups added + common_drop_item.txt empty, like AVA2 (common drops come from common_drop_new.txt) + etc_drop_item.txt empty, like AVA2 + +Usage: make_drops.py <203 locale dir> ... +The item_proto files are every row the servers will load (the live one plus ava2-items' items-server.tsv). +""" +import json,re,sys +from pathlib import Path + +# AVA2 reused these vnums for a different box: 50035 is 203's children's day gift box but AVA2's GM-only +# 'Pct' box handing out thousands of items, so 203's group stays. +KEEP_203={50035} + +def vnums(paths): + result=set() + for p in paths: + for line in Path(p).read_bytes().splitlines(): + head=line.split(b'\t',1)[0].strip() + if head.isdigit():result.add(int(head)) + elif re.fullmatch(rb'\d+~\d+',head): # dragon soul rows cover a vnum range + lo,hi=map(int,head.split(b'~'));result.update(range(lo,hi+1)) + return result + +def groups(data): + """[(name bytes, [body line bytes])] of a CTextFileLoader file ('Group ' then a braced body).""" + lines=data.replace(b'\r\n',b'\n').split(b'\n');result=[];i=0 + while i