From a7a4288e4564a6595512457bda8e7f9ffaaf9832 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Wed, 22 Apr 2026 10:57:19 -0500 Subject: [PATCH] refactor: streamline reputation configuration loading in PropertyManagementComponent --- .gitignore | 3 ++ .../GameDatabase/TestSQL/TestSQLDatabase.h | 1 + .../PropertyManagementComponent.cpp | 51 ++++--------------- 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index d7af5d1f..9afe6387 100644 --- a/.gitignore +++ b/.gitignore @@ -126,3 +126,6 @@ docker-compose.override.yml # CMake scripts !cmake/* !cmake/toolchains/* + +.mcp.json +.claude/ \ No newline at end of file diff --git a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h index 2170830b..887fddac 100644 --- a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h +++ b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h @@ -6,6 +6,7 @@ #include "GameDatabase.h" class TestSQLDatabase : public GameDatabase { +public: void Connect() override; void Destroy(std::string source = "") override; diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index a66e2539..26b262c1 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -90,43 +90,15 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent, const i } // Load reputation config - auto configFloat = [](const std::string& key, const float def) { - const auto& val = Game::config->GetValue(key); - if (val.empty()) { - return def; - } - - float parsedValue {}; - if (GeneralUtils::TryParse(val, parsedValue)) { - return parsedValue; - } - - LOG("Invalid config value for '%s': '%s'. Using default: %f", key.c_str(), val.c_str(), def); - return def; - }; - auto configUint = [](const std::string& key, const std::uint32_t def) { - const auto& val = Game::config->GetValue(key); - if (val.empty()) { - return def; - } - - std::uint32_t parsedValue {}; - if (GeneralUtils::TryParse(val, parsedValue)) { - return parsedValue; - } - - LOG("Invalid config value for '%s': '%s'. Using default: %u", key.c_str(), val.c_str(), def); - return def; - }; - m_RepInterval = configFloat("property_rep_interval", 60.0f); - m_RepDailyCap = configUint("property_rep_daily_cap", 50); - m_RepPerTick = configUint("property_rep_per_tick", 1); - m_RepMultiplier = configFloat("property_rep_multiplier", 1.0f); - m_RepVelocityThreshold = configFloat("property_rep_velocity_threshold", 0.5f); - m_RepSaveInterval = configFloat("property_rep_save_interval", 300.0f); - m_RepDecayRate = configFloat("property_rep_decay_rate", 0.0f); - m_RepDecayInterval = configFloat("property_rep_decay_interval", 86400.0f); - m_RepDecayMinimum = configUint("property_rep_decay_minimum", 0); + m_RepInterval = GeneralUtils::TryParse(Game::config->GetValue("property_rep_interval")).value_or(60.0f); + m_RepDailyCap = GeneralUtils::TryParse(Game::config->GetValue("property_rep_daily_cap")).value_or(50); + m_RepPerTick = GeneralUtils::TryParse(Game::config->GetValue("property_rep_per_tick")).value_or(1); + m_RepMultiplier = GeneralUtils::TryParse(Game::config->GetValue("property_rep_multiplier")).value_or(1.0f); + m_RepVelocityThreshold = GeneralUtils::TryParse(Game::config->GetValue("property_rep_velocity_threshold")).value_or(0.5f); + m_RepSaveInterval = GeneralUtils::TryParse(Game::config->GetValue("property_rep_save_interval")).value_or(300.0f); + m_RepDecayRate = GeneralUtils::TryParse(Game::config->GetValue("property_rep_decay_rate")).value_or(0.0f); + m_RepDecayInterval = GeneralUtils::TryParse(Game::config->GetValue("property_rep_decay_interval")).value_or(86400.0f); + m_RepDecayMinimum = GeneralUtils::TryParse(Game::config->GetValue("property_rep_decay_minimum")).value_or(0); // Load daily reputation contributions and subscribe to position updates m_CurrentDate = GeneralUtils::GetCurrentUTCDate(); @@ -146,6 +118,7 @@ PropertyManagementComponent::~PropertyManagementComponent() { if (instance == this) { instance = nullptr; } + SaveReputation(); } LWOOBJID PropertyManagementComponent::GetOwnerId() const { return owner; @@ -902,10 +875,6 @@ void PropertyManagementComponent::OnChatMessageReceived(const std::string& sMess } } -PropertyManagementComponent::~PropertyManagementComponent() { - SaveReputation(); -} - void PropertyManagementComponent::Update(float deltaTime) { // Check for day rollover const auto currentDate = GeneralUtils::GetCurrentUTCDate();