mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-04-10 01:36:57 +00:00
feat: implement character and property reputation system
- Added ICharacterReputation and IPropertyReputationContribution interfaces for managing character and property reputations. - Implemented MySQL and SQLite database methods for getting and setting character reputations. - Created migration scripts for character and property reputation tables in both MySQL and SQLite. - Updated CharacterComponent to retrieve and set character reputation. - Enhanced PropertyManagementComponent to manage property reputation and contributions. - Added methods for handling reputation contributions and decay. - Introduced CharacterReputationMigration to migrate existing character reputations from XML to the database.
This commit is contained in:
@@ -21,6 +21,8 @@ set(DDATABASES_DATABASES_MYSQL_TABLES_SOURCES
|
||||
"Servers.cpp"
|
||||
"Ugc.cpp"
|
||||
"UgcModularBuild.cpp"
|
||||
"CharacterReputation.cpp"
|
||||
"PropertyReputationContribution.cpp"
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
|
||||
@@ -52,6 +52,18 @@ std::vector<LWOOBJID> MySQLDatabase::GetAccountCharacterIds(const LWOOBJID accou
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
std::vector<LWOOBJID> MySQLDatabase::GetAllCharacterIds() {
|
||||
auto result = ExecuteSelect("SELECT id FROM charinfo;");
|
||||
|
||||
std::vector<LWOOBJID> toReturn;
|
||||
toReturn.reserve(result->rowsCount());
|
||||
while (result->next()) {
|
||||
toReturn.push_back(result->getInt64("id"));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
void MySQLDatabase::InsertNewCharacter(const ICharInfo::Info info) {
|
||||
ExecuteInsert(
|
||||
"INSERT INTO `charinfo`(`id`, `account_id`, `name`, `pending_name`, `needs_rename`, `last_login`) VALUES (?,?,?,?,?,?)",
|
||||
|
||||
17
dDatabase/GameDatabase/MySQL/Tables/CharacterReputation.cpp
Normal file
17
dDatabase/GameDatabase/MySQL/Tables/CharacterReputation.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "MySQLDatabase.h"
|
||||
|
||||
int64_t MySQLDatabase::GetCharacterReputation(const LWOOBJID charId) {
|
||||
auto result = ExecuteSelect("SELECT reputation FROM character_reputation WHERE character_id = ? LIMIT 1;", charId);
|
||||
|
||||
if (!result->next()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return result->getInt64("reputation");
|
||||
}
|
||||
|
||||
void MySQLDatabase::SetCharacterReputation(const LWOOBJID charId, const int64_t reputation) {
|
||||
ExecuteInsert(
|
||||
"INSERT INTO character_reputation (character_id, reputation) VALUES (?, ?) ON DUPLICATE KEY UPDATE reputation = ?;",
|
||||
charId, reputation, reputation);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "MySQLDatabase.h"
|
||||
|
||||
std::vector<IPropertyReputationContribution::ContributionInfo> MySQLDatabase::GetPropertyReputationContributions(
|
||||
const LWOOBJID propertyId, const std::string& date) {
|
||||
auto result = ExecuteSelect(
|
||||
"SELECT player_id, reputation_gained FROM property_reputation_contribution WHERE property_id = ? AND contribution_date = ?;",
|
||||
propertyId, date);
|
||||
|
||||
std::vector<IPropertyReputationContribution::ContributionInfo> contributions;
|
||||
while (result->next()) {
|
||||
IPropertyReputationContribution::ContributionInfo info;
|
||||
info.playerId = result->getUInt64("player_id");
|
||||
info.reputationGained = static_cast<uint32_t>(result->getUInt("reputation_gained"));
|
||||
contributions.push_back(info);
|
||||
}
|
||||
return contributions;
|
||||
}
|
||||
|
||||
void MySQLDatabase::UpdatePropertyReputationContribution(
|
||||
const LWOOBJID propertyId, const LWOOBJID playerId,
|
||||
const std::string& date, const uint32_t reputationGained) {
|
||||
ExecuteInsert(
|
||||
"INSERT INTO property_reputation_contribution (property_id, player_id, contribution_date, reputation_gained) "
|
||||
"VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE reputation_gained = ?;",
|
||||
propertyId, playerId, date, reputationGained, reputationGained);
|
||||
}
|
||||
|
||||
void MySQLDatabase::UpdatePropertyReputation(const LWOOBJID propertyId, const uint32_t reputation) {
|
||||
ExecuteUpdate("UPDATE properties SET reputation = ? WHERE id = ?;", reputation, propertyId);
|
||||
}
|
||||
Reference in New Issue
Block a user