mirror of
https://github.com/EQEmu/Server.git
synced 2026-02-22 06:22:28 +00:00
[Character] Convert Load/Save of Character Potion Belt to Repositories (#3844)
* [Character] Convert Load/Save of Character Potion Belt to Repositories - Converts `LoadCharacterPotionBelt` and `SaveCharacterPotionBelt` to repositories. * Update zonedb.cpp * Update zonedb.cpp
This commit is contained in:
parent
9d48cbcd29
commit
f8de9b9167
@ -6,7 +6,7 @@
|
||||
* Any modifications to base repositories are to be made by the generator only
|
||||
*
|
||||
* @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_POTIONBELT_REPOSITORY_H
|
||||
@ -16,6 +16,7 @@
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseCharacterPotionbeltRepository {
|
||||
public:
|
||||
struct CharacterPotionbelt {
|
||||
@ -116,8 +117,9 @@ public:
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
character_potionbelt_id
|
||||
)
|
||||
);
|
||||
@ -348,6 +350,68 @@ public:
|
||||
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 CharacterPotionbelt &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.potion_id));
|
||||
v.push_back(std::to_string(e.item_id));
|
||||
v.push_back(std::to_string(e.icon));
|
||||
|
||||
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<CharacterPotionbelt> &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.potion_id));
|
||||
v.push_back(std::to_string(e.item_id));
|
||||
v.push_back(std::to_string(e.icon));
|
||||
|
||||
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_POTIONBELT_REPOSITORY_H
|
||||
|
||||
@ -1268,7 +1268,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app)
|
||||
database.LoadCharacterBandolier(cid, &m_pp); /* Load Character Bandolier */
|
||||
database.LoadCharacterBindPoint(cid, &m_pp); /* Load Character Bind */
|
||||
database.LoadCharacterMaterialColor(cid, &m_pp); /* Load Character Material */
|
||||
database.LoadCharacterPotions(cid, &m_pp); /* Load Character Potion Belt */
|
||||
database.LoadCharacterPotionBelt(cid, &m_pp); /* Load Character Potion Belt */
|
||||
database.LoadCharacterCurrency(cid, &m_pp); /* Load Character Currency into PP */
|
||||
database.LoadCharacterData(cid, &m_pp, &m_epp); /* Load Character Data from DB into PP as well as E_PP */
|
||||
database.LoadCharacterSkills(cid, &m_pp); /* Load Character Skills */
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "../common/repositories/character_memmed_spells_repository.h"
|
||||
#include "../common/repositories/character_spells_repository.h"
|
||||
#include "../common/repositories/character_skills_repository.h"
|
||||
#include "../common/repositories/character_potionbelt_repository.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
@ -926,27 +927,33 @@ void ZoneDatabase::LoadCharacterTribute(Client* c){
|
||||
}
|
||||
}
|
||||
|
||||
bool ZoneDatabase::LoadCharacterPotions(uint32 character_id, PlayerProfile_Struct *pp)
|
||||
bool ZoneDatabase::LoadCharacterPotionBelt(uint32 character_id, PlayerProfile_Struct *pp)
|
||||
{
|
||||
std::string query =
|
||||
StringFormat("SELECT `potion_id`, `item_id`, `icon` FROM `character_potionbelt` WHERE `id` = %u LIMIT %u",
|
||||
character_id, EQ::profile::POTION_BELT_SIZE);
|
||||
auto results = database.QueryDatabase(query);
|
||||
int i = 0;
|
||||
for (i = 0; i < EQ::profile::POTION_BELT_SIZE; i++) {
|
||||
const auto& l = CharacterPotionbeltRepository::GetWhere(
|
||||
database,
|
||||
fmt::format(
|
||||
"`id` = {} LIMIT {}",
|
||||
character_id,
|
||||
EQ::profile::POTION_BELT_SIZE
|
||||
)
|
||||
);
|
||||
|
||||
for (int i = 0; i < EQ::profile::POTION_BELT_SIZE; i++) { // Initialize Potion Belt
|
||||
pp->potionbelt.Items[i].Icon = 0;
|
||||
pp->potionbelt.Items[i].ID = 0;
|
||||
pp->potionbelt.Items[i].ID = 0;
|
||||
pp->potionbelt.Items[i].Name[0] = '\0';
|
||||
}
|
||||
|
||||
for (auto& row = results.begin(); row != results.end(); ++row) {
|
||||
i = Strings::ToInt(row[0]);
|
||||
const EQ::ItemData *item_data = database.GetItem(Strings::ToInt(row[1]));
|
||||
if (!item_data)
|
||||
for (const auto& e : l) {
|
||||
const auto* item_data = database.GetItem(e.item_id);
|
||||
if (!item_data) {
|
||||
continue;
|
||||
pp->potionbelt.Items[i].ID = item_data->ID;
|
||||
pp->potionbelt.Items[i].Icon = Strings::ToInt(row[2]);
|
||||
strncpy(pp->potionbelt.Items[i].Name, item_data->Name, 64);
|
||||
}
|
||||
|
||||
pp->potionbelt.Items[e.potion_id].ID = item_data->ID;
|
||||
pp->potionbelt.Items[e.potion_id].Icon = e.icon;
|
||||
|
||||
strncpy(pp->potionbelt.Items[e.potion_id].Name, item_data->Name, 64);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -1066,9 +1073,15 @@ bool ZoneDatabase::SaveCharacterBandolier(uint32 character_id, uint8 bandolier_i
|
||||
|
||||
bool ZoneDatabase::SaveCharacterPotionBelt(uint32 character_id, uint8 potion_id, uint32 item_id, uint32 icon)
|
||||
{
|
||||
std::string query = StringFormat("REPLACE INTO `character_potionbelt` (id, potion_id, item_id, icon) VALUES (%u, %u, %u, %u)", character_id, potion_id, item_id, icon);
|
||||
auto results = QueryDatabase(query);
|
||||
return true;
|
||||
return CharacterPotionbeltRepository::ReplaceOne(
|
||||
*this,
|
||||
CharacterPotionbeltRepository::CharacterPotionbelt{
|
||||
.id = character_id,
|
||||
.potion_id = potion_id,
|
||||
.item_id = item_id,
|
||||
.icon = icon
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool ZoneDatabase::SaveCharacterLeadershipAbilities(uint32 character_id, PlayerProfile_Struct* pp)
|
||||
|
||||
@ -440,7 +440,7 @@ public:
|
||||
bool LoadCharacterLeadershipAbilities(uint32 character_id, PlayerProfile_Struct* pp);
|
||||
bool LoadCharacterMaterialColor(uint32 character_id, PlayerProfile_Struct* pp);
|
||||
bool LoadCharacterMemmedSpells(uint32 character_id, PlayerProfile_Struct* pp);
|
||||
bool LoadCharacterPotions(uint32 character_id, PlayerProfile_Struct* pp);
|
||||
bool LoadCharacterPotionBelt(uint32 character_id, PlayerProfile_Struct* pp);
|
||||
bool LoadCharacterSkills(uint32 character_id, PlayerProfile_Struct* pp);
|
||||
bool LoadCharacterSpellBook(uint32 character_id, PlayerProfile_Struct* pp);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user