LoadMercEquipment converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-08-20 22:00:00 -07:00
parent 2fd2cd4cec
commit 2028a5846c

View File

@ -1606,38 +1606,31 @@ bool ZoneDatabase::DeleteMerc(uint32 merc_id) {
} }
void ZoneDatabase::LoadMercEquipment(Merc *merc) { void ZoneDatabase::LoadMercEquipment(Merc *merc) {
std::string errorMessage;
char* Query = 0;
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT item_id FROM merc_inventory WHERE merc_subtype_id = (SELECT merc_subtype_id FROM merc_subtypes WHERE class_id = '%u' AND tier_id = '%u') AND min_level <= %u AND max_level >= %u", merc->GetClass(), merc->GetTierID(), merc->GetLevel(), merc->GetLevel()), TempErrorMessageBuffer, &DatasetResult)) { std::string query = StringFormat("SELECT item_id FROM merc_inventory "
errorMessage = std::string(TempErrorMessageBuffer); "WHERE merc_subtype_id = ("
} "SELECT merc_subtype_id FROM merc_subtypes "
else { "WHERE class_id = '%u' AND tier_id = '%u') "
int itemCount = 0; "AND min_level <= %u AND max_level >= %u",
merc->GetClass(), merc->GetTierID(),
while(DataRow = mysql_fetch_row(DatasetResult)) { merc->GetLevel(), merc->GetLevel());
if (itemCount == EmuConstants::EQUIPMENT_SIZE) auto results = database.QueryDatabase(query);
break; if(!results.Success()) {
LogFile->write(EQEMuLog::Error, "Error Loading Merc Inventory: %s", results.ErrorMessage().c_str());
if(atoi(DataRow[0]) > 0) { return;
merc->AddItem(itemCount, atoi(DataRow[0]));
itemCount++;
}
}
mysql_free_result(DatasetResult);
} }
safe_delete_array(Query); int itemCount = 0;
Query = 0; for(auto row = results.begin(); row != results.end(); ++row) {
if (itemCount == EmuConstants::EQUIPMENT_SIZE)
break;
if(!errorMessage.empty()) { if(atoi(row[0]) == 0)
LogFile->write(EQEMuLog::Error, "Error Loading Merc Inventory: %s", errorMessage.c_str()); continue;
}
merc->AddItem(itemCount, atoi(row[0]));
itemCount++;
}
} }
uint8 ZoneDatabase::GetGridType(uint32 grid, uint32 zoneid ) { uint8 ZoneDatabase::GetGridType(uint32 grid, uint32 zoneid ) {