[Merchants] Convert Merchant Load to Repositories (#4007)

* [Merchants] Convert Merchant Load to Repositories

# Notes
- Convert `GetMerchantDataForZoneLoad()` to repositories.

# Images
## Load

* Change to LoadMerchants()
This commit is contained in:
Alex King 2024-01-28 22:55:59 -05:00 committed by GitHub
parent bfeeb0ce05
commit b4414d3052
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 63 deletions

View File

@ -660,68 +660,53 @@ void Zone::LoadNewMerchantData(uint32 merchantid) {
merchanttable[merchantid] = merchant_list; merchanttable[merchantid] = merchant_list;
} }
void Zone::GetMerchantDataForZoneLoad() { void Zone::LoadMerchants()
auto query = fmt::format( {
SQL ( const auto& l = MerchantlistRepository::GetWhere(
SELECT content_db,
merchantid, fmt::format(
slot, SQL(
item, `merchantid` IN (
faction_required, SELECT `merchant_id` FROM `npc_types` WHERE `id` IN (
level_required, SELECT `npcID` FROM `spawnentry` WHERE `spawngroupID` IN (
min_status, SELECT `spawngroupID` FROM `spawn2` WHERE `zone` = '{}' AND (`version` = {} OR `version` = -1)
max_status, )
alt_currency_cost,
classes_required,
probability,
bucket_name,
bucket_value,
bucket_comparison
from merchantlist where merchantid IN (
select merchant_id from npc_types where id in (
select npcID from spawnentry where spawngroupID IN (
select spawngroupID from spawn2 where `zone` = '{}' and (`version` = {} OR `version` = -1)
) )
) )
) {}
{} ORDER BY `merchantlist`.`slot`
ORDER BY ),
merchantlist.slot GetShortName(),
), GetInstanceVersion(),
GetShortName(), ContentFilterCriteria::apply()
GetInstanceVersion(), )
ContentFilterCriteria::apply()
); );
auto results = content_db.QueryDatabase(query); LogInfo("Loaded [{}] merchant lists", Strings::Commify(l.size()));
LogInfo("Loaded [{}] merchant lists", Strings::Commify(results.RowCount())); if (l.empty()) {
std::map<uint32, std::list<MerchantList> >::iterator merchant_list;
uint32 npc_id = 0;
if (!results.Success() || !results.RowCount()) {
LogDebug("No Merchant Data found for [{}]", GetShortName()); LogDebug("No Merchant Data found for [{}]", GetShortName());
return; return;
} }
for (auto row : results) { std::map<uint32, std::list<MerchantList>>::iterator ml;
MerchantList mle{}; uint32 npc_id = 0;
mle.id = Strings::ToUnsignedInt(row[0]);
if (npc_id != mle.id) { for (const auto& e : l) {
merchant_list = merchanttable.find(mle.id); if (npc_id != e.merchantid) {
if (merchant_list == merchanttable.end()) { ml = merchanttable.find(e.merchantid);
if (ml == merchanttable.end()) {
std::list<MerchantList> empty; std::list<MerchantList> empty;
merchanttable[mle.id] = empty; merchanttable[e.merchantid] = empty;
merchant_list = merchanttable.find(mle.id); ml = merchanttable.find(e.merchantid);
} }
npc_id = mle.id; npc_id = e.merchantid;
} }
bool found = false; bool found = false;
for (const auto &m : merchant_list->second) { for (const auto &m : ml->second) {
if (m.item == mle.id) { if (m.item == e.merchantid) {
found = true; found = true;
break; break;
} }
@ -731,20 +716,23 @@ void Zone::GetMerchantDataForZoneLoad() {
continue; continue;
} }
mle.slot = Strings::ToUnsignedInt(row[1]); ml->second.push_back(
mle.item = Strings::ToUnsignedInt(row[2]); MerchantList{
mle.faction_required = static_cast<int16>(Strings::ToInt(row[3])); .id = static_cast<uint32>(e.merchantid),
mle.level_required = static_cast<uint8>(Strings::ToUnsignedInt(row[4])); .slot = e.slot,
mle.min_status = static_cast<uint8>(Strings::ToUnsignedInt(row[5])); .item = static_cast<uint32>(e.item),
mle.max_status = static_cast<uint8>(Strings::ToUnsignedInt(row[6])); .faction_required = e.faction_required,
mle.alt_currency_cost = static_cast<uint16>(Strings::ToUnsignedInt(row[7])); .level_required = static_cast<int8>(e.level_required),
mle.classes_required = Strings::ToUnsignedInt(row[8]); .min_status = e.min_status,
mle.probability = static_cast<uint8>(Strings::ToUnsignedInt(row[9])); .max_status = e.max_status,
mle.bucket_name = row[10]; .alt_currency_cost = e.alt_currency_cost,
mle.bucket_value = row[11]; .classes_required = static_cast<uint32>(e.classes_required),
mle.bucket_comparison = static_cast<uint8>(Strings::ToUnsignedInt(row[12])); .probability = static_cast<uint8>(e.probability),
.bucket_name = e.bucket_name,
merchant_list->second.push_back(mle); .bucket_value = e.bucket_value,
.bucket_comparison = e.bucket_comparison
}
);
} }
} }
@ -1200,7 +1188,7 @@ bool Zone::Init(bool is_static) {
content_db.LoadGlobalLoot(); content_db.LoadGlobalLoot();
//Load merchant data //Load merchant data
GetMerchantDataForZoneLoad(); LoadMerchants();
//Load temporary merchant data //Load temporary merchant data
LoadTempMerchantData(); LoadTempMerchantData();

View File

@ -278,7 +278,7 @@ public:
void DoAdventureActions(); void DoAdventureActions();
void DoAdventureAssassinationCountIncrease(); void DoAdventureAssassinationCountIncrease();
void DoAdventureCountIncrease(); void DoAdventureCountIncrease();
void GetMerchantDataForZoneLoad(); void LoadMerchants();
void GetTimeSync(); void GetTimeSync();
void LoadAdventureFlavor(); void LoadAdventureFlavor();
void LoadAlternateAdvancement(); void LoadAlternateAdvancement();