mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-04-26 08:36:30 +00:00
load imagination costs for pet abilities from CDClient
This commit is contained in:
parent
0b4d7b6d92
commit
36e0dbdb5e
@ -1,5 +1,5 @@
|
||||
#ifndef __EPETABILITYTYPE__H__
|
||||
#define __EPETABILITYTYPE__H__
|
||||
#ifndef EPETABILITYTYPE_H
|
||||
#define EPETABILITYTYPE_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@ -10,4 +10,4 @@ enum class ePetAbilityType : uint32_t {
|
||||
DigAtPosition
|
||||
};
|
||||
|
||||
#endif //!__EPETABILITYTYPE__H__
|
||||
#endif //!EPETABILITYTYPE_H
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "CDMissionsTable.h"
|
||||
#include "CDObjectSkillsTable.h"
|
||||
#include "CDObjectsTable.h"
|
||||
#include "CDPetAbilitiesTable.h"
|
||||
#include "CDPhysicsComponentTable.h"
|
||||
#include "CDRebuildComponentTable.h"
|
||||
#include "CDScriptComponentTable.h"
|
||||
@ -41,8 +42,6 @@
|
||||
#include "CDRewardCodesTable.h"
|
||||
#include "CDPetComponentTable.h"
|
||||
|
||||
#include <exception>
|
||||
|
||||
#ifndef CDCLIENT_CACHE_ALL
|
||||
// Uncomment this to cache the full cdclient database into memory. This will make the server load faster, but will use more memory.
|
||||
// A vanilla CDClient takes about 46MB of memory + the regular world data.
|
||||
@ -55,13 +54,6 @@
|
||||
#define CDCLIENT_DONT_CACHE_TABLE(x)
|
||||
#endif
|
||||
|
||||
class CDClientConnectionException : public std::exception {
|
||||
public:
|
||||
virtual const char* what() const throw() {
|
||||
return "CDClientDatabase is not connected!";
|
||||
}
|
||||
};
|
||||
|
||||
// Using a macro to reduce repetitive code and issues from copy and paste.
|
||||
// As a note, ## in a macro is used to concatenate two tokens together.
|
||||
|
||||
@ -97,6 +89,7 @@ DEFINE_TABLE_STORAGE(CDObjectSkillsTable);
|
||||
DEFINE_TABLE_STORAGE(CDObjectsTable);
|
||||
DEFINE_TABLE_STORAGE(CDPhysicsComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDPackageComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDPetAbilitiesTable);
|
||||
DEFINE_TABLE_STORAGE(CDPetComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDProximityMonitorComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDPropertyEntranceComponentTable);
|
||||
@ -112,7 +105,9 @@ DEFINE_TABLE_STORAGE(CDVendorComponentTable);
|
||||
DEFINE_TABLE_STORAGE(CDZoneTableTable);
|
||||
|
||||
void CDClientManager::LoadValuesFromDatabase() {
|
||||
if (!CDClientDatabase::isConnected) throw CDClientConnectionException();
|
||||
if (!CDClientDatabase::isConnected) {
|
||||
throw std::runtime_error{ "CDClientDatabase is not connected!" };
|
||||
}
|
||||
|
||||
CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
|
||||
CDActivitiesTable::Instance().LoadValuesFromDatabase();
|
||||
@ -141,6 +136,7 @@ void CDClientManager::LoadValuesFromDatabase() {
|
||||
CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
|
||||
CDPhysicsComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDPackageComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDPetAbilitiesTable::Instance().LoadValuesFromDatabase();
|
||||
CDPetComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase();
|
||||
CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase();
|
||||
@ -159,5 +155,6 @@ void CDClientManager::LoadValuesFromDatabase() {
|
||||
void CDClientManager::LoadValuesFromDefaults() {
|
||||
LOG("Loading default CDClient tables!");
|
||||
|
||||
CDPetAbilitiesTable::Instance().LoadValuesFromDefaults();
|
||||
CDPetComponentTable::Instance().LoadValuesFromDefaults();
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "GameMessages.h"
|
||||
#include "BrickDatabase.h"
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDPetAbilitiesTable.h"
|
||||
#include "CDPetComponentTable.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "EntityManager.h"
|
||||
@ -911,7 +912,9 @@ void PetComponent::StartInteractBouncer() {
|
||||
if (!destroyableComponent) return;
|
||||
|
||||
auto imagination = destroyableComponent->GetImagination();
|
||||
const int32_t imaginationCost = 2; // TODO: Get rid of this magic number - make static variable from lookup
|
||||
const auto imaginationCost =
|
||||
CDClientManager::GetTable<CDPetAbilitiesTable>()->GetByID(ePetAbilityType::JumpOnObject).imaginationCost;
|
||||
|
||||
if (imagination < imaginationCost) {
|
||||
//GameMessages::SendHelp(user->GetObjectID(), eHelpType::PR_NEED_IMAGINATION, user->GetSystemAddress()); // Check if right message!
|
||||
return;
|
||||
@ -989,7 +992,9 @@ void PetComponent::StartInteractTreasureDig() {
|
||||
if (!destroyableComponent) return;
|
||||
|
||||
auto imagination = destroyableComponent->GetImagination();
|
||||
const int32_t imaginationCost = 1; // TODO: Get rid of this magic number - make static variable from lookup
|
||||
const auto imaginationCost =
|
||||
CDClientManager::GetTable<CDPetAbilitiesTable>()->GetByID(ePetAbilityType::DigAtPosition).imaginationCost;
|
||||
|
||||
if (imagination < imaginationCost) {
|
||||
//GameMessages::SendHelp(user->GetObjectID(), eHelpType::PR_NEED_IMAGINATION, user->GetSystemAddress()); // Check if right message!
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user