Add CDBaseCombatAIComponentTable with LoadValuesFromDefaults support

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-31 21:58:26 +00:00
parent 6bb8040221
commit dac47cc240
5 changed files with 107 additions and 22 deletions

View File

@@ -3,6 +3,7 @@
#include "CDAnimationsTable.h" #include "CDAnimationsTable.h"
#include "CDBehaviorParameterTable.h" #include "CDBehaviorParameterTable.h"
#include "CDBehaviorTemplateTable.h" #include "CDBehaviorTemplateTable.h"
#include "CDBaseCombatAIComponentTable.h"
#include "CDClientDatabase.h" #include "CDClientDatabase.h"
#include "CDComponentsRegistryTable.h" #include "CDComponentsRegistryTable.h"
#include "CDCurrencyTableTable.h" #include "CDCurrencyTableTable.h"
@@ -65,6 +66,7 @@
DEFINE_TABLE_STORAGE(CDActivityRewardsTable); DEFINE_TABLE_STORAGE(CDActivityRewardsTable);
DEFINE_TABLE_STORAGE(CDActivitiesTable); DEFINE_TABLE_STORAGE(CDActivitiesTable);
DEFINE_TABLE_STORAGE(CDAnimationsTable); DEFINE_TABLE_STORAGE(CDAnimationsTable);
DEFINE_TABLE_STORAGE(CDBaseCombatAIComponentTable);
DEFINE_TABLE_STORAGE(CDBehaviorParameterTable); DEFINE_TABLE_STORAGE(CDBehaviorParameterTable);
DEFINE_TABLE_STORAGE(CDBehaviorTemplateTable); DEFINE_TABLE_STORAGE(CDBehaviorTemplateTable);
DEFINE_TABLE_STORAGE(CDBrickIDTableTable); DEFINE_TABLE_STORAGE(CDBrickIDTableTable);
@@ -154,6 +156,7 @@ void CDClientManager::LoadValuesFromDatabase() {
void CDClientManager::LoadValuesFromDefaults() { void CDClientManager::LoadValuesFromDefaults() {
LOG("Loading default CDClient tables!"); LOG("Loading default CDClient tables!");
CDBaseCombatAIComponentTable::Instance().LoadValuesFromDefaults();
CDPetComponentTable::Instance().LoadValuesFromDefaults(); CDPetComponentTable::Instance().LoadValuesFromDefaults();
CDActivitiesTable::Instance().LoadValuesFromDefaults(); CDActivitiesTable::Instance().LoadValuesFromDefaults();
CDActivityRewardsTable::Instance().LoadValuesFromDefaults(); CDActivityRewardsTable::Instance().LoadValuesFromDefaults();

View File

@@ -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();
}

View File

@@ -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

View File

@@ -1,6 +1,7 @@
set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp" set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
"CDActivityRewardsTable.cpp" "CDActivityRewardsTable.cpp"
"CDAnimationsTable.cpp" "CDAnimationsTable.cpp"
"CDBaseCombatAIComponentTable.cpp"
"CDBehaviorParameterTable.cpp" "CDBehaviorParameterTable.cpp"
"CDBehaviorTemplateTable.cpp" "CDBehaviorTemplateTable.cpp"
"CDBrickIDTableTable.cpp" "CDBrickIDTableTable.cpp"

View File

@@ -13,6 +13,7 @@
#include "CDClientDatabase.h" #include "CDClientDatabase.h"
#include "CDClientManager.h" #include "CDClientManager.h"
#include "CDBaseCombatAIComponentTable.h"
#include "DestroyableComponent.h" #include "DestroyableComponent.h"
#include <algorithm> #include <algorithm>
@@ -41,31 +42,20 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id)
m_ForcedTetherTime = 0.0f; m_ForcedTetherTime = 0.0f;
//Grab the aggro information from BaseCombatAI: //Grab the aggro information from BaseCombatAI:
auto componentQuery = CDClientDatabase::CreatePreppedStmt( auto* componentTable = CDClientManager::GetTable<CDBaseCombatAIComponentTable>();
"SELECT aggroRadius, tetherSpeed, pursuitSpeed, softTetherRadius, hardTetherRadius FROM BaseCombatAIComponent WHERE id = ?;"); auto componentEntries = componentTable->Query([id](CDBaseCombatAIComponent entry) {
componentQuery.bind(1, static_cast<int>(id)); return entry.id == static_cast<int32_t>(id);
});
auto componentResult = componentQuery.execQuery(); if (!componentEntries.empty()) {
const auto& component = componentEntries[0];
if (!componentResult.eof()) { m_AggroRadius = component.aggroRadius;
if (!componentResult.fieldIsNull("aggroRadius")) m_TetherSpeed = component.tetherSpeed;
m_AggroRadius = componentResult.getFloatField("aggroRadius"); m_PursuitSpeed = component.pursuitSpeed;
m_SoftTetherRadius = component.softTetherRadius;
if (!componentResult.fieldIsNull("tetherSpeed")) m_HardTetherRadius = component.hardTetherRadius;
m_TetherSpeed = componentResult.getFloatField("tetherSpeed");
if (!componentResult.fieldIsNull("pursuitSpeed"))
m_PursuitSpeed = componentResult.getFloatField("pursuitSpeed");
if (!componentResult.fieldIsNull("softTetherRadius"))
m_SoftTetherRadius = componentResult.getFloatField("softTetherRadius");
if (!componentResult.fieldIsNull("hardTetherRadius"))
m_HardTetherRadius = componentResult.getFloatField("hardTetherRadius");
} }
componentResult.finalize();
// Get aggro and tether radius from settings and use this if it is present. Only overwrite the // Get aggro and tether radius from settings and use this if it is present. Only overwrite the
// radii if it is greater than the one in the database. // radii if it is greater than the one in the database.
if (m_Parent) { if (m_Parent) {