diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 62c494e85..5b095e098 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -186,6 +186,8 @@ SET(repositories repositories/base/base_gm_ips_repository.h repositories/base/base_goallists_repository.h repositories/base/base_graveyard_repository.h + repositories/base/base_grid_repository.h + repositories/base/base_grid_entries_repository.h repositories/base/base_ground_spawns_repository.h repositories/base/base_group_id_repository.h repositories/base/base_group_leaders_repository.h @@ -267,6 +269,7 @@ SET(repositories repositories/base/base_timers_repository.h repositories/base/base_titles_repository.h repositories/base/base_trader_repository.h + repositories/base/base_tradeskill_recipe_repository.h repositories/base/base_tradeskill_recipe_entries_repository.h repositories/base/base_traps_repository.h repositories/base/base_tributes_repository.h @@ -348,6 +351,8 @@ SET(repositories repositories/gm_ips_repository.h repositories/goallists_repository.h repositories/graveyard_repository.h + repositories/grid_repository.h + repositories/grid_entries_repository.h repositories/ground_spawns_repository.h repositories/group_id_repository.h repositories/group_leaders_repository.h @@ -429,6 +434,7 @@ SET(repositories repositories/timers_repository.h repositories/titles_repository.h repositories/trader_repository.h + repositories/tradeskill_recipe_repository.h repositories/tradeskill_recipe_entries_repository.h repositories/traps_repository.h repositories/tributes_repository.h @@ -437,10 +443,6 @@ SET(repositories repositories/veteran_reward_templates_repository.h repositories/zone_repository.h repositories/zone_points_repository.h - - repositories/grid_repository.h - repositories/grid_entries_repository.h - repositories/tradeskill_recipe_repository.h ) SET(common_headers diff --git a/common/repositories/base/base_grid_entries_repository.h b/common/repositories/base/base_grid_entries_repository.h new file mode 100644 index 000000000..6b0f3fcd2 --- /dev/null +++ b/common/repositories/base/base_grid_entries_repository.h @@ -0,0 +1,363 @@ +/** + * EQEmulator: Everquest Server Emulator + * Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY except by those people which sell it, which + * are required to give you total support for your newly bought product; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + */ + +/** + * This repository was automatically generated on Apr 5, 2020 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 + */ + +#ifndef EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H +#define EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H + +#include "../../database.h" +#include "../../string_util.h" + +class BaseGridEntriesRepository { +public: + struct GridEntries { + int gridid; + int zoneid; + int number; + float x; + float y; + float z; + float heading; + int pause; + int8 centerpoint; + }; + + static std::string PrimaryKey() + { + return std::string("number"); + } + + static std::vector Columns() + { + return { + "gridid", + "zoneid", + "number", + "x", + "y", + "z", + "heading", + "pause", + "centerpoint", + }; + } + + static std::string ColumnsRaw() + { + return std::string(implode(", ", Columns())); + } + + static std::string InsertColumnsRaw() + { + std::vector insert_columns; + + for (auto &column : Columns()) { + if (column == PrimaryKey()) { + continue; + } + + insert_columns.push_back(column); + } + + return std::string(implode(", ", insert_columns)); + } + + static std::string TableName() + { + return std::string("grid_entries"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + ColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + InsertColumnsRaw() + ); + } + + static GridEntries NewEntity() + { + GridEntries entry{}; + + entry.gridid = 0; + entry.zoneid = 0; + entry.number = 0; + entry.x = 0; + entry.y = 0; + entry.z = 0; + entry.heading = 0; + entry.pause = 0; + entry.centerpoint = 0; + + return entry; + } + + static GridEntries GetGridEntriesEntry( + const std::vector &grid_entriess, + int grid_entries_id + ) + { + for (auto &grid_entries : grid_entriess) { + if (grid_entries.number == grid_entries_id) { + return grid_entries; + } + } + + return NewEntity(); + } + + static GridEntries FindOne( + int grid_entries_id + ) + { + auto results = content_db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + grid_entries_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + GridEntries entry{}; + + entry.gridid = atoi(row[0]); + entry.zoneid = atoi(row[1]); + entry.number = atoi(row[2]); + entry.x = atof(row[3]); + entry.y = atof(row[4]); + entry.z = atof(row[5]); + entry.heading = atof(row[6]); + entry.pause = atoi(row[7]); + entry.centerpoint = atoi(row[8]); + + return entry; + } + + return NewEntity(); + } + + static int DeleteOne( + int grid_entries_id + ) + { + auto results = content_db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + grid_entries_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + GridEntries grid_entries_entry + ) + { + std::vector update_values; + + auto columns = Columns(); + + update_values.push_back(columns[3] + " = " + std::to_string(grid_entries_entry.x)); + update_values.push_back(columns[4] + " = " + std::to_string(grid_entries_entry.y)); + update_values.push_back(columns[5] + " = " + std::to_string(grid_entries_entry.z)); + update_values.push_back(columns[6] + " = " + std::to_string(grid_entries_entry.heading)); + update_values.push_back(columns[7] + " = " + std::to_string(grid_entries_entry.pause)); + update_values.push_back(columns[8] + " = " + std::to_string(grid_entries_entry.centerpoint)); + + auto results = content_db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + implode(", ", update_values), + PrimaryKey(), + grid_entries_entry.number + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static GridEntries InsertOne( + GridEntries grid_entries_entry + ) + { + std::vector insert_values; + + insert_values.push_back(std::to_string(grid_entries_entry.x)); + insert_values.push_back(std::to_string(grid_entries_entry.y)); + insert_values.push_back(std::to_string(grid_entries_entry.z)); + insert_values.push_back(std::to_string(grid_entries_entry.heading)); + insert_values.push_back(std::to_string(grid_entries_entry.pause)); + insert_values.push_back(std::to_string(grid_entries_entry.centerpoint)); + + auto results = content_db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + implode(",", insert_values) + ) + ); + + if (results.Success()) { + grid_entries_entry.id = results.LastInsertedID(); + return grid_entries_entry; + } + + grid_entries_entry = NewEntity(); + + return grid_entries_entry; + } + + static int InsertMany( + std::vector grid_entries_entries + ) + { + std::vector insert_chunks; + + for (auto &grid_entries_entry: grid_entries_entries) { + std::vector insert_values; + + insert_values.push_back(std::to_string(grid_entries_entry.x)); + insert_values.push_back(std::to_string(grid_entries_entry.y)); + insert_values.push_back(std::to_string(grid_entries_entry.z)); + insert_values.push_back(std::to_string(grid_entries_entry.heading)); + insert_values.push_back(std::to_string(grid_entries_entry.pause)); + insert_values.push_back(std::to_string(grid_entries_entry.centerpoint)); + + insert_chunks.push_back("(" + implode(",", insert_values) + ")"); + } + + std::vector insert_values; + + auto results = content_db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All() + { + std::vector all_entries; + + auto results = content_db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + GridEntries entry{}; + + entry.gridid = atoi(row[0]); + entry.zoneid = atoi(row[1]); + entry.number = atoi(row[2]); + entry.x = atof(row[3]); + entry.y = atof(row[4]); + entry.z = atof(row[5]); + entry.heading = atof(row[6]); + entry.pause = atoi(row[7]); + entry.centerpoint = atoi(row[8]); + + all_entries.push_back(entry); + } + + return all_entries; + } + + static std::vector GetWhere(std::string where_filter) + { + std::vector all_entries; + + auto results = content_db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + GridEntries entry{}; + + entry.gridid = atoi(row[0]); + entry.zoneid = atoi(row[1]); + entry.number = atoi(row[2]); + entry.x = atof(row[3]); + entry.y = atof(row[4]); + entry.z = atof(row[5]); + entry.heading = atof(row[6]); + entry.pause = atoi(row[7]); + entry.centerpoint = atoi(row[8]); + + all_entries.push_back(entry); + } + + return all_entries; + } + + static int DeleteWhere(std::string where_filter) + { + auto results = content_db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + PrimaryKey(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + +}; + +#endif //EQEMU_BASE_GRID_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_grid_repository.h b/common/repositories/base/base_grid_repository.h new file mode 100644 index 000000000..0fedf47a5 --- /dev/null +++ b/common/repositories/base/base_grid_repository.h @@ -0,0 +1,321 @@ +/** + * EQEmulator: Everquest Server Emulator + * Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY except by those people which sell it, which + * are required to give you total support for your newly bought product; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + */ + +/** + * This repository was automatically generated on Apr 5, 2020 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 + */ + +#ifndef EQEMU_BASE_GRID_REPOSITORY_H +#define EQEMU_BASE_GRID_REPOSITORY_H + +#include "../../database.h" +#include "../../string_util.h" + +class BaseGridRepository { +public: + struct Grid { + int id; + int zoneid; + int type; + int type2; + }; + + static std::string PrimaryKey() + { + return std::string("zoneid"); + } + + static std::vector Columns() + { + return { + "id", + "zoneid", + "type", + "type2", + }; + } + + static std::string ColumnsRaw() + { + return std::string(implode(", ", Columns())); + } + + static std::string InsertColumnsRaw() + { + std::vector insert_columns; + + for (auto &column : Columns()) { + if (column == PrimaryKey()) { + continue; + } + + insert_columns.push_back(column); + } + + return std::string(implode(", ", insert_columns)); + } + + static std::string TableName() + { + return std::string("grid"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + ColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + InsertColumnsRaw() + ); + } + + static Grid NewEntity() + { + Grid entry{}; + + entry.id = 0; + entry.zoneid = 0; + entry.type = 0; + entry.type2 = 0; + + return entry; + } + + static Grid GetGridEntry( + const std::vector &grids, + int grid_id + ) + { + for (auto &grid : grids) { + if (grid.zoneid == grid_id) { + return grid; + } + } + + return NewEntity(); + } + + static Grid FindOne( + int grid_id + ) + { + auto results = content_db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + grid_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + Grid entry{}; + + entry.id = atoi(row[0]); + entry.zoneid = atoi(row[1]); + entry.type = atoi(row[2]); + entry.type2 = atoi(row[3]); + + return entry; + } + + return NewEntity(); + } + + static int DeleteOne( + int grid_id + ) + { + auto results = content_db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + grid_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Grid grid_entry + ) + { + std::vector update_values; + + auto columns = Columns(); + + update_values.push_back(columns[2] + " = " + std::to_string(grid_entry.type)); + update_values.push_back(columns[3] + " = " + std::to_string(grid_entry.type2)); + + auto results = content_db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + implode(", ", update_values), + PrimaryKey(), + grid_entry.zoneid + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static Grid InsertOne( + Grid grid_entry + ) + { + std::vector insert_values; + + insert_values.push_back(std::to_string(grid_entry.type)); + insert_values.push_back(std::to_string(grid_entry.type2)); + + auto results = content_db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + implode(",", insert_values) + ) + ); + + if (results.Success()) { + grid_entry.id = results.LastInsertedID(); + return grid_entry; + } + + grid_entry = NewEntity(); + + return grid_entry; + } + + static int InsertMany( + std::vector grid_entries + ) + { + std::vector insert_chunks; + + for (auto &grid_entry: grid_entries) { + std::vector insert_values; + + insert_values.push_back(std::to_string(grid_entry.type)); + insert_values.push_back(std::to_string(grid_entry.type2)); + + insert_chunks.push_back("(" + implode(",", insert_values) + ")"); + } + + std::vector insert_values; + + auto results = content_db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All() + { + std::vector all_entries; + + auto results = content_db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + Grid entry{}; + + entry.id = atoi(row[0]); + entry.zoneid = atoi(row[1]); + entry.type = atoi(row[2]); + entry.type2 = atoi(row[3]); + + all_entries.push_back(entry); + } + + return all_entries; + } + + static std::vector GetWhere(std::string where_filter) + { + std::vector all_entries; + + auto results = content_db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + Grid entry{}; + + entry.id = atoi(row[0]); + entry.zoneid = atoi(row[1]); + entry.type = atoi(row[2]); + entry.type2 = atoi(row[3]); + + all_entries.push_back(entry); + } + + return all_entries; + } + + static int DeleteWhere(std::string where_filter) + { + auto results = content_db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + PrimaryKey(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + +}; + +#endif //EQEMU_BASE_GRID_REPOSITORY_H diff --git a/common/repositories/base/base_tradeskill_recipe_repository.h b/common/repositories/base/base_tradeskill_recipe_repository.h new file mode 100644 index 000000000..58ca82916 --- /dev/null +++ b/common/repositories/base/base_tradeskill_recipe_repository.h @@ -0,0 +1,414 @@ +/** + * EQEmulator: Everquest Server Emulator + * Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY except by those people which sell it, which + * are required to give you total support for your newly bought product; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + */ + +/** + * This repository was automatically generated on Apr 5, 2020 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 + */ + +#ifndef EQEMU_BASE_TRADESKILL_RECIPE_REPOSITORY_H +#define EQEMU_BASE_TRADESKILL_RECIPE_REPOSITORY_H + +#include "../../database.h" +#include "../../string_util.h" + +class BaseTradeskillRecipeRepository { +public: + struct TradeskillRecipe { + int id; + std::string name; + int16 tradeskill; + int16 skillneeded; + int16 trivial; + int8 nofail; + int8 replace_container; + std::string notes; + int8 must_learn; + int8 quest; + int8 enabled; + int8 min_expansion; + int8 max_expansion; + std::string content_flags; + }; + + static std::string PrimaryKey() + { + return std::string("id"); + } + + static std::vector Columns() + { + return { + "id", + "name", + "tradeskill", + "skillneeded", + "trivial", + "nofail", + "replace_container", + "notes", + "must_learn", + "quest", + "enabled", + "min_expansion", + "max_expansion", + "content_flags", + }; + } + + static std::string ColumnsRaw() + { + return std::string(implode(", ", Columns())); + } + + static std::string InsertColumnsRaw() + { + std::vector insert_columns; + + for (auto &column : Columns()) { + if (column == PrimaryKey()) { + continue; + } + + insert_columns.push_back(column); + } + + return std::string(implode(", ", insert_columns)); + } + + static std::string TableName() + { + return std::string("tradeskill_recipe"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + ColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + InsertColumnsRaw() + ); + } + + static TradeskillRecipe NewEntity() + { + TradeskillRecipe entry{}; + + entry.id = 0; + entry.name = ""; + entry.tradeskill = 0; + entry.skillneeded = 0; + entry.trivial = 0; + entry.nofail = 0; + entry.replace_container = 0; + entry.notes = ""; + entry.must_learn = 0; + entry.quest = 0; + entry.enabled = 1; + entry.min_expansion = 0; + entry.max_expansion = 0; + entry.content_flags = ""; + + return entry; + } + + static TradeskillRecipe GetTradeskillRecipeEntry( + const std::vector &tradeskill_recipes, + int tradeskill_recipe_id + ) + { + for (auto &tradeskill_recipe : tradeskill_recipes) { + if (tradeskill_recipe.id == tradeskill_recipe_id) { + return tradeskill_recipe; + } + } + + return NewEntity(); + } + + static TradeskillRecipe FindOne( + int tradeskill_recipe_id + ) + { + auto results = content_db.QueryDatabase( + fmt::format( + "{} WHERE id = {} LIMIT 1", + BaseSelect(), + tradeskill_recipe_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + TradeskillRecipe entry{}; + + entry.id = atoi(row[0]); + entry.name = row[1] ? row[1] : ""; + entry.tradeskill = atoi(row[2]); + entry.skillneeded = atoi(row[3]); + entry.trivial = atoi(row[4]); + entry.nofail = atoi(row[5]); + entry.replace_container = atoi(row[6]); + entry.notes = row[7] ? row[7] : ""; + entry.must_learn = atoi(row[8]); + entry.quest = atoi(row[9]); + entry.enabled = atoi(row[10]); + entry.min_expansion = atoi(row[11]); + entry.max_expansion = atoi(row[12]); + entry.content_flags = row[13] ? row[13] : ""; + + return entry; + } + + return NewEntity(); + } + + static int DeleteOne( + int tradeskill_recipe_id + ) + { + auto results = content_db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + tradeskill_recipe_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + TradeskillRecipe tradeskill_recipe_entry + ) + { + std::vector update_values; + + auto columns = Columns(); + + update_values.push_back(columns[1] + " = '" + EscapeString(tradeskill_recipe_entry.name) + "'"); + update_values.push_back(columns[2] + " = " + std::to_string(tradeskill_recipe_entry.tradeskill)); + update_values.push_back(columns[3] + " = " + std::to_string(tradeskill_recipe_entry.skillneeded)); + update_values.push_back(columns[4] + " = " + std::to_string(tradeskill_recipe_entry.trivial)); + update_values.push_back(columns[5] + " = " + std::to_string(tradeskill_recipe_entry.nofail)); + update_values.push_back(columns[6] + " = " + std::to_string(tradeskill_recipe_entry.replace_container)); + update_values.push_back(columns[7] + " = '" + EscapeString(tradeskill_recipe_entry.notes) + "'"); + update_values.push_back(columns[8] + " = " + std::to_string(tradeskill_recipe_entry.must_learn)); + update_values.push_back(columns[9] + " = " + std::to_string(tradeskill_recipe_entry.quest)); + update_values.push_back(columns[10] + " = " + std::to_string(tradeskill_recipe_entry.enabled)); + update_values.push_back(columns[11] + " = " + std::to_string(tradeskill_recipe_entry.min_expansion)); + update_values.push_back(columns[12] + " = " + std::to_string(tradeskill_recipe_entry.max_expansion)); + update_values.push_back(columns[13] + " = '" + EscapeString(tradeskill_recipe_entry.content_flags) + "'"); + + auto results = content_db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + implode(", ", update_values), + PrimaryKey(), + tradeskill_recipe_entry.id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static TradeskillRecipe InsertOne( + TradeskillRecipe tradeskill_recipe_entry + ) + { + std::vector insert_values; + + insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.name) + "'"); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.tradeskill)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.skillneeded)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.trivial)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.nofail)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.replace_container)); + insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.notes) + "'"); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.must_learn)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.quest)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.enabled)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.min_expansion)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.max_expansion)); + insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.content_flags) + "'"); + + auto results = content_db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + implode(",", insert_values) + ) + ); + + if (results.Success()) { + tradeskill_recipe_entry.id = results.LastInsertedID(); + return tradeskill_recipe_entry; + } + + tradeskill_recipe_entry = NewEntity(); + + return tradeskill_recipe_entry; + } + + static int InsertMany( + std::vector tradeskill_recipe_entries + ) + { + std::vector insert_chunks; + + for (auto &tradeskill_recipe_entry: tradeskill_recipe_entries) { + std::vector insert_values; + + insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.name) + "'"); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.tradeskill)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.skillneeded)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.trivial)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.nofail)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.replace_container)); + insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.notes) + "'"); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.must_learn)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.quest)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.enabled)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.min_expansion)); + insert_values.push_back(std::to_string(tradeskill_recipe_entry.max_expansion)); + insert_values.push_back("'" + EscapeString(tradeskill_recipe_entry.content_flags) + "'"); + + insert_chunks.push_back("(" + implode(",", insert_values) + ")"); + } + + std::vector insert_values; + + auto results = content_db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All() + { + std::vector all_entries; + + auto results = content_db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + TradeskillRecipe entry{}; + + entry.id = atoi(row[0]); + entry.name = row[1] ? row[1] : ""; + entry.tradeskill = atoi(row[2]); + entry.skillneeded = atoi(row[3]); + entry.trivial = atoi(row[4]); + entry.nofail = atoi(row[5]); + entry.replace_container = atoi(row[6]); + entry.notes = row[7] ? row[7] : ""; + entry.must_learn = atoi(row[8]); + entry.quest = atoi(row[9]); + entry.enabled = atoi(row[10]); + entry.min_expansion = atoi(row[11]); + entry.max_expansion = atoi(row[12]); + entry.content_flags = row[13] ? row[13] : ""; + + all_entries.push_back(entry); + } + + return all_entries; + } + + static std::vector GetWhere(std::string where_filter) + { + std::vector all_entries; + + auto results = content_db.QueryDatabase( + fmt::format( + "{} WHERE {}", + BaseSelect(), + where_filter + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + TradeskillRecipe entry{}; + + entry.id = atoi(row[0]); + entry.name = row[1] ? row[1] : ""; + entry.tradeskill = atoi(row[2]); + entry.skillneeded = atoi(row[3]); + entry.trivial = atoi(row[4]); + entry.nofail = atoi(row[5]); + entry.replace_container = atoi(row[6]); + entry.notes = row[7] ? row[7] : ""; + entry.must_learn = atoi(row[8]); + entry.quest = atoi(row[9]); + entry.enabled = atoi(row[10]); + entry.min_expansion = atoi(row[11]); + entry.max_expansion = atoi(row[12]); + entry.content_flags = row[13] ? row[13] : ""; + + all_entries.push_back(entry); + } + + return all_entries; + } + + static int DeleteWhere(std::string where_filter) + { + auto results = content_db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {}", + TableName(), + PrimaryKey(), + where_filter + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + +}; + +#endif //EQEMU_BASE_TRADESKILL_RECIPE_REPOSITORY_H diff --git a/common/repositories/grid_repository.h b/common/repositories/grid_repository.h index cddeed021..ea965546e 100644 --- a/common/repositories/grid_repository.h +++ b/common/repositories/grid_repository.h @@ -23,58 +23,45 @@ #include "../database.h" #include "../string_util.h" +#include "base/base_grid_repository.h" -class GridRepository { +class GridRepository : public BaseGridRepository { public: - struct Grid { - int id; - int zoneid; - int type; - int type2; - }; - static std::vector Columns() - { - return { - "id", - "zoneid", - "type", - "type2", - }; - } + /** + * This file was auto generated on Apr 5, 2020 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) + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * GridRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * GridRepository::GetWhereNeverExpires() + * GridRepository::GetWhereXAndY() + * GridRepository::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 + */ - static std::string ColumnsRaw() - { - return std::string(implode(", ", Columns())); - } - - static std::string TableName() - { - return std::string("grid"); - } - - static std::string BaseSelect() - { - return std::string( - fmt::format( - "SELECT {} FROM {}", - ColumnsRaw(), - TableName() - ) - ); - } - - static Grid NewEntity() - { - Grid entry{}; - - entry.id = 0; - entry.zoneid = 0; - entry.type = 0; - entry.type2 = 0; - - return entry; - } + // Custom extended repository methods here static std::vector GetZoneGrids(int zone_id) { @@ -118,4 +105,4 @@ public: }; -#endif +#endif //EQEMU_GRID_REPOSITORY_H diff --git a/common/repositories/tradeskill_recipe_repository.h b/common/repositories/tradeskill_recipe_repository.h index 15ee26ce3..f0445aa11 100644 --- a/common/repositories/tradeskill_recipe_repository.h +++ b/common/repositories/tradeskill_recipe_repository.h @@ -23,112 +23,48 @@ #include "../database.h" #include "../string_util.h" +#include "base/base_tradeskill_recipe_repository.h" -class TradeskillRecipeRepository { +class TradeskillRecipeRepository: public BaseTradeskillRecipeRepository { public: - struct TradeskillRecipe { - int id; - std::string name; - int tradeskill; - int skillneeded; - int trivial; - uint8 nofail; - int replace_container; - std::string notes; - uint8 must_learn; - uint8 quest; - uint8 enabled; - }; - static std::vector Columns() - { - return { - "id", - "name", - "tradeskill", - "skillneeded", - "trivial", - "nofail", - "replace_container", - "notes", - "must_learn", - "quest", - "enabled", - }; - } + /** + * This file was auto generated on Apr 5, 2020 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) + * + * InsertOne + * UpdateOne + * DeleteOne + * FindOne + * GetWhere(std::string where_filter) + * DeleteWhere(std::string where_filter) + * InsertMany + * All + * + * Example custom methods in a repository + * + * TradeskillRecipeRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * TradeskillRecipeRepository::GetWhereNeverExpires() + * TradeskillRecipeRepository::GetWhereXAndY() + * TradeskillRecipeRepository::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 + */ - static std::string ColumnsRaw() - { - return std::string(implode(", ", Columns())); - } + // Custom extended repository methods here - static std::string TableName() - { - return std::string("tradeskill_recipe"); - } - static std::string BaseSelect() - { - return std::string( - fmt::format( - "SELECT {} FROM {}", - ColumnsRaw(), - TableName() - ) - ); - } - - static TradeskillRecipe NewEntity() - { - TradeskillRecipe entry; - - entry.id = 0; - entry.name = ""; - entry.tradeskill = 0; - entry.skillneeded = 0; - entry.trivial = 0; - entry.nofail = 0; - entry.replace_container = 0; - entry.notes = ""; - entry.must_learn = 0; - entry.quest = 0; - entry.enabled = 0; - - return entry; - } - - static TradeskillRecipe GetRecipe(int recipe_id) - { - auto results = content_db.QueryDatabase( - fmt::format( - "{} WHERE id = {}", - BaseSelect(), - recipe_id - ) - ); - - TradeskillRecipe tradeskill_recipe = NewEntity(); - - auto row = results.begin(); - if (results.RowCount() == 0) { - return tradeskill_recipe; - } - - tradeskill_recipe.id = atoi(row[0]); - tradeskill_recipe.name = (row[1] ? row[1] : ""); - tradeskill_recipe.tradeskill = atoi(row[2]); - tradeskill_recipe.skillneeded = atoi(row[3]); - tradeskill_recipe.trivial = atoi(row[4]); - tradeskill_recipe.nofail = atoi(row[5]); - tradeskill_recipe.replace_container = atoi(row[6]); - tradeskill_recipe.notes = (row[7] ? row[7] : ""); - tradeskill_recipe.must_learn = atoi(row[8]); - tradeskill_recipe.quest = atoi(row[9]); - tradeskill_recipe.enabled = atoi(row[10]); - - return tradeskill_recipe; - } }; -#endif +#endif //EQEMU_TRADESKILL_RECIPE_REPOSITORY_H diff --git a/utils/scripts/generators/repository-generator.pl b/utils/scripts/generators/repository-generator.pl index fca540a3b..060b6b010 100644 --- a/utils/scripts/generators/repository-generator.pl +++ b/utils/scripts/generators/repository-generator.pl @@ -2,7 +2,7 @@ # Author: Akkadius # @file: repository-generator.pl # @description: Script used to generate database repositories -# @example perl ~/code/utils/scripts/generators/repository-generator.pl ~/server/ +# @example perl ~/code/utils/scripts/generators/repository-generator.pl ~/server/ [table|all] [base|extended|all] ############################################# # modules @@ -20,9 +20,10 @@ my $json = new JSON(); ############################################# # args ############################################# -my $server_path = $ARGV[0]; -my $config_path = $server_path . "/eqemu_config.json"; -my $requested_table_to_generate = $ARGV[1] ? $ARGV[1] : ""; +my $server_path = $ARGV[0]; +my $config_path = $server_path . "/eqemu_config.json"; +my $requested_table_to_generate = $ARGV[1] ? $ARGV[1] : "all"; +my $repository_generation_option = $ARGV[2] ? $ARGV[2] : "all"; ############################################# # world path @@ -118,10 +119,10 @@ foreach my $table_to_generate (@tables) { # These tables don't have a typical schema my @table_ignore_list = ( "character_enabledtasks", - "grid", # Manually created + # "grid", # Manually created "grid_entries", # Manually created - "tradeskill_recipe", # Manually created - "character_recipe_list", # Manually created + # "tradeskill_recipe", # Manually created + # "character_recipe_list", # Manually created "guild_bank", "inventory_versions", "raid_leaders", @@ -388,39 +389,48 @@ foreach my $table_to_generate (@tables) { $new_repository =~ s/\{\{ALL_ENTRIES}}/$all_entries/g; $new_repository =~ s/\{\{GENERATED_DATE}}/$generated_date/g; - print $new_base_repository; - print $new_repository; + if ($repository_generation_option eq "all" || $repository_generation_option eq "base") { + print $new_base_repository; + } + + if ($repository_generation_option eq "all" || $repository_generation_option eq "extended") { + print $new_repository; + } ############################################# # write base repository ############################################# - my $generated_base_repository = './common/repositories/base/base_' . $table_to_generate . '_repository.h'; - my $cmake_generated_base_reference = $generated_base_repository; - $cmake_generated_base_reference =~ s/.\/common\///g; - $generated_base_repository_files .= $cmake_generated_base_reference . "\n"; - open(FH, '>', $generated_base_repository) or die $!; - print FH $new_base_repository; - close(FH); + if ($repository_generation_option eq "all" || $repository_generation_option eq "base") { + my $generated_base_repository = './common/repositories/base/base_' . $table_to_generate . '_repository.h'; + my $cmake_generated_base_reference = $generated_base_repository; + $cmake_generated_base_reference =~ s/.\/common\///g; + $generated_base_repository_files .= $cmake_generated_base_reference . "\n"; + open(FH, '>', $generated_base_repository) or die $!; + print FH $new_base_repository; + close(FH); + } ############################################# - # write repository + # write extended repository ############################################# - my $generated_repository = './common/repositories/' . $table_to_generate . '_repository.h'; - my $cmake_generated_reference = $generated_repository; - $cmake_generated_reference =~ s/.\/common\///g; - $generated_repository_files .= $cmake_generated_reference . "\n"; - open(FH, '>', $generated_repository) or die $!; - print FH $new_repository; - close(FH); + if ($repository_generation_option eq "all" || $repository_generation_option eq "extended") { + my $generated_repository = './common/repositories/' . $table_to_generate . '_repository.h'; + my $cmake_generated_reference = $generated_repository; + $cmake_generated_reference =~ s/.\/common\///g; + $generated_repository_files .= $cmake_generated_reference . "\n"; + open(FH, '>', $generated_repository) or die $!; + print FH $new_repository; + close(FH); + } } print "\n# Make sure to add generated repositories to common/CMakeLists.txt under the repositories section\n\n"; -print "\n#Base repository files\n"; +print "\n#Base Repositories\n"; print $generated_base_repository_files . "\n"; -print "\n#repository files\n"; +print "\n#Extended Repositories\n"; print $generated_repository_files . "\n"; sub trim { diff --git a/zone/tradeskills.cpp b/zone/tradeskills.cpp index aba4a8a5d..6c5cea48d 100644 --- a/zone/tradeskills.cpp +++ b/zone/tradeskills.cpp @@ -993,7 +993,7 @@ bool Client::TradeskillExecute(DBTradeskillRecipe_Struct *spec) { aa_chance = spellbonuses.ReduceTradeskillFail[spec->tradeskill] + itembonuses.ReduceTradeskillFail[spec->tradeskill] + aabonuses.ReduceTradeskillFail[spec->tradeskill]; const EQEmu::ItemData* item = nullptr; - + chance = mod_tradeskill_chance(chance, spec); if (((spec->tradeskill==75) || GetGM() || (chance > res)) || zone->random.Roll(aa_chance)) { @@ -1497,7 +1497,7 @@ void Client::LearnRecipe(uint32 recipe_id) return; } - auto tradeskill_recipe = TradeskillRecipeRepository::GetRecipe(recipe_id); + auto tradeskill_recipe = TradeskillRecipeRepository::FindOne(recipe_id); if (tradeskill_recipe.id == 0) { LogError("Invalid recipe [{}]", recipe_id); return; @@ -1542,8 +1542,8 @@ bool Client::CanIncreaseTradeskill(EQEmu::skills::SkillType tradeskill) { uint8 Tailoring = (GetRawSkill(EQEmu::skills::SkillTailoring) > 200) ? 1 : 0; uint8 SkillTotal = Baking + Smithing + Brewing + Fletching + Jewelry + Pottery + Tailoring; //Tradeskills above 200 //New Tanaan AA: Each level allows an additional tradeskill above 200 (first one is free) - uint8 aaLevel = spellbonuses.TradeSkillMastery + itembonuses.TradeSkillMastery + aabonuses.TradeSkillMastery; - + uint8 aaLevel = spellbonuses.TradeSkillMastery + itembonuses.TradeSkillMastery + aabonuses.TradeSkillMastery; + switch (tradeskill) { case EQEmu::skills::SkillBaking: case EQEmu::skills::SkillBlacksmithing: