mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-14 11:28:08 +00:00
Grim LU
Wincent's attempt at making LU into something it isn't supposed to be, an ARPG.
This commit is contained in:
61
dDatabase/Tables/CDLookupTable.cpp
Normal file
61
dDatabase/Tables/CDLookupTable.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "CDLookupTable.h"
|
||||
|
||||
CDLookupTable::CDLookupTable(void) {
|
||||
|
||||
// First, get the size of the table
|
||||
uint32_t size = 0;
|
||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM lookupTable");
|
||||
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 lookupTable");
|
||||
while (!tableData.eof()) {
|
||||
std::string key = tableData.getStringField("id", "");
|
||||
int32_t value = tableData.getIntField("value", -1);
|
||||
|
||||
this->entries.emplace(key, value);
|
||||
this->reverseEntries.emplace(value, key);
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
int32_t CDLookupTable::Lookup(const std::string& key) const {
|
||||
// If the key starts with 'lego-universe:', parse what comes
|
||||
// after the ':' as an integer and return that.
|
||||
if (key.find("lego-universe:") == 0) {
|
||||
return std::stoi(key.substr(14));
|
||||
}
|
||||
|
||||
auto it = this->entries.find(key);
|
||||
if (it != this->entries.end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::vector<std::string> CDLookupTable::ReverseLookup(int32_t value) const {
|
||||
auto range = this->reverseEntries.equal_range(value);
|
||||
std::vector<std::string> keys;
|
||||
for (auto it = range.first; it != range.second; ++it) {
|
||||
keys.push_back(it->second);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
int32_t rose::id(const std::string& key) {
|
||||
return CDLookupTable::Instance().Lookup(key);
|
||||
}
|
23
dDatabase/Tables/CDLookupTable.h
Normal file
23
dDatabase/Tables/CDLookupTable.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
// Custom Classes
|
||||
#include "CDTable.h"
|
||||
|
||||
class CDLookupTable : public CDTable<CDLookupTable> {
|
||||
private:
|
||||
std::unordered_map<std::string, int32_t> entries;
|
||||
std::unordered_multimap<int32_t, std::string> reverseEntries;
|
||||
|
||||
public:
|
||||
CDLookupTable();
|
||||
|
||||
// Lookup
|
||||
int32_t Lookup(const std::string& key) const;
|
||||
|
||||
// Reverse Lookup
|
||||
std::vector<std::string> ReverseLookup(int32_t value) const;
|
||||
};
|
||||
|
||||
namespace rose {
|
||||
int32_t id(const std::string& key);
|
||||
}
|
@@ -35,4 +35,5 @@ set(DDATABASE_TABLES_SOURCES "CDActivitiesTable.cpp"
|
||||
"CDScriptComponentTable.cpp"
|
||||
"CDSkillBehaviorTable.cpp"
|
||||
"CDVendorComponentTable.cpp"
|
||||
"CDLookupTable.cpp"
|
||||
"CDZoneTableTable.cpp" PARENT_SCOPE)
|
||||
|
Reference in New Issue
Block a user