Fix CDClient database dependency issues for component tests by implementing LoadValuesFromDefaults and database connectivity checks

Co-authored-by: aronwk-aaron <26027722+aronwk-aaron@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-09-01 15:22:58 +00:00
parent 9274494023
commit d3b5941458
17 changed files with 247 additions and 13 deletions

View File

@@ -68,28 +68,31 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id)
/*
* Find skills
*/
auto skillQuery = CDClientDatabase::CreatePreppedStmt(
"SELECT skillID, cooldown, behaviorID FROM SkillBehavior WHERE skillID IN (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
skillQuery.bind(1, static_cast<int>(parent->GetLOT()));
// Only execute skill query if database is connected
if (CDClientDatabase::isConnected) {
auto skillQuery = CDClientDatabase::CreatePreppedStmt(
"SELECT skillID, cooldown, behaviorID FROM SkillBehavior WHERE skillID IN (SELECT skillID FROM ObjectSkills WHERE objectTemplate = ?);");
skillQuery.bind(1, static_cast<int>(parent->GetLOT()));
auto result = skillQuery.execQuery();
auto result = skillQuery.execQuery();
while (!result.eof()) {
const auto skillId = static_cast<uint32_t>(result.getIntField("skillID"));
while (!result.eof()) {
const auto skillId = static_cast<uint32_t>(result.getIntField("skillID"));
const auto abilityCooldown = static_cast<float>(result.getFloatField("cooldown"));
const auto abilityCooldown = static_cast<float>(result.getFloatField("cooldown"));
const auto behaviorId = static_cast<uint32_t>(result.getIntField("behaviorID"));
const auto behaviorId = static_cast<uint32_t>(result.getIntField("behaviorID"));
auto* behavior = Behavior::CreateBehavior(behaviorId);
auto* behavior = Behavior::CreateBehavior(behaviorId);
std::stringstream behaviorQuery;
std::stringstream behaviorQuery;
AiSkillEntry entry = { skillId, 0, abilityCooldown, behavior };
AiSkillEntry entry = { skillId, 0, abilityCooldown, behavior };
m_SkillEntries.push_back(entry);
m_SkillEntries.push_back(entry);
result.nextRow();
result.nextRow();
}
}
Stun(1.0f);

View File

@@ -435,6 +435,12 @@ const std::vector<BuffParameter>& BuffComponent::GetBuffParameters(int32_t buffI
return pair->second;
}
// If database is not connected (e.g., in tests), return empty parameters
if (!CDClientDatabase::isConnected) {
m_Cache.insert_or_assign(buffId, std::vector<BuffParameter>{});
return m_Cache.find(buffId)->second;
}
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM BuffParameters WHERE BuffID = ?;");
query.bind(1, static_cast<int>(buffId));