[Character] Convert Delete/Load/Save of Character Leadership Abilities to Repositories (#3847)

# Notes
- Converts `DeleteCharacterLeadershipAbilities`, `LoadCharacterLeadershipAbilities`, and `SaveCharacterLeadershipAbilities` to repositories.

# Images
## Load

## Save

## Delete
This commit is contained in:
Alex King 2024-01-06 23:42:56 -05:00 committed by GitHub
parent 7e23d798d5
commit a5d9a8596a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 104 additions and 31 deletions

View File

@ -6,7 +6,7 @@
* Any modifications to base repositories are to be made by the generator only * Any modifications to base repositories are to be made by the generator only
* *
* @generator ./utils/scripts/generators/repository-generator.pl * @generator ./utils/scripts/generators/repository-generator.pl
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories * @docs https://docs.eqemu.io/developer/repositories
*/ */
#ifndef EQEMU_BASE_CHARACTER_LEADERSHIP_ABILITIES_REPOSITORY_H #ifndef EQEMU_BASE_CHARACTER_LEADERSHIP_ABILITIES_REPOSITORY_H
@ -16,6 +16,7 @@
#include "../../strings.h" #include "../../strings.h"
#include <ctime> #include <ctime>
class BaseCharacterLeadershipAbilitiesRepository { class BaseCharacterLeadershipAbilitiesRepository {
public: public:
struct CharacterLeadershipAbilities { struct CharacterLeadershipAbilities {
@ -112,8 +113,9 @@ public:
{ {
auto results = db.QueryDatabase( auto results = db.QueryDatabase(
fmt::format( fmt::format(
"{} WHERE id = {} LIMIT 1", "{} WHERE {} = {} LIMIT 1",
BaseSelect(), BaseSelect(),
PrimaryKey(),
character_leadership_abilities_id character_leadership_abilities_id
) )
); );
@ -338,6 +340,66 @@ public:
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
} }
static std::string BaseReplace()
{
return fmt::format(
"REPLACE INTO {} ({}) ",
TableName(),
ColumnsRaw()
);
}
static int ReplaceOne(
Database& db,
const CharacterLeadershipAbilities &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.rank));
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseReplace(),
Strings::Implode(",", v)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int ReplaceMany(
Database& db,
const std::vector<CharacterLeadershipAbilities> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.rank));
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
}
std::vector<std::string> v;
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseReplace(),
Strings::Implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
}; };
#endif //EQEMU_BASE_CHARACTER_LEADERSHIP_ABILITIES_REPOSITORY_H #endif //EQEMU_BASE_CHARACTER_LEADERSHIP_ABILITIES_REPOSITORY_H

View File

@ -541,7 +541,7 @@ void Client::ResetAA() {
m_pp.raid_leadership_exp = 0; m_pp.raid_leadership_exp = 0;
database.DeleteCharacterAAs(CharacterID()); database.DeleteCharacterAAs(CharacterID());
database.DeleteCharacterLeadershipAAs(CharacterID()); database.DeleteCharacterLeadershipAbilities(CharacterID());
} }
void Client::SendClearAA() void Client::SendClearAA()

View File

@ -4636,7 +4636,7 @@ void Client::ClearGroupAAs() {
m_pp.raid_leadership_exp = 0; m_pp.raid_leadership_exp = 0;
Save(); Save();
database.SaveCharacterLeadershipAA(CharacterID(), &m_pp); database.SaveCharacterLeadershipAbilities(CharacterID(), &m_pp);
} }
void Client::UpdateGroupAAs(int32 points, uint32 type) { void Client::UpdateGroupAAs(int32 points, uint32 type) {

View File

@ -1277,7 +1277,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app)
database.LoadCharacterMemmedSpells(cid, &m_pp); /* Load Character Memorized Spells */ database.LoadCharacterMemmedSpells(cid, &m_pp); /* Load Character Memorized Spells */
database.LoadCharacterDisciplines(cid, &m_pp); /* Load Character Disciplines */ database.LoadCharacterDisciplines(cid, &m_pp); /* Load Character Disciplines */
database.LoadCharacterLanguages(cid, &m_pp); /* Load Character Languages */ database.LoadCharacterLanguages(cid, &m_pp); /* Load Character Languages */
database.LoadCharacterLeadershipAA(cid, &m_pp); /* Load Character Leadership AA's */ database.LoadCharacterLeadershipAbilities(cid, &m_pp); /* Load Character Leadership AA's */
database.LoadCharacterTribute(this); /* Load CharacterTribute */ database.LoadCharacterTribute(this); /* Load CharacterTribute */
// this pattern is strange // this pattern is strange
@ -11681,7 +11681,7 @@ void Client::Handle_OP_PurchaseLeadershipAA(const EQApplicationPacket *app)
m_pp.raid_leadership_points -= cost; m_pp.raid_leadership_points -= cost;
m_pp.leader_abilities.ranks[aaid]++; m_pp.leader_abilities.ranks[aaid]++;
database.SaveCharacterLeadershipAA(CharacterID(), &m_pp); database.SaveCharacterLeadershipAbilities(CharacterID(), &m_pp);
} }
else { else {
//it is a group ability. //it is a group ability.
@ -11694,7 +11694,7 @@ void Client::Handle_OP_PurchaseLeadershipAA(const EQApplicationPacket *app)
m_pp.group_leadership_points -= cost; m_pp.group_leadership_points -= cost;
m_pp.leader_abilities.ranks[aaid]++; m_pp.leader_abilities.ranks[aaid]++;
database.SaveCharacterLeadershipAA(CharacterID(), &m_pp); database.SaveCharacterLeadershipAbilities(CharacterID(), &m_pp);
} }
//success, send them an update //success, send them an update

View File

@ -23,6 +23,7 @@
#include "../common/repositories/character_languages_repository.h" #include "../common/repositories/character_languages_repository.h"
#include "../common/repositories/criteria/content_filter_criteria.h" #include "../common/repositories/criteria/content_filter_criteria.h"
#include "../common/repositories/spawn2_disabled_repository.h" #include "../common/repositories/spawn2_disabled_repository.h"
#include "../common/repositories/character_leadership_abilities_repository.h"
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
@ -832,13 +833,20 @@ bool ZoneDatabase::LoadCharacterLanguages(uint32 character_id, PlayerProfile_Str
return true; return true;
} }
bool ZoneDatabase::LoadCharacterLeadershipAA(uint32 character_id, PlayerProfile_Struct* pp){ bool ZoneDatabase::LoadCharacterLeadershipAbilities(uint32 character_id, PlayerProfile_Struct* pp)
std::string query = StringFormat("SELECT slot, `rank` FROM character_leadership_abilities WHERE `id` = %u", character_id); {
auto results = database.QueryDatabase(query); uint32 slot = 0; const auto& l = CharacterLeadershipAbilitiesRepository::GetWhere(
for (auto& row = results.begin(); row != results.end(); ++row) { database,
slot = Strings::ToInt(row[0]); fmt::format(
pp->leader_abilities.ranks[slot] = Strings::ToInt(row[1]); "`id` = {}",
character_id
)
);
for (const auto& e : l) {
pp->leader_abilities.ranks[e.slot] = e.rank;
} }
return true; return true;
} }
@ -1131,19 +1139,23 @@ bool ZoneDatabase::SaveCharacterPotionBelt(uint32 character_id, uint8 potion_id,
return true; return true;
} }
bool ZoneDatabase::SaveCharacterLeadershipAA(uint32 character_id, PlayerProfile_Struct* pp){ bool ZoneDatabase::SaveCharacterLeadershipAbilities(uint32 character_id, PlayerProfile_Struct* pp)
uint8 first_entry = 0; std::string query = ""; {
for (int i = 0; i < MAX_LEADERSHIP_AA_ARRAY; i++){ std::vector<CharacterLeadershipAbilitiesRepository::CharacterLeadershipAbilities> v;
if (pp->leader_abilities.ranks[i] > 0){
if (first_entry != 1){ auto e = CharacterLeadershipAbilitiesRepository::NewEntity();
query = StringFormat("REPLACE INTO `character_leadership_abilities` (id, slot, `rank`) VALUES (%i, %u, %u)", character_id, i, pp->leader_abilities.ranks[i]);
first_entry = 1; for (int slot_id = 0; slot_id < MAX_LEADERSHIP_AA_ARRAY; slot_id++) {
} if (pp->leader_abilities.ranks[slot_id] > 0) {
query = query + StringFormat(", (%i, %u, %u)", character_id, i, pp->leader_abilities.ranks[i]); e.id = character_id;
e.slot = slot_id;
e.rank = pp->leader_abilities.ranks[slot_id];
v.emplace_back(e);
} }
} }
auto results = QueryDatabase(query);
return true; return CharacterLeadershipAbilitiesRepository::ReplaceMany(*this, v);
} }
bool ZoneDatabase::SaveCharacterData( bool ZoneDatabase::SaveCharacterData(
@ -1546,10 +1558,9 @@ bool ZoneDatabase::DeleteCharacterBandolier(uint32 character_id, uint32 band_id)
return true; return true;
} }
bool ZoneDatabase::DeleteCharacterLeadershipAAs(uint32 character_id){ bool ZoneDatabase::DeleteCharacterLeadershipAbilities(uint32 character_id)
std::string query = StringFormat("DELETE FROM `character_leadership_abilities` WHERE `id` = %u", character_id); {
QueryDatabase(query); return CharacterLeadershipAbilitiesRepository::DeleteOne(*this, character_id);
return true;
} }
bool ZoneDatabase::DeleteCharacterAAs(uint32 character_id){ bool ZoneDatabase::DeleteCharacterAAs(uint32 character_id){

View File

@ -426,7 +426,7 @@ public:
bool DeleteCharacterBandolier(uint32 character_id, uint32 band_id); bool DeleteCharacterBandolier(uint32 character_id, uint32 band_id);
bool DeleteCharacterDisc(uint32 character_id, uint32 slot_id); bool DeleteCharacterDisc(uint32 character_id, uint32 slot_id);
bool DeleteCharacterDye(uint32 character_id); bool DeleteCharacterDye(uint32 character_id);
bool DeleteCharacterLeadershipAAs(uint32 character_id); bool DeleteCharacterLeadershipAbilities(uint32 character_id);
bool DeleteCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id); bool DeleteCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id);
bool DeleteCharacterSpell(uint32 character_id, uint32 spell_id, uint32 slot_id); bool DeleteCharacterSpell(uint32 character_id, uint32 spell_id, uint32 slot_id);
@ -437,7 +437,7 @@ public:
bool LoadCharacterDisciplines(uint32 character_id, PlayerProfile_Struct* pp); bool LoadCharacterDisciplines(uint32 character_id, PlayerProfile_Struct* pp);
bool LoadCharacterFactionValues(uint32 character_id, faction_map & val_list); bool LoadCharacterFactionValues(uint32 character_id, faction_map & val_list);
bool LoadCharacterLanguages(uint32 character_id, PlayerProfile_Struct* pp); bool LoadCharacterLanguages(uint32 character_id, PlayerProfile_Struct* pp);
bool LoadCharacterLeadershipAA(uint32 character_id, PlayerProfile_Struct* pp); bool LoadCharacterLeadershipAbilities(uint32 character_id, PlayerProfile_Struct* pp);
bool LoadCharacterMaterialColor(uint32 character_id, PlayerProfile_Struct* pp); bool LoadCharacterMaterialColor(uint32 character_id, PlayerProfile_Struct* pp);
bool LoadCharacterMemmedSpells(uint32 character_id, PlayerProfile_Struct* pp); bool LoadCharacterMemmedSpells(uint32 character_id, PlayerProfile_Struct* pp);
bool LoadCharacterPotions(uint32 character_id, PlayerProfile_Struct* pp); bool LoadCharacterPotions(uint32 character_id, PlayerProfile_Struct* pp);
@ -450,7 +450,7 @@ public:
bool SaveCharacterData(Client* c, PlayerProfile_Struct* pp, ExtendedProfile_Struct* m_epp); bool SaveCharacterData(Client* c, PlayerProfile_Struct* pp, ExtendedProfile_Struct* m_epp);
bool SaveCharacterDisc(uint32 character_id, uint32 slot_id, uint32 disc_id); bool SaveCharacterDisc(uint32 character_id, uint32 slot_id, uint32 disc_id);
bool SaveCharacterLanguage(uint32 character_id, uint32 lang_id, uint32 value); bool SaveCharacterLanguage(uint32 character_id, uint32 lang_id, uint32 value);
bool SaveCharacterLeadershipAA(uint32 character_id, PlayerProfile_Struct* pp); bool SaveCharacterLeadershipAbilities(uint32 character_id, PlayerProfile_Struct* pp);
bool SaveCharacterMaterialColor(uint32 character_id, uint32 slot_id, uint32 color); bool SaveCharacterMaterialColor(uint32 character_id, uint32 slot_id, uint32 color);
bool SaveCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id); bool SaveCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id);
bool SaveCharacterPotionBelt(uint32 character_id, uint8 potion_id, uint32 item_id, uint32 icon); bool SaveCharacterPotionBelt(uint32 character_id, uint8 potion_id, uint32 item_id, uint32 icon);