Compare commits

...

9 Commits

Author SHA1 Message Date
David Markowitz
23676cf17b rarityTable 2023-07-25 22:37:32 -07:00
David Markowitz
0642b4ac55 switch to unordered 2023-07-25 22:34:11 -07:00
David Markowitz
6f2d583ca2 unordered 2023-07-25 22:28:24 -07:00
David Markowitz
4a189edf43 rebuild 2023-07-25 22:27:13 -07:00
David Markowitz
84708b860a rewards 2023-07-25 21:44:45 -07:00
David Markowitz
eebf484c4e script comp 2023-07-25 21:39:20 -07:00
David Markowitz
771eb65b92 two tables done 2023-07-25 21:29:06 -07:00
David Markowitz
ff173dffce move to std optional 2023-07-25 19:45:22 -07:00
David Markowitz
dc526aeec1 Move away from constructor queries
Fix up other large tables to have proper backup lookups

Revert "idk im just dumb ig"

This reverts commit 5d5be5df53b8959b42b291613d7db749a65a3585.

idk im just dumb ig
2023-07-25 19:10:37 -07:00
94 changed files with 403 additions and 650 deletions

View File

@@ -13,15 +13,7 @@
#include <sstream>
#include <iostream>
// Enable this to cache all entries in each table for fast access, comes with more memory cost
//#define CDCLIENT_CACHE_ALL
/*!
\file CDClientDatabase.hpp
\brief An interface between the CDClient.sqlite file and the server
*/
//! The CDClient Database namespace
//! The CDClient Database namespace
namespace CDClientDatabase {
//! Opens a connection with the CDClient

View File

@@ -38,43 +38,53 @@
#include "CDFeatureGatingTable.h"
#include "CDRailActivatorComponent.h"
// Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory.
// A vanilla CDClient takes about 46MB of memory + the regular world data.
// #define CDCLIENT_CACHE_ALL
#ifdef CDCLIENT_CACHE_ALL
#define CDCLIENT_DONT_CACHE_TABLE(x) x
#else
#define CDCLIENT_DONT_CACHE_TABLE(x)
#endif
CDClientManager::CDClientManager() {
CDActivityRewardsTable::Instance();
CDAnimationsTable::Instance();
CDBehaviorParameterTable::Instance();
CDBehaviorTemplateTable::Instance();
CDComponentsRegistryTable::Instance();
CDCurrencyTableTable::Instance();
CDDestructibleComponentTable::Instance();
CDEmoteTableTable::Instance();
CDInventoryComponentTable::Instance();
CDItemComponentTable::Instance();
CDItemSetsTable::Instance();
CDItemSetSkillsTable::Instance();
CDLevelProgressionLookupTable::Instance();
CDLootMatrixTable::Instance();
CDLootTableTable::Instance();
CDMissionNPCComponentTable::Instance();
CDMissionTasksTable::Instance();
CDMissionsTable::Instance();
CDObjectSkillsTable::Instance();
CDObjectsTable::Instance();
CDPhysicsComponentTable::Instance();
CDRebuildComponentTable::Instance();
CDScriptComponentTable::Instance();
CDSkillBehaviorTable::Instance();
CDZoneTableTable::Instance();
CDVendorComponentTable::Instance();
CDActivitiesTable::Instance();
CDPackageComponentTable::Instance();
CDProximityMonitorComponentTable::Instance();
CDMovementAIComponentTable::Instance();
CDBrickIDTableTable::Instance();
CDRarityTableTable::Instance();
CDMissionEmailTable::Instance();
CDRewardsTable::Instance();
CDPropertyEntranceComponentTable::Instance();
CDPropertyTemplateTable::Instance();
CDFeatureGatingTable::Instance();
CDRailActivatorComponentTable::Instance();
CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
CDActivitiesTable::Instance().LoadValuesFromDatabase();
CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase());
CDBehaviorParameterTable::Instance().LoadValuesFromDatabase();
CDBehaviorTemplateTable::Instance().LoadValuesFromDatabase();
CDBrickIDTableTable::Instance().LoadValuesFromDatabase();
CDComponentsRegistryTable::Instance().LoadValuesFromDatabase();
CDCurrencyTableTable::Instance().LoadValuesFromDatabase();
CDDestructibleComponentTable::Instance().LoadValuesFromDatabase();
CDEmoteTableTable::Instance().LoadValuesFromDatabase();
CDFeatureGatingTable::Instance().LoadValuesFromDatabase();
CDInventoryComponentTable::Instance().LoadValuesFromDatabase();
CDCLIENT_DONT_CACHE_TABLE(CDItemComponentTable::Instance().LoadValuesFromDatabase());
CDItemSetSkillsTable::Instance().LoadValuesFromDatabase();
CDItemSetsTable::Instance().LoadValuesFromDatabase();
CDLevelProgressionLookupTable::Instance().LoadValuesFromDatabase();
CDLootMatrixTable::Instance().LoadValuesFromDatabase();
CDLootTableTable::Instance().LoadValuesFromDatabase();
CDMissionEmailTable::Instance().LoadValuesFromDatabase();
CDMissionNPCComponentTable::Instance().LoadValuesFromDatabase();
CDMissionTasksTable::Instance().LoadValuesFromDatabase();
CDMissionsTable::Instance().LoadValuesFromDatabase();
CDMovementAIComponentTable::Instance().LoadValuesFromDatabase();
CDObjectSkillsTable::Instance().LoadValuesFromDatabase();
CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
CDPhysicsComponentTable::Instance().LoadValuesFromDatabase();
CDPackageComponentTable::Instance().LoadValuesFromDatabase();
CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase();
CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase();
CDPropertyTemplateTable::Instance().LoadValuesFromDatabase();
CDRailActivatorComponentTable::Instance().LoadValuesFromDatabase();
CDRarityTableTable::Instance().LoadValuesFromDatabase();
CDRebuildComponentTable::Instance().LoadValuesFromDatabase();
CDRewardsTable::Instance().LoadValuesFromDatabase();
CDScriptComponentTable::Instance().LoadValuesFromDatabase();
CDSkillBehaviorTable::Instance().LoadValuesFromDatabase();
CDVendorComponentTable::Instance().LoadValuesFromDatabase();
CDZoneTableTable::Instance().LoadValuesFromDatabase();
}

View File

@@ -1,7 +1,6 @@
#include "CDActivitiesTable.h"
CDActivitiesTable::CDActivitiesTable(void) {
void CDActivitiesTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Activities");
@@ -55,8 +54,3 @@ std::vector<CDActivities> CDActivitiesTable::Query(std::function<bool(CDActiviti
return data;
}
std::vector<CDActivities> CDActivitiesTable::GetEntries(void) const {
return this->entries;
}

View File

@@ -30,9 +30,10 @@ private:
std::vector<CDActivities> entries;
public:
CDActivitiesTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDActivities> Query(std::function<bool(CDActivities)> predicate);
std::vector<CDActivities> GetEntries(void) const;
const std::vector<CDActivities>& GetEntries() const { return this->entries; }
};

View File

@@ -1,6 +1,6 @@
#include "CDActivityRewardsTable.h"
CDActivityRewardsTable::CDActivityRewardsTable(void) {
void CDActivityRewardsTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -43,8 +43,3 @@ std::vector<CDActivityRewards> CDActivityRewardsTable::Query(std::function<bool(
return data;
}
std::vector<CDActivityRewards> CDActivityRewardsTable::GetEntries(void) const {
return this->entries;
}

View File

@@ -18,10 +18,10 @@ private:
std::vector<CDActivityRewards> entries;
public:
CDActivityRewardsTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDActivityRewards> Query(std::function<bool(CDActivityRewards)> predicate);
std::vector<CDActivityRewards> GetEntries(void) const;
std::vector<CDActivityRewards> GetEntries() const;
};

View File

@@ -2,6 +2,35 @@
#include "GeneralUtils.h"
#include "Game.h"
void CDAnimationsTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Animations");
while (!tableData.eof()) {
std::string animation_type = tableData.getStringField("animation_type", "");
DluAssert(!animation_type.empty());
AnimationGroupID animationGroupID = tableData.getIntField("animationGroupID", -1);
DluAssert(animationGroupID != -1);
CDAnimation entry;
entry.animation_name = tableData.getStringField("animation_name", "");
entry.chance_to_play = tableData.getFloatField("chance_to_play", 1.0f);
UNUSED_COLUMN(entry.min_loops = tableData.getIntField("min_loops", 0);)
UNUSED_COLUMN(entry.max_loops = tableData.getIntField("max_loops", 0);)
entry.animation_length = tableData.getFloatField("animation_length", 0.0f);
UNUSED_COLUMN(entry.hideEquip = tableData.getIntField("hideEquip", 0) == 1;)
UNUSED_COLUMN(entry.ignoreUpperBody = tableData.getIntField("ignoreUpperBody", 0) == 1;)
UNUSED_COLUMN(entry.restartable = tableData.getIntField("restartable", 0) == 1;)
UNUSED_COLUMN(entry.face_animation_name = tableData.getStringField("face_animation_name", "");)
UNUSED_COLUMN(entry.priority = tableData.getFloatField("priority", 0.0f);)
UNUSED_COLUMN(entry.blendTime = tableData.getFloatField("blendTime", 0.0f);)
this->animations[CDAnimationKey(animation_type, animationGroupID)].push_back(entry);
tableData.nextRow();
}
tableData.finalize();
}
bool CDAnimationsTable::CacheData(CppSQLite3Statement& queryToCache) {
auto tableData = queryToCache.execQuery();
// If we received a bad lookup, cache it anyways so we do not run the query again.

View File

@@ -27,6 +27,7 @@ class CDAnimationsTable : public CDTable<CDAnimationsTable> {
typedef std::string AnimationID;
typedef std::pair<std::string, AnimationGroupID> CDAnimationKey;
public:
void LoadValuesFromDatabase();
/**
* Given an animationType and the previousAnimationName played, return the next animationType to play.
* If there are more than 1 animationTypes that can be played, one is selected at random but also does not allow

View File

@@ -1,7 +1,7 @@
#include "CDBehaviorParameterTable.h"
#include "GeneralUtils.h"
CDBehaviorParameterTable::CDBehaviorParameterTable(void) {
void CDBehaviorParameterTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM BehaviorParameter");
uint32_t uniqueParameterId = 0;
uint64_t hash = 0;
@@ -53,4 +53,3 @@ std::map<std::string, float> CDBehaviorParameterTable::GetParametersByBehaviorID
}
return returnInfo;
}

View File

@@ -16,7 +16,8 @@ private:
std::unordered_map<uint64_t, CDBehaviorParameter> m_Entries;
std::unordered_map<std::string, uint32_t> m_ParametersList;
public:
CDBehaviorParameterTable();
void LoadValuesFromDatabase();
float GetValue(const uint32_t behaviorID, const std::string& name, const float defaultValue = 0);
std::map<std::string, float> GetParametersByBehaviorID(uint32_t behaviorID);

View File

@@ -1,6 +1,6 @@
#include "CDBehaviorTemplateTable.h"
CDBehaviorTemplateTable::CDBehaviorTemplateTable(void) {
void CDBehaviorTemplateTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -48,7 +48,7 @@ std::vector<CDBehaviorTemplate> CDBehaviorTemplateTable::Query(std::function<boo
return data;
}
std::vector<CDBehaviorTemplate> CDBehaviorTemplateTable::GetEntries(void) const {
const std::vector<CDBehaviorTemplate>& CDBehaviorTemplateTable::GetEntries() const {
return this->entries;
}
@@ -64,4 +64,3 @@ const CDBehaviorTemplate CDBehaviorTemplateTable::GetByBehaviorID(uint32_t behav
return entry->second;
}
}

View File

@@ -19,11 +19,12 @@ private:
std::unordered_map<uint32_t, CDBehaviorTemplate> entriesMappedByBehaviorID;
std::unordered_set<std::string> m_EffectHandles;
public:
CDBehaviorTemplateTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDBehaviorTemplate> Query(std::function<bool(CDBehaviorTemplate)> predicate);
std::vector<CDBehaviorTemplate> GetEntries(void) const;
const std::vector<CDBehaviorTemplate>& GetEntries(void) const;
const CDBehaviorTemplate GetByBehaviorID(uint32_t behaviorID);
};

View File

@@ -1,6 +1,6 @@
#include "CDBrickIDTableTable.h"
CDBrickIDTableTable::CDBrickIDTableTable(void) {
void CDBrickIDTableTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -39,7 +39,7 @@ std::vector<CDBrickIDTable> CDBrickIDTableTable::Query(std::function<bool(CDBric
return data;
}
std::vector<CDBrickIDTable> CDBrickIDTableTable::GetEntries(void) const {
const std::vector<CDBrickIDTable>& CDBrickIDTableTable::GetEntries() const {
return this->entries;
}

View File

@@ -21,9 +21,9 @@ private:
std::vector<CDBrickIDTable> entries;
public:
CDBrickIDTableTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDBrickIDTable> Query(std::function<bool(CDBrickIDTable)> predicate);
std::vector<CDBrickIDTable> GetEntries(void) const;
const std::vector<CDBrickIDTable>& GetEntries() const;
};

View File

@@ -1,25 +1,7 @@
#include "CDComponentsRegistryTable.h"
#include "eReplicaComponentType.h"
#define CDCLIENT_CACHE_ALL
CDComponentsRegistryTable::CDComponentsRegistryTable(void) {
#ifdef CDCLIENT_CACHE_ALL
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ComponentsRegistry");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
// Reserve the size
//this->entries.reserve(size);
void CDComponentsRegistryTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ComponentsRegistry");
while (!tableData.eof()) {
@@ -34,60 +16,35 @@ CDComponentsRegistryTable::CDComponentsRegistryTable(void) {
}
tableData.finalize();
#endif
}
int32_t CDComponentsRegistryTable::GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue) {
const auto& iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id));
auto iter = mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id));
if (iter == this->mappedEntries.end()) {
return defaultValue;
}
return iter->second;
#ifndef CDCLIENT_CACHE_ALL
// Now get the data
std::stringstream query;
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM ComponentsRegistry WHERE id = ? AND component_type = ?;");
query.bind(1, static_cast<int32_t>(id));
query.bind(2, static_cast<int32_t>(componentType));
query << "SELECT * FROM ComponentsRegistry WHERE id = " << std::to_string(id);
auto tableData = CDClientDatabase::ExecuteQuery(query.str());
auto tableData = query.execQuery();
while (!tableData.eof()) {
CDComponentsRegistry entry;
entry.id = tableData.getIntField("id", -1);
entry.component_type = tableData.getIntField("component_type", -1);
entry.component_type = static_cast<eReplicaComponentType>(tableData.getIntField("component_type", 0));
entry.component_id = tableData.getIntField("component_id", -1);
//this->entries.push_back(entry);
//Darwin's stuff:
const auto& it = this->mappedEntries.find(entry.id);
if (it != mappedEntries.end()) {
const auto& iter = it->second.find(entry.component_type);
if (iter == it->second.end()) {
it->second.insert(std::make_pair(entry.component_type, entry.component_id));
}
} else {
std::map<unsigned int, unsigned int> map;
map.insert(std::make_pair(entry.component_type, entry.component_id));
this->mappedEntries.insert(std::make_pair(entry.id, map));
}
this->mappedEntries.insert_or_assign(((uint64_t)entry.component_type) << 32 | ((uint64_t)entry.id), entry.component_id);
tableData.nextRow();
}
tableData.finalize();
iter = this->mappedEntries.find(((uint64_t)componentType) << 32 | ((uint64_t)id));
const auto& it2 = this->mappedEntries.find(id);
if (it2 != mappedEntries.end()) {
const auto& iter = it2->second.find(componentType);
if (iter != it2->second.end()) {
return iter->second;
}
}
return defaultValue;
#endif
return iter == this->mappedEntries.end() ? defaultValue : iter->second;
}

View File

@@ -16,6 +16,6 @@ private:
std::map<uint64_t, uint32_t> mappedEntries; //id, component_type, component_id
public:
CDComponentsRegistryTable();
void LoadValuesFromDatabase();
int32_t GetByIDAndType(uint32_t id, eReplicaComponentType componentType, int32_t defaultValue = 0);
};

View File

@@ -1,7 +1,7 @@
#include "CDCurrencyTableTable.h"
//! Constructor
CDCurrencyTableTable::CDCurrencyTableTable(void) {
void CDCurrencyTableTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -43,7 +43,7 @@ std::vector<CDCurrencyTable> CDCurrencyTableTable::Query(std::function<bool(CDCu
return data;
}
std::vector<CDCurrencyTable> CDCurrencyTableTable::GetEntries(void) const {
const std::vector<CDCurrencyTable>& CDCurrencyTableTable::GetEntries() const {
return this->entries;
}

View File

@@ -23,9 +23,9 @@ private:
std::vector<CDCurrencyTable> entries;
public:
CDCurrencyTableTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDCurrencyTable> Query(std::function<bool(CDCurrencyTable)> predicate);
std::vector<CDCurrencyTable> GetEntries(void) const;
const std::vector<CDCurrencyTable>& GetEntries() const;
};

View File

@@ -1,8 +1,6 @@
#include "CDDestructibleComponentTable.h"
//! Constructor
CDDestructibleComponentTable::CDDestructibleComponentTable(void) {
void CDDestructibleComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM DestructibleComponent");
@@ -52,7 +50,7 @@ std::vector<CDDestructibleComponent> CDDestructibleComponentTable::Query(std::fu
return data;
}
std::vector<CDDestructibleComponent> CDDestructibleComponentTable::GetEntries(void) const {
const std::vector<CDDestructibleComponent>& CDDestructibleComponentTable::GetEntries() const {
return this->entries;
}

View File

@@ -25,9 +25,9 @@ private:
std::vector<CDDestructibleComponent> entries;
public:
CDDestructibleComponentTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDDestructibleComponent> Query(std::function<bool(CDDestructibleComponent)> predicate);
std::vector<CDDestructibleComponent> GetEntries(void) const;
const std::vector<CDDestructibleComponent>& GetEntries(void) const;
};

View File

@@ -1,40 +1,26 @@
#include "CDEmoteTable.h"
//! Constructor
CDEmoteTableTable::CDEmoteTableTable(void) {
void CDEmoteTableTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Emotes");
while (!tableData.eof()) {
CDEmoteTable* entry = new CDEmoteTable();
entry->ID = tableData.getIntField("id", -1);
entry->animationName = tableData.getStringField("animationName", "");
entry->iconFilename = tableData.getStringField("iconFilename", "");
entry->channel = tableData.getIntField("channel", -1);
entry->locked = tableData.getIntField("locked", -1) != 0;
entry->localize = tableData.getIntField("localize", -1) != 0;
entry->locState = tableData.getIntField("locStatus", -1);
entry->gateVersion = tableData.getStringField("gate_version", "");
CDEmoteTable entry;
entry.ID = tableData.getIntField("id", -1);
entry.animationName = tableData.getStringField("animationName", "");
entry.iconFilename = tableData.getStringField("iconFilename", "");
entry.channel = tableData.getIntField("channel", -1);
entry.locked = tableData.getIntField("locked", -1) != 0;
entry.localize = tableData.getIntField("localize", -1) != 0;
entry.locState = tableData.getIntField("locStatus", -1);
entry.gateVersion = tableData.getStringField("gate_version", "");
entries.insert(std::make_pair(entry->ID, entry));
entries.insert(std::make_pair(entry.ID, entry));
tableData.nextRow();
}
tableData.finalize();
}
//! Destructor
CDEmoteTableTable::~CDEmoteTableTable(void) {
for (auto e : entries) {
if (e.second) delete e.second;
}
entries.clear();
}
CDEmoteTable* CDEmoteTableTable::GetEmote(int id) {
for (auto e : entries) {
if (e.first == id) return e.second;
}
return nullptr;
auto itr = entries.find(id);
return itr != entries.end() ? &itr->second : nullptr;
}

View File

@@ -28,11 +28,10 @@ struct CDEmoteTable {
class CDEmoteTableTable : public CDTable<CDEmoteTableTable> {
private:
std::map<int, CDEmoteTable*> entries;
std::map<int, CDEmoteTable> entries;
public:
CDEmoteTableTable();
~CDEmoteTableTable();
void LoadValuesFromDatabase();
// Returns an emote by ID
CDEmoteTable* GetEmote(int id);
};

View File

@@ -1,7 +1,6 @@
#include "CDFeatureGatingTable.h"
//! Constructor
CDFeatureGatingTable::CDFeatureGatingTable(void) {
void CDFeatureGatingTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -53,7 +52,7 @@ bool CDFeatureGatingTable::FeatureUnlocked(const std::string& feature) const {
return false;
}
std::vector<CDFeatureGating> CDFeatureGatingTable::GetEntries(void) const {
const std::vector<CDFeatureGating>& CDFeatureGatingTable::GetEntries() const {
return this->entries;
}

View File

@@ -16,11 +16,12 @@ private:
std::vector<CDFeatureGating> entries;
public:
CDFeatureGatingTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDFeatureGating> Query(std::function<bool(CDFeatureGating)> predicate);
bool FeatureUnlocked(const std::string& feature) const;
std::vector<CDFeatureGating> GetEntries(void) const;
const std::vector<CDFeatureGating>& GetEntries(void) const;
};

View File

@@ -1,7 +1,6 @@
#include "CDInventoryComponentTable.h"
//! Constructor
CDInventoryComponentTable::CDInventoryComponentTable(void) {
void CDInventoryComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -42,7 +41,7 @@ std::vector<CDInventoryComponent> CDInventoryComponentTable::Query(std::function
return data;
}
std::vector<CDInventoryComponent> CDInventoryComponentTable::GetEntries(void) const {
const std::vector<CDInventoryComponent>& CDInventoryComponentTable::GetEntries() const {
return this->entries;
}

View File

@@ -15,9 +15,9 @@ private:
std::vector<CDInventoryComponent> entries;
public:
CDInventoryComponentTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDInventoryComponent> Query(std::function<bool(CDInventoryComponent)> predicate);
std::vector<CDInventoryComponent> GetEntries(void) const;
const std::vector<CDInventoryComponent>& GetEntries() const;
};

View File

@@ -3,11 +3,7 @@
CDItemComponent CDItemComponentTable::Default = {};
//! Constructor
CDItemComponentTable::CDItemComponentTable(void) {
Default = CDItemComponent();
#ifdef CDCLIENT_CACHE_ALL
void CDItemComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ItemComponent");
@@ -55,13 +51,13 @@ CDItemComponentTable::CDItemComponentTable(void) {
entry.currencyLOT = tableData.getIntField("currencyLOT", -1);
entry.altCurrencyCost = tableData.getIntField("altCurrencyCost", -1);
entry.subItems = tableData.getStringField("subItems", "");
entry.audioEventUse = tableData.getStringField("audioEventUse", "");
UNUSED_COLUMN(entry.audioEventUse = tableData.getStringField("audioEventUse", ""));
entry.noEquipAnimation = tableData.getIntField("noEquipAnimation", -1) == 1 ? true : false;
entry.commendationLOT = tableData.getIntField("commendationLOT", -1);
entry.commendationCost = tableData.getIntField("commendationCost", -1);
entry.audioEquipMetaEventSet = tableData.getStringField("audioEquipMetaEventSet", "");
UNUSED_COLUMN(entry.audioEquipMetaEventSet = tableData.getStringField("audioEquipMetaEventSet", ""));
entry.currencyCosts = tableData.getStringField("currencyCosts", "");
entry.ingredientInfo = tableData.getStringField("ingredientInfo", "");
UNUSED_COLUMN(entry.ingredientInfo = tableData.getStringField("ingredientInfo", ""));
entry.locStatus = tableData.getIntField("locStatus", -1);
entry.forgeType = tableData.getIntField("forgeType", -1);
entry.SellMultiplier = tableData.getFloatField("SellMultiplier", -1.0f);
@@ -71,7 +67,6 @@ CDItemComponentTable::CDItemComponentTable(void) {
}
tableData.finalize();
#endif
}
const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int skillID) {
@@ -80,12 +75,10 @@ const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int s
return it->second;
}
#ifndef CDCLIENT_CACHE_ALL
std::stringstream query;
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM ItemComponent WHERE id = ?;");
query.bind(1, static_cast<int32_t>(skillID));
query << "SELECT * FROM ItemComponent WHERE id = " << std::to_string(skillID);
auto tableData = CDClientDatabase::ExecuteQuery(query.str());
auto tableData = query.execQuery();
if (tableData.eof()) {
entries.insert(std::make_pair(skillID, Default));
return Default;
@@ -144,7 +137,6 @@ const CDItemComponent& CDItemComponentTable::GetItemComponentByID(unsigned int s
if (it2 != this->entries.end()) {
return it2->second;
}
#endif
return Default;
}

View File

@@ -54,7 +54,7 @@ private:
std::map<unsigned int, CDItemComponent> entries;
public:
CDItemComponentTable();
void LoadValuesFromDatabase();
static std::map<LOT, uint32_t> ParseCraftingCurrencies(const CDItemComponent& itemComponent);
// Gets an entry by ID

View File

@@ -1,7 +1,6 @@
#include "CDItemSetSkillsTable.h"
//! Constructor
CDItemSetSkillsTable::CDItemSetSkillsTable(void) {
void CDItemSetSkillsTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -41,7 +40,7 @@ std::vector<CDItemSetSkills> CDItemSetSkillsTable::Query(std::function<bool(CDIt
return data;
}
std::vector<CDItemSetSkills> CDItemSetSkillsTable::GetEntries(void) const {
const std::vector<CDItemSetSkills>& CDItemSetSkillsTable::GetEntries() const {
return this->entries;
}

View File

@@ -14,11 +14,11 @@ private:
std::vector<CDItemSetSkills> entries;
public:
CDItemSetSkillsTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDItemSetSkills> Query(std::function<bool(CDItemSetSkills)> predicate);
std::vector<CDItemSetSkills> GetEntries(void) const;
const std::vector<CDItemSetSkills>& GetEntries() const;
std::vector<CDItemSetSkills> GetBySkillID(unsigned int SkillSetID);
};

View File

@@ -1,7 +1,6 @@
#include "CDItemSetsTable.h"
//! Constructor
CDItemSetsTable::CDItemSetsTable(void) {
void CDItemSetsTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -53,7 +52,7 @@ std::vector<CDItemSets> CDItemSetsTable::Query(std::function<bool(CDItemSets)> p
return data;
}
std::vector<CDItemSets> CDItemSetsTable::GetEntries(void) const {
const std::vector<CDItemSets>& CDItemSetsTable::GetEntries() const {
return this->entries;
}

View File

@@ -26,10 +26,10 @@ private:
std::vector<CDItemSets> entries;
public:
CDItemSetsTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDItemSets> Query(std::function<bool(CDItemSets)> predicate);
std::vector<CDItemSets> GetEntries(void) const;
const std::vector<CDItemSets>& GetEntries(void) const;
};

View File

@@ -1,7 +1,6 @@
#include "CDLevelProgressionLookupTable.h"
//! Constructor
CDLevelProgressionLookupTable::CDLevelProgressionLookupTable(void) {
void CDLevelProgressionLookupTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -32,7 +31,6 @@ CDLevelProgressionLookupTable::CDLevelProgressionLookupTable(void) {
tableData.finalize();
}
//! Queries the table with a custom "where" clause
std::vector<CDLevelProgressionLookup> CDLevelProgressionLookupTable::Query(std::function<bool(CDLevelProgressionLookup)> predicate) {
std::vector<CDLevelProgressionLookup> data = cpplinq::from(this->entries)
@@ -42,8 +40,7 @@ std::vector<CDLevelProgressionLookup> CDLevelProgressionLookupTable::Query(std::
return data;
}
//! Gets all the entries in the table
std::vector<CDLevelProgressionLookup> CDLevelProgressionLookupTable::GetEntries(void) const {
const std::vector<CDLevelProgressionLookup>& CDLevelProgressionLookupTable::GetEntries() const {
return this->entries;
}

View File

@@ -14,10 +14,10 @@ private:
std::vector<CDLevelProgressionLookup> entries;
public:
CDLevelProgressionLookupTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDLevelProgressionLookup> Query(std::function<bool(CDLevelProgressionLookup)> predicate);
// Gets all the entries in the table
std::vector<CDLevelProgressionLookup> GetEntries(void) const;
const std::vector<CDLevelProgressionLookup>& GetEntries() const;
};

View File

@@ -1,7 +1,6 @@
#include "CDLootMatrixTable.h"
//! Constructor
CDLootMatrixTable::CDLootMatrixTable(void) {
void CDLootMatrixTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -47,7 +46,7 @@ std::vector<CDLootMatrix> CDLootMatrixTable::Query(std::function<bool(CDLootMatr
return data;
}
const std::vector<CDLootMatrix>& CDLootMatrixTable::GetEntries(void) const {
const std::vector<CDLootMatrix>& CDLootMatrixTable::GetEntries() const {
return this->entries;
}

View File

@@ -20,10 +20,10 @@ private:
std::vector<CDLootMatrix> entries;
public:
CDLootMatrixTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDLootMatrix> Query(std::function<bool(CDLootMatrix)> predicate);
const std::vector<CDLootMatrix>& GetEntries(void) const;
const std::vector<CDLootMatrix>& GetEntries() const;
};

View File

@@ -1,7 +1,6 @@
#include "CDLootTableTable.h"
//! Constructor
CDLootTableTable::CDLootTableTable(void) {
void CDLootTableTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -46,7 +45,7 @@ std::vector<CDLootTable> CDLootTableTable::Query(std::function<bool(CDLootTable)
}
//! Gets all the entries in the table
const std::vector<CDLootTable>& CDLootTableTable::GetEntries(void) const {
const std::vector<CDLootTable>& CDLootTableTable::GetEntries() const {
return this->entries;
}

View File

@@ -16,10 +16,10 @@ private:
std::vector<CDLootTable> entries;
public:
CDLootTableTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDLootTable> Query(std::function<bool(CDLootTable)> predicate);
const std::vector<CDLootTable>& GetEntries(void) const;
const std::vector<CDLootTable>& GetEntries() const;
};

View File

@@ -1,7 +1,6 @@
#include "CDMissionEmailTable.h"
//! Constructor
CDMissionEmailTable::CDMissionEmailTable(void) {
void CDMissionEmailTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -48,7 +47,7 @@ std::vector<CDMissionEmail> CDMissionEmailTable::Query(std::function<bool(CDMiss
}
//! Gets all the entries in the table
std::vector<CDMissionEmail> CDMissionEmailTable::GetEntries(void) const {
const std::vector<CDMissionEmail>& CDMissionEmailTable::GetEntries() const {
return this->entries;
}

View File

@@ -20,9 +20,9 @@ private:
std::vector<CDMissionEmail> entries;
public:
CDMissionEmailTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDMissionEmail> Query(std::function<bool(CDMissionEmail)> predicate);
std::vector<CDMissionEmail> GetEntries(void) const;
const std::vector<CDMissionEmail>& GetEntries() const;
};

View File

@@ -1,7 +1,6 @@
#include "CDMissionNPCComponentTable.h"
//! Constructor
CDMissionNPCComponentTable::CDMissionNPCComponentTable(void) {
void CDMissionNPCComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -45,7 +44,7 @@ std::vector<CDMissionNPCComponent> CDMissionNPCComponentTable::Query(std::functi
}
//! Gets all the entries in the table
std::vector<CDMissionNPCComponent> CDMissionNPCComponentTable::GetEntries(void) const {
const std::vector<CDMissionNPCComponent>& CDMissionNPCComponentTable::GetEntries() const {
return this->entries;
}

View File

@@ -16,12 +16,12 @@ private:
std::vector<CDMissionNPCComponent> entries;
public:
CDMissionNPCComponentTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDMissionNPCComponent> Query(std::function<bool(CDMissionNPCComponent)> predicate);
// Gets all the entries in the table
std::vector<CDMissionNPCComponent> GetEntries(void) const;
const std::vector<CDMissionNPCComponent>& GetEntries() const;
};

View File

@@ -1,7 +1,6 @@
#include "CDMissionTasksTable.h"
//! Constructor
CDMissionTasksTable::CDMissionTasksTable(void) {
void CDMissionTasksTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -56,16 +55,14 @@ std::vector<CDMissionTasks*> CDMissionTasksTable::GetByMissionID(uint32_t missio
for (auto& entry : this->entries) {
if (entry.id == missionID) {
CDMissionTasks* task = const_cast<CDMissionTasks*>(&entry);
tasks.push_back(task);
tasks.push_back(&entry);
}
}
return tasks;
}
const std::vector<CDMissionTasks>& CDMissionTasksTable::GetEntries(void) const {
const std::vector<CDMissionTasks>& CDMissionTasksTable::GetEntries() const {
return this->entries;
}

View File

@@ -24,12 +24,12 @@ private:
std::vector<CDMissionTasks> entries;
public:
CDMissionTasksTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDMissionTasks> Query(std::function<bool(CDMissionTasks)> predicate);
std::vector<CDMissionTasks*> GetByMissionID(uint32_t missionID);
const std::vector<CDMissionTasks>& GetEntries(void) const;
const std::vector<CDMissionTasks>& GetEntries() const;
};

View File

@@ -2,8 +2,7 @@
CDMissions CDMissionsTable::Default = {};
//! Constructor
CDMissionsTable::CDMissionsTable(void) {
void CDMissionsTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;

View File

@@ -65,12 +65,12 @@ private:
std::vector<CDMissions> entries;
public:
CDMissionsTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDMissions> Query(std::function<bool(CDMissions)> predicate);
// Gets all the entries in the table
const std::vector<CDMissions>& GetEntries(void) const;
const std::vector<CDMissions>& GetEntries() const;
const CDMissions* GetPtrByMissionID(uint32_t missionID) const;

View File

@@ -1,7 +1,6 @@
#include "CDMovementAIComponentTable.h"
//! Constructor
CDMovementAIComponentTable::CDMovementAIComponentTable(void) {
void CDMovementAIComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -37,7 +36,6 @@ CDMovementAIComponentTable::CDMovementAIComponentTable(void) {
tableData.finalize();
}
//! Queries the table with a custom "where" clause
std::vector<CDMovementAIComponent> CDMovementAIComponentTable::Query(std::function<bool(CDMovementAIComponent)> predicate) {
std::vector<CDMovementAIComponent> data = cpplinq::from(this->entries)
@@ -47,8 +45,7 @@ std::vector<CDMovementAIComponent> CDMovementAIComponentTable::Query(std::functi
return data;
}
//! Gets all the entries in the table
std::vector<CDMovementAIComponent> CDMovementAIComponentTable::GetEntries(void) const {
const std::vector<CDMovementAIComponent>& CDMovementAIComponentTable::GetEntries(void) const {
return this->entries;
}

View File

@@ -19,10 +19,10 @@ private:
std::vector<CDMovementAIComponent> entries;
public:
CDMovementAIComponentTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDMovementAIComponent> Query(std::function<bool(CDMovementAIComponent)> predicate);
// Gets all the entries in the table
std::vector<CDMovementAIComponent> GetEntries(void) const;
const std::vector<CDMovementAIComponent>& GetEntries() const;
};

View File

@@ -1,7 +1,6 @@
#include "CDObjectSkillsTable.h"
//! Constructor
CDObjectSkillsTable::CDObjectSkillsTable(void) {
void CDObjectSkillsTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -33,7 +32,6 @@ CDObjectSkillsTable::CDObjectSkillsTable(void) {
tableData.finalize();
}
//! Queries the table with a custom "where" clause
std::vector<CDObjectSkills> CDObjectSkillsTable::Query(std::function<bool(CDObjectSkills)> predicate) {
std::vector<CDObjectSkills> data = cpplinq::from(this->entries)
@@ -43,7 +41,6 @@ std::vector<CDObjectSkills> CDObjectSkillsTable::Query(std::function<bool(CDObje
return data;
}
//! Gets all the entries in the table
std::vector<CDObjectSkills> CDObjectSkillsTable::GetEntries(void) const {
const std::vector<CDObjectSkills>& CDObjectSkillsTable::GetEntries() const {
return this->entries;
}

View File

@@ -15,12 +15,12 @@ private:
std::vector<CDObjectSkills> entries;
public:
CDObjectSkillsTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDObjectSkills> Query(std::function<bool(CDObjectSkills)> predicate);
// Gets all the entries in the table
std::vector<CDObjectSkills> GetEntries(void) const;
const std::vector<CDObjectSkills>& GetEntries() const;
};

View File

@@ -1,8 +1,6 @@
#include "CDObjectsTable.h"
//! Constructor
CDObjectsTable::CDObjectsTable(void) {
#ifdef CDCLIENT_CACHE_ALL
void CDObjectsTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM Objects");
@@ -20,25 +18,24 @@ CDObjectsTable::CDObjectsTable(void) {
CDObjects entry;
entry.id = tableData.getIntField("id", -1);
entry.name = tableData.getStringField("name", "");
entry.placeable = tableData.getIntField("placeable", -1);
UNUSED_COLUMN(entry.placeable = tableData.getIntField("placeable", -1);)
entry.type = tableData.getStringField("type", "");
entry.description = tableData.getStringField("description", "");
entry.localize = tableData.getIntField("localize", -1);
entry.npcTemplateID = tableData.getIntField("npcTemplateID", -1);
entry.displayName = tableData.getStringField("displayName", "");
UNUSED_COLUMN(entry.description = tableData.getStringField("description", "");)
UNUSED_COLUMN(entry.localize = tableData.getIntField("localize", -1);)
UNUSED_COLUMN(entry.npcTemplateID = tableData.getIntField("npcTemplateID", -1);)
UNUSED_COLUMN(entry.displayName = tableData.getStringField("displayName", "");)
entry.interactionDistance = tableData.getFloatField("interactionDistance", -1.0f);
entry.nametag = tableData.getIntField("nametag", -1);
entry._internalNotes = tableData.getStringField("_internalNotes", "");
entry.locStatus = tableData.getIntField("locStatus", -1);
entry.gate_version = tableData.getStringField("gate_version", "");
entry.HQ_valid = tableData.getIntField("HQ_valid", -1);
UNUSED_COLUMN(entry.nametag = tableData.getIntField("nametag", -1);)
UNUSED_COLUMN(entry._internalNotes = tableData.getStringField("_internalNotes", "");)
UNUSED_COLUMN(entry.locStatus = tableData.getIntField("locStatus", -1);)
UNUSED_COLUMN(entry.gate_version = tableData.getStringField("gate_version", "");)
UNUSED_COLUMN(entry.HQ_valid = tableData.getIntField("HQ_valid", -1);)
this->entries.insert(std::make_pair(entry.id, entry));
tableData.nextRow();
}
tableData.finalize();
#endif
m_default.id = 0;
}
@@ -49,12 +46,10 @@ const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) {
return it->second;
}
#ifndef CDCLIENT_CACHE_ALL
std::stringstream query;
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM Objects WHERE id = ?;");
query.bind(1, static_cast<int32_t>(LOT));
query << "SELECT * FROM Objects WHERE id = " << std::to_string(LOT);
auto tableData = CDClientDatabase::ExecuteQuery(query.str());
auto tableData = query.execQuery();
if (tableData.eof()) {
this->entries.insert(std::make_pair(LOT, m_default));
return m_default;
@@ -88,7 +83,6 @@ const CDObjects& CDObjectsTable::GetByID(unsigned int LOT) {
if (it2 != entries.end()) {
return it2->second;
}
#endif
return m_default;
}

View File

@@ -26,7 +26,7 @@ private:
CDObjects m_default;
public:
CDObjectsTable();
void LoadValuesFromDatabase();
// Gets an entry by ID
const CDObjects& GetByID(unsigned int LOT);
};

View File

@@ -1,7 +1,6 @@
#include "CDPackageComponentTable.h"
//! Constructor
CDPackageComponentTable::CDPackageComponentTable(void) {
void CDPackageComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -43,7 +42,7 @@ std::vector<CDPackageComponent> CDPackageComponentTable::Query(std::function<boo
}
//! Gets all the entries in the table
std::vector<CDPackageComponent> CDPackageComponentTable::GetEntries(void) const {
const std::vector<CDPackageComponent>& CDPackageComponentTable::GetEntries() const {
return this->entries;
}

View File

@@ -14,9 +14,9 @@ private:
std::vector<CDPackageComponent> entries;
public:
CDPackageComponentTable(void);
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDPackageComponent> Query(std::function<bool(CDPackageComponent)> predicate);
std::vector<CDPackageComponent> GetEntries(void) const;
const std::vector<CDPackageComponent>& GetEntries() const;
};

View File

@@ -1,46 +1,35 @@
#include "CDPhysicsComponentTable.h"
CDPhysicsComponentTable::CDPhysicsComponentTable(void) {
void CDPhysicsComponentTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PhysicsComponent");
while (!tableData.eof()) {
CDPhysicsComponent* entry = new CDPhysicsComponent();
entry->id = tableData.getIntField("id", -1);
entry->bStatic = tableData.getIntField("static", -1) != 0;
entry->physicsAsset = tableData.getStringField("physics_asset", "");
CDPhysicsComponent entry;
entry.id = tableData.getIntField("id", -1);
entry.bStatic = tableData.getIntField("static", -1) != 0;
entry.physicsAsset = tableData.getStringField("physics_asset", "");
UNUSED(entry->jump = tableData.getIntField("jump", -1) != 0);
UNUSED(entry->doublejump = tableData.getIntField("doublejump", -1) != 0);
entry->speed = tableData.getFloatField("speed", -1);
entry.speed = tableData.getFloatField("speed", -1);
UNUSED(entry->rotSpeed = tableData.getFloatField("rotSpeed", -1));
entry->playerHeight = tableData.getFloatField("playerHeight");
entry->playerRadius = tableData.getFloatField("playerRadius");
entry->pcShapeType = tableData.getIntField("pcShapeType");
entry->collisionGroup = tableData.getIntField("collisionGroup");
entry.playerHeight = tableData.getFloatField("playerHeight");
entry.playerRadius = tableData.getFloatField("playerRadius");
entry.pcShapeType = tableData.getIntField("pcShapeType");
entry.collisionGroup = tableData.getIntField("collisionGroup");
UNUSED(entry->airSpeed = tableData.getFloatField("airSpeed"));
UNUSED(entry->boundaryAsset = tableData.getStringField("boundaryAsset"));
UNUSED(entry->jumpAirSpeed = tableData.getFloatField("jumpAirSpeed"));
UNUSED(entry->friction = tableData.getFloatField("friction"));
UNUSED(entry->gravityVolumeAsset = tableData.getStringField("gravityVolumeAsset"));
m_entries.insert(std::make_pair(entry->id, entry));
m_entries.insert(std::make_pair(entry.id, entry));
tableData.nextRow();
}
tableData.finalize();
}
CDPhysicsComponentTable::~CDPhysicsComponentTable() {
for (auto e : m_entries) {
if (e.second) delete e.second;
}
m_entries.clear();
}
CDPhysicsComponent* CDPhysicsComponentTable::GetByID(unsigned int componentID) {
for (auto e : m_entries) {
if (e.first == componentID) return e.second;
}
return nullptr;
auto itr = m_entries.find(componentID);
return itr != m_entries.end() ? &itr->second : nullptr;
}

View File

@@ -23,12 +23,11 @@ struct CDPhysicsComponent {
class CDPhysicsComponentTable : public CDTable<CDPhysicsComponentTable> {
public:
CDPhysicsComponentTable();
~CDPhysicsComponentTable();
void LoadValuesFromDatabase();
static const std::string GetTableName() { return "PhysicsComponent"; };
CDPhysicsComponent* GetByID(unsigned int componentID);
private:
std::map<unsigned int, CDPhysicsComponent*> m_entries;
std::map<unsigned int, CDPhysicsComponent> m_entries;
};

View File

@@ -1,7 +1,6 @@
#include "CDPropertyEntranceComponentTable.h"
CDPropertyEntranceComponentTable::CDPropertyEntranceComponentTable() {
void CDPropertyEntranceComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
size_t size = 0;

View File

@@ -11,12 +11,12 @@ struct CDPropertyEntranceComponent {
class CDPropertyEntranceComponentTable : public CDTable<CDPropertyEntranceComponentTable> {
public:
CDPropertyEntranceComponentTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
CDPropertyEntranceComponent GetByID(uint32_t id);
// Gets all the entries in the table
[[nodiscard]] std::vector<CDPropertyEntranceComponent> GetEntries() const { return entries; }
[[nodiscard]] const std::vector<CDPropertyEntranceComponent>& GetEntries() const { return entries; }
private:
std::vector<CDPropertyEntranceComponent> entries{};
CDPropertyEntranceComponent defaultEntry{};

View File

@@ -1,6 +1,6 @@
#include "CDPropertyTemplateTable.h"
CDPropertyTemplateTable::CDPropertyTemplateTable() {
void CDPropertyTemplateTable::LoadValuesFromDatabase() {
// First, get the size of the table
size_t size = 0;

View File

@@ -10,7 +10,7 @@ struct CDPropertyTemplate {
class CDPropertyTemplateTable : public CDTable<CDPropertyTemplateTable> {
public:
CDPropertyTemplateTable();
void LoadValuesFromDatabase();
static const std::string GetTableName() { return "PropertyTemplate"; };
CDPropertyTemplate GetByMapID(uint32_t mapID);

View File

@@ -1,7 +1,6 @@
#include "CDProximityMonitorComponentTable.h"
//! Constructor
CDProximityMonitorComponentTable::CDProximityMonitorComponentTable(void) {
void CDProximityMonitorComponentTable::LoadValuesFromDatabase() {
// First, get the size of the table
unsigned int size = 0;
@@ -33,7 +32,6 @@ CDProximityMonitorComponentTable::CDProximityMonitorComponentTable(void) {
tableData.finalize();
}
//! Queries the table with a custom "where" clause
std::vector<CDProximityMonitorComponent> CDProximityMonitorComponentTable::Query(std::function<bool(CDProximityMonitorComponent)> predicate) {
std::vector<CDProximityMonitorComponent> data = cpplinq::from(this->entries)
@@ -43,8 +41,7 @@ std::vector<CDProximityMonitorComponent> CDProximityMonitorComponentTable::Query
return data;
}
//! Gets all the entries in the table
std::vector<CDProximityMonitorComponent> CDProximityMonitorComponentTable::GetEntries(void) const {
const std::vector<CDProximityMonitorComponent>& CDProximityMonitorComponentTable::GetEntries() const {
return this->entries;
}

View File

@@ -15,9 +15,9 @@ private:
std::vector<CDProximityMonitorComponent> entries;
public:
CDProximityMonitorComponentTable(void);
void LoadValuesFromDatabase();
//! Queries the table with a custom "where" clause
std::vector<CDProximityMonitorComponent> Query(std::function<bool(CDProximityMonitorComponent)> predicate);
std::vector<CDProximityMonitorComponent> GetEntries(void) const;
const std::vector<CDProximityMonitorComponent>& GetEntries() const;
};

View File

@@ -1,7 +1,7 @@
#include "CDRailActivatorComponent.h"
#include "GeneralUtils.h"
CDRailActivatorComponentTable::CDRailActivatorComponentTable() {
void CDRailActivatorComponentTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RailActivatorComponent;");
while (!tableData.eof()) {
CDRailActivatorComponent entry;
@@ -52,7 +52,7 @@ CDRailActivatorComponent CDRailActivatorComponentTable::GetEntryByID(int32_t id)
return {};
}
std::vector<CDRailActivatorComponent> CDRailActivatorComponentTable::GetEntries() const {
const std::vector<CDRailActivatorComponent>& CDRailActivatorComponentTable::GetEntries() const {
return m_Entries;
}

View File

@@ -22,10 +22,10 @@ struct CDRailActivatorComponent {
class CDRailActivatorComponentTable : public CDTable<CDRailActivatorComponentTable> {
public:
CDRailActivatorComponentTable();
void LoadValuesFromDatabase();
static const std::string GetTableName() { return "RailActivatorComponent"; };
[[nodiscard]] CDRailActivatorComponent GetEntryByID(int32_t id) const;
[[nodiscard]] std::vector<CDRailActivatorComponent> GetEntries() const;
[[nodiscard]] const std::vector<CDRailActivatorComponent>& GetEntries() const;
private:
static std::pair<uint32_t, std::u16string> EffectPairFromString(std::string& str);
std::vector<CDRailActivatorComponent> m_Entries{};

View File

@@ -1,32 +1,16 @@
#include "CDRarityTableTable.h"
//! Constructor
CDRarityTableTable::CDRarityTableTable(void) {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM RarityTable");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
// Reserve the size
this->entries.reserve(size);
void CDRarityTableTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RarityTable");
while (!tableData.eof()) {
CDRarityTable entry;
entry.id = tableData.getIntField("id", -1);
uint32_t id = tableData.getIntField("id", -1);
entry.randmax = tableData.getFloatField("randmax", -1);
entry.rarity = tableData.getIntField("rarity", -1);
entry.RarityTableIndex = tableData.getIntField("RarityTableIndex", -1);
this->entries.push_back(entry);
this->entries.insert_or_assign(id, entry);
tableData.nextRow();
}
@@ -34,17 +18,7 @@ CDRarityTableTable::CDRarityTableTable(void) {
}
//! Queries the table with a custom "where" clause
std::vector<CDRarityTable> CDRarityTableTable::Query(std::function<bool(CDRarityTable)> predicate) {
std::vector<CDRarityTable> data = cpplinq::from(this->entries)
>> cpplinq::where(predicate)
>> cpplinq::to_vector();
return data;
const std::optional<CDRarityTable> CDRarityTableTable::Get(uint32_t id) {
auto it = this->entries.find(id);
return it != this->entries.end() ? std::make_optional(it->second) : std::nullopt;
}
//! Gets all the entries in the table
const std::vector<CDRarityTable>& CDRarityTableTable::GetEntries(void) const {
return this->entries;
}

View File

@@ -28,13 +28,11 @@ struct CDRarityTable {
class CDRarityTableTable : public CDTable<CDRarityTableTable> {
private:
std::vector<CDRarityTable> entries;
std::unordered_map<uint32_t, CDRarityTable> entries;
public:
CDRarityTableTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDRarityTable> Query(std::function<bool(CDRarityTable)> predicate);
const std::vector<CDRarityTable>& GetEntries() const;
const std::optional<CDRarityTable> Get(uint32_t predicate);
};

View File

@@ -1,27 +1,11 @@
#include "CDRebuildComponentTable.h"
//! Constructor
CDRebuildComponentTable::CDRebuildComponentTable(void) {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM RebuildComponent");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
// Reserve the size
this->entries.reserve(size);
void CDRebuildComponentTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM RebuildComponent");
while (!tableData.eof()) {
CDRebuildComponent entry;
entry.id = tableData.getIntField("id", -1);
uint32_t id = tableData.getIntField("id", -1);
entry.reset_time = tableData.getFloatField("reset_time", -1.0f);
entry.complete_time = tableData.getFloatField("complete_time", -1.0f);
entry.take_imagination = tableData.getIntField("take_imagination", -1);
@@ -32,25 +16,12 @@ CDRebuildComponentTable::CDRebuildComponentTable(void) {
entry.post_imagination_cost = tableData.getIntField("post_imagination_cost", -1);
entry.time_before_smash = tableData.getFloatField("time_before_smash", -1.0f);
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<CDRebuildComponent> CDRebuildComponentTable::Query(std::function<bool(CDRebuildComponent)> predicate) {
std::vector<CDRebuildComponent> data = cpplinq::from(this->entries)
>> cpplinq::where(predicate)
>> cpplinq::to_vector();
return data;
const std::optional<CDRebuildComponent> CDRebuildComponentTable::Get(uint32_t componentId) {
auto it = this->entries.find(componentId);
return it != this->entries.end() ? std::make_optional(it->second) : std::nullopt;
}
//! Gets all the entries in the table
std::vector<CDRebuildComponent> CDRebuildComponentTable::GetEntries(void) const {
return this->entries;
}

View File

@@ -4,7 +4,6 @@
#include "CDTable.h"
struct CDRebuildComponent {
unsigned int id; //!< The component Id
float reset_time; //!< The reset time
float complete_time; //!< The complete time
unsigned int take_imagination; //!< The amount of imagination it costs
@@ -18,13 +17,11 @@ struct CDRebuildComponent {
class CDRebuildComponentTable : public CDTable<CDRebuildComponentTable> {
private:
std::vector<CDRebuildComponent> entries;
std::unordered_map<uint32_t, CDRebuildComponent> entries;
public:
CDRebuildComponentTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDRebuildComponent> Query(std::function<bool(CDRebuildComponent)> predicate);
std::vector<CDRebuildComponent> GetEntries() const;
const std::optional<CDRebuildComponent> Get(uint32_t componentId);
};

View File

@@ -1,35 +1,27 @@
#include "CDRewardsTable.h"
CDRewardsTable::CDRewardsTable(void) {
void CDRewardsTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM Rewards");
while (!tableData.eof()) {
CDRewards* entry = new CDRewards();
entry->id = tableData.getIntField("id", -1);
entry->levelID = tableData.getIntField("LevelID", -1);
entry->missionID = tableData.getIntField("MissionID", -1);
entry->rewardType = tableData.getIntField("RewardType", -1);
entry->value = tableData.getIntField("value", -1);
entry->count = tableData.getIntField("count", -1);
CDRewards entry;
uint32_t id = tableData.getIntField("id", -1);
entry.levelID = tableData.getIntField("LevelID", -1);
entry.missionID = tableData.getIntField("MissionID", -1);
entry.rewardType = tableData.getIntField("RewardType", -1);
entry.value = tableData.getIntField("value", -1);
entry.count = tableData.getIntField("count", -1);
m_entries.insert(std::make_pair(entry->id, entry));
m_entries.push_back(entry);
tableData.nextRow();
}
tableData.finalize();
}
CDRewardsTable::~CDRewardsTable(void) {
for (auto e : m_entries) {
if (e.second) delete e.second;
}
m_entries.clear();
}
std::vector<CDRewards*> CDRewardsTable::GetByLevelID(uint32_t levelID) {
std::vector<CDRewards*> result{};
for (const auto& e : m_entries) {
if (e.second->levelID == levelID) result.push_back(e.second);
std::vector<CDRewards> CDRewardsTable::GetByLevelID(uint32_t levelID) {
std::vector<CDRewards> result;
for (const auto& levelData : m_entries) {
if (levelData.levelID == levelID) result.push_back(levelData);
}
return result;

View File

@@ -3,7 +3,6 @@
#include <string>
struct CDRewards {
int32_t id;
int32_t levelID;
int32_t missionID;
int32_t rewardType;
@@ -13,12 +12,8 @@ struct CDRewards {
class CDRewardsTable : public CDTable<CDRewardsTable> {
public:
CDRewardsTable();
~CDRewardsTable();
static const std::string GetTableName() { return "Rewards"; };
std::vector<CDRewards*> GetByLevelID(uint32_t levelID);
void LoadValuesFromDatabase();
std::vector<CDRewards> GetByLevelID(uint32_t levelID);
private:
std::map<uint32_t, CDRewards*> m_entries;
std::vector<CDRewards> m_entries;
};

View File

@@ -1,40 +1,21 @@
#include "CDScriptComponentTable.h"
//! Constructor
CDScriptComponentTable::CDScriptComponentTable(void) {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ScriptComponent");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
void CDScriptComponentTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ScriptComponent");
while (!tableData.eof()) {
CDScriptComponent entry;
entry.id = tableData.getIntField("id", -1);
uint32_t id = tableData.getIntField("id", -1);
entry.script_name = tableData.getStringField("script_name", "");
entry.client_script_name = tableData.getStringField("client_script_name", "");
this->entries.insert(std::make_pair(entry.id, entry));
this->entries.insert_or_assign(id, entry);
tableData.nextRow();
}
tableData.finalize();
}
const CDScriptComponent& CDScriptComponentTable::GetByID(unsigned int id) {
std::map<unsigned int, CDScriptComponent>::iterator it = this->entries.find(id);
if (it != this->entries.end()) {
return it->second;
}
return m_ToReturnWhenNoneFound;
const std::optional<CDScriptComponent> CDScriptComponentTable::GetByID(unsigned int id) {
auto it = this->entries.find(id);
return (it != this->entries.end()) ? std::make_optional<CDScriptComponent>(it->second) : std::nullopt;
}

View File

@@ -4,19 +4,16 @@
#include "CDTable.h"
struct CDScriptComponent {
unsigned int id; //!< The component ID
std::string script_name; //!< The script name
std::string client_script_name; //!< The client script name
std::string script_name; //!< The script name
std::string client_script_name; //!< The client script name
};
class CDScriptComponentTable : public CDTable<CDScriptComponentTable> {
private:
std::map<unsigned int, CDScriptComponent> entries;
CDScriptComponent m_ToReturnWhenNoneFound;
std::unordered_map<unsigned int, CDScriptComponent> entries;
public:
CDScriptComponentTable();
void LoadValuesFromDatabase();
// Gets an entry by scriptID
const CDScriptComponent& GetByID(unsigned int id);
const std::optional<CDScriptComponent> GetByID(unsigned int id);
};

View File

@@ -1,29 +1,10 @@
#include "CDSkillBehaviorTable.h"
//#include "Logger.hpp"
//! Constructor
CDSkillBehaviorTable::CDSkillBehaviorTable(void) {
m_empty = CDSkillBehavior();
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM SkillBehavior");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
// Reserve the size
//this->entries.reserve(size);
// Now get the data
void CDSkillBehaviorTable::LoadValuesFromDatabase() {
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM SkillBehavior");
while (!tableData.eof()) {
CDSkillBehavior entry;
entry.skillID = tableData.getIntField("skillID", -1);
uint32_t skillID = tableData.getIntField("skillID", -1);
UNUSED(entry.locStatus = tableData.getIntField("locStatus", -1));
entry.behaviorID = tableData.getIntField("behaviorID", -1);
entry.imaginationcost = tableData.getIntField("imaginationcost", -1);
@@ -43,27 +24,13 @@ CDSkillBehaviorTable::CDSkillBehaviorTable(void) {
UNUSED(entry.gate_version = tableData.getStringField("gate_version", ""));
UNUSED(entry.cancelType = tableData.getIntField("cancelType", -1));
this->entries.insert(std::make_pair(entry.skillID, entry));
//this->entries.push_back(entry);
this->entries.insert_or_assign(skillID, entry);
tableData.nextRow();
}
tableData.finalize();
}
//! Queries the table with a custom "where" clause
std::vector<CDSkillBehavior> CDSkillBehaviorTable::Query(std::function<bool(CDSkillBehavior)> predicate) {
std::vector<CDSkillBehavior> data; //So MSVC shuts up
return data;
}
//! Gets an entry by ID
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

@@ -4,7 +4,6 @@
#include "CDTable.h"
struct CDSkillBehavior {
unsigned int skillID; //!< The Skill ID of the skill
UNUSED(unsigned int locStatus); //!< ??
unsigned int behaviorID; //!< The Behavior ID of the skill
unsigned int imaginationcost; //!< The imagination cost of the skill
@@ -27,15 +26,11 @@ struct CDSkillBehavior {
class CDSkillBehaviorTable : public CDTable<CDSkillBehaviorTable> {
private:
std::map<unsigned int, CDSkillBehavior> entries;
CDSkillBehavior m_empty;
std::unordered_map<uint32_t, CDSkillBehavior> entries;
public:
CDSkillBehaviorTable();
// Queries the table with a custom "where" clause
std::vector<CDSkillBehavior> Query(std::function<bool(CDSkillBehavior)> predicate);
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,51 +1,22 @@
#include "CDVendorComponentTable.h"
//! Constructor
CDVendorComponentTable::CDVendorComponentTable(void) {
// 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);
void CDVendorComponentTable::LoadValuesFromDatabase() {
// 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
std::vector<CDVendorComponent> CDVendorComponentTable::GetEntries(void) 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::unordered_map<uint32_t, CDVendorComponent> entries;
public:
CDVendorComponentTable();
void LoadValuesFromDatabase();
// Queries the table with a custom "where" clause
std::vector<CDVendorComponent> Query(std::function<bool(CDVendorComponent)> predicate);
std::vector<CDVendorComponent> GetEntries(void) const;
const std::optional<CDVendorComponent> Query(uint32_t id);
};

View File

@@ -1,19 +1,6 @@
#include "CDZoneTableTable.h"
//! Constructor
CDZoneTableTable::CDZoneTableTable(void) {
// First, get the size of the table
unsigned int size = 0;
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ZoneTable");
while (!tableSize.eof()) {
size = tableSize.getIntField(0, 0);
tableSize.nextRow();
}
tableSize.finalize();
void CDZoneTableTable::LoadValuesFromDatabase() {
// Now get the data
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM ZoneTable");
while (!tableData.eof()) {
@@ -49,18 +36,11 @@ CDZoneTableTable::CDZoneTableTable(void) {
this->m_Entries.insert(std::make_pair(entry.zoneID, entry));
tableData.nextRow();
}
tableData.finalize();
}
//! Queries the table with a zoneID to find.
const CDZoneTable* CDZoneTableTable::Query(unsigned int zoneID) {
const std::optional<CDZoneTable> CDZoneTableTable::Query(unsigned int zoneID) {
const auto& iter = m_Entries.find(zoneID);
if (iter != m_Entries.end()) {
return &iter->second;
}
return nullptr;
return iter != m_Entries.end() ? std::make_optional(iter->second) : std::nullopt;
}

View File

@@ -1,6 +1,5 @@
#pragma once
// Custom Classes
#include "CDTable.h"
struct CDZoneTable {
@@ -35,11 +34,11 @@ struct CDZoneTable {
class CDZoneTableTable : public CDTable<CDZoneTableTable> {
private:
std::map<unsigned int, CDZoneTable> m_Entries;
std::unordered_map<uint32_t, CDZoneTable> m_Entries;
public:
CDZoneTableTable();
void LoadValuesFromDatabase();
// Queries the table with a zoneID to find.
const CDZoneTable* Query(unsigned int zoneID);
const std::optional<CDZoneTable> Query(unsigned int zoneID);
};

View File

@@ -463,9 +463,11 @@ void Entity::Initialize() {
if (scriptComponentID > 0 || m_Character) {
std::string clientScriptName;
if (!m_Character) {
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
scriptName = scriptCompData.script_name;
clientScriptName = scriptCompData.client_script_name;
auto scriptCompData = scriptCompTable->GetByID(scriptComponentID);
if (scriptCompData) {
scriptName = scriptCompData->script_name;
clientScriptName = scriptCompData->client_script_name;
}
} else {
scriptName = "";
}
@@ -504,16 +506,17 @@ void Entity::Initialize() {
// ZoneControl script
if (m_TemplateID == 2365) {
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
auto* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
const auto zoneID = Game::zoneManager->GetZoneID();
const CDZoneTable* zoneData = zoneTable->Query(zoneID.GetMapID());
auto zoneData = zoneTable->Query(zoneID.GetMapID());
if (zoneData != nullptr) {
if (zoneData) {
int zoneScriptID = zoneData->scriptID;
CDScriptComponent zoneScriptData = scriptCompTable->GetByID(zoneScriptID);
ScriptComponent* comp = new ScriptComponent(this, zoneScriptData.script_name, true);
m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPT, comp));
auto zoneScriptData = scriptCompTable->GetByID(zoneScriptID);
if (zoneScriptData) {
ScriptComponent* comp = new ScriptComponent(this, zoneScriptData->script_name, true);
m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPT, comp));
}
}
}
@@ -533,17 +536,17 @@ void Entity::Initialize() {
m_Components.insert(std::make_pair(eReplicaComponentType::QUICK_BUILD, comp));
CDRebuildComponentTable* rebCompTable = CDClientManager::Instance().GetTable<CDRebuildComponentTable>();
std::vector<CDRebuildComponent> rebCompData = rebCompTable->Query([=](CDRebuildComponent entry) { return (entry.id == rebuildComponentID); });
auto rebCompData = rebCompTable->Get(rebuildComponentID);
if (rebCompData.size() > 0) {
comp->SetResetTime(rebCompData[0].reset_time);
comp->SetCompleteTime(rebCompData[0].complete_time);
comp->SetTakeImagination(rebCompData[0].take_imagination);
comp->SetInterruptible(rebCompData[0].interruptible);
comp->SetSelfActivator(rebCompData[0].self_activator);
comp->SetActivityId(rebCompData[0].activityID);
comp->SetPostImaginationCost(rebCompData[0].post_imagination_cost);
comp->SetTimeBeforeSmash(rebCompData[0].time_before_smash);
if (rebCompData) {
comp->SetResetTime(rebCompData->reset_time);
comp->SetCompleteTime(rebCompData->complete_time);
comp->SetTakeImagination(rebCompData->take_imagination);
comp->SetInterruptible(rebCompData->interruptible);
comp->SetSelfActivator(rebCompData->self_activator);
comp->SetActivityId(rebCompData->activityID);
comp->SetPostImaginationCost(rebCompData->post_imagination_cost);
comp->SetTimeBeforeSmash(rebCompData->time_before_smash);
const auto rebuildResetTime = GetVar<float>(u"rebuild_reset_time");
@@ -1628,9 +1631,9 @@ void Entity::PickupItem(const LWOOBJID& objectID) {
std::vector<CDObjectSkills> skills = skillsTable->Query([=](CDObjectSkills entry) {return (entry.objectTemplate == p.second.lot); });
for (CDObjectSkills skill : skills) {
CDSkillBehaviorTable* skillBehTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
CDSkillBehavior behaviorData = skillBehTable->GetSkillByID(skill.skillID);
SkillComponent::HandleUnmanaged(behaviorData.behaviorID, GetObjectID());
auto behaviorData = skillBehTable->GetSkillByID(skill.skillID);
if (!behaviorData) continue;
SkillComponent::HandleUnmanaged(behaviorData->behaviorID, GetObjectID());
auto* missionComponent = GetComponent<MissionComponent>();

View File

@@ -42,7 +42,8 @@ void OverTimeBehavior::Load() {
// Since m_Action is a skillID and not a behavior, get is correlated behaviorID.
CDSkillBehaviorTable* skillTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
m_ActionBehaviorId = skillTable->GetSkillByID(m_Action).behaviorID;
auto skillData = skillTable->GetSkillByID(m_Action);
if (skillData) m_ActionBehaviorId = skillData->behaviorID;
m_Delay = GetFloat("delay");
m_NumIntervals = GetInt("num_intervals");

View File

@@ -104,7 +104,12 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO
if (parameter.name == "overtime") {
auto* behaviorTemplateTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
behaviorID = behaviorTemplateTable->GetSkillByID(parameter.values[0]).behaviorID;
auto skillInfo = behaviorTemplateTable->GetSkillByID(parameter.values[0]);
if (skillInfo) {
behaviorID = skillInfo->behaviorID;
} else {
Game::logger->Log("BuffComponent", "Failed to find skill info for skill ID %d!", parameter.values[0]);
}
stacks = static_cast<int32_t>(parameter.values[1]);
tick = parameter.values[2];
const auto unknown2 = parameter.values[3]; // Always 0

View File

@@ -933,8 +933,9 @@ void InventoryComponent::EquipScripts(Item* equippedItem) {
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(equippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
if (scriptComponentID > -1) {
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
auto scriptCompData = scriptCompTable->GetByID(scriptComponentID);
if (!scriptCompData) return;
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData->script_name);
if (!itemScript) {
Game::logger->Log("InventoryComponent", "null script?");
}
@@ -948,8 +949,9 @@ void InventoryComponent::UnequipScripts(Item* unequippedItem) {
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(unequippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
if (scriptComponentID > -1) {
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
auto scriptCompData = scriptCompTable->GetByID(scriptComponentID);
if (!scriptCompData) return;
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData->script_name);
if (!itemScript) {
Game::logger->Log("InventoryComponent", "null script?");
}
@@ -1341,8 +1343,12 @@ std::vector<uint32_t> InventoryComponent::FindBuffs(Item* item, bool castOnEquip
for (const auto& result : results) {
if (result.castOnType == 1) {
const auto entry = behaviors->GetSkillByID(result.skillID);
if (!entry) {
Game::logger->Log("InventoryComponent", "Buff %i not in database!", result.skillID);
if (entry.skillID == 0) {
continue;
}
if (entry->skillID == 0) {
Game::logger->Log("InventoryComponent", "Failed to find buff behavior for skill (%i)!", result.skillID);
continue;
@@ -1353,7 +1359,7 @@ std::vector<uint32_t> InventoryComponent::FindBuffs(Item* item, bool castOnEquip
}
// If item is not a proxy, add its buff to the added buffs.
if (item->GetParent() == LWOOBJID_EMPTY) buffs.push_back(static_cast<uint32_t>(entry.behaviorID));
if (item->GetParent() == LWOOBJID_EMPTY) buffs.push_back(static_cast<uint32_t>(entry->behaviorID));
}
}

View File

@@ -56,19 +56,19 @@ void LevelProgressionComponent::HandleLevelUp() {
// Tell the client we beginning to send level rewards.
if (rewardingItem) GameMessages::NotifyLevelRewards(m_Parent->GetObjectID(), m_Parent->GetSystemAddress(), m_Level, rewardingItem);
for (auto* reward : rewards) {
switch (reward->rewardType) {
for (const auto& reward : rewards) {
switch (reward.rewardType) {
case 0:
inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LEVEL_REWARD);
inventoryComponent->AddItem(reward.value, reward.count, eLootSourceType::LEVEL_REWARD);
break;
case 4:
{
auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS);
items->SetSize(items->GetSize() + reward->value);
items->SetSize(items->GetSize() + reward.value);
}
break;
case 9:
SetSpeedBase(static_cast<float>(reward->value) );
SetSpeedBase(static_cast<float>(reward.value) );
controllablePhysicsComponent->SetSpeedMultiplier(GetSpeedBase() / 500.0f);
break;
case 11:

View File

@@ -235,7 +235,12 @@ bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LW
// if it's not in the cache look it up and cache it
if (pair == m_skillBehaviorCache.end()) {
auto skillTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
behaviorId = skillTable->GetSkillByID(skillId).behaviorID;
auto skill = skillTable->GetSkillByID(skillId);
if (!skill) {
Game::logger->LogDebug("SkillComponent", "Tried to cast skill %i but found no skill", skillId);
return false;
}
behaviorId = skill->behaviorID;
m_skillBehaviorCache.insert_or_assign(skillId, behaviorId);
} else {
behaviorId = pair->second;

View File

@@ -127,12 +127,12 @@ void VendorComponent::SetupConstants() {
int componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::VENDOR);
auto* vendorComponentTable = CDClientManager::Instance().GetTable<CDVendorComponentTable>();
std::vector<CDVendorComponent> vendorComps = vendorComponentTable->Query([=](CDVendorComponent entry) { return (entry.id == componentID); });
if (vendorComps.empty()) return;
m_BuyScalar = vendorComps[0].buyScalar;
m_SellScalar = vendorComps[0].sellScalar;
m_RefreshTimeSeconds = vendorComps[0].refreshTimeSeconds;
m_LootMatrixID = vendorComps[0].LootMatrixIndex;
auto vendorCompData = vendorComponentTable->Query(componentID);
if (!vendorCompData) return;
m_BuyScalar = vendorCompData->buyScalar;
m_SellScalar = vendorCompData->sellScalar;
m_RefreshTimeSeconds = vendorCompData->refreshTimeSeconds;
m_LootMatrixID = vendorCompData->LootMatrixIndex;
}
bool VendorComponent::SellsItem(const LOT item) const {

View File

@@ -288,7 +288,12 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System
}
CDSkillBehaviorTable* skillTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
unsigned int behaviorId = skillTable->GetSkillByID(startSkill.skillID).behaviorID;
auto skill = skillTable->GetSkillByID(startSkill.skillID);
if (!skill) {
Game::logger->Log("GameMessageHandler", "Failed to find skill %d in the skill table!", startSkill.skillID);
return;
}
unsigned int behaviorId = skill->behaviorID;
bool success = false;
@@ -301,7 +306,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream* inStream, const System
if (success && entity->GetCharacter()) {
DestroyableComponent* destComp = entity->GetComponent<DestroyableComponent>();
destComp->SetImagination(destComp->GetImagination() - skillTable->GetSkillByID(startSkill.skillID).imaginationcost);
destComp->SetImagination(destComp->GetImagination() - skill->imaginationcost);
}
delete bs;

View File

@@ -131,11 +131,12 @@ void ItemSet::OnEquip(const LOT lot) {
for (const auto skill : skillSet) {
auto* skillTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID;
auto skillData = skillTable->GetSkillByID(skill);
if (!skillData) continue;
missionComponent->Progress(eMissionTaskType::USE_SKILL, skill);
skillComponent->HandleUnmanaged(behaviorId, m_InventoryComponent->GetParent()->GetObjectID());
skillComponent->HandleUnmanaged(skillData->behaviorID, m_InventoryComponent->GetParent()->GetObjectID());
}
}
@@ -163,9 +164,10 @@ void ItemSet::OnUnEquip(const LOT lot) {
for (const auto skill : skillSet) {
auto* skillTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
const auto behaviorId = skillTable->GetSkillByID(skill).behaviorID;
auto skillData = skillTable->GetSkillByID(skill);
if (!skillData) continue;
skillComponent->HandleUnCast(behaviorId, m_InventoryComponent->GetParent()->GetObjectID());
skillComponent->HandleUnCast(skillData->behaviorID, m_InventoryComponent->GetParent()->GetObjectID());
}
}

View File

@@ -84,7 +84,6 @@
#include "eMasterMessageType.h"
#include "CDObjectsTable.h"
#include "CDZoneTableTable.h"
void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr) {
auto commandCopy = command;

View File

@@ -372,9 +372,9 @@ Instance* InstanceManager::FindPrivateInstance(const std::string& password) {
int InstanceManager::GetSoftCap(LWOMAPID mapID) {
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
if (zoneTable) {
const CDZoneTable* zone = zoneTable->Query(mapID);
auto zone = zoneTable->Query(mapID);
if (zone != nullptr) {
if (zone) {
return zone->population_soft_cap;
}
}
@@ -385,9 +385,9 @@ int InstanceManager::GetSoftCap(LWOMAPID mapID) {
int InstanceManager::GetHardCap(LWOMAPID mapID) {
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
if (zoneTable) {
const CDZoneTable* zone = zoneTable->Query(mapID);
auto zone = zoneTable->Query(mapID);
if (zone != nullptr) {
if (zone) {
return zone->population_hard_cap;
}
}

View File

@@ -23,9 +23,10 @@ void QbEnemyStunner::OnRebuildComplete(Entity* self, Entity* target) {
// For each skill, cast it with the associated behavior ID.
for (auto skill : skills) {
CDSkillBehaviorTable* skillBehaviorTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
CDSkillBehavior behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID);
auto behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID);
if (!behaviorData) continue;
skillBehaviorMap.insert(std::make_pair(skill.skillID, behaviorData.behaviorID));
skillBehaviorMap.insert(std::make_pair(skill.skillID, behaviorData->behaviorID));
}
// If there are no skills found, insert a default skill to use.

View File

@@ -17,10 +17,11 @@ void FireFirstSkillonStartup::OnStartup(Entity* self) {
// For each skill, cast it with the associated behavior ID.
for (auto skill : skills) {
CDSkillBehaviorTable* skillBehaviorTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
CDSkillBehavior behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID);
auto behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID);
if (!behaviorData) continue;
// Should parent entity be null, make the originator self.
const auto target = self->GetParentEntity() ? self->GetParentEntity()->GetObjectID() : self->GetObjectID();
skillComponent->CalculateBehavior(skill.skillID, behaviorData.behaviorID, LWOOBJID_EMPTY, false, false, target);
skillComponent->CalculateBehavior(skill.skillID, behaviorData->behaviorID, LWOOBJID_EMPTY, false, false, target);
}
}

View File

@@ -165,8 +165,8 @@ void Zone::LoadZoneIntoMemory() {
std::string Zone::GetFilePathForZoneID() {
//We're gonna go ahead and presume we've got the db loaded already:
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
const CDZoneTable* zone = zoneTable->Query(this->GetZoneID().GetMapID());
if (zone != nullptr) {
auto zone = zoneTable->Query(this->GetZoneID().GetMapID());
if (zone) {
std::string toReturn = "maps/" + zone->zoneName;
std::transform(toReturn.begin(), toReturn.end(), toReturn.begin(), ::tolower);
return toReturn;

View File

@@ -12,7 +12,6 @@
#include "CDZoneTableTable.h"
#include <chrono>
#include "eObjectBits.h"
#include "CDZoneTableTable.h"
#include "AssetManager.h"
#include "../dWorldServer/ObjectIDManager.h"
@@ -31,9 +30,9 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
if (zoneTable != nullptr) {
const CDZoneTable* zone = zoneTable->Query(zoneID.GetMapID());
auto zone = zoneTable->Query(zoneID.GetMapID());
if (zone != nullptr) {
if (zone) {
zoneControlTemplate = zone->zoneControlTemplate != -1 ? zone->zoneControlTemplate : 2365;
const auto min = zone->ghostdistance_min != -1.0f ? zone->ghostdistance_min : 100;
const auto max = zone->ghostdistance != -1.0f ? zone->ghostdistance : 100;
@@ -235,8 +234,8 @@ uint32_t dZoneManager::GetUniqueMissionIdStartingValue() {
bool dZoneManager::CheckIfAccessibleZone(LWOMAPID zoneID) {
//We're gonna go ahead and presume we've got the db loaded already:
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
const CDZoneTable* zone = zoneTable->Query(zoneID);
if (zone != nullptr) {
auto zone = zoneTable->Query(zoneID);
if (zone) {
return Game::assetManager->HasFile(("maps/" + zone->zoneName).c_str());
} else {
return false;