mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 09:31:30 +00:00
[Character] Convert Delete/Load/Save of Character Bandolier to Repositories (#3845)
* [Character] Convert Delete/Load/Save of Character Bandolier to Repositories - Converts `DeleteCharacterBandolier`, `LoadCharacterBandolier`, and `SaveCharacterBandolier` to repositories. * Update zonedb.cpp * Update zonedb.cpp * Update zonedb.cpp * Update zonedb.cpp * Update zonedb.cpp
This commit is contained in:
parent
f8de9b9167
commit
397096996c
@ -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_BANDOLIER_REPOSITORY_H
|
#ifndef EQEMU_BASE_CHARACTER_BANDOLIER_REPOSITORY_H
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#include "../../strings.h"
|
#include "../../strings.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
class BaseCharacterBandolierRepository {
|
class BaseCharacterBandolierRepository {
|
||||||
public:
|
public:
|
||||||
struct CharacterBandolier {
|
struct CharacterBandolier {
|
||||||
@ -124,8 +125,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_bandolier_id
|
character_bandolier_id
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -368,6 +370,72 @@ 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 CharacterBandolier &e
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::vector<std::string> v;
|
||||||
|
|
||||||
|
v.push_back(std::to_string(e.id));
|
||||||
|
v.push_back(std::to_string(e.bandolier_id));
|
||||||
|
v.push_back(std::to_string(e.bandolier_slot));
|
||||||
|
v.push_back(std::to_string(e.item_id));
|
||||||
|
v.push_back(std::to_string(e.icon));
|
||||||
|
v.push_back("'" + Strings::Escape(e.bandolier_name) + "'");
|
||||||
|
|
||||||
|
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<CharacterBandolier> &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.bandolier_id));
|
||||||
|
v.push_back(std::to_string(e.bandolier_slot));
|
||||||
|
v.push_back(std::to_string(e.item_id));
|
||||||
|
v.push_back(std::to_string(e.icon));
|
||||||
|
v.push_back("'" + Strings::Escape(e.bandolier_name) + "'");
|
||||||
|
|
||||||
|
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_BANDOLIER_REPOSITORY_H
|
#endif //EQEMU_BASE_CHARACTER_BANDOLIER_REPOSITORY_H
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
#include "../common/repositories/character_spells_repository.h"
|
#include "../common/repositories/character_spells_repository.h"
|
||||||
#include "../common/repositories/character_skills_repository.h"
|
#include "../common/repositories/character_skills_repository.h"
|
||||||
#include "../common/repositories/character_potionbelt_repository.h"
|
#include "../common/repositories/character_potionbelt_repository.h"
|
||||||
|
#include "../common/repositories/character_bandolier_repository.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -873,38 +874,47 @@ bool ZoneDatabase::LoadCharacterMaterialColor(uint32 character_id, PlayerProfile
|
|||||||
|
|
||||||
bool ZoneDatabase::LoadCharacterBandolier(uint32 character_id, PlayerProfile_Struct* pp)
|
bool ZoneDatabase::LoadCharacterBandolier(uint32 character_id, PlayerProfile_Struct* pp)
|
||||||
{
|
{
|
||||||
std::string query = StringFormat("SELECT `bandolier_id`, `bandolier_slot`, `item_id`, `icon`, `bandolier_name` FROM `character_bandolier` WHERE `id` = %u LIMIT %u",
|
const auto& l = CharacterBandolierRepository::GetWhere(
|
||||||
character_id, EQ::profile::BANDOLIERS_SIZE);
|
database,
|
||||||
auto results = database.QueryDatabase(query); int i = 0; int r = 0; int si = 0;
|
fmt::format(
|
||||||
for (i = 0; i < EQ::profile::BANDOLIERS_SIZE; i++) {
|
"`id` = {} LIMIT {}",
|
||||||
|
character_id,
|
||||||
|
EQ::profile::BANDOLIERS_SIZE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int i = 0; i < EQ::profile::BANDOLIERS_SIZE; i++) {
|
||||||
pp->bandoliers[i].Name[0] = '\0';
|
pp->bandoliers[i].Name[0] = '\0';
|
||||||
|
|
||||||
for (int si = 0; si < EQ::profile::BANDOLIER_ITEM_COUNT; si++) {
|
for (int si = 0; si < EQ::profile::BANDOLIER_ITEM_COUNT; si++) {
|
||||||
pp->bandoliers[i].Items[si].ID = 0;
|
pp->bandoliers[i].Items[si].ID = 0;
|
||||||
pp->bandoliers[i].Items[si].Icon = 0;
|
pp->bandoliers[i].Items[si].Icon = 0;
|
||||||
|
|
||||||
pp->bandoliers[i].Items[si].Name[0] = '\0';
|
pp->bandoliers[i].Items[si].Name[0] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& row = results.begin(); row != results.end(); ++row) {
|
for (const auto& e : l) {
|
||||||
r = 0;
|
const auto* item_data = database.GetItem(e.item_id);
|
||||||
i = Strings::ToInt(row[r]); /* Bandolier ID */ r++;
|
|
||||||
si = Strings::ToInt(row[r]); /* Bandolier Slot */ r++;
|
|
||||||
|
|
||||||
const EQ::ItemData* item_data = database.GetItem(Strings::ToInt(row[r]));
|
|
||||||
if (item_data) {
|
if (item_data) {
|
||||||
pp->bandoliers[i].Items[si].ID = item_data->ID; r++;
|
pp->bandoliers[e.bandolier_id].Items[e.bandolier_slot].ID = item_data->ID;
|
||||||
pp->bandoliers[i].Items[si].Icon = Strings::ToInt(row[r]); r++; // Must use db value in case an Ornamentation is assigned
|
pp->bandoliers[e.bandolier_id].Items[e.bandolier_slot].Icon = e.icon;
|
||||||
strncpy(pp->bandoliers[i].Items[si].Name, item_data->Name, 64);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pp->bandoliers[i].Items[si].ID = 0; r++;
|
|
||||||
pp->bandoliers[i].Items[si].Icon = 0; r++;
|
|
||||||
pp->bandoliers[i].Items[si].Name[0] = '\0';
|
|
||||||
}
|
|
||||||
strcpy(pp->bandoliers[i].Name, row[r]); r++;
|
|
||||||
|
|
||||||
si++; // What is this for!?
|
strncpy(
|
||||||
|
pp->bandoliers[e.bandolier_id].Items[e.bandolier_slot].Name,
|
||||||
|
item_data->Name,
|
||||||
|
64
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
pp->bandoliers[e.bandolier_id].Items[e.bandolier_slot].ID = 0;
|
||||||
|
pp->bandoliers[e.bandolier_id].Items[e.bandolier_slot].Icon = 0;
|
||||||
|
|
||||||
|
pp->bandoliers[e.bandolier_id].Items[e.bandolier_slot].Name[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(pp->bandoliers[e.bandolier_id].Name, e.bandolier_name.c_str(), 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1061,14 +1071,26 @@ void ZoneDatabase::SaveCharacterTribute(Client* c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::SaveCharacterBandolier(uint32 character_id, uint8 bandolier_id, uint8 bandolier_slot, uint32 item_id, uint32 icon, const char* bandolier_name)
|
bool ZoneDatabase::SaveCharacterBandolier(
|
||||||
|
uint32 character_id,
|
||||||
|
uint8 bandolier_id,
|
||||||
|
uint8 bandolier_slot,
|
||||||
|
uint32 item_id,
|
||||||
|
uint32 icon,
|
||||||
|
const char* bandolier_name
|
||||||
|
)
|
||||||
{
|
{
|
||||||
char bandolier_name_esc[64];
|
return CharacterBandolierRepository::ReplaceOne(
|
||||||
DoEscapeString(bandolier_name_esc, bandolier_name, strlen(bandolier_name));
|
*this,
|
||||||
std::string query = StringFormat("REPLACE INTO `character_bandolier` (id, bandolier_id, bandolier_slot, item_id, icon, bandolier_name) VALUES (%u, %u, %u, %u, %u,'%s')", character_id, bandolier_id, bandolier_slot, item_id, icon, bandolier_name_esc);
|
CharacterBandolierRepository::CharacterBandolier{
|
||||||
auto results = QueryDatabase(query);
|
.id = character_id,
|
||||||
LogDebug("ZoneDatabase::SaveCharacterBandolier for character ID: [{}], bandolier_id: [{}], bandolier_slot: [{}] item_id: [{}], icon:[{}] band_name:[{}] done", character_id, bandolier_id, bandolier_slot, item_id, icon, bandolier_name);
|
.bandolier_id = bandolier_id,
|
||||||
return true;
|
.bandolier_slot = bandolier_slot,
|
||||||
|
.item_id = item_id,
|
||||||
|
.icon = icon,
|
||||||
|
.bandolier_name = bandolier_name
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::SaveCharacterPotionBelt(uint32 character_id, uint8 potion_id, uint32 item_id, uint32 icon)
|
bool ZoneDatabase::SaveCharacterPotionBelt(uint32 character_id, uint8 potion_id, uint32 item_id, uint32 icon)
|
||||||
@ -1335,10 +1357,16 @@ bool ZoneDatabase::DeleteCharacterDisc(uint32 character_id, uint32 slot_id){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::DeleteCharacterBandolier(uint32 character_id, uint32 band_id){
|
bool ZoneDatabase::DeleteCharacterBandolier(uint32 character_id, uint32 bandolier_id)
|
||||||
std::string query = StringFormat("DELETE FROM `character_bandolier` WHERE `bandolier_id` = %u AND `id` = %u", band_id, character_id);
|
{
|
||||||
QueryDatabase(query);
|
return CharacterBandolierRepository::DeleteWhere(
|
||||||
return true;
|
*this,
|
||||||
|
fmt::format(
|
||||||
|
"`id` = {} AND `bandolier_id` = {}",
|
||||||
|
character_id,
|
||||||
|
bandolier_id
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::DeleteCharacterLeadershipAbilities(uint32 character_id)
|
bool ZoneDatabase::DeleteCharacterLeadershipAbilities(uint32 character_id)
|
||||||
|
|||||||
@ -423,7 +423,7 @@ public:
|
|||||||
void DeleteItemRecast(uint32 char_id, uint32 recast_type);
|
void DeleteItemRecast(uint32 char_id, uint32 recast_type);
|
||||||
|
|
||||||
bool DeleteCharacterAAs(uint32 character_id);
|
bool DeleteCharacterAAs(uint32 character_id);
|
||||||
bool DeleteCharacterBandolier(uint32 character_id, uint32 band_id);
|
bool DeleteCharacterBandolier(uint32 character_id, uint32 bandolier_id);
|
||||||
bool DeleteCharacterDisc(uint32 character_id, uint32 slot_id);
|
bool DeleteCharacterDisc(uint32 character_id, uint32 slot_id);
|
||||||
bool DeleteCharacterMaterialColor(uint32 character_id);
|
bool DeleteCharacterMaterialColor(uint32 character_id);
|
||||||
bool DeleteCharacterLeadershipAbilities(uint32 character_id);
|
bool DeleteCharacterLeadershipAbilities(uint32 character_id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user