mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 23:08:31 +00:00
Add CDBaseCombatAIComponentTable with LoadValuesFromDefaults support
Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "CDAnimationsTable.h"
|
||||
#include "CDBehaviorParameterTable.h"
|
||||
#include "CDBehaviorTemplateTable.h"
|
||||
#include "CDBaseCombatAIComponentTable.h"
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDCurrencyTableTable.h"
|
||||
@@ -65,6 +66,7 @@
|
||||
DEFINE_TABLE_STORAGE(CDActivityRewardsTable);
|
||||
DEFINE_TABLE_STORAGE(CDActivitiesTable);
|
||||
DEFINE_TABLE_STORAGE(CDAnimationsTable);
|
||||
DEFINE_TABLE_STORAGE(CDBaseCombatAIComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDBehaviorParameterTable);
|
||||
DEFINE_TABLE_STORAGE(CDBehaviorTemplateTable);
|
||||
DEFINE_TABLE_STORAGE(CDBrickIDTableTable);
|
||||
@@ -154,6 +156,7 @@ void CDClientManager::LoadValuesFromDatabase() {
|
||||
void CDClientManager::LoadValuesFromDefaults() {
|
||||
LOG("Loading default CDClient tables!");
|
||||
|
||||
CDBaseCombatAIComponentTable::Instance().LoadValuesFromDefaults();
|
||||
CDPetComponentTable::Instance().LoadValuesFromDefaults();
|
||||
CDActivitiesTable::Instance().LoadValuesFromDefaults();
|
||||
CDActivityRewardsTable::Instance().LoadValuesFromDefaults();
|
||||
|
@@ -0,0 +1,67 @@
|
||||
#include "CDBaseCombatAIComponentTable.h"
|
||||
|
||||
namespace {
|
||||
// Default entries for fallback
|
||||
CDBaseCombatAIComponent defaultEntry{
|
||||
.id = 1,
|
||||
.aggroRadius = 25.0f,
|
||||
.tetherSpeed = 4.0f,
|
||||
.pursuitSpeed = 2.0f,
|
||||
.softTetherRadius = 25.0f,
|
||||
.hardTetherRadius = 100.0f,
|
||||
};
|
||||
}
|
||||
|
||||
void CDBaseCombatAIComponentTable::LoadValuesFromDatabase() {
|
||||
// First, get the size of the table
|
||||
uint32_t size = 0;
|
||||
auto tableSize = CDClientDatabase::CreatePreppedStmt("SELECT COUNT(*) FROM BaseCombatAIComponent");
|
||||
auto tableSizeResult = tableSize.execQuery();
|
||||
while (!tableSizeResult.eof()) {
|
||||
size = tableSizeResult.getIntField(0, 0);
|
||||
tableSizeResult.nextRow();
|
||||
}
|
||||
tableSizeResult.finalize();
|
||||
|
||||
// Reserve the size
|
||||
auto& entries = GetEntriesMutable();
|
||||
entries.reserve(size);
|
||||
|
||||
// Now get the data
|
||||
auto tableData = CDClientDatabase::CreatePreppedStmt("SELECT * FROM BaseCombatAIComponent");
|
||||
auto tableDataResult = tableData.execQuery();
|
||||
|
||||
while (!tableDataResult.eof()) {
|
||||
CDBaseCombatAIComponent entry;
|
||||
|
||||
entry.id = tableDataResult.getIntField("id", -1);
|
||||
entry.aggroRadius = tableDataResult.getFloatField("aggroRadius", 25.0f);
|
||||
entry.tetherSpeed = tableDataResult.getFloatField("tetherSpeed", 4.0f);
|
||||
entry.pursuitSpeed = tableDataResult.getFloatField("pursuitSpeed", 2.0f);
|
||||
entry.softTetherRadius = tableDataResult.getFloatField("softTetherRadius", 25.0f);
|
||||
entry.hardTetherRadius = tableDataResult.getFloatField("hardTetherRadius", 100.0f);
|
||||
|
||||
entries.push_back(entry);
|
||||
tableDataResult.nextRow();
|
||||
}
|
||||
|
||||
tableData.finalize();
|
||||
}
|
||||
|
||||
void CDBaseCombatAIComponentTable::LoadValuesFromDefaults() {
|
||||
auto& entries = GetEntriesMutable();
|
||||
entries.clear();
|
||||
entries.push_back(defaultEntry);
|
||||
}
|
||||
|
||||
std::vector<CDBaseCombatAIComponent> CDBaseCombatAIComponentTable::Query(std::function<bool(CDBaseCombatAIComponent)> predicate) {
|
||||
std::vector<CDBaseCombatAIComponent> data = cpplinq::from(GetEntries())
|
||||
>> cpplinq::where(predicate)
|
||||
>> cpplinq::to_vector();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const std::vector<CDBaseCombatAIComponent>& CDBaseCombatAIComponentTable::GetEntries() const {
|
||||
return CDTable::GetEntries();
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
#ifndef CDBASECOMBATAICOMPONENTTABLE_H
|
||||
#define CDBASECOMBATAICOMPONENTTABLE_H
|
||||
|
||||
#include "CDTable.h"
|
||||
|
||||
struct CDBaseCombatAIComponent {
|
||||
int32_t id;
|
||||
float aggroRadius;
|
||||
float tetherSpeed;
|
||||
float pursuitSpeed;
|
||||
float softTetherRadius;
|
||||
float hardTetherRadius;
|
||||
};
|
||||
|
||||
class CDBaseCombatAIComponentTable : public CDTable<CDBaseCombatAIComponentTable, std::vector<CDBaseCombatAIComponent>> {
|
||||
public:
|
||||
void LoadValuesFromDatabase();
|
||||
void LoadValuesFromDefaults();
|
||||
|
||||
std::vector<CDBaseCombatAIComponent> Query(std::function<bool(CDBaseCombatAIComponent)> predicate);
|
||||
const std::vector<CDBaseCombatAIComponent>& GetEntries() const;
|
||||
};
|
||||
|
||||
#endif //CDBASECOMBATAICOMPONENTTABLE_H
|
@@ -1,6 +1,7 @@
|
||||
set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
|
||||
"CDActivityRewardsTable.cpp"
|
||||
"CDAnimationsTable.cpp"
|
||||
"CDBaseCombatAIComponentTable.cpp"
|
||||
"CDBehaviorParameterTable.cpp"
|
||||
"CDBehaviorTemplateTable.cpp"
|
||||
"CDBrickIDTableTable.cpp"
|
||||
|
Reference in New Issue
Block a user