[Character] Convert Delete/Load/Save of Character Material to Repositories (#3846)

* [Character] Convert Delete/Load/Save of Character Material to Repositories

- Convert `DeleteCharacterMaterialColor`, `LoadCharacterMaterialColor`, and `SaveCharacterMaterialColor` to repositories.

* Cleanup
This commit is contained in:
Alex King 2024-01-07 00:03:54 -05:00 committed by GitHub
parent a5d9a8596a
commit c1e984dfc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 112 additions and 26 deletions

View File

@ -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_MATERIAL_REPOSITORY_H
@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseCharacterMaterialRepository {
public:
struct CharacterMaterial {
@ -128,8 +129,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
character_material_id
)
);
@ -377,6 +379,74 @@ 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 CharacterMaterial &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.blue));
v.push_back(std::to_string(e.green));
v.push_back(std::to_string(e.red));
v.push_back(std::to_string(e.use_tint));
v.push_back(std::to_string(e.color));
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<CharacterMaterial> &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.blue));
v.push_back(std::to_string(e.green));
v.push_back(std::to_string(e.red));
v.push_back(std::to_string(e.use_tint));
v.push_back(std::to_string(e.color));
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_MATERIAL_REPOSITORY_H

View File

@ -11261,7 +11261,7 @@ void Client::Undye()
SendWearChange(slot);
}
database.DeleteCharacterDye(CharacterID());
database.DeleteCharacterMaterialColor(CharacterID());
}
void Client::SetTrackingID(uint32 entity_id)

View File

@ -24,6 +24,7 @@
#include "../common/repositories/criteria/content_filter_criteria.h"
#include "../common/repositories/spawn2_disabled_repository.h"
#include "../common/repositories/character_leadership_abilities_repository.h"
#include "../common/repositories/character_material_repository.h"
#include <ctime>
#include <iostream>
@ -940,17 +941,23 @@ bool ZoneDatabase::LoadCharacterCurrency(uint32 character_id, PlayerProfile_Stru
return true;
}
bool ZoneDatabase::LoadCharacterMaterialColor(uint32 character_id, PlayerProfile_Struct* pp){
std::string query = StringFormat("SELECT slot, blue, green, red, use_tint, color FROM `character_material` WHERE `id` = %u LIMIT 9", character_id);
auto results = database.QueryDatabase(query); int i = 0; int r = 0;
for (auto& row = results.begin(); row != results.end(); ++row) {
r = 0;
i = Strings::ToInt(row[r]); /* Slot */ r++;
pp->item_tint.Slot[i].Blue = Strings::ToInt(row[r]); r++;
pp->item_tint.Slot[i].Green = Strings::ToInt(row[r]); r++;
pp->item_tint.Slot[i].Red = Strings::ToInt(row[r]); r++;
pp->item_tint.Slot[i].UseTint = Strings::ToInt(row[r]);
bool ZoneDatabase::LoadCharacterMaterialColor(uint32 character_id, PlayerProfile_Struct* pp)
{
const auto& l = CharacterMaterialRepository::GetWhere(
database,
fmt::format(
"`id` = {} LIMIT 9",
character_id
)
);
for (const auto& e : l) {
pp->item_tint.Slot[e.slot].Blue = e.blue;
pp->item_tint.Slot[e.slot].Green = e.green;
pp->item_tint.Slot[e.slot].Red = e.red;
pp->item_tint.Slot[e.slot].UseTint = e.use_tint;
}
return true;
}
@ -1068,14 +1075,24 @@ bool ZoneDatabase::SaveCharacterLanguage(uint32 character_id, uint32 lang_id, ui
return true;
}
bool ZoneDatabase::SaveCharacterMaterialColor(uint32 character_id, uint32 slot_id, uint32 color){
uint8 red = (color & 0x00FF0000) >> 16;
uint8 green = (color & 0x0000FF00) >> 8;
uint8 blue = (color & 0x000000FF);
bool ZoneDatabase::SaveCharacterMaterialColor(uint32 character_id, uint8 slot_id, uint32 color)
{
const uint8 red = (color & 0x00FF0000) >> 16;
const uint8 green = (color & 0x0000FF00) >> 8;
const uint8 blue = (color & 0x000000FF);
std::string query = StringFormat("REPLACE INTO `character_material` (id, slot, red, green, blue, color, use_tint) VALUES (%u, %u, %u, %u, %u, %u, 255)", character_id, slot_id, red, green, blue, color); auto results = QueryDatabase(query);
LogDebug("ZoneDatabase::SaveCharacterMaterialColor for character ID: [{}], slot_id: [{}] color: [{}] done", character_id, slot_id, color);
return true;
return CharacterMaterialRepository::ReplaceOne(
*this,
CharacterMaterialRepository::CharacterMaterial{
.id = character_id,
.slot = slot_id,
.blue = blue,
.green = green,
.red = red,
.use_tint = UINT8_MAX,
.color = color
}
);
}
bool ZoneDatabase::SaveCharacterSkill(uint32 character_id, uint32 skill_id, uint32 value){
@ -1569,10 +1586,9 @@ bool ZoneDatabase::DeleteCharacterAAs(uint32 character_id){
return true;
}
bool ZoneDatabase::DeleteCharacterDye(uint32 character_id){
std::string query = StringFormat("DELETE FROM `character_material` WHERE `id` = %u", character_id);
QueryDatabase(query);
return true;
bool ZoneDatabase::DeleteCharacterMaterialColor(uint32 character_id)
{
return CharacterMaterialRepository::DeleteOne(*this, character_id);
}
bool ZoneDatabase::DeleteCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id){

View File

@ -425,7 +425,7 @@ public:
bool DeleteCharacterAAs(uint32 character_id);
bool DeleteCharacterBandolier(uint32 character_id, uint32 band_id);
bool DeleteCharacterDisc(uint32 character_id, uint32 slot_id);
bool DeleteCharacterDye(uint32 character_id);
bool DeleteCharacterMaterialColor(uint32 character_id);
bool DeleteCharacterLeadershipAbilities(uint32 character_id);
bool DeleteCharacterMemorizedSpell(uint32 character_id, uint32 spell_id, uint32 slot_id);
bool DeleteCharacterSpell(uint32 character_id, uint32 spell_id, uint32 slot_id);
@ -451,7 +451,7 @@ public:
bool SaveCharacterDisc(uint32 character_id, uint32 slot_id, uint32 disc_id);
bool SaveCharacterLanguage(uint32 character_id, uint32 lang_id, uint32 value);
bool SaveCharacterLeadershipAbilities(uint32 character_id, PlayerProfile_Struct* pp);
bool SaveCharacterMaterialColor(uint32 character_id, uint32 slot_id, uint32 color);
bool SaveCharacterMaterialColor(uint32 character_id, uint8 slot_id, uint32 color);
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 SaveCharacterSkill(uint32 character_id, uint32 skill_id, uint32 value);