mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-11 15:58:36 +00:00
[Merchants] Add Merchant Data Bucket capability. (#2160)
* [Merchants] Add Merchant Data Bucket capability.
- Allows server operators to limit merchant items based on data bucket values and comparisons.
- Adds 3 columns, bucket_name, bucket_value, and bucket_comparison to merchantlist table.
- Bucket is checked based on GetBucketKey()-bucket_name.
- Buckets are mass loaded when using the merchant so it's not a database call per item, just a grouping of all their buckets from the start.
- This is a nearly year old pull request redone for master.
- bucket_comparison Values are as follows:
- bucket_comparison 0: bucket_name == bucket_value
- bucket_comparison 1: bucket_name != bucket_value
- bucket_comparison 2: bucket_name >= bucket_value
- bucket_comparison 3: bucket_name <= bucket_value
- bucket_comparison 4: bucket_name > bucket_value
- bucket_comparison 5: bucket_name < bucket_value
- bucket_comparison 6: bucket_name is any of pipe(|)-separated bucket_value
- bucket_comparison 7: bucket_name is not any of pipe(|)-separated bucket_value
- bucket_comparison 8: bucket_name is between first and second value of pipe(|)-separated bucket_value
- bucket_comparison 9: bucket_name is not between first and second value of pipe(|)-separated bucket_value
* Revert query change.
This commit is contained in:
+59
-53
@@ -605,26 +605,25 @@ void Zone::LoadTempMerchantData()
|
||||
|
||||
void Zone::LoadNewMerchantData(uint32 merchantid) {
|
||||
|
||||
std::list<MerchantList> merlist;
|
||||
std::list<MerchantList> merchant_list;
|
||||
|
||||
std::string query = fmt::format(
|
||||
auto query = fmt::format(
|
||||
SQL(
|
||||
SELECT
|
||||
item,
|
||||
slot,
|
||||
faction_required,
|
||||
level_required,
|
||||
alt_currency_cost,
|
||||
classes_required,
|
||||
probability
|
||||
FROM
|
||||
merchantlist
|
||||
WHERE
|
||||
merchantid = {}
|
||||
{}
|
||||
ORDER BY
|
||||
slot
|
||||
),
|
||||
item,
|
||||
slot,
|
||||
faction_required,
|
||||
level_required,
|
||||
alt_currency_cost,
|
||||
classes_required,
|
||||
probability,
|
||||
bucket_name,
|
||||
bucket_value,
|
||||
bucket_comparison
|
||||
FROM merchantlist
|
||||
WHERE merchantid = {} {}
|
||||
ORDER BY slot
|
||||
),
|
||||
merchantid,
|
||||
ContentFilterCriteria::apply()
|
||||
);
|
||||
@@ -634,25 +633,28 @@ void Zone::LoadNewMerchantData(uint32 merchantid) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
for (auto row : results) {
|
||||
MerchantList ml;
|
||||
ml.id = merchantid;
|
||||
ml.item = atoul(row[0]);
|
||||
ml.slot = atoul(row[1]);
|
||||
ml.faction_required = atoul(row[2]);
|
||||
ml.level_required = atoul(row[3]);
|
||||
ml.alt_currency_cost = atoul(row[4]);
|
||||
ml.classes_required = atoul(row[5]);
|
||||
ml.probability = atoul(row[6]);
|
||||
merlist.push_back(ml);
|
||||
ml.id = merchantid;
|
||||
ml.item = std::stoul(row[0]);
|
||||
ml.slot = std::stoul(row[1]);
|
||||
ml.faction_required = static_cast<int16>(std::stoi(row[2]));
|
||||
ml.level_required = static_cast<uint8>(std::stoul(row[3]));
|
||||
ml.alt_currency_cost = static_cast<uint16>(std::stoul(row[4]));
|
||||
ml.classes_required = std::stoul(row[5]);
|
||||
ml.probability = static_cast<uint8>(std::stoul(row[6]));
|
||||
ml.bucket_name = row[7];
|
||||
ml.bucket_value = row[8];
|
||||
ml.bucket_comparison = static_cast<uint8>(std::stoul(row[9]));
|
||||
merchant_list.push_back(ml);
|
||||
}
|
||||
|
||||
merchanttable[merchantid] = merlist;
|
||||
merchanttable[merchantid] = merchant_list;
|
||||
}
|
||||
|
||||
void Zone::GetMerchantDataForZoneLoad() {
|
||||
LogInfo("Loading Merchant Lists");
|
||||
std::string query = fmt::format(
|
||||
auto query = fmt::format(
|
||||
SQL (
|
||||
SELECT
|
||||
DISTINCT merchantlist.merchantid,
|
||||
@@ -662,7 +664,10 @@ void Zone::GetMerchantDataForZoneLoad() {
|
||||
merchantlist.level_required,
|
||||
merchantlist.alt_currency_cost,
|
||||
merchantlist.classes_required,
|
||||
merchantlist.probability
|
||||
merchantlist.probability,
|
||||
merchantlist.bucket_name,
|
||||
merchantlist.bucket_value,
|
||||
merchantlist.bucket_comparison
|
||||
FROM
|
||||
merchantlist,
|
||||
npc_types,
|
||||
@@ -688,49 +693,50 @@ void Zone::GetMerchantDataForZoneLoad() {
|
||||
std::map<uint32, std::list<MerchantList> >::iterator merchant_list;
|
||||
|
||||
uint32 npc_id = 0;
|
||||
if (results.RowCount() == 0) {
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
LogDebug("No Merchant Data found for [{}]", GetShortName());
|
||||
return;
|
||||
}
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
MerchantList merchant_list_entry{};
|
||||
merchant_list_entry.id = atoul(row[0]);
|
||||
if (npc_id != merchant_list_entry.id) {
|
||||
merchant_list = merchanttable.find(merchant_list_entry.id);
|
||||
|
||||
for (auto row : results) {
|
||||
MerchantList mle{};
|
||||
mle.id = atoul(row[0]);
|
||||
if (npc_id != mle.id) {
|
||||
merchant_list = merchanttable.find(mle.id);
|
||||
if (merchant_list == merchanttable.end()) {
|
||||
std::list<MerchantList> empty;
|
||||
merchanttable[merchant_list_entry.id] = empty;
|
||||
merchant_list = merchanttable.find(merchant_list_entry.id);
|
||||
merchanttable[mle.id] = empty;
|
||||
merchant_list = merchanttable.find(mle.id);
|
||||
}
|
||||
|
||||
npc_id = merchant_list_entry.id;
|
||||
npc_id = mle.id;
|
||||
}
|
||||
|
||||
auto iter = merchant_list->second.begin();
|
||||
bool found = false;
|
||||
while (iter != merchant_list->second.end()) {
|
||||
if ((*iter).item == merchant_list_entry.id) {
|
||||
for (const auto &m : merchant_list->second) {
|
||||
if (m.item == mle.id) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mle.slot = std::stoul(row[0]);
|
||||
mle.item = std::stoul(row[1]);
|
||||
mle.faction_required = static_cast<int16>(std::stoi(row[2]));
|
||||
mle.level_required = static_cast<uint8>(std::stoul(row[3]));
|
||||
mle.alt_currency_cost = static_cast<uint16>(std::stoul(row[4]));
|
||||
mle.classes_required = std::stoul(row[5]);
|
||||
mle.probability = static_cast<uint8>(std::stoul(row[6]));
|
||||
mle.bucket_name = row[7];
|
||||
mle.bucket_value = row[8];
|
||||
mle.bucket_comparison = static_cast<uint8>(std::stoul(row[9]));
|
||||
|
||||
merchant_list_entry.slot = atoul(row[1]);
|
||||
merchant_list_entry.item = atoul(row[2]);
|
||||
merchant_list_entry.faction_required = atoul(row[3]);
|
||||
merchant_list_entry.level_required = atoul(row[4]);
|
||||
merchant_list_entry.alt_currency_cost = atoul(row[5]);
|
||||
merchant_list_entry.classes_required = atoul(row[6]);
|
||||
merchant_list_entry.probability = atoul(row[7]);
|
||||
|
||||
merchant_list->second.push_back(merchant_list_entry);
|
||||
merchant_list->second.push_back(mle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Zone::LoadMercTemplates(){
|
||||
|
||||
Reference in New Issue
Block a user