DarkflameServer/dDatabase/CDClientDatabase/CDClientTables/CDRarityTableTable.cpp

36 lines
989 B
C++
Raw Normal View History

#include "CDRarityTableTable.h"
void CDRarityTableTable::LoadValuesFromDatabase() {
2022-07-28 13:39:57 +00:00
// First, get the size of the table
uint32_t size = 0;
2022-07-28 13:39:57 +00:00
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM RarityTable");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
2022-07-28 13:39:57 +00:00
// Reserve the size
auto& entries = GetEntriesMutable();
entries.reserve(size);
2022-07-28 13:39:57 +00:00
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RarityTable order by randmax desc;");
2022-07-28 13:39:57 +00:00
while (!tableData.eof()) {
uint32_t rarityTableIndex = tableData.getIntField("RarityTableIndex", -1);
2022-07-28 13:39:57 +00:00
CDRarityTable entry;
entry.randmax = tableData.getFloatField("randmax", -1);
entry.rarity = tableData.getIntField("rarity", -1);
entries[rarityTableIndex].push_back(entry);
2022-07-28 13:39:57 +00:00
tableData.nextRow();
}
}
const std::vector<CDRarityTable>& CDRarityTableTable::GetRarityTable(uint32_t id) {
return GetEntriesMutable()[id];
}