[Pets] Convert Load/Save of Pet Info to Repositories (#3853)

* [Pets] Convert Save/Load of Pet Info to Repositories

- Convert `LoadPetInfo` to repositories.
- `SavePetInfo` already used repositories, cleanup logic.

* Update repositories.

* Update zonedb.cpp
This commit is contained in:
Alex King
2024-01-07 00:59:02 -05:00
committed by GitHub
parent 1227f35382
commit f3de3e8c31
6 changed files with 393 additions and 158 deletions
+10
View File
@@ -716,6 +716,16 @@ namespace Language {
constexpr uint8 MaxValue = 100;
}
namespace PetInfoType {
constexpr int Current = 0;
constexpr int Suspended = 1;
}
namespace BuffEffectType {
constexpr uint8 None = 0;
constexpr uint8 Buff = 2;
constexpr uint8 InverseBuff = 4;
}
typedef enum {
FilterNone = 0,
@@ -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_PET_BUFFS_REPOSITORY_H
@@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseCharacterPetBuffsRepository {
public:
struct CharacterPetBuffs {
@@ -144,8 +145,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
character_pet_buffs_id
)
);
@@ -418,6 +420,82 @@ 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 CharacterPetBuffs &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.pet));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.spell_id));
v.push_back(std::to_string(e.caster_level));
v.push_back("'" + Strings::Escape(e.castername) + "'");
v.push_back(std::to_string(e.ticsremaining));
v.push_back(std::to_string(e.counters));
v.push_back(std::to_string(e.numhits));
v.push_back(std::to_string(e.rune));
v.push_back(std::to_string(e.instrument_mod));
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<CharacterPetBuffs> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.pet));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.spell_id));
v.push_back(std::to_string(e.caster_level));
v.push_back("'" + Strings::Escape(e.castername) + "'");
v.push_back(std::to_string(e.ticsremaining));
v.push_back(std::to_string(e.counters));
v.push_back(std::to_string(e.numhits));
v.push_back(std::to_string(e.rune));
v.push_back(std::to_string(e.instrument_mod));
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_PET_BUFFS_REPOSITORY_H
@@ -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_PET_INFO_REPOSITORY_H
@@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseCharacterPetInfoRepository {
public:
struct CharacterPetInfo {
@@ -136,8 +137,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
character_pet_info_id
)
);
@@ -398,6 +400,78 @@ 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 CharacterPetInfo &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.pet));
v.push_back("'" + Strings::Escape(e.petname) + "'");
v.push_back(std::to_string(e.petpower));
v.push_back(std::to_string(e.spell_id));
v.push_back(std::to_string(e.hp));
v.push_back(std::to_string(e.mana));
v.push_back(std::to_string(e.size));
v.push_back(std::to_string(e.taunting));
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<CharacterPetInfo> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.pet));
v.push_back("'" + Strings::Escape(e.petname) + "'");
v.push_back(std::to_string(e.petpower));
v.push_back(std::to_string(e.spell_id));
v.push_back(std::to_string(e.hp));
v.push_back(std::to_string(e.mana));
v.push_back(std::to_string(e.size));
v.push_back(std::to_string(e.taunting));
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_PET_INFO_REPOSITORY_H
@@ -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_PET_INVENTORY_REPOSITORY_H
@@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseCharacterPetInventoryRepository {
public:
struct CharacterPetInventory {
@@ -116,8 +117,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
character_pet_inventory_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 CharacterPetInventory &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.pet));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.item_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<CharacterPetInventory> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.pet));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.item_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_PET_INVENTORY_REPOSITORY_H