mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-20 17:31:30 +00:00
Filter merchants [skip ci]
This commit is contained in:
parent
9a90bdf91a
commit
6e3922b7cc
125
zone/zone.cpp
125
zone/zone.cpp
@ -502,14 +502,35 @@ void Zone::LoadTempMerchantData()
|
|||||||
void Zone::LoadNewMerchantData(uint32 merchantid) {
|
void Zone::LoadNewMerchantData(uint32 merchantid) {
|
||||||
|
|
||||||
std::list<MerchantList> merlist;
|
std::list<MerchantList> merlist;
|
||||||
std::string query = StringFormat("SELECT item, slot, faction_required, level_required, alt_currency_cost, "
|
|
||||||
"classes_required, probability FROM merchantlist WHERE merchantid=%d ORDER BY slot", merchantid);
|
std::string query = fmt::format(
|
||||||
|
SQL(
|
||||||
|
SELECT
|
||||||
|
item,
|
||||||
|
slot,
|
||||||
|
faction_required,
|
||||||
|
level_required,
|
||||||
|
alt_currency_cost,
|
||||||
|
classes_required,
|
||||||
|
probability
|
||||||
|
FROM
|
||||||
|
merchantlist
|
||||||
|
WHERE
|
||||||
|
merchantid = {}
|
||||||
|
{}
|
||||||
|
ORDER BY
|
||||||
|
slot
|
||||||
|
),
|
||||||
|
merchantid,
|
||||||
|
ContentFilterCriteria::apply()
|
||||||
|
);
|
||||||
|
|
||||||
auto results = content_db.QueryDatabase(query);
|
auto results = content_db.QueryDatabase(query);
|
||||||
if (!results.Success()) {
|
if (!results.Success()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto row = results.begin(); row != results.end(); ++row) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
MerchantList ml;
|
MerchantList ml;
|
||||||
ml.id = merchantid;
|
ml.id = merchantid;
|
||||||
ml.item = atoul(row[0]);
|
ml.item = atoul(row[0]);
|
||||||
@ -527,48 +548,65 @@ void Zone::LoadNewMerchantData(uint32 merchantid) {
|
|||||||
|
|
||||||
void Zone::GetMerchantDataForZoneLoad() {
|
void Zone::GetMerchantDataForZoneLoad() {
|
||||||
LogInfo("Loading Merchant Lists");
|
LogInfo("Loading Merchant Lists");
|
||||||
std::string query = StringFormat(
|
std::string query = fmt::format(
|
||||||
"SELECT "
|
SQL (
|
||||||
"DISTINCT ml.merchantid, "
|
SELECT
|
||||||
"ml.slot, "
|
DISTINCT ml.merchantid,
|
||||||
"ml.item, "
|
ml.slot,
|
||||||
"ml.faction_required, "
|
ml.item,
|
||||||
"ml.level_required, "
|
ml.faction_required,
|
||||||
"ml.alt_currency_cost, "
|
ml.level_required,
|
||||||
"ml.classes_required, "
|
ml.alt_currency_cost,
|
||||||
"ml.probability "
|
ml.classes_required,
|
||||||
"FROM "
|
ml.probability
|
||||||
"merchantlist AS ml, "
|
FROM
|
||||||
"npc_types AS nt, "
|
merchantlist AS ml,
|
||||||
"spawnentry AS se, "
|
npc_types AS nt,
|
||||||
"spawn2 AS s2 "
|
spawnentry AS se,
|
||||||
"WHERE nt.merchant_id = ml.merchantid AND nt.id = se.npcid "
|
spawn2 AS s2
|
||||||
"AND se.spawngroupid = s2.spawngroupid AND s2.zone = '%s' AND s2.version = %i "
|
WHERE
|
||||||
"ORDER BY ml.slot ", GetShortName(), GetInstanceVersion());
|
nt.merchant_id = ml.merchantid
|
||||||
|
AND nt.id = se.npcid
|
||||||
|
AND se.spawngroupid = s2.spawngroupid
|
||||||
|
AND s2.zone = '{}'
|
||||||
|
AND s2.version = {}
|
||||||
|
{}
|
||||||
|
ORDER BY
|
||||||
|
ml.slot
|
||||||
|
),
|
||||||
|
GetShortName(),
|
||||||
|
GetInstanceVersion(),
|
||||||
|
ContentFilterCriteria::apply()
|
||||||
|
);
|
||||||
|
|
||||||
auto results = content_db.QueryDatabase(query);
|
auto results = content_db.QueryDatabase(query);
|
||||||
std::map<uint32, std::list<MerchantList> >::iterator cur;
|
|
||||||
uint32 npcid = 0;
|
std::map<uint32, std::list<MerchantList> >::iterator merchant_list;
|
||||||
|
|
||||||
|
uint32 npc_id = 0;
|
||||||
|
|
||||||
if (results.RowCount() == 0) {
|
if (results.RowCount() == 0) {
|
||||||
LogDebug("No Merchant Data found for [{}]", GetShortName());
|
LogDebug("No Merchant Data found for [{}]", GetShortName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
MerchantList ml;
|
MerchantList merchant_list_entry{};
|
||||||
ml.id = atoul(row[0]);
|
merchant_list_entry.id = atoul(row[0]);
|
||||||
if (npcid != ml.id) {
|
if (npc_id != merchant_list_entry.id) {
|
||||||
cur = merchanttable.find(ml.id);
|
merchant_list = merchanttable.find(merchant_list_entry.id);
|
||||||
if (cur == merchanttable.end()) {
|
if (merchant_list == merchanttable.end()) {
|
||||||
std::list<MerchantList> empty;
|
std::list<MerchantList> empty;
|
||||||
merchanttable[ml.id] = empty;
|
merchanttable[merchant_list_entry.id] = empty;
|
||||||
cur = merchanttable.find(ml.id);
|
merchant_list = merchanttable.find(merchant_list_entry.id);
|
||||||
}
|
|
||||||
npcid = ml.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto iter = cur->second.begin();
|
npc_id = merchant_list_entry.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto iter = merchant_list->second.begin();
|
||||||
bool found = false;
|
bool found = false;
|
||||||
while (iter != cur->second.end()) {
|
while (iter != merchant_list->second.end()) {
|
||||||
if ((*iter).item == ml.id) {
|
if ((*iter).item == merchant_list_entry.id) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -579,14 +617,15 @@ void Zone::GetMerchantDataForZoneLoad() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ml.slot = atoul(row[1]);
|
merchant_list_entry.slot = atoul(row[1]);
|
||||||
ml.item = atoul(row[2]);
|
merchant_list_entry.item = atoul(row[2]);
|
||||||
ml.faction_required = atoul(row[3]);
|
merchant_list_entry.faction_required = atoul(row[3]);
|
||||||
ml.level_required = atoul(row[4]);
|
merchant_list_entry.level_required = atoul(row[4]);
|
||||||
ml.alt_currency_cost = atoul(row[5]);
|
merchant_list_entry.alt_currency_cost = atoul(row[5]);
|
||||||
ml.classes_required = atoul(row[6]);
|
merchant_list_entry.classes_required = atoul(row[6]);
|
||||||
ml.probability = atoul(row[7]);
|
merchant_list_entry.probability = atoul(row[7]);
|
||||||
cur->second.push_back(ml);
|
|
||||||
|
merchant_list->second.push_back(merchant_list_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user