mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-16 05:11:29 +00:00
[Character] Convert Delete/Save of Character Memmed Spells to Repositories (#3841)
* [Character] Convert Delete/Save of Memmed Spells to Repositories - Converts `DeleteCharacterMemorizedSpell` and `LoadCharacterMemmedSpells` to repositories. * Update zonedb.cpp * Update zonedb.cpp
This commit is contained in:
parent
05f09b56e6
commit
bc4bebb4a9
@ -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_MEMMED_SPELLS_REPOSITORY_H
|
#ifndef EQEMU_BASE_CHARACTER_MEMMED_SPELLS_REPOSITORY_H
|
||||||
@ -16,6 +16,7 @@
|
|||||||
#include "../../strings.h"
|
#include "../../strings.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
|
|
||||||
class BaseCharacterMemmedSpellsRepository {
|
class BaseCharacterMemmedSpellsRepository {
|
||||||
public:
|
public:
|
||||||
struct CharacterMemmedSpells {
|
struct CharacterMemmedSpells {
|
||||||
@ -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_memmed_spells_id
|
character_memmed_spells_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 CharacterMemmedSpells &e
|
||||||
|
)
|
||||||
|
{
|
||||||
|
std::vector<std::string> v;
|
||||||
|
|
||||||
|
v.push_back(std::to_string(e.id));
|
||||||
|
v.push_back(std::to_string(e.slot_id));
|
||||||
|
v.push_back(std::to_string(e.spell_id));
|
||||||
|
|
||||||
|
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<CharacterMemmedSpells> &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_id));
|
||||||
|
v.push_back(std::to_string(e.spell_id));
|
||||||
|
|
||||||
|
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_MEMMED_SPELLS_REPOSITORY_H
|
#endif //EQEMU_BASE_CHARACTER_MEMMED_SPELLS_REPOSITORY_H
|
||||||
|
|||||||
@ -5602,7 +5602,7 @@ void Client::UnmemSpell(int slot, bool update_client)
|
|||||||
|
|
||||||
LogSpells("Spell [{}] forgotten from slot [{}]", m_pp.mem_spells[slot], slot);
|
LogSpells("Spell [{}] forgotten from slot [{}]", m_pp.mem_spells[slot], slot);
|
||||||
|
|
||||||
database.DeleteCharacterMemorizedSpell(CharacterID(), m_pp.mem_spells[slot], slot);
|
database.DeleteCharacterMemorizedSpell(CharacterID(), slot);
|
||||||
|
|
||||||
if (update_client) {
|
if (update_client) {
|
||||||
MemorizeSpell(slot, m_pp.mem_spells[slot], memSpellForget);
|
MemorizeSpell(slot, m_pp.mem_spells[slot], memSpellForget);
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "../common/repositories/spawn2_disabled_repository.h"
|
#include "../common/repositories/spawn2_disabled_repository.h"
|
||||||
#include "../common/repositories/character_leadership_abilities_repository.h"
|
#include "../common/repositories/character_leadership_abilities_repository.h"
|
||||||
#include "../common/repositories/character_material_repository.h"
|
#include "../common/repositories/character_material_repository.h"
|
||||||
|
#include "../common/repositories/character_memmed_spells_repository.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -658,26 +659,26 @@ bool ZoneDatabase::LoadCharacterFactionValues(uint32 character_id, faction_map &
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::LoadCharacterMemmedSpells(uint32 character_id, PlayerProfile_Struct* pp){
|
bool ZoneDatabase::LoadCharacterMemmedSpells(uint32 character_id, PlayerProfile_Struct* pp)
|
||||||
std::string query = StringFormat(
|
{
|
||||||
"SELECT "
|
const auto& l = CharacterMemmedSpellsRepository::GetWhere(
|
||||||
"slot_id, "
|
database,
|
||||||
"`spell_id` "
|
fmt::format(
|
||||||
"FROM "
|
"`id` = {} ORDER BY `slot_id`",
|
||||||
"`character_memmed_spells` "
|
character_id
|
||||||
"WHERE `id` = %u ORDER BY `slot_id`", character_id);
|
)
|
||||||
auto results = database.QueryDatabase(query);
|
);
|
||||||
int i = 0;
|
|
||||||
/* Initialize Spells */
|
for (int i = 0; i < EQ::spells::SPELL_GEM_COUNT; i++) { // Initialize Spells
|
||||||
for (i = 0; i < EQ::spells::SPELL_GEM_COUNT; i++){
|
pp->mem_spells[i] = UINT32_MAX;
|
||||||
pp->mem_spells[i] = 0xFFFFFFFF;
|
|
||||||
}
|
}
|
||||||
for (auto& row = results.begin(); row != results.end(); ++row) {
|
|
||||||
i = Strings::ToInt(row[0]);
|
for (const auto& e : l) {
|
||||||
if (i < EQ::spells::SPELL_GEM_COUNT && Strings::ToInt(row[1]) <= SPDAT_RECORDS){
|
if (e.slot_id < EQ::spells::SPELL_GEM_COUNT && IsValidSpell(e.spell_id)) {
|
||||||
pp->mem_spells[i] = Strings::ToInt(row[1]);
|
pp->mem_spells[e.slot_id] = e.spell_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1267,10 +1268,18 @@ bool ZoneDatabase::SaveCharacterAA(uint32 character_id, uint32 aa_id, uint32 cur
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::SaveCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){
|
bool ZoneDatabase::SaveCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){
|
||||||
if (spell_id > SPDAT_RECORDS){ return false; }
|
if (!IsValidSpell(spell_id)) {
|
||||||
std::string query = StringFormat("REPLACE INTO `character_memmed_spells` (id, slot_id, spell_id) VALUES (%u, %u, %u)", character_id, slot_id, spell_id);
|
return false;
|
||||||
QueryDatabase(query);
|
}
|
||||||
return true;
|
|
||||||
|
return CharacterMemmedSpellsRepository::ReplaceOne(
|
||||||
|
*this,
|
||||||
|
CharacterMemmedSpellsRepository::CharacterMemmedSpells{
|
||||||
|
.id = character_id,
|
||||||
|
.slot_id = static_cast<uint16_t>(slot_id),
|
||||||
|
.spell_id = static_cast<uint16_t>(spell_id)
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::SaveCharacterSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){
|
bool ZoneDatabase::SaveCharacterSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){
|
||||||
@ -1314,10 +1323,16 @@ bool ZoneDatabase::DeleteCharacterMaterialColor(uint32 character_id)
|
|||||||
return CharacterMaterialRepository::DeleteOne(*this, character_id);
|
return CharacterMaterialRepository::DeleteOne(*this, character_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::DeleteCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){
|
bool ZoneDatabase::DeleteCharacterMemorizedSpell(uint32 character_id, uint32 slot_id)
|
||||||
std::string query = StringFormat("DELETE FROM `character_memmed_spells` WHERE `slot_id` = %u AND `id` = %u", slot_id, character_id);
|
{
|
||||||
QueryDatabase(query);
|
return CharacterMemmedSpellsRepository::DeleteWhere(
|
||||||
return true;
|
*this,
|
||||||
|
fmt::format(
|
||||||
|
"`id` = {} AND `slot_id` = {}",
|
||||||
|
character_id,
|
||||||
|
slot_id
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::NoRentExpired(const char* name){
|
bool ZoneDatabase::NoRentExpired(const char* name){
|
||||||
|
|||||||
@ -427,7 +427,7 @@ public:
|
|||||||
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);
|
||||||
bool DeleteCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id);
|
bool DeleteCharacterMemorizedSpell(uint32 character_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);
|
||||||
|
|
||||||
bool LoadCharacterBandolier(uint32 character_id, PlayerProfile_Struct* pp);
|
bool LoadCharacterBandolier(uint32 character_id, PlayerProfile_Struct* pp);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user