two tables done

This commit is contained in:
David Markowitz
2023-07-25 21:29:06 -07:00
parent ff173dffce
commit 771eb65b92
16 changed files with 60 additions and 74 deletions

View File

@@ -1,8 +1,6 @@
#include "CDSkillBehaviorTable.h"
void CDSkillBehaviorTable::LoadValuesFromDatabase() {
m_empty = CDSkillBehavior();
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM SkillBehavior");
@@ -49,12 +47,8 @@ void CDSkillBehaviorTable::LoadValuesFromDatabase() {
tableData.finalize();
}
const CDSkillBehavior& CDSkillBehaviorTable::GetSkillByID(unsigned int skillID) {
std::map<unsigned int, CDSkillBehavior>::iterator it = this->entries.find(skillID);
if (it != this->entries.end()) {
return it->second;
}
return m_empty;
const std::optional<CDSkillBehavior> CDSkillBehaviorTable::GetSkillByID(unsigned int skillID) {
auto it = this->entries.find(skillID);
return it != this->entries.end() ? std::make_optional(it->second) : std::nullopt;
}

View File

@@ -28,12 +28,10 @@ struct CDSkillBehavior {
class CDSkillBehaviorTable : public CDTable<CDSkillBehaviorTable> {
private:
std::map<unsigned int, CDSkillBehavior> entries;
CDSkillBehavior m_empty;
public:
void LoadValuesFromDatabase();
// Gets an entry by skillID
const CDSkillBehavior& GetSkillByID(unsigned int skillID);
const std::optional<CDSkillBehavior> GetSkillByID(unsigned int skillID);
};

View File

@@ -5,6 +5,7 @@
#include "DluAssert.h"
#include <functional>
#include <optional>
#include <string>
#include <vector>
#include <map>

View File

@@ -1,50 +1,24 @@
#include "CDVendorComponentTable.h"
void CDVendorComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM VendorComponent");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
// Reserve the size
this->entries.reserve(size);
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM VendorComponent");
while (!tableData.eof()) {
CDVendorComponent entry;
entry.id = tableData.getIntField("id", -1);
uint32_t id = tableData.getIntField("id", -1);
entry.buyScalar = tableData.getFloatField("buyScalar", -1.0f);
entry.sellScalar = tableData.getFloatField("sellScalar", -1.0f);
entry.refreshTimeSeconds = tableData.getFloatField("refreshTimeSeconds", -1.0f);
entry.LootMatrixIndex = tableData.getIntField("LootMatrixIndex", -1);
this->entries.push_back(entry);
this->entries.insert_or_assign(id, entry);
tableData.nextRow();
}
tableData.finalize();
}
//! Queries the table with a custom "where" clause
std::vector<CDVendorComponent> CDVendorComponentTable::Query(std::function<bool(CDVendorComponent)> predicate) {
std::vector<CDVendorComponent> data = cpplinq::from(this->entries)
>> cpplinq::where(predicate)
>> cpplinq::to_vector();
return data;
const std::optional<CDVendorComponent> CDVendorComponentTable::Query(uint32_t id) {
const auto& iter = entries.find(id);
return iter != entries.end() ? std::make_optional(iter->second) : std::nullopt;
}
//! Gets all the entries in the table
const std::vector<CDVendorComponent>& CDVendorComponentTable::GetEntries() const {
return this->entries;
}

View File

@@ -4,7 +4,6 @@
#include "CDTable.h"
struct CDVendorComponent {
unsigned int id; //!< The Component ID
float buyScalar; //!< Buy Scalar (what does that mean?)
float sellScalar; //!< Sell Scalar (what does that mean?)
float refreshTimeSeconds; //!< The refresh time
@@ -13,13 +12,11 @@ struct CDVendorComponent {
class CDVendorComponentTable : public CDTable<CDVendorComponentTable> {
private:
std::vector<CDVendorComponent> entries;
std::map<uint32_t, CDVendorComponent> entries;
public:
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDVendorComponent> Query(std::function<bool(CDVendorComponent)> predicate);
const std::vector<CDVendorComponent>& GetEntries(void) const;
const std::optional<CDVendorComponent> Query(uint32_t id);
};

View File

@@ -2,8 +2,6 @@
#include "CDTable.h"
#include <optional>
struct CDZoneTable {
unsigned int zoneID; //!< The Zone ID of the object
unsigned int locStatus; //!< The Locale Status(?)