mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-15 20:08:14 +00:00
load imagination costs for pet abilities from CDClient
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include "CDPetAbilitiesTable.h"
|
||||
#include "ePetAbilityType.h"
|
||||
|
||||
namespace {
|
||||
// Default entries for fallback
|
||||
CDPetAbilities defaultEntry{
|
||||
.id = ePetAbilityType::Invalid,
|
||||
UNUSED_ENTRY(.AbilityName = "invalid",)
|
||||
.imaginationCost = 0,
|
||||
UNUSED_ENTRY(.locStatus = 2,)
|
||||
};
|
||||
}
|
||||
|
||||
void CDPetAbilitiesTable::LoadValuesFromDatabase() {
|
||||
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PetAbilities");
|
||||
auto& entries = GetEntriesMutable();
|
||||
while (!tableData.eof()) {
|
||||
const auto abilityId =
|
||||
static_cast<ePetAbilityType>(tableData.getIntField("id", static_cast<int>(defaultEntry.id)));
|
||||
auto& entry = entries[abilityId];
|
||||
|
||||
entry.id = abilityId;
|
||||
UNUSED_COLUMN(entry.abilityName = tableData.getStringField("AbilityName", defaultEntry.abilityName));
|
||||
entry.imaginationCost = tableData.getIntField("ImaginationCost", defaultEntry.imaginationCost);
|
||||
UNUSED_COLUMN(entry.locStatus = tableData.getIntField("locStatus", defaultEntry.locStatus));
|
||||
|
||||
tableData.nextRow();
|
||||
}
|
||||
}
|
||||
|
||||
void CDPetAbilitiesTable::LoadValuesFromDefaults() {
|
||||
GetEntriesMutable().emplace(defaultEntry.id, defaultEntry);
|
||||
}
|
||||
|
||||
const CDPetAbilities& CDPetAbilitiesTable::GetByID(const ePetAbilityType id) {
|
||||
const auto& entries = GetEntries();
|
||||
const auto itr = entries.find(id);
|
||||
if (itr == entries.cend()) {
|
||||
LOG("Unable to load pet ability (ID %i) values from database! Using default values instead.", id);
|
||||
return defaultEntry;
|
||||
}
|
||||
return itr->second;
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include "CDTable.h"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
// Forward declarations
|
||||
enum class ePetAbilityType : uint32_t;
|
||||
|
||||
struct CDPetAbilities {
|
||||
ePetAbilityType id;
|
||||
UNUSED_COLUMN(std::string abilityName;)
|
||||
int32_t imaginationCost;
|
||||
UNUSED_COLUMN(uint32_t locStatus;)
|
||||
};
|
||||
|
||||
class CDPetAbilitiesTable : public CDTable<CDPetAbilitiesTable, std::map<ePetAbilityType, CDPetAbilities>> {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Load values from the CD client database
|
||||
*/
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
/**
|
||||
* Load the default values into memory instead of attempting to connect to the CD client database
|
||||
*/
|
||||
void LoadValuesFromDefaults();
|
||||
|
||||
/**
|
||||
* Gets the pet ability table corresponding to the pet ability ID
|
||||
* @returns A pointer to the corresponding table, or nullptr if one could not be found
|
||||
*/
|
||||
const CDPetAbilities& GetByID(const ePetAbilityType id);
|
||||
};
|
@@ -50,13 +50,13 @@ void CDPetComponentTable::LoadValuesFromDatabase() {
|
||||
}
|
||||
|
||||
void CDPetComponentTable::LoadValuesFromDefaults() {
|
||||
GetEntriesMutable().insert(std::make_pair(defaultEntry.id, defaultEntry));
|
||||
GetEntriesMutable().emplace(defaultEntry.id, defaultEntry);
|
||||
}
|
||||
|
||||
CDPetComponent& CDPetComponentTable::GetByID(const uint32_t componentID) {
|
||||
auto& entries = GetEntriesMutable();
|
||||
auto itr = entries.find(componentID);
|
||||
if (itr == entries.end()) {
|
||||
const CDPetComponent& CDPetComponentTable::GetByID(const uint32_t componentID) {
|
||||
const auto& entries = GetEntriesMutable();
|
||||
const auto itr = entries.find(componentID);
|
||||
if (itr == entries.cend()) {
|
||||
LOG("Unable to load pet component (ID %i) values from database! Using default values instead.", componentID);
|
||||
return defaultEntry;
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
* Load values from the CD client database
|
||||
*/
|
||||
void LoadValuesFromDatabase();
|
||||
|
||||
|
||||
/**
|
||||
* Load the default values into memory instead of attempting to connect to the CD client database
|
||||
*/
|
||||
@@ -38,5 +38,5 @@ public:
|
||||
* Gets the pet component table corresponding to the pet component ID
|
||||
* @returns A reference to the corresponding table, or the default if one could not be found
|
||||
*/
|
||||
CDPetComponent& GetByID(const uint32_t componentID);
|
||||
const CDPetComponent& GetByID(const uint32_t componentID);
|
||||
};
|
||||
|
@@ -23,6 +23,7 @@ set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
|
||||
"CDMovementAIComponentTable.cpp"
|
||||
"CDObjectSkillsTable.cpp"
|
||||
"CDObjectsTable.cpp"
|
||||
"CDPetAbilitiesTable.cpp"
|
||||
"CDPetComponentTable.cpp"
|
||||
"CDPackageComponentTable.cpp"
|
||||
"CDPhysicsComponentTable.cpp"
|
||||
|
Reference in New Issue
Block a user