Decouple temporary merchant list call [skip ci]

This commit is contained in:
Akkadius 2020-03-30 21:32:59 -05:00
parent 43716332aa
commit 79dbddd56e
7 changed files with 115 additions and 73 deletions

View File

@ -472,21 +472,16 @@ void Database::AssignRaidToInstance(uint32 raid_id, uint32 instance_id)
}
void Database::BuryCorpsesInInstance(uint16 instance_id) {
std::string query = StringFormat(
"UPDATE `character_corpses` "
"SET `is_buried` = 1, "
"`instance_id` = 0 "
"WHERE "
"`instance_id` = %u ",
instance_id
);
auto results = QueryDatabase(query);
QueryDatabase(
fmt::format(
"UPDATE character_corpses SET is_buried = 1, instance_id = 0 WHERE instance_id = {}",
instance_id
)
);
}
void Database::DeleteInstance(uint16 instance_id)
{
// TODO: BOUNDARY REWRITE
std::string query = StringFormat("DELETE FROM instance_list WHERE id=%u", instance_id);
QueryDatabase(query);

View File

@ -115,6 +115,7 @@ namespace Logs {
Flee,
Aura,
HotReload,
Merchants,
MaxCategoryID /* Don't Remove this */
};
@ -189,6 +190,7 @@ namespace Logs {
"Flee",
"Aura",
"HotReload",
"Merchants",
};
}

View File

@ -571,6 +571,16 @@
OutF(LogSys, Logs::Detail, Logs::HotReload, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogMerchants(message, ...) do {\
if (LogSys.log_settings[Logs::Merchants].is_category_enabled == 1)\
OutF(LogSys, Logs::General, Logs::Merchants, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogMerchantsDetail(message, ...) do {\
if (LogSys.log_settings[Logs::Merchants].is_category_enabled == 1)\
OutF(LogSys, Logs::Detail, Logs::Merchants, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\
if (LogSys.log_settings[log_category].is_category_enabled == 1)\
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
@ -910,6 +920,12 @@
#define LogHotReloadDetail(message, ...) do {\
} while (0)
#define LogMerchants(message, ...) do {\
} while (0)
#define LogMerchantsDetail(message, ...) do {\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\
} while (0)

View File

@ -480,7 +480,7 @@ bool ZoneDatabase::PopulateZoneSpawnListClose(uint32 zoneid, LinkedList<Spawn2*>
zone_name,
version
);
results = QueryDatabase(query);
results = database.QueryDatabase(query);
if (!results.Success()) {
return false;
@ -547,7 +547,7 @@ bool ZoneDatabase::PopulateZoneSpawnList(uint32 zoneid, LinkedList<Spawn2*> &spa
"WHERE instance_id = %u",
zone->GetInstanceID()
);
auto results = QueryDatabase(spawn_query);
auto results = database.QueryDatabase(spawn_query);
for (auto row = results.begin(); row != results.end(); ++row) {
uint32 start_duration = atoi(row[1]) > 0 ? atoi(row[1]) : 0;
uint32 end_duration = atoi(row[2]) > 0 ? atoi(row[2]) : 0;
@ -989,7 +989,7 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
query = StringFormat("SELECT id, value FROM spawn_condition_values "
"WHERE zone = '%s' AND instance_id = %u",
zone_name, instance_id);
results = content_db.QueryDatabase(query);
results = database.QueryDatabase(query);
if (!results.Success()) {
spawn_conditions.clear();
return false;

View File

@ -575,7 +575,7 @@ void NPC::AssignWaypoints(int32 grid_id, int start_wp)
Waypoints.clear();
roamer = false;
auto grid_entry = GridRepository::GetGrid(zone->grids, grid_id);
auto grid_entry = GridRepository::GetGrid(zone->zone_grids, grid_id);
if (grid_entry.id == 0) {
return;
}
@ -588,7 +588,7 @@ void NPC::AssignWaypoints(int32 grid_id, int start_wp)
roamer = true;
max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list
for (auto &entry : zone->grid_entries) {
for (auto &entry : zone->zone_grid_entries) {
if (entry.gridid == grid_id) {
wplist new_waypoint{};
new_waypoint.index = max_wp;

View File

@ -419,48 +419,79 @@ uint32 Zone::GetTempMerchantQuantity(uint32 NPCID, uint32 Slot) {
return 0;
}
void Zone::LoadTempMerchantData() {
void Zone::LoadTempMerchantData()
{
LogInfo("Loading Temporary Merchant Lists");
std::string query = StringFormat(
"SELECT "
"DISTINCT ml.npcid, "
"ml.slot, "
"ml.charges, "
"ml.itemid "
"FROM "
"merchantlist_temp ml, "
"spawnentry se, "
"spawn2 s2 "
"WHERE "
"ml.npcid = se.npcid "
"AND se.spawngroupid = s2.spawngroupid "
"AND s2.zone = '%s' AND s2.version = %i "
"ORDER BY ml.slot ", GetShortName(), GetInstanceVersion());
auto results = content_db.QueryDatabase(query);
if (!results.Success()) {
return;
}
std::map<uint32, std::list<TempMerchantList> >::iterator cur;
uint32 npcid = 0;
auto results = content_db.QueryDatabase(
fmt::format(
SQL(
SELECT
DISTINCT npc_types.id
FROM
npc_types
JOIN spawnentry ON spawnentry.npcID = npc_types.id
JOIN spawn2 ON spawn2.spawngroupID = spawnentry.spawngroupID
WHERE
spawn2.zone = '{}'
AND spawn2.version = {}
),
GetShortName(),
GetInstanceVersion()
)
);
std::vector<std::string> npc_ids;
for (auto row = results.begin(); row != results.end(); ++row) {
TempMerchantList ml;
ml.npcid = atoul(row[0]);
if (npcid != ml.npcid){
cur = tmpmerchanttable.find(ml.npcid);
if (cur == tmpmerchanttable.end()) {
std::list<TempMerchantList> empty;
tmpmerchanttable[ml.npcid] = empty;
cur = tmpmerchanttable.find(ml.npcid);
}
npcid = ml.npcid;
}
ml.slot = atoul(row[1]);
ml.charges = atoul(row[2]);
ml.item = atoul(row[3]);
ml.origslot = ml.slot;
cur->second.push_back(ml);
npc_ids.push_back(row[0]);
}
results = database.QueryDatabase(
fmt::format(
SQL(
npcid,
slot,
charges,
itemid
FROM merchantlist_temp
WHERE npcid IN ({})
),
implode(", ", npc_ids)
)
);
std::map<uint32, std::list<TempMerchantList> >::iterator temp_merchant_table_entry;
uint32 npc_id = 0;
for (auto row = results.begin(); row != results.end(); ++row) {
TempMerchantList temp_merchant_list;
temp_merchant_list.npcid = atoul(row[0]);
if (npc_id != temp_merchant_list.npcid) {
temp_merchant_table_entry = tmpmerchanttable.find(temp_merchant_list.npcid);
if (temp_merchant_table_entry == tmpmerchanttable.end()) {
std::list<TempMerchantList> empty;
tmpmerchanttable[temp_merchant_list.npcid] = empty;
temp_merchant_table_entry = tmpmerchanttable.find(temp_merchant_list.npcid);
}
npc_id = temp_merchant_list.npcid;
}
temp_merchant_list.slot = atoul(row[1]);
temp_merchant_list.charges = atoul(row[2]);
temp_merchant_list.item = atoul(row[3]);
temp_merchant_list.origslot = temp_merchant_list.slot;
LogMerchants(
"[LoadTempMerchantData] Loading merchant temp items npc_id [{}] slot [{}] charges [{}] item [{}] origslot [{}]",
npc_id,
temp_merchant_list.slot,
temp_merchant_list.charges,
temp_merchant_list.item,
temp_merchant_list.origslot
);
temp_merchant_table_entry->second.push_back(temp_merchant_list);
}
pQueuedMerchantsWorkID = 0;
}
void Zone::LoadNewMerchantData(uint32 merchantid) {
@ -807,7 +838,6 @@ Zone::Zone(uint32 in_zoneid, uint32 in_instanceid, const char* in_short_name)
pgraveyard_id = 0;
pgraveyard_zoneid = 0;
pMaxClients = 0;
pQueuedMerchantsWorkID = 0;
pvpzone = false;
if(database.GetServerType() == 1)
pvpzone = true;
@ -907,16 +937,18 @@ Zone::~Zone() {
//Modified for timezones.
bool Zone::Init(bool iStaticZone) {
SetStaticZone(iStaticZone);
//load the zone config file.
if (!LoadZoneCFG(zone->GetShortName(), zone->GetInstanceVersion())) // try loading the zone name...
LoadZoneCFG(zone->GetFileName(), zone->GetInstanceVersion()); // if that fails, try the file name, then load defaults
if(RuleManager::Instance()->GetActiveRulesetID() != default_ruleset)
{
//load the zone config file.
if (!LoadZoneCFG(zone->GetShortName(), zone->GetInstanceVersion())) { // try loading the zone name...
LoadZoneCFG(
zone->GetFileName(),
zone->GetInstanceVersion()
);
} // if that fails, try the file name, then load defaults
if (RuleManager::Instance()->GetActiveRulesetID() != default_ruleset) {
std::string r_name = RuleManager::Instance()->GetRulesetName(&database, default_ruleset);
if(r_name.size() > 0)
{
if (r_name.size() > 0) {
RuleManager::Instance()->LoadRules(&database, r_name.c_str(), false);
}
}
@ -980,12 +1012,11 @@ bool Zone::Init(bool iStaticZone) {
LogInfo("Flushing old respawn timers");
database.QueryDatabase("DELETE FROM `respawn_times` WHERE (`start` + `duration`) < UNIX_TIMESTAMP(NOW())");
//load up the zone's doors (prints inside)
zone->LoadZoneDoors(zone->GetShortName(), zone->GetInstanceVersion());
zone->LoadZoneBlockedSpells(zone->GetZoneID());
//clear trader items if we are loading the bazaar
if(strncasecmp(short_name,"bazaar",6)==0) {
if (strncasecmp(short_name, "bazaar", 6) == 0) {
database.DeleteTraderItem(0);
database.DeleteBuyLines(0);
}
@ -2487,6 +2518,6 @@ void Zone::SetQuestHotReloadQueued(bool in_quest_hot_reload_queued)
void Zone::LoadGrids()
{
grids = GridRepository::GetZoneGrids(GetZoneID());
grid_entries = GridEntriesRepository::GetZoneGridEntries(GetZoneID());
}
zone_grids = GridRepository::GetZoneGrids(GetZoneID());
zone_grid_entries = GridEntriesRepository::GetZoneGridEntries(GetZoneID());
}

View File

@ -205,8 +205,8 @@ public:
std::unordered_map<int, std::unique_ptr<AA::Ability>> aa_abilities;
std::unordered_map<int, std::unique_ptr<AA::Rank>> aa_ranks;
std::vector<GridRepository::Grid> grids;
std::vector<GridEntriesRepository::GridEntry> grid_entries;
std::vector<GridRepository::Grid> zone_grids;
std::vector<GridEntriesRepository::GridEntry> zone_grid_entries;
time_t weather_timer;
Timer spawn2_timer;
@ -372,8 +372,6 @@ private:
uint32 pMaxClients;
uint32 zoneid;
uint32 m_last_ucss_update;
uint32 pQueuedMerchantsWorkID;
uint32 pQueuedTempMerchantsWorkID;
GlobalLootManager m_global_loot;
LinkedList<ZoneClientAuth_Struct *> client_auth_list;