diff --git a/common/repositories/spawngroup_repository.h b/common/repositories/spawngroup_repository.h index 7c55711b6..356ccd0ad 100644 --- a/common/repositories/spawngroup_repository.h +++ b/common/repositories/spawngroup_repository.h @@ -17,30 +17,36 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ + #ifndef EQEMU_SPAWNGROUP_REPOSITORY_H #define EQEMU_SPAWNGROUP_REPOSITORY_H #include "../database.h" #include "../string_util.h" -class SpawnGroupRepository { +class SpawngroupRepository { public: - struct SpawnGroup { + struct Spawngroup { int id; std::string name; int8 spawn_limit; - int dist; + float dist; float max_x; float min_x; float max_y; float min_y; int delay; int mindelay; - int despawn; + int8 despawn; int despawn_timer; - int wp_spawns; + int8 wp_spawns; }; + static std::string PrimaryKey() + { + return std::string("id"); + } + static std::vector Columns() { return { @@ -65,6 +71,21 @@ public: 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("spawngroup"); @@ -72,18 +93,25 @@ public: static std::string BaseSelect() { - return std::string( - fmt::format( - "SELECT {} FROM {}", - ColumnsRaw(), - TableName() - ) + return fmt::format( + "SELECT {} FROM {}", + ColumnsRaw(), + TableName() ); } - static SpawnGroup NewEntity() + static std::string BaseInsert() { - SpawnGroup entry; + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + InsertColumnsRaw() + ); + } + + static Spawngroup NewEntity() + { + Spawngroup entry{}; entry.id = 0; entry.name = ""; @@ -93,36 +121,44 @@ public: entry.min_x = 0; entry.max_y = 0; entry.min_y = 0; - entry.delay = 0; - entry.mindelay = 0; + entry.delay = 45000; + entry.mindelay = 15000; entry.despawn = 0; - entry.despawn_timer = 0; + entry.despawn_timer = 100; entry.wp_spawns = 0; return entry; } - static std::vector GetZoneSpawnGroups( - const std::string &zone_short_name, - int zone_version + static Spawngroup GetSpawngroupEntry( + const std::vector &spawngroups, + int spawngroup_id ) { - std::vector spawn_groups; + for (auto &spawngroup : spawngroups) { + if (spawngroup.id == spawngroup_id) { + return spawngroup; + } + } + return NewEntity(); + } + + static Spawngroup FindOne( + int spawngroup_id + ) + { auto results = content_db.QueryDatabase( fmt::format( - SQL ( - {} INNER JOIN spawn2 ON spawn2.spawngroupID = spawngroup.id - WHERE spawn2.zone = '{}' and spawn2.version = {} - ), + "{} WHERE id = {} LIMIT 1", BaseSelect(), - zone_short_name, - zone_version + spawngroup_id ) ); - for (auto row = results.begin(); row != results.end(); ++row) { - SpawnGroup entry{}; + auto row = results.begin(); + if (results.RowCount() == 1) { + Spawngroup entry{}; entry.id = atoi(row[0]); entry.name = row[1]; @@ -138,27 +174,173 @@ public: entry.despawn_timer = atoi(row[11]); entry.wp_spawns = atoi(row[12]); - spawn_groups.push_back(entry); - } - - return spawn_groups; - } - - static SpawnGroup GetGrid( - const std::vector &spawn_groups, - int spawn_group_id - ) - { - for (auto &row : spawn_groups) { - if (row.id == spawn_group_id) { - return row; - } + return entry; } return NewEntity(); } + static int DeleteOne( + int spawngroup_id + ) + { + auto results = content_db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + spawngroup_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Spawngroup spawngroup_entry + ) + { + std::vector update_values; + + auto columns = Columns(); + + update_values.push_back(columns[1] + " = '" + EscapeString(spawngroup_entry.name) + "'"); + update_values.push_back(columns[2] + " = " + std::to_string(spawngroup_entry.spawn_limit)); + update_values.push_back(columns[3] + " = '" + EscapeString(spawngroup_entry.dist) + "'"); + update_values.push_back(columns[4] + " = '" + EscapeString(spawngroup_entry.max_x) + "'"); + update_values.push_back(columns[5] + " = '" + EscapeString(spawngroup_entry.min_x) + "'"); + update_values.push_back(columns[6] + " = '" + EscapeString(spawngroup_entry.max_y) + "'"); + update_values.push_back(columns[7] + " = '" + EscapeString(spawngroup_entry.min_y) + "'"); + update_values.push_back(columns[8] + " = " + std::to_string(spawngroup_entry.delay)); + update_values.push_back(columns[9] + " = " + std::to_string(spawngroup_entry.mindelay)); + update_values.push_back(columns[10] + " = " + std::to_string(spawngroup_entry.despawn)); + update_values.push_back(columns[11] + " = " + std::to_string(spawngroup_entry.despawn_timer)); + update_values.push_back(columns[12] + " = " + std::to_string(spawngroup_entry.wp_spawns)); + + auto results = content_db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + implode(", ", update_values), + PrimaryKey(), + spawngroup_entry.id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static Spawngroup InsertOne( + Spawngroup spawngroup_entry + ) + { + std::vector insert_values; + + insert_values.push_back("'" + EscapeString(spawngroup_entry.name) + "'"); + insert_values.push_back(std::to_string(spawngroup_entry.spawn_limit)); + insert_values.push_back("'" + EscapeString(spawngroup_entry.dist) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.max_x) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.min_x) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.max_y) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.min_y) + "'"); + insert_values.push_back(std::to_string(spawngroup_entry.delay)); + insert_values.push_back(std::to_string(spawngroup_entry.mindelay)); + insert_values.push_back(std::to_string(spawngroup_entry.despawn)); + insert_values.push_back(std::to_string(spawngroup_entry.despawn_timer)); + insert_values.push_back(std::to_string(spawngroup_entry.wp_spawns)); + + auto results = content_db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + implode(",", insert_values) + ) + ); + + if (results.Success()) { + spawngroup_entry.id = results.LastInsertedID(); + return spawngroup_entry; + } + + spawngroup_entry = InstanceListRepository::NewEntity(); + + return spawngroup_entry; + } + + static int InsertMany( + std::vector spawngroup_entries + ) + { + std::vector insert_chunks; + + for (auto &spawngroup_entry: spawngroup_entries) { + std::vector insert_values; + + insert_values.push_back("'" + EscapeString(spawngroup_entry.name) + "'"); + insert_values.push_back(std::to_string(spawngroup_entry.spawn_limit)); + insert_values.push_back("'" + EscapeString(spawngroup_entry.dist) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.max_x) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.min_x) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.max_y) + "'"); + insert_values.push_back("'" + EscapeString(spawngroup_entry.min_y) + "'"); + insert_values.push_back(std::to_string(spawngroup_entry.delay)); + insert_values.push_back(std::to_string(spawngroup_entry.mindelay)); + insert_values.push_back(std::to_string(spawngroup_entry.despawn)); + insert_values.push_back(std::to_string(spawngroup_entry.despawn_timer)); + insert_values.push_back(std::to_string(spawngroup_entry.wp_spawns)); + + 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) { + Spawngroup entry{}; + + entry.id = atoi(row[0]); + entry.name = row[1]; + entry.spawn_limit = atoi(row[2]); + entry.dist = atof(row[3]); + entry.max_x = atof(row[4]); + entry.min_x = atof(row[5]); + entry.max_y = atof(row[6]); + entry.min_y = atof(row[7]); + entry.delay = atoi(row[8]); + entry.mindelay = atoi(row[9]); + entry.despawn = atoi(row[10]); + entry.despawn_timer = atoi(row[11]); + entry.wp_spawns = atoi(row[12]); + + all_entries.push_back(entry); + } + + return all_entries; + } + }; - #endif //EQEMU_SPAWNGROUP_REPOSITORY_H diff --git a/common/repositories/tradeskill_recipe_repository.h b/common/repositories/tradeskill_recipe_repository.h index 428d120ac..15ee26ce3 100644 --- a/common/repositories/tradeskill_recipe_repository.h +++ b/common/repositories/tradeskill_recipe_repository.h @@ -29,22 +29,17 @@ public: struct TradeskillRecipe { int id; std::string name; - int16 tradeskill; - int16 skillneeded; - int16 trivial; - int8 nofail; - int8 replace_container; + int tradeskill; + int skillneeded; + int trivial; + uint8 nofail; + int replace_container; std::string notes; - int8 must_learn; - int8 quest; - int8 enabled; + uint8 must_learn; + uint8 quest; + uint8 enabled; }; - static std::string PrimaryKey() - { - return std::string("id"); - } - static std::vector Columns() { return { @@ -67,21 +62,6 @@ public: 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"); @@ -89,25 +69,18 @@ public: static std::string BaseSelect() { - return fmt::format( - "SELECT {} FROM {}", - ColumnsRaw(), - TableName() - ); - } - - static std::string BaseInsert() - { - return fmt::format( - "INSERT INTO {} ({}) ", - TableName(), - InsertColumnsRaw() + return std::string( + fmt::format( + "SELECT {} FROM {}", + ColumnsRaw(), + TableName() + ) ); } static TradeskillRecipe NewEntity() { - TradeskillRecipe entry{}; + TradeskillRecipe entry; entry.id = 0; entry.name = ""; @@ -116,215 +89,46 @@ public: entry.trivial = 0; entry.nofail = 0; entry.replace_container = 0; - entry.notes = 0; + entry.notes = ""; entry.must_learn = 0; entry.quest = 0; - entry.enabled = 1; + entry.enabled = 0; 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 - ) + static TradeskillRecipe GetRecipe(int recipe_id) { auto results = content_db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE id = {}", BaseSelect(), - tradeskill_recipe_id + recipe_id ) ); + TradeskillRecipe tradeskill_recipe = NewEntity(); + auto row = results.begin(); - if (results.RowCount() == 1) { - TradeskillRecipe entry{}; - - entry.id = atoi(row[0]); - entry.name = 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]; - entry.must_learn = atoi(row[8]); - entry.quest = atoi(row[9]); - entry.enabled = atoi(row[10]); - - return entry; + if (results.RowCount() == 0) { + return tradeskill_recipe; } - return NewEntity(); - } + 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]); - 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)); - - 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)); - - 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 = InstanceListRepository::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_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]; - 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]; - entry.must_learn = atoi(row[8]); - entry.quest = atoi(row[9]); - entry.enabled = atoi(row[10]); - - all_entries.push_back(entry); - } - - return all_entries; + return tradeskill_recipe; } }; -#endif //EQEMU_TRADESKILL_RECIPE_REPOSITORY_H +#endif diff --git a/utils/scripts/generators/repository-generator.pl b/utils/scripts/generators/repository-generator.pl index f55c9f1f3..a902b81f2 100644 --- a/utils/scripts/generators/repository-generator.pl +++ b/utils/scripts/generators/repository-generator.pl @@ -117,6 +117,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_entries", # Manually created + "tradeskill_recipe", # Manually created + "character_recipe_list", # Manually created "eqtime", "db_version", "keyring",