mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-05-12 18:35:06 +00:00
refactor: streamline reputation configuration loading in PropertyManagementComponent
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -126,3 +126,6 @@ docker-compose.override.yml
|
|||||||
# CMake scripts
|
# CMake scripts
|
||||||
!cmake/*
|
!cmake/*
|
||||||
!cmake/toolchains/*
|
!cmake/toolchains/*
|
||||||
|
|
||||||
|
.mcp.json
|
||||||
|
.claude/
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "GameDatabase.h"
|
#include "GameDatabase.h"
|
||||||
|
|
||||||
class TestSQLDatabase : public GameDatabase {
|
class TestSQLDatabase : public GameDatabase {
|
||||||
|
public:
|
||||||
void Connect() override;
|
void Connect() override;
|
||||||
void Destroy(std::string source = "") override;
|
void Destroy(std::string source = "") override;
|
||||||
|
|
||||||
|
|||||||
@@ -90,43 +90,15 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent, const i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load reputation config
|
// Load reputation config
|
||||||
auto configFloat = [](const std::string& key, const float def) {
|
m_RepInterval = GeneralUtils::TryParse<float>(Game::config->GetValue("property_rep_interval")).value_or(60.0f);
|
||||||
const auto& val = Game::config->GetValue(key);
|
m_RepDailyCap = GeneralUtils::TryParse<std::uint32_t>(Game::config->GetValue("property_rep_daily_cap")).value_or(50);
|
||||||
if (val.empty()) {
|
m_RepPerTick = GeneralUtils::TryParse<std::uint32_t>(Game::config->GetValue("property_rep_per_tick")).value_or(1);
|
||||||
return def;
|
m_RepMultiplier = GeneralUtils::TryParse<float>(Game::config->GetValue("property_rep_multiplier")).value_or(1.0f);
|
||||||
}
|
m_RepVelocityThreshold = GeneralUtils::TryParse<float>(Game::config->GetValue("property_rep_velocity_threshold")).value_or(0.5f);
|
||||||
|
m_RepSaveInterval = GeneralUtils::TryParse<float>(Game::config->GetValue("property_rep_save_interval")).value_or(300.0f);
|
||||||
float parsedValue {};
|
m_RepDecayRate = GeneralUtils::TryParse<float>(Game::config->GetValue("property_rep_decay_rate")).value_or(0.0f);
|
||||||
if (GeneralUtils::TryParse<float>(val, parsedValue)) {
|
m_RepDecayInterval = GeneralUtils::TryParse<float>(Game::config->GetValue("property_rep_decay_interval")).value_or(86400.0f);
|
||||||
return parsedValue;
|
m_RepDecayMinimum = GeneralUtils::TryParse<std::uint32_t>(Game::config->GetValue("property_rep_decay_minimum")).value_or(0);
|
||||||
}
|
|
||||||
|
|
||||||
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<std::uint32_t>(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);
|
|
||||||
|
|
||||||
// Load daily reputation contributions and subscribe to position updates
|
// Load daily reputation contributions and subscribe to position updates
|
||||||
m_CurrentDate = GeneralUtils::GetCurrentUTCDate();
|
m_CurrentDate = GeneralUtils::GetCurrentUTCDate();
|
||||||
@@ -146,6 +118,7 @@ PropertyManagementComponent::~PropertyManagementComponent() {
|
|||||||
if (instance == this) {
|
if (instance == this) {
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
}
|
}
|
||||||
|
SaveReputation();
|
||||||
}
|
}
|
||||||
LWOOBJID PropertyManagementComponent::GetOwnerId() const {
|
LWOOBJID PropertyManagementComponent::GetOwnerId() const {
|
||||||
return owner;
|
return owner;
|
||||||
@@ -902,10 +875,6 @@ void PropertyManagementComponent::OnChatMessageReceived(const std::string& sMess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyManagementComponent::~PropertyManagementComponent() {
|
|
||||||
SaveReputation();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertyManagementComponent::Update(float deltaTime) {
|
void PropertyManagementComponent::Update(float deltaTime) {
|
||||||
// Check for day rollover
|
// Check for day rollover
|
||||||
const auto currentDate = GeneralUtils::GetCurrentUTCDate();
|
const auto currentDate = GeneralUtils::GetCurrentUTCDate();
|
||||||
|
|||||||
Reference in New Issue
Block a user