mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-04-26 16:46:31 +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__
|
#ifndef EPETABILITYTYPE_H
|
||||||
#define __EPETABILITYTYPE__H__
|
#define EPETABILITYTYPE_H
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@ -10,4 +10,4 @@ enum class ePetAbilityType : uint32_t {
|
|||||||
DigAtPosition
|
DigAtPosition
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!__EPETABILITYTYPE__H__
|
#endif //!EPETABILITYTYPE_H
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "CDMissionsTable.h"
|
#include "CDMissionsTable.h"
|
||||||
#include "CDObjectSkillsTable.h"
|
#include "CDObjectSkillsTable.h"
|
||||||
#include "CDObjectsTable.h"
|
#include "CDObjectsTable.h"
|
||||||
|
#include "CDPetAbilitiesTable.h"
|
||||||
#include "CDPhysicsComponentTable.h"
|
#include "CDPhysicsComponentTable.h"
|
||||||
#include "CDRebuildComponentTable.h"
|
#include "CDRebuildComponentTable.h"
|
||||||
#include "CDScriptComponentTable.h"
|
#include "CDScriptComponentTable.h"
|
||||||
@ -41,8 +42,6 @@
|
|||||||
#include "CDRewardCodesTable.h"
|
#include "CDRewardCodesTable.h"
|
||||||
#include "CDPetComponentTable.h"
|
#include "CDPetComponentTable.h"
|
||||||
|
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
#ifndef CDCLIENT_CACHE_ALL
|
#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.
|
// 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.
|
// A vanilla CDClient takes about 46MB of memory + the regular world data.
|
||||||
@ -55,13 +54,6 @@
|
|||||||
#define CDCLIENT_DONT_CACHE_TABLE(x)
|
#define CDCLIENT_DONT_CACHE_TABLE(x)
|
||||||
#endif
|
#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.
|
// 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.
|
// 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(CDObjectsTable);
|
||||||
DEFINE_TABLE_STORAGE(CDPhysicsComponentTable);
|
DEFINE_TABLE_STORAGE(CDPhysicsComponentTable);
|
||||||
DEFINE_TABLE_STORAGE(CDPackageComponentTable);
|
DEFINE_TABLE_STORAGE(CDPackageComponentTable);
|
||||||
|
DEFINE_TABLE_STORAGE(CDPetAbilitiesTable);
|
||||||
DEFINE_TABLE_STORAGE(CDPetComponentTable);
|
DEFINE_TABLE_STORAGE(CDPetComponentTable);
|
||||||
DEFINE_TABLE_STORAGE(CDProximityMonitorComponentTable);
|
DEFINE_TABLE_STORAGE(CDProximityMonitorComponentTable);
|
||||||
DEFINE_TABLE_STORAGE(CDPropertyEntranceComponentTable);
|
DEFINE_TABLE_STORAGE(CDPropertyEntranceComponentTable);
|
||||||
@ -112,7 +105,9 @@ DEFINE_TABLE_STORAGE(CDVendorComponentTable);
|
|||||||
DEFINE_TABLE_STORAGE(CDZoneTableTable);
|
DEFINE_TABLE_STORAGE(CDZoneTableTable);
|
||||||
|
|
||||||
void CDClientManager::LoadValuesFromDatabase() {
|
void CDClientManager::LoadValuesFromDatabase() {
|
||||||
if (!CDClientDatabase::isConnected) throw CDClientConnectionException();
|
if (!CDClientDatabase::isConnected) {
|
||||||
|
throw std::runtime_error{ "CDClientDatabase is not connected!" };
|
||||||
|
}
|
||||||
|
|
||||||
CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
|
CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
|
||||||
CDActivitiesTable::Instance().LoadValuesFromDatabase();
|
CDActivitiesTable::Instance().LoadValuesFromDatabase();
|
||||||
@ -141,6 +136,7 @@ void CDClientManager::LoadValuesFromDatabase() {
|
|||||||
CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
|
CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
|
||||||
CDPhysicsComponentTable::Instance().LoadValuesFromDatabase();
|
CDPhysicsComponentTable::Instance().LoadValuesFromDatabase();
|
||||||
CDPackageComponentTable::Instance().LoadValuesFromDatabase();
|
CDPackageComponentTable::Instance().LoadValuesFromDatabase();
|
||||||
|
CDPetAbilitiesTable::Instance().LoadValuesFromDatabase();
|
||||||
CDPetComponentTable::Instance().LoadValuesFromDatabase();
|
CDPetComponentTable::Instance().LoadValuesFromDatabase();
|
||||||
CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase();
|
CDProximityMonitorComponentTable::Instance().LoadValuesFromDatabase();
|
||||||
CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase();
|
CDPropertyEntranceComponentTable::Instance().LoadValuesFromDatabase();
|
||||||
@ -159,5 +155,6 @@ void CDClientManager::LoadValuesFromDatabase() {
|
|||||||
void CDClientManager::LoadValuesFromDefaults() {
|
void CDClientManager::LoadValuesFromDefaults() {
|
||||||
LOG("Loading default CDClient tables!");
|
LOG("Loading default CDClient tables!");
|
||||||
|
|
||||||
|
CDPetAbilitiesTable::Instance().LoadValuesFromDefaults();
|
||||||
CDPetComponentTable::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() {
|
void CDPetComponentTable::LoadValuesFromDefaults() {
|
||||||
GetEntriesMutable().insert(std::make_pair(defaultEntry.id, defaultEntry));
|
GetEntriesMutable().emplace(defaultEntry.id, defaultEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
CDPetComponent& CDPetComponentTable::GetByID(const uint32_t componentID) {
|
const CDPetComponent& CDPetComponentTable::GetByID(const uint32_t componentID) {
|
||||||
auto& entries = GetEntriesMutable();
|
const auto& entries = GetEntriesMutable();
|
||||||
auto itr = entries.find(componentID);
|
const auto itr = entries.find(componentID);
|
||||||
if (itr == entries.end()) {
|
if (itr == entries.cend()) {
|
||||||
LOG("Unable to load pet component (ID %i) values from database! Using default values instead.", componentID);
|
LOG("Unable to load pet component (ID %i) values from database! Using default values instead.", componentID);
|
||||||
return defaultEntry;
|
return defaultEntry;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
* Load values from the CD client database
|
* Load values from the CD client database
|
||||||
*/
|
*/
|
||||||
void LoadValuesFromDatabase();
|
void LoadValuesFromDatabase();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the default values into memory instead of attempting to connect to the CD client database
|
* 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
|
* 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
|
* @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"
|
"CDMovementAIComponentTable.cpp"
|
||||||
"CDObjectSkillsTable.cpp"
|
"CDObjectSkillsTable.cpp"
|
||||||
"CDObjectsTable.cpp"
|
"CDObjectsTable.cpp"
|
||||||
|
"CDPetAbilitiesTable.cpp"
|
||||||
"CDPetComponentTable.cpp"
|
"CDPetComponentTable.cpp"
|
||||||
"CDPackageComponentTable.cpp"
|
"CDPackageComponentTable.cpp"
|
||||||
"CDPhysicsComponentTable.cpp"
|
"CDPhysicsComponentTable.cpp"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "GameMessages.h"
|
#include "GameMessages.h"
|
||||||
#include "BrickDatabase.h"
|
#include "BrickDatabase.h"
|
||||||
#include "CDClientDatabase.h"
|
#include "CDClientDatabase.h"
|
||||||
|
#include "CDPetAbilitiesTable.h"
|
||||||
#include "CDPetComponentTable.h"
|
#include "CDPetComponentTable.h"
|
||||||
#include "ChatPackets.h"
|
#include "ChatPackets.h"
|
||||||
#include "EntityManager.h"
|
#include "EntityManager.h"
|
||||||
@ -911,7 +912,9 @@ void PetComponent::StartInteractBouncer() {
|
|||||||
if (!destroyableComponent) return;
|
if (!destroyableComponent) return;
|
||||||
|
|
||||||
auto imagination = destroyableComponent->GetImagination();
|
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) {
|
if (imagination < imaginationCost) {
|
||||||
//GameMessages::SendHelp(user->GetObjectID(), eHelpType::PR_NEED_IMAGINATION, user->GetSystemAddress()); // Check if right message!
|
//GameMessages::SendHelp(user->GetObjectID(), eHelpType::PR_NEED_IMAGINATION, user->GetSystemAddress()); // Check if right message!
|
||||||
return;
|
return;
|
||||||
@ -989,7 +992,9 @@ void PetComponent::StartInteractTreasureDig() {
|
|||||||
if (!destroyableComponent) return;
|
if (!destroyableComponent) return;
|
||||||
|
|
||||||
auto imagination = destroyableComponent->GetImagination();
|
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) {
|
if (imagination < imaginationCost) {
|
||||||
//GameMessages::SendHelp(user->GetObjectID(), eHelpType::PR_NEED_IMAGINATION, user->GetSystemAddress()); // Check if right message!
|
//GameMessages::SendHelp(user->GetObjectID(), eHelpType::PR_NEED_IMAGINATION, user->GetSystemAddress()); // Check if right message!
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user