diff --git a/common/repositories/base/base_bot_buffs_repository.h b/common/repositories/base/base_bot_buffs_repository.h new file mode 100644 index 000000000..729f4363c --- /dev/null +++ b/common/repositories/base/base_bot_buffs_repository.h @@ -0,0 +1,512 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_BUFFS_REPOSITORY_H +#define EQEMU_BASE_BOT_BUFFS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotBuffsRepository { +public: + struct BotBuffs { + uint32_t buffs_index; + uint32_t bot_id; + uint32_t spell_id; + uint8_t caster_level; + uint32_t duration_formula; + uint32_t tics_remaining; + uint32_t poison_counters; + uint32_t disease_counters; + uint32_t curse_counters; + uint32_t corruption_counters; + uint32_t numhits; + uint32_t melee_rune; + uint32_t magic_rune; + uint32_t dot_rune; + int8_t persistent; + int32_t caston_x; + int32_t caston_y; + int32_t caston_z; + uint32_t extra_di_chance; + int32_t instrument_mod; + }; + + static std::string PrimaryKey() + { + return std::string("buffs_index"); + } + + static std::vector Columns() + { + return { + "buffs_index", + "bot_id", + "spell_id", + "caster_level", + "duration_formula", + "tics_remaining", + "poison_counters", + "disease_counters", + "curse_counters", + "corruption_counters", + "numhits", + "melee_rune", + "magic_rune", + "dot_rune", + "persistent", + "caston_x", + "caston_y", + "caston_z", + "extra_di_chance", + "instrument_mod", + }; + } + + static std::vector SelectColumns() + { + return { + "buffs_index", + "bot_id", + "spell_id", + "caster_level", + "duration_formula", + "tics_remaining", + "poison_counters", + "disease_counters", + "curse_counters", + "corruption_counters", + "numhits", + "melee_rune", + "magic_rune", + "dot_rune", + "persistent", + "caston_x", + "caston_y", + "caston_z", + "extra_di_chance", + "instrument_mod", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_buffs"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotBuffs NewEntity() + { + BotBuffs e{}; + + e.buffs_index = 0; + e.bot_id = 0; + e.spell_id = 0; + e.caster_level = 0; + e.duration_formula = 0; + e.tics_remaining = 0; + e.poison_counters = 0; + e.disease_counters = 0; + e.curse_counters = 0; + e.corruption_counters = 0; + e.numhits = 0; + e.melee_rune = 0; + e.magic_rune = 0; + e.dot_rune = 0; + e.persistent = 0; + e.caston_x = 0; + e.caston_y = 0; + e.caston_z = 0; + e.extra_di_chance = 0; + e.instrument_mod = 10; + + return e; + } + + static BotBuffs GetBotBuffs( + const std::vector &bot_buffss, + int bot_buffs_id + ) + { + for (auto &bot_buffs : bot_buffss) { + if (bot_buffs.buffs_index == bot_buffs_id) { + return bot_buffs; + } + } + + return NewEntity(); + } + + static BotBuffs FindOne( + Database& db, + int bot_buffs_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_buffs_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotBuffs e{}; + + e.buffs_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.duration_formula = static_cast(strtoul(row[4], nullptr, 10)); + e.tics_remaining = static_cast(strtoul(row[5], nullptr, 10)); + e.poison_counters = static_cast(strtoul(row[6], nullptr, 10)); + e.disease_counters = static_cast(strtoul(row[7], nullptr, 10)); + e.curse_counters = static_cast(strtoul(row[8], nullptr, 10)); + e.corruption_counters = static_cast(strtoul(row[9], nullptr, 10)); + e.numhits = static_cast(strtoul(row[10], nullptr, 10)); + e.melee_rune = static_cast(strtoul(row[11], nullptr, 10)); + e.magic_rune = static_cast(strtoul(row[12], nullptr, 10)); + e.dot_rune = static_cast(strtoul(row[13], nullptr, 10)); + e.persistent = static_cast(atoi(row[14])); + e.caston_x = static_cast(atoi(row[15])); + e.caston_y = static_cast(atoi(row[16])); + e.caston_z = static_cast(atoi(row[17])); + e.extra_di_chance = static_cast(strtoul(row[18], nullptr, 10)); + e.instrument_mod = static_cast(atoi(row[19])); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_buffs_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_buffs_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotBuffs &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[2] + " = " + std::to_string(e.spell_id)); + v.push_back(columns[3] + " = " + std::to_string(e.caster_level)); + v.push_back(columns[4] + " = " + std::to_string(e.duration_formula)); + v.push_back(columns[5] + " = " + std::to_string(e.tics_remaining)); + v.push_back(columns[6] + " = " + std::to_string(e.poison_counters)); + v.push_back(columns[7] + " = " + std::to_string(e.disease_counters)); + v.push_back(columns[8] + " = " + std::to_string(e.curse_counters)); + v.push_back(columns[9] + " = " + std::to_string(e.corruption_counters)); + v.push_back(columns[10] + " = " + std::to_string(e.numhits)); + v.push_back(columns[11] + " = " + std::to_string(e.melee_rune)); + v.push_back(columns[12] + " = " + std::to_string(e.magic_rune)); + v.push_back(columns[13] + " = " + std::to_string(e.dot_rune)); + v.push_back(columns[14] + " = " + std::to_string(e.persistent)); + v.push_back(columns[15] + " = " + std::to_string(e.caston_x)); + v.push_back(columns[16] + " = " + std::to_string(e.caston_y)); + v.push_back(columns[17] + " = " + std::to_string(e.caston_z)); + v.push_back(columns[18] + " = " + std::to_string(e.extra_di_chance)); + v.push_back(columns[19] + " = " + std::to_string(e.instrument_mod)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.buffs_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotBuffs InsertOne( + Database& db, + BotBuffs e + ) + { + std::vector v; + + v.push_back(std::to_string(e.buffs_index)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.caster_level)); + v.push_back(std::to_string(e.duration_formula)); + v.push_back(std::to_string(e.tics_remaining)); + v.push_back(std::to_string(e.poison_counters)); + v.push_back(std::to_string(e.disease_counters)); + v.push_back(std::to_string(e.curse_counters)); + v.push_back(std::to_string(e.corruption_counters)); + v.push_back(std::to_string(e.numhits)); + v.push_back(std::to_string(e.melee_rune)); + v.push_back(std::to_string(e.magic_rune)); + v.push_back(std::to_string(e.dot_rune)); + v.push_back(std::to_string(e.persistent)); + v.push_back(std::to_string(e.caston_x)); + v.push_back(std::to_string(e.caston_y)); + v.push_back(std::to_string(e.caston_z)); + v.push_back(std::to_string(e.extra_di_chance)); + v.push_back(std::to_string(e.instrument_mod)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.buffs_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.buffs_index)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.caster_level)); + v.push_back(std::to_string(e.duration_formula)); + v.push_back(std::to_string(e.tics_remaining)); + v.push_back(std::to_string(e.poison_counters)); + v.push_back(std::to_string(e.disease_counters)); + v.push_back(std::to_string(e.curse_counters)); + v.push_back(std::to_string(e.corruption_counters)); + v.push_back(std::to_string(e.numhits)); + v.push_back(std::to_string(e.melee_rune)); + v.push_back(std::to_string(e.magic_rune)); + v.push_back(std::to_string(e.dot_rune)); + v.push_back(std::to_string(e.persistent)); + v.push_back(std::to_string(e.caston_x)); + v.push_back(std::to_string(e.caston_y)); + v.push_back(std::to_string(e.caston_z)); + v.push_back(std::to_string(e.extra_di_chance)); + v.push_back(std::to_string(e.instrument_mod)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotBuffs e{}; + + e.buffs_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.duration_formula = static_cast(strtoul(row[4], nullptr, 10)); + e.tics_remaining = static_cast(strtoul(row[5], nullptr, 10)); + e.poison_counters = static_cast(strtoul(row[6], nullptr, 10)); + e.disease_counters = static_cast(strtoul(row[7], nullptr, 10)); + e.curse_counters = static_cast(strtoul(row[8], nullptr, 10)); + e.corruption_counters = static_cast(strtoul(row[9], nullptr, 10)); + e.numhits = static_cast(strtoul(row[10], nullptr, 10)); + e.melee_rune = static_cast(strtoul(row[11], nullptr, 10)); + e.magic_rune = static_cast(strtoul(row[12], nullptr, 10)); + e.dot_rune = static_cast(strtoul(row[13], nullptr, 10)); + e.persistent = static_cast(atoi(row[14])); + e.caston_x = static_cast(atoi(row[15])); + e.caston_y = static_cast(atoi(row[16])); + e.caston_z = static_cast(atoi(row[17])); + e.extra_di_chance = static_cast(strtoul(row[18], nullptr, 10)); + e.instrument_mod = static_cast(atoi(row[19])); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotBuffs e{}; + + e.buffs_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.duration_formula = static_cast(strtoul(row[4], nullptr, 10)); + e.tics_remaining = static_cast(strtoul(row[5], nullptr, 10)); + e.poison_counters = static_cast(strtoul(row[6], nullptr, 10)); + e.disease_counters = static_cast(strtoul(row[7], nullptr, 10)); + e.curse_counters = static_cast(strtoul(row[8], nullptr, 10)); + e.corruption_counters = static_cast(strtoul(row[9], nullptr, 10)); + e.numhits = static_cast(strtoul(row[10], nullptr, 10)); + e.melee_rune = static_cast(strtoul(row[11], nullptr, 10)); + e.magic_rune = static_cast(strtoul(row[12], nullptr, 10)); + e.dot_rune = static_cast(strtoul(row[13], nullptr, 10)); + e.persistent = static_cast(atoi(row[14])); + e.caston_x = static_cast(atoi(row[15])); + e.caston_y = static_cast(atoi(row[16])); + e.caston_z = static_cast(atoi(row[17])); + e.extra_di_chance = static_cast(strtoul(row[18], nullptr, 10)); + e.instrument_mod = static_cast(atoi(row[19])); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_BUFFS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_create_combinations_repository.h b/common/repositories/base/base_bot_create_combinations_repository.h new file mode 100644 index 000000000..1f096db5b --- /dev/null +++ b/common/repositories/base/base_bot_create_combinations_repository.h @@ -0,0 +1,333 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_CREATE_COMBINATIONS_REPOSITORY_H +#define EQEMU_BASE_BOT_CREATE_COMBINATIONS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotCreateCombinationsRepository { +public: + struct BotCreateCombinations { + uint32_t race; + uint32_t classes; + }; + + static std::string PrimaryKey() + { + return std::string("race"); + } + + static std::vector Columns() + { + return { + "race", + "classes", + }; + } + + static std::vector SelectColumns() + { + return { + "race", + "classes", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_create_combinations"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotCreateCombinations NewEntity() + { + BotCreateCombinations e{}; + + e.race = 0; + e.classes = 0; + + return e; + } + + static BotCreateCombinations GetBotCreateCombinations( + const std::vector &bot_create_combinationss, + int bot_create_combinations_id + ) + { + for (auto &bot_create_combinations : bot_create_combinationss) { + if (bot_create_combinations.race == bot_create_combinations_id) { + return bot_create_combinations; + } + } + + return NewEntity(); + } + + static BotCreateCombinations FindOne( + Database& db, + int bot_create_combinations_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_create_combinations_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotCreateCombinations e{}; + + e.race = static_cast(strtoul(row[0], nullptr, 10)); + e.classes = static_cast(strtoul(row[1], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_create_combinations_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_create_combinations_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotCreateCombinations &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[0] + " = " + std::to_string(e.race)); + v.push_back(columns[1] + " = " + std::to_string(e.classes)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.race + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotCreateCombinations InsertOne( + Database& db, + BotCreateCombinations e + ) + { + std::vector v; + + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.classes)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.race = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.classes)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotCreateCombinations e{}; + + e.race = static_cast(strtoul(row[0], nullptr, 10)); + e.classes = static_cast(strtoul(row[1], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotCreateCombinations e{}; + + e.race = static_cast(strtoul(row[0], nullptr, 10)); + e.classes = static_cast(strtoul(row[1], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_CREATE_COMBINATIONS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_data_repository.h b/common/repositories/base/base_bot_data_repository.h new file mode 100644 index 000000000..f51c467c5 --- /dev/null +++ b/common/repositories/base/base_bot_data_repository.h @@ -0,0 +1,792 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_DATA_REPOSITORY_H +#define EQEMU_BASE_BOT_DATA_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotDataRepository { +public: + struct BotData { + uint32_t bot_id; + uint32_t owner_id; + uint32_t spells_id; + std::string name; + std::string last_name; + std::string title; + std::string suffix; + int16_t zone_id; + int8_t gender; + int16_t race; + int8_t class_; + uint8_t level; + uint32_t deity; + uint32_t creation_day; + uint32_t last_spawn; + uint32_t time_spawned; + float size; + int32_t face; + int32_t hair_color; + int32_t hair_style; + int32_t beard; + int32_t beard_color; + int32_t eye_color_1; + int32_t eye_color_2; + int32_t drakkin_heritage; + int32_t drakkin_tattoo; + int32_t drakkin_details; + int16_t ac; + int32_t atk; + int32_t hp; + int32_t mana; + int32_t str; + int32_t sta; + int32_t cha; + int32_t dex; + int32_t int_; + int32_t agi; + int32_t wis; + int16_t fire; + int16_t cold; + int16_t magic; + int16_t poison; + int16_t disease; + int16_t corruption; + uint32_t show_helm; + uint32_t follow_distance; + uint8_t stop_melee_level; + int32_t expansion_bitmask; + }; + + static std::string PrimaryKey() + { + return std::string("bot_id"); + } + + static std::vector Columns() + { + return { + "bot_id", + "owner_id", + "spells_id", + "name", + "last_name", + "title", + "suffix", + "zone_id", + "gender", + "race", + "`class`", + "level", + "deity", + "creation_day", + "last_spawn", + "time_spawned", + "size", + "face", + "hair_color", + "hair_style", + "beard", + "beard_color", + "eye_color_1", + "eye_color_2", + "drakkin_heritage", + "drakkin_tattoo", + "drakkin_details", + "ac", + "atk", + "hp", + "mana", + "str", + "sta", + "cha", + "dex", + "`int`", + "agi", + "wis", + "fire", + "cold", + "magic", + "poison", + "disease", + "corruption", + "show_helm", + "follow_distance", + "stop_melee_level", + "expansion_bitmask", + }; + } + + static std::vector SelectColumns() + { + return { + "bot_id", + "owner_id", + "spells_id", + "name", + "last_name", + "title", + "suffix", + "zone_id", + "gender", + "race", + "`class`", + "level", + "deity", + "creation_day", + "last_spawn", + "time_spawned", + "size", + "face", + "hair_color", + "hair_style", + "beard", + "beard_color", + "eye_color_1", + "eye_color_2", + "drakkin_heritage", + "drakkin_tattoo", + "drakkin_details", + "ac", + "atk", + "hp", + "mana", + "str", + "sta", + "cha", + "dex", + "`int`", + "agi", + "wis", + "fire", + "cold", + "magic", + "poison", + "disease", + "corruption", + "show_helm", + "follow_distance", + "stop_melee_level", + "expansion_bitmask", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_data"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotData NewEntity() + { + BotData e{}; + + e.bot_id = 0; + e.owner_id = 0; + e.spells_id = 0; + e.name = ""; + e.last_name = ""; + e.title = ""; + e.suffix = ""; + e.zone_id = 0; + e.gender = 0; + e.race = 0; + e.class_ = 0; + e.level = 0; + e.deity = 0; + e.creation_day = 0; + e.last_spawn = 0; + e.time_spawned = 0; + e.size = 0; + e.face = 1; + e.hair_color = 1; + e.hair_style = 1; + e.beard = 0; + e.beard_color = 1; + e.eye_color_1 = 1; + e.eye_color_2 = 1; + e.drakkin_heritage = 0; + e.drakkin_tattoo = 0; + e.drakkin_details = 0; + e.ac = 0; + e.atk = 0; + e.hp = 0; + e.mana = 0; + e.str = 75; + e.sta = 75; + e.cha = 75; + e.dex = 75; + e.int_ = 75; + e.agi = 75; + e.wis = 75; + e.fire = 0; + e.cold = 0; + e.magic = 0; + e.poison = 0; + e.disease = 0; + e.corruption = 0; + e.show_helm = 0; + e.follow_distance = 200; + e.stop_melee_level = 255; + e.expansion_bitmask = -1; + + return e; + } + + static BotData GetBotData( + const std::vector &bot_datas, + int bot_data_id + ) + { + for (auto &bot_data : bot_datas) { + if (bot_data.bot_id == bot_data_id) { + return bot_data; + } + } + + return NewEntity(); + } + + static BotData FindOne( + Database& db, + int bot_data_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_data_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotData e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.owner_id = static_cast(strtoul(row[1], nullptr, 10)); + e.spells_id = static_cast(strtoul(row[2], nullptr, 10)); + e.name = row[3] ? row[3] : ""; + e.last_name = row[4] ? row[4] : ""; + e.title = row[5] ? row[5] : ""; + e.suffix = row[6] ? row[6] : ""; + e.zone_id = static_cast(atoi(row[7])); + e.gender = static_cast(atoi(row[8])); + e.race = static_cast(atoi(row[9])); + e.class_ = static_cast(atoi(row[10])); + e.level = static_cast(strtoul(row[11], nullptr, 10)); + e.deity = static_cast(strtoul(row[12], nullptr, 10)); + e.creation_day = static_cast(strtoul(row[13], nullptr, 10)); + e.last_spawn = static_cast(strtoul(row[14], nullptr, 10)); + e.time_spawned = static_cast(strtoul(row[15], nullptr, 10)); + e.size = strtof(row[16], nullptr); + e.face = static_cast(atoi(row[17])); + e.hair_color = static_cast(atoi(row[18])); + e.hair_style = static_cast(atoi(row[19])); + e.beard = static_cast(atoi(row[20])); + e.beard_color = static_cast(atoi(row[21])); + e.eye_color_1 = static_cast(atoi(row[22])); + e.eye_color_2 = static_cast(atoi(row[23])); + e.drakkin_heritage = static_cast(atoi(row[24])); + e.drakkin_tattoo = static_cast(atoi(row[25])); + e.drakkin_details = static_cast(atoi(row[26])); + e.ac = static_cast(atoi(row[27])); + e.atk = static_cast(atoi(row[28])); + e.hp = static_cast(atoi(row[29])); + e.mana = static_cast(atoi(row[30])); + e.str = static_cast(atoi(row[31])); + e.sta = static_cast(atoi(row[32])); + e.cha = static_cast(atoi(row[33])); + e.dex = static_cast(atoi(row[34])); + e.int_ = static_cast(atoi(row[35])); + e.agi = static_cast(atoi(row[36])); + e.wis = static_cast(atoi(row[37])); + e.fire = static_cast(atoi(row[38])); + e.cold = static_cast(atoi(row[39])); + e.magic = static_cast(atoi(row[40])); + e.poison = static_cast(atoi(row[41])); + e.disease = static_cast(atoi(row[42])); + e.corruption = static_cast(atoi(row[43])); + e.show_helm = static_cast(strtoul(row[44], nullptr, 10)); + e.follow_distance = static_cast(strtoul(row[45], nullptr, 10)); + e.stop_melee_level = static_cast(strtoul(row[46], nullptr, 10)); + e.expansion_bitmask = static_cast(atoi(row[47])); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_data_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_data_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotData &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.owner_id)); + v.push_back(columns[2] + " = " + std::to_string(e.spells_id)); + v.push_back(columns[3] + " = '" + Strings::Escape(e.name) + "'"); + v.push_back(columns[4] + " = '" + Strings::Escape(e.last_name) + "'"); + v.push_back(columns[5] + " = '" + Strings::Escape(e.title) + "'"); + v.push_back(columns[6] + " = '" + Strings::Escape(e.suffix) + "'"); + v.push_back(columns[7] + " = " + std::to_string(e.zone_id)); + v.push_back(columns[8] + " = " + std::to_string(e.gender)); + v.push_back(columns[9] + " = " + std::to_string(e.race)); + v.push_back(columns[10] + " = " + std::to_string(e.class_)); + v.push_back(columns[11] + " = " + std::to_string(e.level)); + v.push_back(columns[12] + " = " + std::to_string(e.deity)); + v.push_back(columns[13] + " = " + std::to_string(e.creation_day)); + v.push_back(columns[14] + " = " + std::to_string(e.last_spawn)); + v.push_back(columns[15] + " = " + std::to_string(e.time_spawned)); + v.push_back(columns[16] + " = " + std::to_string(e.size)); + v.push_back(columns[17] + " = " + std::to_string(e.face)); + v.push_back(columns[18] + " = " + std::to_string(e.hair_color)); + v.push_back(columns[19] + " = " + std::to_string(e.hair_style)); + v.push_back(columns[20] + " = " + std::to_string(e.beard)); + v.push_back(columns[21] + " = " + std::to_string(e.beard_color)); + v.push_back(columns[22] + " = " + std::to_string(e.eye_color_1)); + v.push_back(columns[23] + " = " + std::to_string(e.eye_color_2)); + v.push_back(columns[24] + " = " + std::to_string(e.drakkin_heritage)); + v.push_back(columns[25] + " = " + std::to_string(e.drakkin_tattoo)); + v.push_back(columns[26] + " = " + std::to_string(e.drakkin_details)); + v.push_back(columns[27] + " = " + std::to_string(e.ac)); + v.push_back(columns[28] + " = " + std::to_string(e.atk)); + v.push_back(columns[29] + " = " + std::to_string(e.hp)); + v.push_back(columns[30] + " = " + std::to_string(e.mana)); + v.push_back(columns[31] + " = " + std::to_string(e.str)); + v.push_back(columns[32] + " = " + std::to_string(e.sta)); + v.push_back(columns[33] + " = " + std::to_string(e.cha)); + v.push_back(columns[34] + " = " + std::to_string(e.dex)); + v.push_back(columns[35] + " = " + std::to_string(e.int_)); + v.push_back(columns[36] + " = " + std::to_string(e.agi)); + v.push_back(columns[37] + " = " + std::to_string(e.wis)); + v.push_back(columns[38] + " = " + std::to_string(e.fire)); + v.push_back(columns[39] + " = " + std::to_string(e.cold)); + v.push_back(columns[40] + " = " + std::to_string(e.magic)); + v.push_back(columns[41] + " = " + std::to_string(e.poison)); + v.push_back(columns[42] + " = " + std::to_string(e.disease)); + v.push_back(columns[43] + " = " + std::to_string(e.corruption)); + v.push_back(columns[44] + " = " + std::to_string(e.show_helm)); + v.push_back(columns[45] + " = " + std::to_string(e.follow_distance)); + v.push_back(columns[46] + " = " + std::to_string(e.stop_melee_level)); + v.push_back(columns[47] + " = " + std::to_string(e.expansion_bitmask)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.bot_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotData InsertOne( + Database& db, + BotData e + ) + { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.owner_id)); + v.push_back(std::to_string(e.spells_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.last_name) + "'"); + v.push_back("'" + Strings::Escape(e.title) + "'"); + v.push_back("'" + Strings::Escape(e.suffix) + "'"); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.creation_day)); + v.push_back(std::to_string(e.last_spawn)); + v.push_back(std::to_string(e.time_spawned)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.face)); + v.push_back(std::to_string(e.hair_color)); + v.push_back(std::to_string(e.hair_style)); + v.push_back(std::to_string(e.beard)); + v.push_back(std::to_string(e.beard_color)); + v.push_back(std::to_string(e.eye_color_1)); + v.push_back(std::to_string(e.eye_color_2)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.drakkin_tattoo)); + v.push_back(std::to_string(e.drakkin_details)); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.atk)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.str)); + v.push_back(std::to_string(e.sta)); + v.push_back(std::to_string(e.cha)); + v.push_back(std::to_string(e.dex)); + v.push_back(std::to_string(e.int_)); + v.push_back(std::to_string(e.agi)); + v.push_back(std::to_string(e.wis)); + v.push_back(std::to_string(e.fire)); + v.push_back(std::to_string(e.cold)); + v.push_back(std::to_string(e.magic)); + v.push_back(std::to_string(e.poison)); + v.push_back(std::to_string(e.disease)); + v.push_back(std::to_string(e.corruption)); + v.push_back(std::to_string(e.show_helm)); + v.push_back(std::to_string(e.follow_distance)); + v.push_back(std::to_string(e.stop_melee_level)); + v.push_back(std::to_string(e.expansion_bitmask)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.bot_id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.owner_id)); + v.push_back(std::to_string(e.spells_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.last_name) + "'"); + v.push_back("'" + Strings::Escape(e.title) + "'"); + v.push_back("'" + Strings::Escape(e.suffix) + "'"); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.creation_day)); + v.push_back(std::to_string(e.last_spawn)); + v.push_back(std::to_string(e.time_spawned)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.face)); + v.push_back(std::to_string(e.hair_color)); + v.push_back(std::to_string(e.hair_style)); + v.push_back(std::to_string(e.beard)); + v.push_back(std::to_string(e.beard_color)); + v.push_back(std::to_string(e.eye_color_1)); + v.push_back(std::to_string(e.eye_color_2)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.drakkin_tattoo)); + v.push_back(std::to_string(e.drakkin_details)); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.atk)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.str)); + v.push_back(std::to_string(e.sta)); + v.push_back(std::to_string(e.cha)); + v.push_back(std::to_string(e.dex)); + v.push_back(std::to_string(e.int_)); + v.push_back(std::to_string(e.agi)); + v.push_back(std::to_string(e.wis)); + v.push_back(std::to_string(e.fire)); + v.push_back(std::to_string(e.cold)); + v.push_back(std::to_string(e.magic)); + v.push_back(std::to_string(e.poison)); + v.push_back(std::to_string(e.disease)); + v.push_back(std::to_string(e.corruption)); + v.push_back(std::to_string(e.show_helm)); + v.push_back(std::to_string(e.follow_distance)); + v.push_back(std::to_string(e.stop_melee_level)); + v.push_back(std::to_string(e.expansion_bitmask)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotData e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.owner_id = static_cast(strtoul(row[1], nullptr, 10)); + e.spells_id = static_cast(strtoul(row[2], nullptr, 10)); + e.name = row[3] ? row[3] : ""; + e.last_name = row[4] ? row[4] : ""; + e.title = row[5] ? row[5] : ""; + e.suffix = row[6] ? row[6] : ""; + e.zone_id = static_cast(atoi(row[7])); + e.gender = static_cast(atoi(row[8])); + e.race = static_cast(atoi(row[9])); + e.class_ = static_cast(atoi(row[10])); + e.level = static_cast(strtoul(row[11], nullptr, 10)); + e.deity = static_cast(strtoul(row[12], nullptr, 10)); + e.creation_day = static_cast(strtoul(row[13], nullptr, 10)); + e.last_spawn = static_cast(strtoul(row[14], nullptr, 10)); + e.time_spawned = static_cast(strtoul(row[15], nullptr, 10)); + e.size = strtof(row[16], nullptr); + e.face = static_cast(atoi(row[17])); + e.hair_color = static_cast(atoi(row[18])); + e.hair_style = static_cast(atoi(row[19])); + e.beard = static_cast(atoi(row[20])); + e.beard_color = static_cast(atoi(row[21])); + e.eye_color_1 = static_cast(atoi(row[22])); + e.eye_color_2 = static_cast(atoi(row[23])); + e.drakkin_heritage = static_cast(atoi(row[24])); + e.drakkin_tattoo = static_cast(atoi(row[25])); + e.drakkin_details = static_cast(atoi(row[26])); + e.ac = static_cast(atoi(row[27])); + e.atk = static_cast(atoi(row[28])); + e.hp = static_cast(atoi(row[29])); + e.mana = static_cast(atoi(row[30])); + e.str = static_cast(atoi(row[31])); + e.sta = static_cast(atoi(row[32])); + e.cha = static_cast(atoi(row[33])); + e.dex = static_cast(atoi(row[34])); + e.int_ = static_cast(atoi(row[35])); + e.agi = static_cast(atoi(row[36])); + e.wis = static_cast(atoi(row[37])); + e.fire = static_cast(atoi(row[38])); + e.cold = static_cast(atoi(row[39])); + e.magic = static_cast(atoi(row[40])); + e.poison = static_cast(atoi(row[41])); + e.disease = static_cast(atoi(row[42])); + e.corruption = static_cast(atoi(row[43])); + e.show_helm = static_cast(strtoul(row[44], nullptr, 10)); + e.follow_distance = static_cast(strtoul(row[45], nullptr, 10)); + e.stop_melee_level = static_cast(strtoul(row[46], nullptr, 10)); + e.expansion_bitmask = static_cast(atoi(row[47])); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotData e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.owner_id = static_cast(strtoul(row[1], nullptr, 10)); + e.spells_id = static_cast(strtoul(row[2], nullptr, 10)); + e.name = row[3] ? row[3] : ""; + e.last_name = row[4] ? row[4] : ""; + e.title = row[5] ? row[5] : ""; + e.suffix = row[6] ? row[6] : ""; + e.zone_id = static_cast(atoi(row[7])); + e.gender = static_cast(atoi(row[8])); + e.race = static_cast(atoi(row[9])); + e.class_ = static_cast(atoi(row[10])); + e.level = static_cast(strtoul(row[11], nullptr, 10)); + e.deity = static_cast(strtoul(row[12], nullptr, 10)); + e.creation_day = static_cast(strtoul(row[13], nullptr, 10)); + e.last_spawn = static_cast(strtoul(row[14], nullptr, 10)); + e.time_spawned = static_cast(strtoul(row[15], nullptr, 10)); + e.size = strtof(row[16], nullptr); + e.face = static_cast(atoi(row[17])); + e.hair_color = static_cast(atoi(row[18])); + e.hair_style = static_cast(atoi(row[19])); + e.beard = static_cast(atoi(row[20])); + e.beard_color = static_cast(atoi(row[21])); + e.eye_color_1 = static_cast(atoi(row[22])); + e.eye_color_2 = static_cast(atoi(row[23])); + e.drakkin_heritage = static_cast(atoi(row[24])); + e.drakkin_tattoo = static_cast(atoi(row[25])); + e.drakkin_details = static_cast(atoi(row[26])); + e.ac = static_cast(atoi(row[27])); + e.atk = static_cast(atoi(row[28])); + e.hp = static_cast(atoi(row[29])); + e.mana = static_cast(atoi(row[30])); + e.str = static_cast(atoi(row[31])); + e.sta = static_cast(atoi(row[32])); + e.cha = static_cast(atoi(row[33])); + e.dex = static_cast(atoi(row[34])); + e.int_ = static_cast(atoi(row[35])); + e.agi = static_cast(atoi(row[36])); + e.wis = static_cast(atoi(row[37])); + e.fire = static_cast(atoi(row[38])); + e.cold = static_cast(atoi(row[39])); + e.magic = static_cast(atoi(row[40])); + e.poison = static_cast(atoi(row[41])); + e.disease = static_cast(atoi(row[42])); + e.corruption = static_cast(atoi(row[43])); + e.show_helm = static_cast(strtoul(row[44], nullptr, 10)); + e.follow_distance = static_cast(strtoul(row[45], nullptr, 10)); + e.stop_melee_level = static_cast(strtoul(row[46], nullptr, 10)); + e.expansion_bitmask = static_cast(atoi(row[47])); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_DATA_REPOSITORY_H diff --git a/common/repositories/base/base_bot_group_members_repository.h b/common/repositories/base/base_bot_group_members_repository.h new file mode 100644 index 000000000..2fbd9c0ca --- /dev/null +++ b/common/repositories/base/base_bot_group_members_repository.h @@ -0,0 +1,342 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_GROUP_MEMBERS_REPOSITORY_H +#define EQEMU_BASE_BOT_GROUP_MEMBERS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotGroupMembersRepository { +public: + struct BotGroupMembers { + uint32_t group_members_index; + uint32_t groups_index; + uint32_t bot_id; + }; + + static std::string PrimaryKey() + { + return std::string("group_members_index"); + } + + static std::vector Columns() + { + return { + "group_members_index", + "groups_index", + "bot_id", + }; + } + + static std::vector SelectColumns() + { + return { + "group_members_index", + "groups_index", + "bot_id", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_group_members"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotGroupMembers NewEntity() + { + BotGroupMembers e{}; + + e.group_members_index = 0; + e.groups_index = 0; + e.bot_id = 0; + + return e; + } + + static BotGroupMembers GetBotGroupMembers( + const std::vector &bot_group_memberss, + int bot_group_members_id + ) + { + for (auto &bot_group_members : bot_group_memberss) { + if (bot_group_members.group_members_index == bot_group_members_id) { + return bot_group_members; + } + } + + return NewEntity(); + } + + static BotGroupMembers FindOne( + Database& db, + int bot_group_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_group_members_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotGroupMembers e{}; + + e.group_members_index = static_cast(strtoul(row[0], nullptr, 10)); + e.groups_index = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_group_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_group_members_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotGroupMembers &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.groups_index)); + v.push_back(columns[2] + " = " + std::to_string(e.bot_id)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.group_members_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotGroupMembers InsertOne( + Database& db, + BotGroupMembers e + ) + { + std::vector v; + + v.push_back(std::to_string(e.group_members_index)); + v.push_back(std::to_string(e.groups_index)); + v.push_back(std::to_string(e.bot_id)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.group_members_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.group_members_index)); + v.push_back(std::to_string(e.groups_index)); + v.push_back(std::to_string(e.bot_id)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotGroupMembers e{}; + + e.group_members_index = static_cast(strtoul(row[0], nullptr, 10)); + e.groups_index = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotGroupMembers e{}; + + e.group_members_index = static_cast(strtoul(row[0], nullptr, 10)); + e.groups_index = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_GROUP_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_groups_repository.h b/common/repositories/base/base_bot_groups_repository.h new file mode 100644 index 000000000..ac86e329e --- /dev/null +++ b/common/repositories/base/base_bot_groups_repository.h @@ -0,0 +1,352 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_GROUPS_REPOSITORY_H +#define EQEMU_BASE_BOT_GROUPS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotGroupsRepository { +public: + struct BotGroups { + uint32_t groups_index; + uint32_t group_leader_id; + std::string group_name; + uint8_t auto_spawn; + }; + + static std::string PrimaryKey() + { + return std::string("groups_index"); + } + + static std::vector Columns() + { + return { + "groups_index", + "group_leader_id", + "group_name", + "auto_spawn", + }; + } + + static std::vector SelectColumns() + { + return { + "groups_index", + "group_leader_id", + "group_name", + "auto_spawn", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_groups"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotGroups NewEntity() + { + BotGroups e{}; + + e.groups_index = 0; + e.group_leader_id = 0; + e.group_name = ""; + e.auto_spawn = 0; + + return e; + } + + static BotGroups GetBotGroups( + const std::vector &bot_groupss, + int bot_groups_id + ) + { + for (auto &bot_groups : bot_groupss) { + if (bot_groups.groups_index == bot_groups_id) { + return bot_groups; + } + } + + return NewEntity(); + } + + static BotGroups FindOne( + Database& db, + int bot_groups_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_groups_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotGroups e{}; + + e.groups_index = static_cast(strtoul(row[0], nullptr, 10)); + e.group_leader_id = static_cast(strtoul(row[1], nullptr, 10)); + e.group_name = row[2] ? row[2] : ""; + e.auto_spawn = static_cast(strtoul(row[3], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_groups_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_groups_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotGroups &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.group_leader_id)); + v.push_back(columns[2] + " = '" + Strings::Escape(e.group_name) + "'"); + v.push_back(columns[3] + " = " + std::to_string(e.auto_spawn)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.groups_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotGroups InsertOne( + Database& db, + BotGroups e + ) + { + std::vector v; + + v.push_back(std::to_string(e.groups_index)); + v.push_back(std::to_string(e.group_leader_id)); + v.push_back("'" + Strings::Escape(e.group_name) + "'"); + v.push_back(std::to_string(e.auto_spawn)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.groups_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.groups_index)); + v.push_back(std::to_string(e.group_leader_id)); + v.push_back("'" + Strings::Escape(e.group_name) + "'"); + v.push_back(std::to_string(e.auto_spawn)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotGroups e{}; + + e.groups_index = static_cast(strtoul(row[0], nullptr, 10)); + e.group_leader_id = static_cast(strtoul(row[1], nullptr, 10)); + e.group_name = row[2] ? row[2] : ""; + e.auto_spawn = static_cast(strtoul(row[3], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotGroups e{}; + + e.groups_index = static_cast(strtoul(row[0], nullptr, 10)); + e.group_leader_id = static_cast(strtoul(row[1], nullptr, 10)); + e.group_name = row[2] ? row[2] : ""; + e.auto_spawn = static_cast(strtoul(row[3], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_GROUPS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_guild_members_repository.h b/common/repositories/base/base_bot_guild_members_repository.h new file mode 100644 index 000000000..162938274 --- /dev/null +++ b/common/repositories/base/base_bot_guild_members_repository.h @@ -0,0 +1,403 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_GUILD_MEMBERS_REPOSITORY_H +#define EQEMU_BASE_BOT_GUILD_MEMBERS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotGuildMembersRepository { +public: + struct BotGuildMembers { + int32_t bot_id; + uint32_t guild_id; + uint8_t rank; + uint8_t tribute_enable; + uint32_t total_tribute; + uint32_t last_tribute; + uint8_t banker; + std::string public_note; + uint8_t alt; + }; + + static std::string PrimaryKey() + { + return std::string("bot_id"); + } + + static std::vector Columns() + { + return { + "bot_id", + "guild_id", + "rank", + "tribute_enable", + "total_tribute", + "last_tribute", + "banker", + "public_note", + "alt", + }; + } + + static std::vector SelectColumns() + { + return { + "bot_id", + "guild_id", + "rank", + "tribute_enable", + "total_tribute", + "last_tribute", + "banker", + "public_note", + "alt", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_guild_members"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotGuildMembers NewEntity() + { + BotGuildMembers e{}; + + e.bot_id = 0; + e.guild_id = 0; + e.rank = 0; + e.tribute_enable = 0; + e.total_tribute = 0; + e.last_tribute = 0; + e.banker = 0; + e.public_note = ""; + e.alt = 0; + + return e; + } + + static BotGuildMembers GetBotGuildMembers( + const std::vector &bot_guild_memberss, + int bot_guild_members_id + ) + { + for (auto &bot_guild_members : bot_guild_memberss) { + if (bot_guild_members.bot_id == bot_guild_members_id) { + return bot_guild_members; + } + } + + return NewEntity(); + } + + static BotGuildMembers FindOne( + Database& db, + int bot_guild_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_guild_members_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotGuildMembers e{}; + + e.bot_id = static_cast(atoi(row[0])); + e.guild_id = static_cast(strtoul(row[1], nullptr, 10)); + e.rank = static_cast(strtoul(row[2], nullptr, 10)); + e.tribute_enable = static_cast(strtoul(row[3], nullptr, 10)); + e.total_tribute = static_cast(strtoul(row[4], nullptr, 10)); + e.last_tribute = static_cast(strtoul(row[5], nullptr, 10)); + e.banker = static_cast(strtoul(row[6], nullptr, 10)); + e.public_note = row[7] ? row[7] : ""; + e.alt = static_cast(strtoul(row[8], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_guild_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_guild_members_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotGuildMembers &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[0] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[1] + " = " + std::to_string(e.guild_id)); + v.push_back(columns[2] + " = " + std::to_string(e.rank)); + v.push_back(columns[3] + " = " + std::to_string(e.tribute_enable)); + v.push_back(columns[4] + " = " + std::to_string(e.total_tribute)); + v.push_back(columns[5] + " = " + std::to_string(e.last_tribute)); + v.push_back(columns[6] + " = " + std::to_string(e.banker)); + v.push_back(columns[7] + " = '" + Strings::Escape(e.public_note) + "'"); + v.push_back(columns[8] + " = " + std::to_string(e.alt)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.bot_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotGuildMembers InsertOne( + Database& db, + BotGuildMembers e + ) + { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.tribute_enable)); + v.push_back(std::to_string(e.total_tribute)); + v.push_back(std::to_string(e.last_tribute)); + v.push_back(std::to_string(e.banker)); + v.push_back("'" + Strings::Escape(e.public_note) + "'"); + v.push_back(std::to_string(e.alt)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.bot_id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.tribute_enable)); + v.push_back(std::to_string(e.total_tribute)); + v.push_back(std::to_string(e.last_tribute)); + v.push_back(std::to_string(e.banker)); + v.push_back("'" + Strings::Escape(e.public_note) + "'"); + v.push_back(std::to_string(e.alt)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotGuildMembers e{}; + + e.bot_id = static_cast(atoi(row[0])); + e.guild_id = static_cast(strtoul(row[1], nullptr, 10)); + e.rank = static_cast(strtoul(row[2], nullptr, 10)); + e.tribute_enable = static_cast(strtoul(row[3], nullptr, 10)); + e.total_tribute = static_cast(strtoul(row[4], nullptr, 10)); + e.last_tribute = static_cast(strtoul(row[5], nullptr, 10)); + e.banker = static_cast(strtoul(row[6], nullptr, 10)); + e.public_note = row[7] ? row[7] : ""; + e.alt = static_cast(strtoul(row[8], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotGuildMembers e{}; + + e.bot_id = static_cast(atoi(row[0])); + e.guild_id = static_cast(strtoul(row[1], nullptr, 10)); + e.rank = static_cast(strtoul(row[2], nullptr, 10)); + e.tribute_enable = static_cast(strtoul(row[3], nullptr, 10)); + e.total_tribute = static_cast(strtoul(row[4], nullptr, 10)); + e.last_tribute = static_cast(strtoul(row[5], nullptr, 10)); + e.banker = static_cast(strtoul(row[6], nullptr, 10)); + e.public_note = row[7] ? row[7] : ""; + e.alt = static_cast(strtoul(row[8], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_GUILD_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_heal_rotation_members_repository.h b/common/repositories/base/base_bot_heal_rotation_members_repository.h new file mode 100644 index 000000000..af89601d6 --- /dev/null +++ b/common/repositories/base/base_bot_heal_rotation_members_repository.h @@ -0,0 +1,342 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_HEAL_ROTATION_MEMBERS_REPOSITORY_H +#define EQEMU_BASE_BOT_HEAL_ROTATION_MEMBERS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotHealRotationMembersRepository { +public: + struct BotHealRotationMembers { + uint32_t member_index; + uint32_t heal_rotation_index; + uint32_t bot_id; + }; + + static std::string PrimaryKey() + { + return std::string("member_index"); + } + + static std::vector Columns() + { + return { + "member_index", + "heal_rotation_index", + "bot_id", + }; + } + + static std::vector SelectColumns() + { + return { + "member_index", + "heal_rotation_index", + "bot_id", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_heal_rotation_members"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotHealRotationMembers NewEntity() + { + BotHealRotationMembers e{}; + + e.member_index = 0; + e.heal_rotation_index = 0; + e.bot_id = 0; + + return e; + } + + static BotHealRotationMembers GetBotHealRotationMembers( + const std::vector &bot_heal_rotation_memberss, + int bot_heal_rotation_members_id + ) + { + for (auto &bot_heal_rotation_members : bot_heal_rotation_memberss) { + if (bot_heal_rotation_members.member_index == bot_heal_rotation_members_id) { + return bot_heal_rotation_members; + } + } + + return NewEntity(); + } + + static BotHealRotationMembers FindOne( + Database& db, + int bot_heal_rotation_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_heal_rotation_members_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotHealRotationMembers e{}; + + e.member_index = static_cast(strtoul(row[0], nullptr, 10)); + e.heal_rotation_index = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_heal_rotation_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_heal_rotation_members_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotHealRotationMembers &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.heal_rotation_index)); + v.push_back(columns[2] + " = " + std::to_string(e.bot_id)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.member_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotHealRotationMembers InsertOne( + Database& db, + BotHealRotationMembers e + ) + { + std::vector v; + + v.push_back(std::to_string(e.member_index)); + v.push_back(std::to_string(e.heal_rotation_index)); + v.push_back(std::to_string(e.bot_id)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.member_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.member_index)); + v.push_back(std::to_string(e.heal_rotation_index)); + v.push_back(std::to_string(e.bot_id)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotHealRotationMembers e{}; + + e.member_index = static_cast(strtoul(row[0], nullptr, 10)); + e.heal_rotation_index = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotHealRotationMembers e{}; + + e.member_index = static_cast(strtoul(row[0], nullptr, 10)); + e.heal_rotation_index = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_HEAL_ROTATION_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_heal_rotation_targets_repository.h b/common/repositories/base/base_bot_heal_rotation_targets_repository.h new file mode 100644 index 000000000..b5bef9c2b --- /dev/null +++ b/common/repositories/base/base_bot_heal_rotation_targets_repository.h @@ -0,0 +1,342 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_HEAL_ROTATION_TARGETS_REPOSITORY_H +#define EQEMU_BASE_BOT_HEAL_ROTATION_TARGETS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotHealRotationTargetsRepository { +public: + struct BotHealRotationTargets { + uint32_t target_index; + uint32_t heal_rotation_index; + std::string target_name; + }; + + static std::string PrimaryKey() + { + return std::string("target_index"); + } + + static std::vector Columns() + { + return { + "target_index", + "heal_rotation_index", + "target_name", + }; + } + + static std::vector SelectColumns() + { + return { + "target_index", + "heal_rotation_index", + "target_name", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_heal_rotation_targets"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotHealRotationTargets NewEntity() + { + BotHealRotationTargets e{}; + + e.target_index = 0; + e.heal_rotation_index = 0; + e.target_name = ""; + + return e; + } + + static BotHealRotationTargets GetBotHealRotationTargets( + const std::vector &bot_heal_rotation_targetss, + int bot_heal_rotation_targets_id + ) + { + for (auto &bot_heal_rotation_targets : bot_heal_rotation_targetss) { + if (bot_heal_rotation_targets.target_index == bot_heal_rotation_targets_id) { + return bot_heal_rotation_targets; + } + } + + return NewEntity(); + } + + static BotHealRotationTargets FindOne( + Database& db, + int bot_heal_rotation_targets_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_heal_rotation_targets_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotHealRotationTargets e{}; + + e.target_index = static_cast(strtoul(row[0], nullptr, 10)); + e.heal_rotation_index = static_cast(strtoul(row[1], nullptr, 10)); + e.target_name = row[2] ? row[2] : ""; + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_heal_rotation_targets_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_heal_rotation_targets_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotHealRotationTargets &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.heal_rotation_index)); + v.push_back(columns[2] + " = '" + Strings::Escape(e.target_name) + "'"); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.target_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotHealRotationTargets InsertOne( + Database& db, + BotHealRotationTargets e + ) + { + std::vector v; + + v.push_back(std::to_string(e.target_index)); + v.push_back(std::to_string(e.heal_rotation_index)); + v.push_back("'" + Strings::Escape(e.target_name) + "'"); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.target_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.target_index)); + v.push_back(std::to_string(e.heal_rotation_index)); + v.push_back("'" + Strings::Escape(e.target_name) + "'"); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotHealRotationTargets e{}; + + e.target_index = static_cast(strtoul(row[0], nullptr, 10)); + e.heal_rotation_index = static_cast(strtoul(row[1], nullptr, 10)); + e.target_name = row[2] ? row[2] : ""; + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotHealRotationTargets e{}; + + e.target_index = static_cast(strtoul(row[0], nullptr, 10)); + e.heal_rotation_index = static_cast(strtoul(row[1], nullptr, 10)); + e.target_name = row[2] ? row[2] : ""; + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_HEAL_ROTATION_TARGETS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_heal_rotations_repository.h b/common/repositories/base/base_bot_heal_rotations_repository.h new file mode 100644 index 000000000..f39e0b403 --- /dev/null +++ b/common/repositories/base/base_bot_heal_rotations_repository.h @@ -0,0 +1,442 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_HEAL_ROTATIONS_REPOSITORY_H +#define EQEMU_BASE_BOT_HEAL_ROTATIONS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotHealRotationsRepository { +public: + struct BotHealRotations { + uint32_t heal_rotation_index; + uint32_t bot_id; + uint32_t interval; + uint32_t fast_heals; + uint32_t adaptive_targeting; + uint32_t casting_override; + std::string safe_hp_base; + std::string safe_hp_cloth; + std::string safe_hp_leather; + std::string safe_hp_chain; + std::string safe_hp_plate; + std::string critical_hp_base; + std::string critical_hp_cloth; + std::string critical_hp_leather; + std::string critical_hp_chain; + std::string critical_hp_plate; + }; + + static std::string PrimaryKey() + { + return std::string("heal_rotation_index"); + } + + static std::vector Columns() + { + return { + "heal_rotation_index", + "bot_id", + "interval", + "fast_heals", + "adaptive_targeting", + "casting_override", + "safe_hp_base", + "safe_hp_cloth", + "safe_hp_leather", + "safe_hp_chain", + "safe_hp_plate", + "critical_hp_base", + "critical_hp_cloth", + "critical_hp_leather", + "critical_hp_chain", + "critical_hp_plate", + }; + } + + static std::vector SelectColumns() + { + return { + "heal_rotation_index", + "bot_id", + "interval", + "fast_heals", + "adaptive_targeting", + "casting_override", + "safe_hp_base", + "safe_hp_cloth", + "safe_hp_leather", + "safe_hp_chain", + "safe_hp_plate", + "critical_hp_base", + "critical_hp_cloth", + "critical_hp_leather", + "critical_hp_chain", + "critical_hp_plate", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_heal_rotations"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotHealRotations NewEntity() + { + BotHealRotations e{}; + + e.heal_rotation_index = 0; + e.bot_id = 0; + e.interval = 0; + e.fast_heals = 0; + e.adaptive_targeting = 0; + e.casting_override = 0; + e.safe_hp_base = 0; + e.safe_hp_cloth = 0; + e.safe_hp_leather = 0; + e.safe_hp_chain = 0; + e.safe_hp_plate = 0; + e.critical_hp_base = 0; + e.critical_hp_cloth = 0; + e.critical_hp_leather = 0; + e.critical_hp_chain = 0; + e.critical_hp_plate = 0; + + return e; + } + + static BotHealRotations GetBotHealRotations( + const std::vector &bot_heal_rotationss, + int bot_heal_rotations_id + ) + { + for (auto &bot_heal_rotations : bot_heal_rotationss) { + if (bot_heal_rotations.heal_rotation_index == bot_heal_rotations_id) { + return bot_heal_rotations; + } + } + + return NewEntity(); + } + + static BotHealRotations FindOne( + Database& db, + int bot_heal_rotations_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_heal_rotations_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotHealRotations e{}; + + e.heal_rotation_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.interval = static_cast(strtoul(row[2], nullptr, 10)); + e.fast_heals = static_cast(strtoul(row[3], nullptr, 10)); + e.adaptive_targeting = static_cast(strtoul(row[4], nullptr, 10)); + e.casting_override = static_cast(strtoul(row[5], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_heal_rotations_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_heal_rotations_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotHealRotations &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[2] + " = " + std::to_string(e.interval)); + v.push_back(columns[3] + " = " + std::to_string(e.fast_heals)); + v.push_back(columns[4] + " = " + std::to_string(e.adaptive_targeting)); + v.push_back(columns[5] + " = " + std::to_string(e.casting_override)); + v.push_back(columns[6] + " = " + std::to_string(e.safe_hp_base)); + v.push_back(columns[7] + " = " + std::to_string(e.safe_hp_cloth)); + v.push_back(columns[8] + " = " + std::to_string(e.safe_hp_leather)); + v.push_back(columns[9] + " = " + std::to_string(e.safe_hp_chain)); + v.push_back(columns[10] + " = " + std::to_string(e.safe_hp_plate)); + v.push_back(columns[11] + " = " + std::to_string(e.critical_hp_base)); + v.push_back(columns[12] + " = " + std::to_string(e.critical_hp_cloth)); + v.push_back(columns[13] + " = " + std::to_string(e.critical_hp_leather)); + v.push_back(columns[14] + " = " + std::to_string(e.critical_hp_chain)); + v.push_back(columns[15] + " = " + std::to_string(e.critical_hp_plate)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.heal_rotation_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotHealRotations InsertOne( + Database& db, + BotHealRotations e + ) + { + std::vector v; + + v.push_back(std::to_string(e.heal_rotation_index)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.interval)); + v.push_back(std::to_string(e.fast_heals)); + v.push_back(std::to_string(e.adaptive_targeting)); + v.push_back(std::to_string(e.casting_override)); + v.push_back(std::to_string(e.safe_hp_base)); + v.push_back(std::to_string(e.safe_hp_cloth)); + v.push_back(std::to_string(e.safe_hp_leather)); + v.push_back(std::to_string(e.safe_hp_chain)); + v.push_back(std::to_string(e.safe_hp_plate)); + v.push_back(std::to_string(e.critical_hp_base)); + v.push_back(std::to_string(e.critical_hp_cloth)); + v.push_back(std::to_string(e.critical_hp_leather)); + v.push_back(std::to_string(e.critical_hp_chain)); + v.push_back(std::to_string(e.critical_hp_plate)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.heal_rotation_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.heal_rotation_index)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.interval)); + v.push_back(std::to_string(e.fast_heals)); + v.push_back(std::to_string(e.adaptive_targeting)); + v.push_back(std::to_string(e.casting_override)); + v.push_back(std::to_string(e.safe_hp_base)); + v.push_back(std::to_string(e.safe_hp_cloth)); + v.push_back(std::to_string(e.safe_hp_leather)); + v.push_back(std::to_string(e.safe_hp_chain)); + v.push_back(std::to_string(e.safe_hp_plate)); + v.push_back(std::to_string(e.critical_hp_base)); + v.push_back(std::to_string(e.critical_hp_cloth)); + v.push_back(std::to_string(e.critical_hp_leather)); + v.push_back(std::to_string(e.critical_hp_chain)); + v.push_back(std::to_string(e.critical_hp_plate)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotHealRotations e{}; + + e.heal_rotation_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.interval = static_cast(strtoul(row[2], nullptr, 10)); + e.fast_heals = static_cast(strtoul(row[3], nullptr, 10)); + e.adaptive_targeting = static_cast(strtoul(row[4], nullptr, 10)); + e.casting_override = static_cast(strtoul(row[5], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotHealRotations e{}; + + e.heal_rotation_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.interval = static_cast(strtoul(row[2], nullptr, 10)); + e.fast_heals = static_cast(strtoul(row[3], nullptr, 10)); + e.adaptive_targeting = static_cast(strtoul(row[4], nullptr, 10)); + e.casting_override = static_cast(strtoul(row[5], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_HEAL_ROTATIONS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_inspect_messages_repository.h b/common/repositories/base/base_bot_inspect_messages_repository.h new file mode 100644 index 000000000..bcf19437e --- /dev/null +++ b/common/repositories/base/base_bot_inspect_messages_repository.h @@ -0,0 +1,333 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_INSPECT_MESSAGES_REPOSITORY_H +#define EQEMU_BASE_BOT_INSPECT_MESSAGES_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotInspectMessagesRepository { +public: + struct BotInspectMessages { + uint32_t bot_id; + std::string inspect_message; + }; + + static std::string PrimaryKey() + { + return std::string("bot_id"); + } + + static std::vector Columns() + { + return { + "bot_id", + "inspect_message", + }; + } + + static std::vector SelectColumns() + { + return { + "bot_id", + "inspect_message", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_inspect_messages"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotInspectMessages NewEntity() + { + BotInspectMessages e{}; + + e.bot_id = 0; + e.inspect_message = ""; + + return e; + } + + static BotInspectMessages GetBotInspectMessages( + const std::vector &bot_inspect_messagess, + int bot_inspect_messages_id + ) + { + for (auto &bot_inspect_messages : bot_inspect_messagess) { + if (bot_inspect_messages.bot_id == bot_inspect_messages_id) { + return bot_inspect_messages; + } + } + + return NewEntity(); + } + + static BotInspectMessages FindOne( + Database& db, + int bot_inspect_messages_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_inspect_messages_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotInspectMessages e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.inspect_message = row[1] ? row[1] : ""; + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_inspect_messages_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_inspect_messages_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotInspectMessages &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[0] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[1] + " = '" + Strings::Escape(e.inspect_message) + "'"); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.bot_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotInspectMessages InsertOne( + Database& db, + BotInspectMessages e + ) + { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back("'" + Strings::Escape(e.inspect_message) + "'"); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.bot_id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back("'" + Strings::Escape(e.inspect_message) + "'"); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotInspectMessages e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.inspect_message = row[1] ? row[1] : ""; + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotInspectMessages e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.inspect_message = row[1] ? row[1] : ""; + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_INSPECT_MESSAGES_REPOSITORY_H diff --git a/common/repositories/base/base_bot_inventories_repository.h b/common/repositories/base/base_bot_inventories_repository.h new file mode 100644 index 000000000..4f0545148 --- /dev/null +++ b/common/repositories/base/base_bot_inventories_repository.h @@ -0,0 +1,482 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_INVENTORIES_REPOSITORY_H +#define EQEMU_BASE_BOT_INVENTORIES_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotInventoriesRepository { +public: + struct BotInventories { + uint32_t inventories_index; + uint32_t bot_id; + uint32_t slot_id; + uint32_t item_id; + uint16_t inst_charges; + uint32_t inst_color; + uint8_t inst_no_drop; + std::string inst_custom_data; + uint32_t ornament_icon; + uint32_t ornament_id_file; + int32_t ornament_hero_model; + uint32_t augment_1; + uint32_t augment_2; + uint32_t augment_3; + uint32_t augment_4; + uint32_t augment_5; + uint32_t augment_6; + }; + + static std::string PrimaryKey() + { + return std::string("inventories_index"); + } + + static std::vector Columns() + { + return { + "inventories_index", + "bot_id", + "slot_id", + "item_id", + "inst_charges", + "inst_color", + "inst_no_drop", + "inst_custom_data", + "ornament_icon", + "ornament_id_file", + "ornament_hero_model", + "augment_1", + "augment_2", + "augment_3", + "augment_4", + "augment_5", + "augment_6", + }; + } + + static std::vector SelectColumns() + { + return { + "inventories_index", + "bot_id", + "slot_id", + "item_id", + "inst_charges", + "inst_color", + "inst_no_drop", + "inst_custom_data", + "ornament_icon", + "ornament_id_file", + "ornament_hero_model", + "augment_1", + "augment_2", + "augment_3", + "augment_4", + "augment_5", + "augment_6", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_inventories"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotInventories NewEntity() + { + BotInventories e{}; + + e.inventories_index = 0; + e.bot_id = 0; + e.slot_id = 0; + e.item_id = 0; + e.inst_charges = 0; + e.inst_color = 0; + e.inst_no_drop = 0; + e.inst_custom_data = ""; + e.ornament_icon = 0; + e.ornament_id_file = 0; + e.ornament_hero_model = 0; + e.augment_1 = 0; + e.augment_2 = 0; + e.augment_3 = 0; + e.augment_4 = 0; + e.augment_5 = 0; + e.augment_6 = 0; + + return e; + } + + static BotInventories GetBotInventories( + const std::vector &bot_inventoriess, + int bot_inventories_id + ) + { + for (auto &bot_inventories : bot_inventoriess) { + if (bot_inventories.inventories_index == bot_inventories_id) { + return bot_inventories; + } + } + + return NewEntity(); + } + + static BotInventories FindOne( + Database& db, + int bot_inventories_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_inventories_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotInventories e{}; + + e.inventories_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.slot_id = static_cast(strtoul(row[2], nullptr, 10)); + e.item_id = static_cast(strtoul(row[3], nullptr, 10)); + e.inst_charges = static_cast(strtoul(row[4], nullptr, 10)); + e.inst_color = static_cast(strtoul(row[5], nullptr, 10)); + e.inst_no_drop = static_cast(strtoul(row[6], nullptr, 10)); + e.inst_custom_data = row[7] ? row[7] : ""; + e.ornament_icon = static_cast(strtoul(row[8], nullptr, 10)); + e.ornament_id_file = static_cast(strtoul(row[9], nullptr, 10)); + e.ornament_hero_model = static_cast(atoi(row[10])); + e.augment_1 = static_cast(strtoul(row[11], nullptr, 10)); + e.augment_2 = static_cast(strtoul(row[12], nullptr, 10)); + e.augment_3 = static_cast(strtoul(row[13], nullptr, 10)); + e.augment_4 = static_cast(strtoul(row[14], nullptr, 10)); + e.augment_5 = static_cast(strtoul(row[15], nullptr, 10)); + e.augment_6 = static_cast(strtoul(row[16], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_inventories_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_inventories_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotInventories &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[2] + " = " + std::to_string(e.slot_id)); + v.push_back(columns[3] + " = " + std::to_string(e.item_id)); + v.push_back(columns[4] + " = " + std::to_string(e.inst_charges)); + v.push_back(columns[5] + " = " + std::to_string(e.inst_color)); + v.push_back(columns[6] + " = " + std::to_string(e.inst_no_drop)); + v.push_back(columns[7] + " = '" + Strings::Escape(e.inst_custom_data) + "'"); + v.push_back(columns[8] + " = " + std::to_string(e.ornament_icon)); + v.push_back(columns[9] + " = " + std::to_string(e.ornament_id_file)); + v.push_back(columns[10] + " = " + std::to_string(e.ornament_hero_model)); + v.push_back(columns[11] + " = " + std::to_string(e.augment_1)); + v.push_back(columns[12] + " = " + std::to_string(e.augment_2)); + v.push_back(columns[13] + " = " + std::to_string(e.augment_3)); + v.push_back(columns[14] + " = " + std::to_string(e.augment_4)); + v.push_back(columns[15] + " = " + std::to_string(e.augment_5)); + v.push_back(columns[16] + " = " + std::to_string(e.augment_6)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.inventories_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotInventories InsertOne( + Database& db, + BotInventories e + ) + { + std::vector v; + + v.push_back(std::to_string(e.inventories_index)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.slot_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.inst_charges)); + v.push_back(std::to_string(e.inst_color)); + v.push_back(std::to_string(e.inst_no_drop)); + v.push_back("'" + Strings::Escape(e.inst_custom_data) + "'"); + v.push_back(std::to_string(e.ornament_icon)); + v.push_back(std::to_string(e.ornament_id_file)); + v.push_back(std::to_string(e.ornament_hero_model)); + v.push_back(std::to_string(e.augment_1)); + v.push_back(std::to_string(e.augment_2)); + v.push_back(std::to_string(e.augment_3)); + v.push_back(std::to_string(e.augment_4)); + v.push_back(std::to_string(e.augment_5)); + v.push_back(std::to_string(e.augment_6)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.inventories_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.inventories_index)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.slot_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.inst_charges)); + v.push_back(std::to_string(e.inst_color)); + v.push_back(std::to_string(e.inst_no_drop)); + v.push_back("'" + Strings::Escape(e.inst_custom_data) + "'"); + v.push_back(std::to_string(e.ornament_icon)); + v.push_back(std::to_string(e.ornament_id_file)); + v.push_back(std::to_string(e.ornament_hero_model)); + v.push_back(std::to_string(e.augment_1)); + v.push_back(std::to_string(e.augment_2)); + v.push_back(std::to_string(e.augment_3)); + v.push_back(std::to_string(e.augment_4)); + v.push_back(std::to_string(e.augment_5)); + v.push_back(std::to_string(e.augment_6)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotInventories e{}; + + e.inventories_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.slot_id = static_cast(strtoul(row[2], nullptr, 10)); + e.item_id = static_cast(strtoul(row[3], nullptr, 10)); + e.inst_charges = static_cast(strtoul(row[4], nullptr, 10)); + e.inst_color = static_cast(strtoul(row[5], nullptr, 10)); + e.inst_no_drop = static_cast(strtoul(row[6], nullptr, 10)); + e.inst_custom_data = row[7] ? row[7] : ""; + e.ornament_icon = static_cast(strtoul(row[8], nullptr, 10)); + e.ornament_id_file = static_cast(strtoul(row[9], nullptr, 10)); + e.ornament_hero_model = static_cast(atoi(row[10])); + e.augment_1 = static_cast(strtoul(row[11], nullptr, 10)); + e.augment_2 = static_cast(strtoul(row[12], nullptr, 10)); + e.augment_3 = static_cast(strtoul(row[13], nullptr, 10)); + e.augment_4 = static_cast(strtoul(row[14], nullptr, 10)); + e.augment_5 = static_cast(strtoul(row[15], nullptr, 10)); + e.augment_6 = static_cast(strtoul(row[16], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotInventories e{}; + + e.inventories_index = static_cast(strtoul(row[0], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[1], nullptr, 10)); + e.slot_id = static_cast(strtoul(row[2], nullptr, 10)); + e.item_id = static_cast(strtoul(row[3], nullptr, 10)); + e.inst_charges = static_cast(strtoul(row[4], nullptr, 10)); + e.inst_color = static_cast(strtoul(row[5], nullptr, 10)); + e.inst_no_drop = static_cast(strtoul(row[6], nullptr, 10)); + e.inst_custom_data = row[7] ? row[7] : ""; + e.ornament_icon = static_cast(strtoul(row[8], nullptr, 10)); + e.ornament_id_file = static_cast(strtoul(row[9], nullptr, 10)); + e.ornament_hero_model = static_cast(atoi(row[10])); + e.augment_1 = static_cast(strtoul(row[11], nullptr, 10)); + e.augment_2 = static_cast(strtoul(row[12], nullptr, 10)); + e.augment_3 = static_cast(strtoul(row[13], nullptr, 10)); + e.augment_4 = static_cast(strtoul(row[14], nullptr, 10)); + e.augment_5 = static_cast(strtoul(row[15], nullptr, 10)); + e.augment_6 = static_cast(strtoul(row[16], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_INVENTORIES_REPOSITORY_H diff --git a/common/repositories/base/base_bot_owner_options_repository.h b/common/repositories/base/base_bot_owner_options_repository.h new file mode 100644 index 000000000..3bc31c539 --- /dev/null +++ b/common/repositories/base/base_bot_owner_options_repository.h @@ -0,0 +1,343 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_OWNER_OPTIONS_REPOSITORY_H +#define EQEMU_BASE_BOT_OWNER_OPTIONS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotOwnerOptionsRepository { +public: + struct BotOwnerOptions { + uint32_t owner_id; + uint16_t option_type; + uint16_t option_value; + }; + + static std::string PrimaryKey() + { + return std::string("owner_id"); + } + + static std::vector Columns() + { + return { + "owner_id", + "option_type", + "option_value", + }; + } + + static std::vector SelectColumns() + { + return { + "owner_id", + "option_type", + "option_value", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_owner_options"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotOwnerOptions NewEntity() + { + BotOwnerOptions e{}; + + e.owner_id = 0; + e.option_type = 0; + e.option_value = 0; + + return e; + } + + static BotOwnerOptions GetBotOwnerOptions( + const std::vector &bot_owner_optionss, + int bot_owner_options_id + ) + { + for (auto &bot_owner_options : bot_owner_optionss) { + if (bot_owner_options.owner_id == bot_owner_options_id) { + return bot_owner_options; + } + } + + return NewEntity(); + } + + static BotOwnerOptions FindOne( + Database& db, + int bot_owner_options_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_owner_options_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotOwnerOptions e{}; + + e.owner_id = static_cast(strtoul(row[0], nullptr, 10)); + e.option_type = static_cast(strtoul(row[1], nullptr, 10)); + e.option_value = static_cast(strtoul(row[2], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_owner_options_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_owner_options_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotOwnerOptions &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[0] + " = " + std::to_string(e.owner_id)); + v.push_back(columns[1] + " = " + std::to_string(e.option_type)); + v.push_back(columns[2] + " = " + std::to_string(e.option_value)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.owner_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotOwnerOptions InsertOne( + Database& db, + BotOwnerOptions e + ) + { + std::vector v; + + v.push_back(std::to_string(e.owner_id)); + v.push_back(std::to_string(e.option_type)); + v.push_back(std::to_string(e.option_value)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.owner_id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.owner_id)); + v.push_back(std::to_string(e.option_type)); + v.push_back(std::to_string(e.option_value)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotOwnerOptions e{}; + + e.owner_id = static_cast(strtoul(row[0], nullptr, 10)); + e.option_type = static_cast(strtoul(row[1], nullptr, 10)); + e.option_value = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotOwnerOptions e{}; + + e.owner_id = static_cast(strtoul(row[0], nullptr, 10)); + e.option_type = static_cast(strtoul(row[1], nullptr, 10)); + e.option_value = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_OWNER_OPTIONS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_pet_buffs_repository.h b/common/repositories/base/base_bot_pet_buffs_repository.h new file mode 100644 index 000000000..e5b8fb92c --- /dev/null +++ b/common/repositories/base/base_bot_pet_buffs_repository.h @@ -0,0 +1,362 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_PET_BUFFS_REPOSITORY_H +#define EQEMU_BASE_BOT_PET_BUFFS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotPetBuffsRepository { +public: + struct BotPetBuffs { + uint32_t pet_buffs_index; + uint32_t pets_index; + uint32_t spell_id; + uint32_t caster_level; + uint32_t duration; + }; + + static std::string PrimaryKey() + { + return std::string("pet_buffs_index"); + } + + static std::vector Columns() + { + return { + "pet_buffs_index", + "pets_index", + "spell_id", + "caster_level", + "duration", + }; + } + + static std::vector SelectColumns() + { + return { + "pet_buffs_index", + "pets_index", + "spell_id", + "caster_level", + "duration", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_pet_buffs"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotPetBuffs NewEntity() + { + BotPetBuffs e{}; + + e.pet_buffs_index = 0; + e.pets_index = 0; + e.spell_id = 0; + e.caster_level = 0; + e.duration = 0; + + return e; + } + + static BotPetBuffs GetBotPetBuffs( + const std::vector &bot_pet_buffss, + int bot_pet_buffs_id + ) + { + for (auto &bot_pet_buffs : bot_pet_buffss) { + if (bot_pet_buffs.pet_buffs_index == bot_pet_buffs_id) { + return bot_pet_buffs; + } + } + + return NewEntity(); + } + + static BotPetBuffs FindOne( + Database& db, + int bot_pet_buffs_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_pet_buffs_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotPetBuffs e{}; + + e.pet_buffs_index = static_cast(strtoul(row[0], nullptr, 10)); + e.pets_index = static_cast(strtoul(row[1], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.duration = static_cast(strtoul(row[4], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_pet_buffs_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_pet_buffs_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotPetBuffs &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.pets_index)); + v.push_back(columns[2] + " = " + std::to_string(e.spell_id)); + v.push_back(columns[3] + " = " + std::to_string(e.caster_level)); + v.push_back(columns[4] + " = " + std::to_string(e.duration)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.pet_buffs_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotPetBuffs InsertOne( + Database& db, + BotPetBuffs e + ) + { + std::vector v; + + v.push_back(std::to_string(e.pet_buffs_index)); + v.push_back(std::to_string(e.pets_index)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.caster_level)); + v.push_back(std::to_string(e.duration)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.pet_buffs_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.pet_buffs_index)); + v.push_back(std::to_string(e.pets_index)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.caster_level)); + v.push_back(std::to_string(e.duration)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotPetBuffs e{}; + + e.pet_buffs_index = static_cast(strtoul(row[0], nullptr, 10)); + e.pets_index = static_cast(strtoul(row[1], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.duration = static_cast(strtoul(row[4], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotPetBuffs e{}; + + e.pet_buffs_index = static_cast(strtoul(row[0], nullptr, 10)); + e.pets_index = static_cast(strtoul(row[1], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.duration = static_cast(strtoul(row[4], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_PET_BUFFS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_pet_inventories_repository.h b/common/repositories/base/base_bot_pet_inventories_repository.h new file mode 100644 index 000000000..f8c9e918f --- /dev/null +++ b/common/repositories/base/base_bot_pet_inventories_repository.h @@ -0,0 +1,342 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_PET_INVENTORIES_REPOSITORY_H +#define EQEMU_BASE_BOT_PET_INVENTORIES_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotPetInventoriesRepository { +public: + struct BotPetInventories { + uint32_t pet_inventories_index; + uint32_t pets_index; + uint32_t item_id; + }; + + static std::string PrimaryKey() + { + return std::string("pet_inventories_index"); + } + + static std::vector Columns() + { + return { + "pet_inventories_index", + "pets_index", + "item_id", + }; + } + + static std::vector SelectColumns() + { + return { + "pet_inventories_index", + "pets_index", + "item_id", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_pet_inventories"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotPetInventories NewEntity() + { + BotPetInventories e{}; + + e.pet_inventories_index = 0; + e.pets_index = 0; + e.item_id = 0; + + return e; + } + + static BotPetInventories GetBotPetInventories( + const std::vector &bot_pet_inventoriess, + int bot_pet_inventories_id + ) + { + for (auto &bot_pet_inventories : bot_pet_inventoriess) { + if (bot_pet_inventories.pet_inventories_index == bot_pet_inventories_id) { + return bot_pet_inventories; + } + } + + return NewEntity(); + } + + static BotPetInventories FindOne( + Database& db, + int bot_pet_inventories_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_pet_inventories_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotPetInventories e{}; + + e.pet_inventories_index = static_cast(strtoul(row[0], nullptr, 10)); + e.pets_index = static_cast(strtoul(row[1], nullptr, 10)); + e.item_id = static_cast(strtoul(row[2], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_pet_inventories_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_pet_inventories_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotPetInventories &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.pets_index)); + v.push_back(columns[2] + " = " + std::to_string(e.item_id)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.pet_inventories_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotPetInventories InsertOne( + Database& db, + BotPetInventories e + ) + { + std::vector v; + + v.push_back(std::to_string(e.pet_inventories_index)); + v.push_back(std::to_string(e.pets_index)); + v.push_back(std::to_string(e.item_id)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.pet_inventories_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.pet_inventories_index)); + v.push_back(std::to_string(e.pets_index)); + v.push_back(std::to_string(e.item_id)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotPetInventories e{}; + + e.pet_inventories_index = static_cast(strtoul(row[0], nullptr, 10)); + e.pets_index = static_cast(strtoul(row[1], nullptr, 10)); + e.item_id = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotPetInventories e{}; + + e.pet_inventories_index = static_cast(strtoul(row[0], nullptr, 10)); + e.pets_index = static_cast(strtoul(row[1], nullptr, 10)); + e.item_id = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_PET_INVENTORIES_REPOSITORY_H diff --git a/common/repositories/base/base_bot_pets_repository.h b/common/repositories/base/base_bot_pets_repository.h new file mode 100644 index 000000000..59e43a6dc --- /dev/null +++ b/common/repositories/base/base_bot_pets_repository.h @@ -0,0 +1,372 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_PETS_REPOSITORY_H +#define EQEMU_BASE_BOT_PETS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotPetsRepository { +public: + struct BotPets { + uint32_t pets_index; + uint32_t spell_id; + uint32_t bot_id; + std::string name; + int32_t mana; + int32_t hp; + }; + + static std::string PrimaryKey() + { + return std::string("pets_index"); + } + + static std::vector Columns() + { + return { + "pets_index", + "spell_id", + "bot_id", + "name", + "mana", + "hp", + }; + } + + static std::vector SelectColumns() + { + return { + "pets_index", + "spell_id", + "bot_id", + "name", + "mana", + "hp", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_pets"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotPets NewEntity() + { + BotPets e{}; + + e.pets_index = 0; + e.spell_id = 0; + e.bot_id = 0; + e.name = ""; + e.mana = 0; + e.hp = 0; + + return e; + } + + static BotPets GetBotPets( + const std::vector &bot_petss, + int bot_pets_id + ) + { + for (auto &bot_pets : bot_petss) { + if (bot_pets.pets_index == bot_pets_id) { + return bot_pets; + } + } + + return NewEntity(); + } + + static BotPets FindOne( + Database& db, + int bot_pets_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_pets_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotPets e{}; + + e.pets_index = static_cast(strtoul(row[0], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + e.name = row[3] ? row[3] : ""; + e.mana = static_cast(atoi(row[4])); + e.hp = static_cast(atoi(row[5])); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_pets_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_pets_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotPets &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.spell_id)); + v.push_back(columns[2] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[3] + " = '" + Strings::Escape(e.name) + "'"); + v.push_back(columns[4] + " = " + std::to_string(e.mana)); + v.push_back(columns[5] + " = " + std::to_string(e.hp)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.pets_index + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotPets InsertOne( + Database& db, + BotPets e + ) + { + std::vector v; + + v.push_back(std::to_string(e.pets_index)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.bot_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.hp)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.pets_index = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.pets_index)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.bot_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.hp)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotPets e{}; + + e.pets_index = static_cast(strtoul(row[0], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + e.name = row[3] ? row[3] : ""; + e.mana = static_cast(atoi(row[4])); + e.hp = static_cast(atoi(row[5])); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotPets e{}; + + e.pets_index = static_cast(strtoul(row[0], nullptr, 10)); + e.spell_id = static_cast(strtoul(row[1], nullptr, 10)); + e.bot_id = static_cast(strtoul(row[2], nullptr, 10)); + e.name = row[3] ? row[3] : ""; + e.mana = static_cast(atoi(row[4])); + e.hp = static_cast(atoi(row[5])); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_PETS_REPOSITORY_H diff --git a/common/repositories/base/base_bot_spell_casting_chances_repository.h b/common/repositories/base/base_bot_spell_casting_chances_repository.h new file mode 100644 index 000000000..544c08d29 --- /dev/null +++ b/common/repositories/base/base_bot_spell_casting_chances_repository.h @@ -0,0 +1,512 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_SPELL_CASTING_CHANCES_REPOSITORY_H +#define EQEMU_BASE_BOT_SPELL_CASTING_CHANCES_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotSpellCastingChancesRepository { +public: + struct BotSpellCastingChances { + int32_t id; + uint8_t spell_type_index; + uint8_t class_id; + uint8_t stance_index; + uint8_t nHSND_value; + uint8_t pH_value; + uint8_t pS_value; + uint8_t pHS_value; + uint8_t pN_value; + uint8_t pHN_value; + uint8_t pSN_value; + uint8_t pHSN_value; + uint8_t pD_value; + uint8_t pHD_value; + uint8_t pSD_value; + uint8_t pHSD_value; + uint8_t pND_value; + uint8_t pHND_value; + uint8_t pSND_value; + uint8_t pHSND_value; + }; + + static std::string PrimaryKey() + { + return std::string("id"); + } + + static std::vector Columns() + { + return { + "id", + "spell_type_index", + "class_id", + "stance_index", + "nHSND_value", + "pH_value", + "pS_value", + "pHS_value", + "pN_value", + "pHN_value", + "pSN_value", + "pHSN_value", + "pD_value", + "pHD_value", + "pSD_value", + "pHSD_value", + "pND_value", + "pHND_value", + "pSND_value", + "pHSND_value", + }; + } + + static std::vector SelectColumns() + { + return { + "id", + "spell_type_index", + "class_id", + "stance_index", + "nHSND_value", + "pH_value", + "pS_value", + "pHS_value", + "pN_value", + "pHN_value", + "pSN_value", + "pHSN_value", + "pD_value", + "pHD_value", + "pSD_value", + "pHSD_value", + "pND_value", + "pHND_value", + "pSND_value", + "pHSND_value", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_spell_casting_chances"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotSpellCastingChances NewEntity() + { + BotSpellCastingChances e{}; + + e.id = 0; + e.spell_type_index = 0; + e.class_id = 0; + e.stance_index = 0; + e.nHSND_value = 0; + e.pH_value = 0; + e.pS_value = 0; + e.pHS_value = 0; + e.pN_value = 0; + e.pHN_value = 0; + e.pSN_value = 0; + e.pHSN_value = 0; + e.pD_value = 0; + e.pHD_value = 0; + e.pSD_value = 0; + e.pHSD_value = 0; + e.pND_value = 0; + e.pHND_value = 0; + e.pSND_value = 0; + e.pHSND_value = 0; + + return e; + } + + static BotSpellCastingChances GetBotSpellCastingChances( + const std::vector &bot_spell_casting_chancess, + int bot_spell_casting_chances_id + ) + { + for (auto &bot_spell_casting_chances : bot_spell_casting_chancess) { + if (bot_spell_casting_chances.id == bot_spell_casting_chances_id) { + return bot_spell_casting_chances; + } + } + + return NewEntity(); + } + + static BotSpellCastingChances FindOne( + Database& db, + int bot_spell_casting_chances_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_spell_casting_chances_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotSpellCastingChances e{}; + + e.id = static_cast(atoi(row[0])); + e.spell_type_index = static_cast(strtoul(row[1], nullptr, 10)); + e.class_id = static_cast(strtoul(row[2], nullptr, 10)); + e.stance_index = static_cast(strtoul(row[3], nullptr, 10)); + e.nHSND_value = static_cast(strtoul(row[4], nullptr, 10)); + e.pH_value = static_cast(strtoul(row[5], nullptr, 10)); + e.pS_value = static_cast(strtoul(row[6], nullptr, 10)); + e.pHS_value = static_cast(strtoul(row[7], nullptr, 10)); + e.pN_value = static_cast(strtoul(row[8], nullptr, 10)); + e.pHN_value = static_cast(strtoul(row[9], nullptr, 10)); + e.pSN_value = static_cast(strtoul(row[10], nullptr, 10)); + e.pHSN_value = static_cast(strtoul(row[11], nullptr, 10)); + e.pD_value = static_cast(strtoul(row[12], nullptr, 10)); + e.pHD_value = static_cast(strtoul(row[13], nullptr, 10)); + e.pSD_value = static_cast(strtoul(row[14], nullptr, 10)); + e.pHSD_value = static_cast(strtoul(row[15], nullptr, 10)); + e.pND_value = static_cast(strtoul(row[16], nullptr, 10)); + e.pHND_value = static_cast(strtoul(row[17], nullptr, 10)); + e.pSND_value = static_cast(strtoul(row[18], nullptr, 10)); + e.pHSND_value = static_cast(strtoul(row[19], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_spell_casting_chances_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_spell_casting_chances_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotSpellCastingChances &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.spell_type_index)); + v.push_back(columns[2] + " = " + std::to_string(e.class_id)); + v.push_back(columns[3] + " = " + std::to_string(e.stance_index)); + v.push_back(columns[4] + " = " + std::to_string(e.nHSND_value)); + v.push_back(columns[5] + " = " + std::to_string(e.pH_value)); + v.push_back(columns[6] + " = " + std::to_string(e.pS_value)); + v.push_back(columns[7] + " = " + std::to_string(e.pHS_value)); + v.push_back(columns[8] + " = " + std::to_string(e.pN_value)); + v.push_back(columns[9] + " = " + std::to_string(e.pHN_value)); + v.push_back(columns[10] + " = " + std::to_string(e.pSN_value)); + v.push_back(columns[11] + " = " + std::to_string(e.pHSN_value)); + v.push_back(columns[12] + " = " + std::to_string(e.pD_value)); + v.push_back(columns[13] + " = " + std::to_string(e.pHD_value)); + v.push_back(columns[14] + " = " + std::to_string(e.pSD_value)); + v.push_back(columns[15] + " = " + std::to_string(e.pHSD_value)); + v.push_back(columns[16] + " = " + std::to_string(e.pND_value)); + v.push_back(columns[17] + " = " + std::to_string(e.pHND_value)); + v.push_back(columns[18] + " = " + std::to_string(e.pSND_value)); + v.push_back(columns[19] + " = " + std::to_string(e.pHSND_value)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotSpellCastingChances InsertOne( + Database& db, + BotSpellCastingChances e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.spell_type_index)); + v.push_back(std::to_string(e.class_id)); + v.push_back(std::to_string(e.stance_index)); + v.push_back(std::to_string(e.nHSND_value)); + v.push_back(std::to_string(e.pH_value)); + v.push_back(std::to_string(e.pS_value)); + v.push_back(std::to_string(e.pHS_value)); + v.push_back(std::to_string(e.pN_value)); + v.push_back(std::to_string(e.pHN_value)); + v.push_back(std::to_string(e.pSN_value)); + v.push_back(std::to_string(e.pHSN_value)); + v.push_back(std::to_string(e.pD_value)); + v.push_back(std::to_string(e.pHD_value)); + v.push_back(std::to_string(e.pSD_value)); + v.push_back(std::to_string(e.pHSD_value)); + v.push_back(std::to_string(e.pND_value)); + v.push_back(std::to_string(e.pHND_value)); + v.push_back(std::to_string(e.pSND_value)); + v.push_back(std::to_string(e.pHSND_value)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.spell_type_index)); + v.push_back(std::to_string(e.class_id)); + v.push_back(std::to_string(e.stance_index)); + v.push_back(std::to_string(e.nHSND_value)); + v.push_back(std::to_string(e.pH_value)); + v.push_back(std::to_string(e.pS_value)); + v.push_back(std::to_string(e.pHS_value)); + v.push_back(std::to_string(e.pN_value)); + v.push_back(std::to_string(e.pHN_value)); + v.push_back(std::to_string(e.pSN_value)); + v.push_back(std::to_string(e.pHSN_value)); + v.push_back(std::to_string(e.pD_value)); + v.push_back(std::to_string(e.pHD_value)); + v.push_back(std::to_string(e.pSD_value)); + v.push_back(std::to_string(e.pHSD_value)); + v.push_back(std::to_string(e.pND_value)); + v.push_back(std::to_string(e.pHND_value)); + v.push_back(std::to_string(e.pSND_value)); + v.push_back(std::to_string(e.pHSND_value)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotSpellCastingChances e{}; + + e.id = static_cast(atoi(row[0])); + e.spell_type_index = static_cast(strtoul(row[1], nullptr, 10)); + e.class_id = static_cast(strtoul(row[2], nullptr, 10)); + e.stance_index = static_cast(strtoul(row[3], nullptr, 10)); + e.nHSND_value = static_cast(strtoul(row[4], nullptr, 10)); + e.pH_value = static_cast(strtoul(row[5], nullptr, 10)); + e.pS_value = static_cast(strtoul(row[6], nullptr, 10)); + e.pHS_value = static_cast(strtoul(row[7], nullptr, 10)); + e.pN_value = static_cast(strtoul(row[8], nullptr, 10)); + e.pHN_value = static_cast(strtoul(row[9], nullptr, 10)); + e.pSN_value = static_cast(strtoul(row[10], nullptr, 10)); + e.pHSN_value = static_cast(strtoul(row[11], nullptr, 10)); + e.pD_value = static_cast(strtoul(row[12], nullptr, 10)); + e.pHD_value = static_cast(strtoul(row[13], nullptr, 10)); + e.pSD_value = static_cast(strtoul(row[14], nullptr, 10)); + e.pHSD_value = static_cast(strtoul(row[15], nullptr, 10)); + e.pND_value = static_cast(strtoul(row[16], nullptr, 10)); + e.pHND_value = static_cast(strtoul(row[17], nullptr, 10)); + e.pSND_value = static_cast(strtoul(row[18], nullptr, 10)); + e.pHSND_value = static_cast(strtoul(row[19], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotSpellCastingChances e{}; + + e.id = static_cast(atoi(row[0])); + e.spell_type_index = static_cast(strtoul(row[1], nullptr, 10)); + e.class_id = static_cast(strtoul(row[2], nullptr, 10)); + e.stance_index = static_cast(strtoul(row[3], nullptr, 10)); + e.nHSND_value = static_cast(strtoul(row[4], nullptr, 10)); + e.pH_value = static_cast(strtoul(row[5], nullptr, 10)); + e.pS_value = static_cast(strtoul(row[6], nullptr, 10)); + e.pHS_value = static_cast(strtoul(row[7], nullptr, 10)); + e.pN_value = static_cast(strtoul(row[8], nullptr, 10)); + e.pHN_value = static_cast(strtoul(row[9], nullptr, 10)); + e.pSN_value = static_cast(strtoul(row[10], nullptr, 10)); + e.pHSN_value = static_cast(strtoul(row[11], nullptr, 10)); + e.pD_value = static_cast(strtoul(row[12], nullptr, 10)); + e.pHD_value = static_cast(strtoul(row[13], nullptr, 10)); + e.pSD_value = static_cast(strtoul(row[14], nullptr, 10)); + e.pHSD_value = static_cast(strtoul(row[15], nullptr, 10)); + e.pND_value = static_cast(strtoul(row[16], nullptr, 10)); + e.pHND_value = static_cast(strtoul(row[17], nullptr, 10)); + e.pSND_value = static_cast(strtoul(row[18], nullptr, 10)); + e.pHSND_value = static_cast(strtoul(row[19], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_SPELL_CASTING_CHANCES_REPOSITORY_H diff --git a/common/repositories/base/base_bot_spells_entries_repository.h b/common/repositories/base/base_bot_spells_entries_repository.h new file mode 100644 index 000000000..72a7d837a --- /dev/null +++ b/common/repositories/base/base_bot_spells_entries_repository.h @@ -0,0 +1,462 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_SPELLS_ENTRIES_REPOSITORY_H +#define EQEMU_BASE_BOT_SPELLS_ENTRIES_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotSpellsEntriesRepository { +public: + struct BotSpellsEntries { + uint32_t id; + int32_t npc_spells_id; + int16_t spellid; + uint32_t type; + uint8_t minlevel; + uint8_t maxlevel; + int16_t manacost; + int32_t recast_delay; + int16_t priority; + int32_t resist_adjust; + int16_t min_hp; + int16_t max_hp; + std::string bucket_name; + std::string bucket_value; + uint8_t bucket_comparison; + }; + + static std::string PrimaryKey() + { + return std::string("id"); + } + + static std::vector Columns() + { + return { + "id", + "npc_spells_id", + "spellid", + "type", + "minlevel", + "maxlevel", + "manacost", + "recast_delay", + "priority", + "resist_adjust", + "min_hp", + "max_hp", + "bucket_name", + "bucket_value", + "bucket_comparison", + }; + } + + static std::vector SelectColumns() + { + return { + "id", + "npc_spells_id", + "spellid", + "type", + "minlevel", + "maxlevel", + "manacost", + "recast_delay", + "priority", + "resist_adjust", + "min_hp", + "max_hp", + "bucket_name", + "bucket_value", + "bucket_comparison", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_spells_entries"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotSpellsEntries NewEntity() + { + BotSpellsEntries e{}; + + e.id = 0; + e.npc_spells_id = 0; + e.spellid = 0; + e.type = 0; + e.minlevel = 0; + e.maxlevel = 255; + e.manacost = -1; + e.recast_delay = -1; + e.priority = 0; + e.resist_adjust = 0; + e.min_hp = 0; + e.max_hp = 0; + e.bucket_name = ""; + e.bucket_value = ""; + e.bucket_comparison = 0; + + return e; + } + + static BotSpellsEntries GetBotSpellsEntries( + const std::vector &bot_spells_entriess, + int bot_spells_entries_id + ) + { + for (auto &bot_spells_entries : bot_spells_entriess) { + if (bot_spells_entries.id == bot_spells_entries_id) { + return bot_spells_entries; + } + } + + return NewEntity(); + } + + static BotSpellsEntries FindOne( + Database& db, + int bot_spells_entries_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_spells_entries_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotSpellsEntries e{}; + + e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.npc_spells_id = static_cast(atoi(row[1])); + e.spellid = static_cast(atoi(row[2])); + e.type = static_cast(strtoul(row[3], nullptr, 10)); + e.minlevel = static_cast(strtoul(row[4], nullptr, 10)); + e.maxlevel = static_cast(strtoul(row[5], nullptr, 10)); + e.manacost = static_cast(atoi(row[6])); + e.recast_delay = static_cast(atoi(row[7])); + e.priority = static_cast(atoi(row[8])); + e.resist_adjust = static_cast(atoi(row[9])); + e.min_hp = static_cast(atoi(row[10])); + e.max_hp = static_cast(atoi(row[11])); + e.bucket_name = row[12] ? row[12] : ""; + e.bucket_value = row[13] ? row[13] : ""; + e.bucket_comparison = static_cast(strtoul(row[14], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_spells_entries_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_spells_entries_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotSpellsEntries &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = " + std::to_string(e.npc_spells_id)); + v.push_back(columns[2] + " = " + std::to_string(e.spellid)); + v.push_back(columns[3] + " = " + std::to_string(e.type)); + v.push_back(columns[4] + " = " + std::to_string(e.minlevel)); + v.push_back(columns[5] + " = " + std::to_string(e.maxlevel)); + v.push_back(columns[6] + " = " + std::to_string(e.manacost)); + v.push_back(columns[7] + " = " + std::to_string(e.recast_delay)); + v.push_back(columns[8] + " = " + std::to_string(e.priority)); + v.push_back(columns[9] + " = " + std::to_string(e.resist_adjust)); + v.push_back(columns[10] + " = " + std::to_string(e.min_hp)); + v.push_back(columns[11] + " = " + std::to_string(e.max_hp)); + v.push_back(columns[12] + " = '" + Strings::Escape(e.bucket_name) + "'"); + v.push_back(columns[13] + " = '" + Strings::Escape(e.bucket_value) + "'"); + v.push_back(columns[14] + " = " + std::to_string(e.bucket_comparison)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotSpellsEntries InsertOne( + Database& db, + BotSpellsEntries e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.npc_spells_id)); + v.push_back(std::to_string(e.spellid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.minlevel)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.manacost)); + v.push_back(std::to_string(e.recast_delay)); + v.push_back(std::to_string(e.priority)); + v.push_back(std::to_string(e.resist_adjust)); + v.push_back(std::to_string(e.min_hp)); + v.push_back(std::to_string(e.max_hp)); + v.push_back("'" + Strings::Escape(e.bucket_name) + "'"); + v.push_back("'" + Strings::Escape(e.bucket_value) + "'"); + v.push_back(std::to_string(e.bucket_comparison)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.npc_spells_id)); + v.push_back(std::to_string(e.spellid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.minlevel)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.manacost)); + v.push_back(std::to_string(e.recast_delay)); + v.push_back(std::to_string(e.priority)); + v.push_back(std::to_string(e.resist_adjust)); + v.push_back(std::to_string(e.min_hp)); + v.push_back(std::to_string(e.max_hp)); + v.push_back("'" + Strings::Escape(e.bucket_name) + "'"); + v.push_back("'" + Strings::Escape(e.bucket_value) + "'"); + v.push_back(std::to_string(e.bucket_comparison)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotSpellsEntries e{}; + + e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.npc_spells_id = static_cast(atoi(row[1])); + e.spellid = static_cast(atoi(row[2])); + e.type = static_cast(strtoul(row[3], nullptr, 10)); + e.minlevel = static_cast(strtoul(row[4], nullptr, 10)); + e.maxlevel = static_cast(strtoul(row[5], nullptr, 10)); + e.manacost = static_cast(atoi(row[6])); + e.recast_delay = static_cast(atoi(row[7])); + e.priority = static_cast(atoi(row[8])); + e.resist_adjust = static_cast(atoi(row[9])); + e.min_hp = static_cast(atoi(row[10])); + e.max_hp = static_cast(atoi(row[11])); + e.bucket_name = row[12] ? row[12] : ""; + e.bucket_value = row[13] ? row[13] : ""; + e.bucket_comparison = static_cast(strtoul(row[14], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotSpellsEntries e{}; + + e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.npc_spells_id = static_cast(atoi(row[1])); + e.spellid = static_cast(atoi(row[2])); + e.type = static_cast(strtoul(row[3], nullptr, 10)); + e.minlevel = static_cast(strtoul(row[4], nullptr, 10)); + e.maxlevel = static_cast(strtoul(row[5], nullptr, 10)); + e.manacost = static_cast(atoi(row[6])); + e.recast_delay = static_cast(atoi(row[7])); + e.priority = static_cast(atoi(row[8])); + e.resist_adjust = static_cast(atoi(row[9])); + e.min_hp = static_cast(atoi(row[10])); + e.max_hp = static_cast(atoi(row[11])); + e.bucket_name = row[12] ? row[12] : ""; + e.bucket_value = row[13] ? row[13] : ""; + e.bucket_comparison = static_cast(strtoul(row[14], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_SPELLS_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_bot_stances_repository.h b/common/repositories/base/base_bot_stances_repository.h new file mode 100644 index 000000000..045203d63 --- /dev/null +++ b/common/repositories/base/base_bot_stances_repository.h @@ -0,0 +1,333 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_STANCES_REPOSITORY_H +#define EQEMU_BASE_BOT_STANCES_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotStancesRepository { +public: + struct BotStances { + uint32_t bot_id; + uint8_t stance_id; + }; + + static std::string PrimaryKey() + { + return std::string("bot_id"); + } + + static std::vector Columns() + { + return { + "bot_id", + "stance_id", + }; + } + + static std::vector SelectColumns() + { + return { + "bot_id", + "stance_id", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_stances"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotStances NewEntity() + { + BotStances e{}; + + e.bot_id = 0; + e.stance_id = 0; + + return e; + } + + static BotStances GetBotStances( + const std::vector &bot_stancess, + int bot_stances_id + ) + { + for (auto &bot_stances : bot_stancess) { + if (bot_stances.bot_id == bot_stances_id) { + return bot_stances; + } + } + + return NewEntity(); + } + + static BotStances FindOne( + Database& db, + int bot_stances_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_stances_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotStances e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.stance_id = static_cast(strtoul(row[1], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_stances_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_stances_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotStances &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[0] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[1] + " = " + std::to_string(e.stance_id)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.bot_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotStances InsertOne( + Database& db, + BotStances e + ) + { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.stance_id)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.bot_id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.stance_id)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotStances e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.stance_id = static_cast(strtoul(row[1], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotStances e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.stance_id = static_cast(strtoul(row[1], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_STANCES_REPOSITORY_H diff --git a/common/repositories/base/base_bot_timers_repository.h b/common/repositories/base/base_bot_timers_repository.h new file mode 100644 index 000000000..16858859b --- /dev/null +++ b/common/repositories/base/base_bot_timers_repository.h @@ -0,0 +1,343 @@ +/** + * DO NOT MODIFY THIS FILE + * + * This repository was automatically generated and is NOT to be modified directly. + * Any repository modifications are meant to be made to the repository extending the base. + * 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 + */ + +#ifndef EQEMU_BASE_BOT_TIMERS_REPOSITORY_H +#define EQEMU_BASE_BOT_TIMERS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseBotTimersRepository { +public: + struct BotTimers { + uint32_t bot_id; + uint32_t timer_id; + uint32_t timer_value; + }; + + static std::string PrimaryKey() + { + return std::string("bot_id"); + } + + static std::vector Columns() + { + return { + "bot_id", + "timer_id", + "timer_value", + }; + } + + static std::vector SelectColumns() + { + return { + "bot_id", + "timer_id", + "timer_value", + }; + } + + static std::string ColumnsRaw() + { + return std::string(Strings::Implode(", ", Columns())); + } + + static std::string SelectColumnsRaw() + { + return std::string(Strings::Implode(", ", SelectColumns())); + } + + static std::string TableName() + { + return std::string("bot_timers"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static BotTimers NewEntity() + { + BotTimers e{}; + + e.bot_id = 0; + e.timer_id = 0; + e.timer_value = 0; + + return e; + } + + static BotTimers GetBotTimers( + const std::vector &bot_timerss, + int bot_timers_id + ) + { + for (auto &bot_timers : bot_timerss) { + if (bot_timers.bot_id == bot_timers_id) { + return bot_timers; + } + } + + return NewEntity(); + } + + static BotTimers FindOne( + Database& db, + int bot_timers_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + bot_timers_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + BotTimers e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.timer_id = static_cast(strtoul(row[1], nullptr, 10)); + e.timer_value = static_cast(strtoul(row[2], nullptr, 10)); + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int bot_timers_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + bot_timers_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const BotTimers &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[0] + " = " + std::to_string(e.bot_id)); + v.push_back(columns[1] + " = " + std::to_string(e.timer_id)); + v.push_back(columns[2] + " = " + std::to_string(e.timer_value)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.bot_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static BotTimers InsertOne( + Database& db, + BotTimers e + ) + { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.timer_id)); + v.push_back(std::to_string(e.timer_value)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.bot_id = results.LastInsertedID(); + return e; + } + + e = NewEntity(); + + return e; + } + + static int InsertMany( + Database& db, + const std::vector &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.timer_id)); + v.push_back(std::to_string(e.timer_value)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotTimers e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.timer_id = static_cast(strtoul(row[1], nullptr, 10)); + e.timer_value = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + BotTimers e{}; + + e.bot_id = static_cast(strtoul(row[0], nullptr, 10)); + e.timer_id = static_cast(strtoul(row[1], nullptr, 10)); + e.timer_value = static_cast(strtoul(row[2], nullptr, 10)); + + all_entries.push_back(e); + } + + return all_entries; + } + + static int DeleteWhere(Database& db, const std::string &where_filter) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int Truncate(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "TRUNCATE TABLE {}", + TableName() + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int64 GetMaxId(Database& db) + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COALESCE(MAX({}), 0) FROM {}", + PrimaryKey(), + TableName() + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + + static int64 Count(Database& db, const std::string &where_filter = "") + { + auto results = db.QueryDatabase( + fmt::format( + "SELECT COUNT(*) FROM {} {}", + TableName(), + (where_filter.empty() ? "" : "WHERE " + where_filter) + ) + ); + + return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); + } + +}; + +#endif //EQEMU_BASE_BOT_TIMERS_REPOSITORY_H diff --git a/common/repositories/bot_buffs_repository.h b/common/repositories/bot_buffs_repository.h new file mode 100644 index 000000000..e7019601c --- /dev/null +++ b/common/repositories/bot_buffs_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_BUFFS_REPOSITORY_H +#define EQEMU_BOT_BUFFS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_buffs_repository.h" + +class BotBuffsRepository: public BaseBotBuffsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotBuffsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotBuffsRepository::GetWhereNeverExpires() + * BotBuffsRepository::GetWhereXAndY() + * BotBuffsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_BUFFS_REPOSITORY_H diff --git a/common/repositories/bot_create_combinations_repository.h b/common/repositories/bot_create_combinations_repository.h new file mode 100644 index 000000000..3955c9155 --- /dev/null +++ b/common/repositories/bot_create_combinations_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_CREATE_COMBINATIONS_REPOSITORY_H +#define EQEMU_BOT_CREATE_COMBINATIONS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_create_combinations_repository.h" + +class BotCreateCombinationsRepository: public BaseBotCreateCombinationsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotCreateCombinationsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotCreateCombinationsRepository::GetWhereNeverExpires() + * BotCreateCombinationsRepository::GetWhereXAndY() + * BotCreateCombinationsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_CREATE_COMBINATIONS_REPOSITORY_H diff --git a/common/repositories/bot_data_repository.h b/common/repositories/bot_data_repository.h new file mode 100644 index 000000000..e26781118 --- /dev/null +++ b/common/repositories/bot_data_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_DATA_REPOSITORY_H +#define EQEMU_BOT_DATA_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_data_repository.h" + +class BotDataRepository: public BaseBotDataRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotDataRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotDataRepository::GetWhereNeverExpires() + * BotDataRepository::GetWhereXAndY() + * BotDataRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_DATA_REPOSITORY_H diff --git a/common/repositories/bot_group_members_repository.h b/common/repositories/bot_group_members_repository.h new file mode 100644 index 000000000..837a5167e --- /dev/null +++ b/common/repositories/bot_group_members_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_GROUP_MEMBERS_REPOSITORY_H +#define EQEMU_BOT_GROUP_MEMBERS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_group_members_repository.h" + +class BotGroupMembersRepository: public BaseBotGroupMembersRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotGroupMembersRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotGroupMembersRepository::GetWhereNeverExpires() + * BotGroupMembersRepository::GetWhereXAndY() + * BotGroupMembersRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_GROUP_MEMBERS_REPOSITORY_H diff --git a/common/repositories/bot_groups_repository.h b/common/repositories/bot_groups_repository.h new file mode 100644 index 000000000..bd58f1356 --- /dev/null +++ b/common/repositories/bot_groups_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_GROUPS_REPOSITORY_H +#define EQEMU_BOT_GROUPS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_groups_repository.h" + +class BotGroupsRepository: public BaseBotGroupsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotGroupsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotGroupsRepository::GetWhereNeverExpires() + * BotGroupsRepository::GetWhereXAndY() + * BotGroupsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_GROUPS_REPOSITORY_H diff --git a/common/repositories/bot_guild_members_repository.h b/common/repositories/bot_guild_members_repository.h new file mode 100644 index 000000000..314a24b23 --- /dev/null +++ b/common/repositories/bot_guild_members_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_GUILD_MEMBERS_REPOSITORY_H +#define EQEMU_BOT_GUILD_MEMBERS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_guild_members_repository.h" + +class BotGuildMembersRepository: public BaseBotGuildMembersRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotGuildMembersRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotGuildMembersRepository::GetWhereNeverExpires() + * BotGuildMembersRepository::GetWhereXAndY() + * BotGuildMembersRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_GUILD_MEMBERS_REPOSITORY_H diff --git a/common/repositories/bot_heal_rotation_members_repository.h b/common/repositories/bot_heal_rotation_members_repository.h new file mode 100644 index 000000000..4e0c1d057 --- /dev/null +++ b/common/repositories/bot_heal_rotation_members_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_HEAL_ROTATION_MEMBERS_REPOSITORY_H +#define EQEMU_BOT_HEAL_ROTATION_MEMBERS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_heal_rotation_members_repository.h" + +class BotHealRotationMembersRepository: public BaseBotHealRotationMembersRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotHealRotationMembersRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotHealRotationMembersRepository::GetWhereNeverExpires() + * BotHealRotationMembersRepository::GetWhereXAndY() + * BotHealRotationMembersRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_HEAL_ROTATION_MEMBERS_REPOSITORY_H diff --git a/common/repositories/bot_heal_rotation_targets_repository.h b/common/repositories/bot_heal_rotation_targets_repository.h new file mode 100644 index 000000000..1faa29ac4 --- /dev/null +++ b/common/repositories/bot_heal_rotation_targets_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_HEAL_ROTATION_TARGETS_REPOSITORY_H +#define EQEMU_BOT_HEAL_ROTATION_TARGETS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_heal_rotation_targets_repository.h" + +class BotHealRotationTargetsRepository: public BaseBotHealRotationTargetsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotHealRotationTargetsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotHealRotationTargetsRepository::GetWhereNeverExpires() + * BotHealRotationTargetsRepository::GetWhereXAndY() + * BotHealRotationTargetsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_HEAL_ROTATION_TARGETS_REPOSITORY_H diff --git a/common/repositories/bot_heal_rotations_repository.h b/common/repositories/bot_heal_rotations_repository.h new file mode 100644 index 000000000..a5994fc5d --- /dev/null +++ b/common/repositories/bot_heal_rotations_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_HEAL_ROTATIONS_REPOSITORY_H +#define EQEMU_BOT_HEAL_ROTATIONS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_heal_rotations_repository.h" + +class BotHealRotationsRepository: public BaseBotHealRotationsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotHealRotationsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotHealRotationsRepository::GetWhereNeverExpires() + * BotHealRotationsRepository::GetWhereXAndY() + * BotHealRotationsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_HEAL_ROTATIONS_REPOSITORY_H diff --git a/common/repositories/bot_inspect_messages_repository.h b/common/repositories/bot_inspect_messages_repository.h new file mode 100644 index 000000000..27d486a57 --- /dev/null +++ b/common/repositories/bot_inspect_messages_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_INSPECT_MESSAGES_REPOSITORY_H +#define EQEMU_BOT_INSPECT_MESSAGES_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_inspect_messages_repository.h" + +class BotInspectMessagesRepository: public BaseBotInspectMessagesRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotInspectMessagesRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotInspectMessagesRepository::GetWhereNeverExpires() + * BotInspectMessagesRepository::GetWhereXAndY() + * BotInspectMessagesRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_INSPECT_MESSAGES_REPOSITORY_H diff --git a/common/repositories/bot_inventories_repository.h b/common/repositories/bot_inventories_repository.h new file mode 100644 index 000000000..84123fc22 --- /dev/null +++ b/common/repositories/bot_inventories_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_INVENTORIES_REPOSITORY_H +#define EQEMU_BOT_INVENTORIES_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_inventories_repository.h" + +class BotInventoriesRepository: public BaseBotInventoriesRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotInventoriesRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotInventoriesRepository::GetWhereNeverExpires() + * BotInventoriesRepository::GetWhereXAndY() + * BotInventoriesRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_INVENTORIES_REPOSITORY_H diff --git a/common/repositories/bot_owner_options_repository.h b/common/repositories/bot_owner_options_repository.h new file mode 100644 index 000000000..ecc698e7d --- /dev/null +++ b/common/repositories/bot_owner_options_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_OWNER_OPTIONS_REPOSITORY_H +#define EQEMU_BOT_OWNER_OPTIONS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_owner_options_repository.h" + +class BotOwnerOptionsRepository: public BaseBotOwnerOptionsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotOwnerOptionsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotOwnerOptionsRepository::GetWhereNeverExpires() + * BotOwnerOptionsRepository::GetWhereXAndY() + * BotOwnerOptionsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_OWNER_OPTIONS_REPOSITORY_H diff --git a/common/repositories/bot_pet_buffs_repository.h b/common/repositories/bot_pet_buffs_repository.h new file mode 100644 index 000000000..546b94f8b --- /dev/null +++ b/common/repositories/bot_pet_buffs_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_PET_BUFFS_REPOSITORY_H +#define EQEMU_BOT_PET_BUFFS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_pet_buffs_repository.h" + +class BotPetBuffsRepository: public BaseBotPetBuffsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotPetBuffsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotPetBuffsRepository::GetWhereNeverExpires() + * BotPetBuffsRepository::GetWhereXAndY() + * BotPetBuffsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_PET_BUFFS_REPOSITORY_H diff --git a/common/repositories/bot_pet_inventories_repository.h b/common/repositories/bot_pet_inventories_repository.h new file mode 100644 index 000000000..0ad1c7460 --- /dev/null +++ b/common/repositories/bot_pet_inventories_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_PET_INVENTORIES_REPOSITORY_H +#define EQEMU_BOT_PET_INVENTORIES_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_pet_inventories_repository.h" + +class BotPetInventoriesRepository: public BaseBotPetInventoriesRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotPetInventoriesRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotPetInventoriesRepository::GetWhereNeverExpires() + * BotPetInventoriesRepository::GetWhereXAndY() + * BotPetInventoriesRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_PET_INVENTORIES_REPOSITORY_H diff --git a/common/repositories/bot_pets_repository.h b/common/repositories/bot_pets_repository.h new file mode 100644 index 000000000..808d52bc2 --- /dev/null +++ b/common/repositories/bot_pets_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_PETS_REPOSITORY_H +#define EQEMU_BOT_PETS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_pets_repository.h" + +class BotPetsRepository: public BaseBotPetsRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotPetsRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotPetsRepository::GetWhereNeverExpires() + * BotPetsRepository::GetWhereXAndY() + * BotPetsRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_PETS_REPOSITORY_H diff --git a/common/repositories/bot_spell_casting_chances_repository.h b/common/repositories/bot_spell_casting_chances_repository.h new file mode 100644 index 000000000..b8c2ac921 --- /dev/null +++ b/common/repositories/bot_spell_casting_chances_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_SPELL_CASTING_CHANCES_REPOSITORY_H +#define EQEMU_BOT_SPELL_CASTING_CHANCES_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_spell_casting_chances_repository.h" + +class BotSpellCastingChancesRepository: public BaseBotSpellCastingChancesRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotSpellCastingChancesRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotSpellCastingChancesRepository::GetWhereNeverExpires() + * BotSpellCastingChancesRepository::GetWhereXAndY() + * BotSpellCastingChancesRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_SPELL_CASTING_CHANCES_REPOSITORY_H diff --git a/common/repositories/bot_spells_entries_repository.h b/common/repositories/bot_spells_entries_repository.h new file mode 100644 index 000000000..5901df341 --- /dev/null +++ b/common/repositories/bot_spells_entries_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_SPELLS_ENTRIES_REPOSITORY_H +#define EQEMU_BOT_SPELLS_ENTRIES_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_spells_entries_repository.h" + +class BotSpellsEntriesRepository: public BaseBotSpellsEntriesRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotSpellsEntriesRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotSpellsEntriesRepository::GetWhereNeverExpires() + * BotSpellsEntriesRepository::GetWhereXAndY() + * BotSpellsEntriesRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_SPELLS_ENTRIES_REPOSITORY_H diff --git a/common/repositories/bot_stances_repository.h b/common/repositories/bot_stances_repository.h new file mode 100644 index 000000000..a9a0e49e0 --- /dev/null +++ b/common/repositories/bot_stances_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_STANCES_REPOSITORY_H +#define EQEMU_BOT_STANCES_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_stances_repository.h" + +class BotStancesRepository: public BaseBotStancesRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotStancesRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotStancesRepository::GetWhereNeverExpires() + * BotStancesRepository::GetWhereXAndY() + * BotStancesRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_STANCES_REPOSITORY_H diff --git a/common/repositories/bot_timers_repository.h b/common/repositories/bot_timers_repository.h new file mode 100644 index 000000000..19cf9269e --- /dev/null +++ b/common/repositories/bot_timers_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_BOT_TIMERS_REPOSITORY_H +#define EQEMU_BOT_TIMERS_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_bot_timers_repository.h" + +class BotTimersRepository: public BaseBotTimersRepository { +public: + + /** + * This file was auto generated and can be modified and extended upon + * + * Base repository methods are automatically + * generated in the "base" version of this repository. The base repository + * is immutable and to be left untouched, while methods in this class + * are used as extension methods for more specific persistence-layer + * accessors or mutators. + * + * Base Methods (Subject to be expanded upon in time) + * + * Note: Not all tables are designed appropriately to fit functionality with all base methods + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * BotTimersRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * BotTimersRepository::GetWhereNeverExpires() + * BotTimersRepository::GetWhereXAndY() + * BotTimersRepository::DeleteWhereXAndY() + * + * Most of the above could be covered by base methods, but if you as a developer + * find yourself re-using logic for other parts of the code, its best to just make a + * method that can be re-used easily elsewhere especially if it can use a base repository + * method and encapsulate filters there + */ + + // Custom extended repository methods here + +}; + +#endif //EQEMU_BOT_TIMERS_REPOSITORY_H diff --git a/utils/scripts/generators/repository-generator.pl b/utils/scripts/generators/repository-generator.pl index 8ce5a8b69..775c90444 100644 --- a/utils/scripts/generators/repository-generator.pl +++ b/utils/scripts/generators/repository-generator.pl @@ -119,6 +119,7 @@ foreach my $table_to_generate (@tables) { my $table_found_in_schema = 0; my @categories = ( + "bot_tables", "content_tables", "version_tables", "state_tables",