mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-09-05 06:48:37 +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"
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDBaseCombatAIComponentTable.h"
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -41,31 +42,20 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id)
|
||||
m_ForcedTetherTime = 0.0f;
|
||||
|
||||
//Grab the aggro information from BaseCombatAI:
|
||||
auto componentQuery = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT aggroRadius, tetherSpeed, pursuitSpeed, softTetherRadius, hardTetherRadius FROM BaseCombatAIComponent WHERE id = ?;");
|
||||
componentQuery.bind(1, static_cast<int>(id));
|
||||
auto* componentTable = CDClientManager::GetTable<CDBaseCombatAIComponentTable>();
|
||||
auto componentEntries = componentTable->Query([id](CDBaseCombatAIComponent entry) {
|
||||
return entry.id == static_cast<int32_t>(id);
|
||||
});
|
||||
|
||||
auto componentResult = componentQuery.execQuery();
|
||||
|
||||
if (!componentResult.eof()) {
|
||||
if (!componentResult.fieldIsNull("aggroRadius"))
|
||||
m_AggroRadius = componentResult.getFloatField("aggroRadius");
|
||||
|
||||
if (!componentResult.fieldIsNull("tetherSpeed"))
|
||||
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");
|
||||
if (!componentEntries.empty()) {
|
||||
const auto& component = componentEntries[0];
|
||||
m_AggroRadius = component.aggroRadius;
|
||||
m_TetherSpeed = component.tetherSpeed;
|
||||
m_PursuitSpeed = component.pursuitSpeed;
|
||||
m_SoftTetherRadius = component.softTetherRadius;
|
||||
m_HardTetherRadius = component.hardTetherRadius;
|
||||
}
|
||||
|
||||
componentResult.finalize();
|
||||
|
||||
// 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.
|
||||
if (m_Parent) {
|
||||
|
Reference in New Issue
Block a user