Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38b62cfdbd | ||
|
|
cd395c73b7 |
@@ -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 <AVA2 locale dir> <203 locale dir> <out dir> <item_proto.txt>...`, 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 <name>
|
||||
{
|
||||
map_index 0 # 0 = every map, otherwise the maps listed
|
||||
level_range <min> <max> # killer level
|
||||
<n> <item vnum> <count> <pct> # 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.
|
||||
@@ -47,7 +47,7 @@ final VNUM COUNT [VNUM COUNT]x0..5
|
||||
|
||||
A kill counts for the player that `CHARACTER::Reward` gives the quest kill event to, which is the `DistributeExp` attacker. As in AVA2, it counts only when the monster is within 20 levels of the player. A party member who is not that attacker gets nothing. Type 9 needs a vnum because selling any item could be farmed with cheap shop items.
|
||||
|
||||
The shipped file has seasons 202610–202612, starting at local midnight on the first of each month (Europe/Berlin, the server's zone). Each has:
|
||||
The shipped file has seasons 202610–202712 (through 2028-01-01), starting at local midnight on the first of each month (Europe/Berlin, the server's zone). Each has:
|
||||
- eight missions, rewards taken from 40250 items;
|
||||
- a final reward of the three pearls and 70024.
|
||||
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __INC_ITEM_MANAGER__
|
||||
#define __INC_ITEM_MANAGER__
|
||||
#include "port_feature_types.h"
|
||||
#include <climits>
|
||||
|
||||
#ifdef M2_USE_POOL
|
||||
#include "pool.h"
|
||||
@@ -273,6 +274,31 @@ class CDropItemGroup
|
||||
std::vector<SDropItemGroupInfo> 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<DWORD> m_vecMapIndex;
|
||||
std::vector<DWORD> m_vecProbs;
|
||||
std::vector<std::pair<DWORD, DWORD> > m_vecItems;
|
||||
};
|
||||
|
||||
class CLevelItemGroup
|
||||
{
|
||||
struct SLevelItemGroupInfo
|
||||
@@ -393,6 +419,7 @@ class ITEM_MANAGER : public singleton<ITEM_MANAGER>
|
||||
bool CreateDropItem(LPCHARACTER pkChr, LPCHARACTER pkKiller, std::vector<LPITEM> & 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<ITEM_MANAGER>
|
||||
std::map<DWORD, CMobItemGroup*> m_map_pkMobItemGroup;
|
||||
std::map<DWORD, CLevelItemGroup*> m_map_pkLevelItemGroup;
|
||||
std::map<DWORD, CBuyerThiefGlovesItemGroup*> m_map_pkGloveItemGroup;
|
||||
std::vector<CCommonDropNew*> m_vec_pkCommonNewItemGroup;
|
||||
|
||||
// CHECK_UNIQUE_GROUP
|
||||
std::map<DWORD, int> m_ItemToSpecialGroup;
|
||||
|
||||
@@ -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<CCommonDropNew*> 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)
|
||||
|
||||
@@ -13,6 +13,13 @@ std::vector<PortWikiRow> ITEM_MANAGER::PortWikiDrops(DWORD race) {
|
||||
if (mob->m_table.bRank<MOB_RANK_MAX_NUM)
|
||||
for (const auto& row:g_vec_pkCommonDropItem[mob->m_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;i<group->m_vecItems.size() && i<group->m_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);
|
||||
|
||||
@@ -155,7 +155,7 @@ static bool Parses(const std::string& text){PortBpConfig c;std::istringstream in
|
||||
int main(int argc,char** argv){
|
||||
basePath=argv[1];
|
||||
// --- the shipped config
|
||||
{PortBpConfig c;std::ifstream in(argv[2]);assert(c.Parse(in));assert(c.seasons.size()==3 && c.seasons[0].id==202610);
|
||||
{PortBpConfig c;std::ifstream in(argv[2]);assert(c.Parse(in));assert(c.seasons.size()==15 && c.seasons[0].id==202610 && c.seasons.back().id==202712);
|
||||
for(auto& s:c.seasons){assert(s.missions.size()==8 && s.final.size()==4);for(auto& m:s.missions)for(auto& r:m.rewards)assert(tables.count(r.vnum));
|
||||
for(auto& r:s.final)assert(tables.count(r.vnum));}
|
||||
assert(c.seasons[0].end==c.seasons[1].start && c.Active(1790805600)==&c.seasons[0] && !c.Active(1790805599));}
|
||||
|
||||
@@ -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')
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <AVA2 locale dir> <203 locale dir> <output dir> <item_proto.txt>...
|
||||
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 <name>' then a braced body)."""
|
||||
lines=data.replace(b'\r\n',b'\n').split(b'\n');result=[];i=0
|
||||
while i<len(lines):
|
||||
m=re.match(rb'\s*group\s+(.*?)\s*$',lines[i],re.I)
|
||||
if not m:
|
||||
if lines[i].strip() and not lines[i].strip().startswith((b'#',b'//')):raise SystemExit('unexpected line %r'%lines[i])
|
||||
i+=1;continue
|
||||
assert lines[i+1].strip()==b'{',lines[i:i+2]
|
||||
j=i+2;body=[]
|
||||
while lines[j].strip()!=b'}':body.append(lines[j]);j+=1
|
||||
result.append((m.group(1),body));i=j+1
|
||||
return result
|
||||
|
||||
def key(body,name):
|
||||
for line in body:
|
||||
t=line.split()
|
||||
if t and t[0].lower()==name.encode():return t[1:]
|
||||
return None
|
||||
|
||||
def entries(body):
|
||||
return [line.split() for line in body if line.split() and line.split()[0].isdigit()]
|
||||
|
||||
def render(name,head,items):
|
||||
out=[b'Group\t'+name,b'{']+[b'\t'+b'\t'.join(t) for t in head]
|
||||
out+=[b'\t'+b'\t'.join([str(k).encode()]+t[1:]) for k,t in enumerate(items,1)]
|
||||
return out+[b'}']
|
||||
|
||||
def filtered(gs,known,item_column,dropped):
|
||||
"""Groups with unknown items removed and indexes renumbered; groups left empty are skipped."""
|
||||
out=[]
|
||||
for name,body in gs:
|
||||
head=[line.split() for line in body if line.split() and not line.split()[0].isdigit()]
|
||||
items=[]
|
||||
for t in entries(body):
|
||||
token=t[item_column]
|
||||
if token.isdigit() and int(token) not in known:dropped.setdefault(int(token),0);dropped[int(token)]+=1;continue
|
||||
items.append(t)
|
||||
if items:out+=render(name,head,items)
|
||||
return out
|
||||
|
||||
def build(ava,live,output,protos):
|
||||
known=vnums(protos);report={}
|
||||
output.mkdir(parents=True,exist_ok=True)
|
||||
mob=groups((ava/'mob_drop_item.txt').read_bytes())
|
||||
assert all(key(b,'type')[0].lower()==b'drop' for _,b in mob) # every AVA2 group is a 'drop' group
|
||||
assert max(len(entries(b)) for _,b in mob)<256
|
||||
dropped={};text=filtered(mob,known,1,dropped)
|
||||
(output/'mob_drop_item.txt').write_bytes(b'\n'.join(text)+b'\n')
|
||||
report['mob_groups']=sum(1 for l in text if l==b'{');report['mob_dropped']=dropped
|
||||
common=groups((ava/'common_drop_new.txt').read_bytes())
|
||||
dropped={};text=filtered(common,known,1,dropped)
|
||||
(output/'common_drop_new.txt').write_bytes(b'\n'.join(text)+b'\n')
|
||||
report['common_new_groups']=sum(1 for l in text if l==b'{');report['common_new_dropped']=dropped
|
||||
theirs=groups((ava/'special_item_group.txt').read_bytes());ours=groups((live/'special_item_group.txt').read_bytes())
|
||||
assert all((key(b,'type') or [b'x'])[0].lower()!=b'attr' for _,b in theirs)
|
||||
theirs=[(n,b) for n,b in theirs if int(key(b,'vnum')[0]) not in KEEP_203]
|
||||
replaced={int(key(b,'vnum')[0]) for _,b in theirs}
|
||||
dropped={};text=[]
|
||||
for name,body in ours:
|
||||
if int(key(body,'vnum')[0]) in replaced:continue
|
||||
text+=[b'Group\t'+name,b'{']+body+[b'}']
|
||||
text+=filtered(theirs,known,1,dropped)
|
||||
(output/'special_item_group.txt').write_bytes(b'\n'.join(text)+b'\n')
|
||||
kept=[int(key(b,'vnum')[0]) for _,b in ours if int(key(b,'vnum')[0]) not in replaced]
|
||||
report.update(special_kept_203=len(kept),special_from_ava2=len(replaced),
|
||||
special_replaced=sorted(replaced&{int(key(b,'vnum')[0]) for _,b in ours}),special_dropped=dropped)
|
||||
for name in ('common_drop_item.txt','etc_drop_item.txt'):(output/name).write_bytes(b'')
|
||||
for k in [k for k in report if k.endswith('_dropped')]:report[k]={str(v):n for v,n in sorted(report[k].items())}
|
||||
(output/'report.json').write_text(json.dumps(report,indent=1)+'\n')
|
||||
return report
|
||||
|
||||
if __name__=='__main__':
|
||||
if len(sys.argv)<5:sys.exit(__doc__)
|
||||
r=build(Path(sys.argv[1]),Path(sys.argv[2]),Path(sys.argv[3]),sys.argv[4:])
|
||||
print(json.dumps({k:(len(v) if isinstance(v,(list,dict)) else v) for k,v in r.items()}))
|
||||
@@ -48,3 +48,147 @@ mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-01 (Europe/Berlin)
|
||||
season 202701 1798758000 1801436400
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-02 (Europe/Berlin)
|
||||
season 202702 1801436400 1803855600
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-03 (Europe/Berlin)
|
||||
season 202703 1803855600 1806530400
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-04 (Europe/Berlin)
|
||||
season 202704 1806530400 1809122400
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-05 (Europe/Berlin)
|
||||
season 202705 1809122400 1811800800
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-06 (Europe/Berlin)
|
||||
season 202706 1811800800 1814392800
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-07 (Europe/Berlin)
|
||||
season 202707 1814392800 1817071200
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-08 (Europe/Berlin)
|
||||
season 202708 1817071200 1819749600
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-09 (Europe/Berlin)
|
||||
season 202709 1819749600 1822341600
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-10 (Europe/Berlin)
|
||||
season 202710 1822341600 1825023600
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-11 (Europe/Berlin)
|
||||
season 202711 1825023600 1827615600
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
# 2027-12 (Europe/Berlin)
|
||||
season 202712 1827615600 1830294000
|
||||
mission 1 1 0 20000 70043 1 71153 5
|
||||
mission 2 2 0 30 25041 2 71032 1
|
||||
mission 3 3 0 300 50513 3
|
||||
mission 4 4 0 172800 71094 2
|
||||
mission 5 5 0 100 27987 5
|
||||
mission 6 6 0 50 25040 2
|
||||
mission 7 7 0 5 71153 5
|
||||
mission 8 8 0 50000000 71084 20
|
||||
final 27992 2 27993 1 27994 1 70024 1
|
||||
|
||||
|
Reference in New Issue
Block a user