From 90d74c2ed108f9e4b7bf58c4fd29e950ecac6f6c Mon Sep 17 00:00:00 2001 From: Aleos Date: Sat, 21 Nov 2020 18:41:43 -0500 Subject: [PATCH] Cleanup/skill db fixes (#5560) * Cleanup of some minor skill db issues. * Fixes CastCancel documentation to describe default as false. Thanks to @Tokeiburu! Co-authored-by: Lemongrass3110 --- db/import-tmpl/skill_db.yml | 2 +- db/pre-re/skill_db.yml | 2 +- db/re/skill_db.yml | 2 +- db/skill_db.yml | 2 +- doc/yaml/db/skill_db.yml | 2 +- src/tool/csv2yaml.cpp | 53 ++++++++++++++++++++----------------- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/db/import-tmpl/skill_db.yml b/db/import-tmpl/skill_db.yml index 5aee1174cd..e2e155091e 100644 --- a/db/import-tmpl/skill_db.yml +++ b/db/import-tmpl/skill_db.yml @@ -55,7 +55,7 @@ # NoNearNPC: Determines if the skill can be used near a NPC. (Optional) # AdditionalRange Number of cells from an NPC where the skill can be cast. (Optional) # Type: Type of NPC. -# CastCancel Cancel cast when hit. (Default: true) +# CastCancel Cancel cast when hit. (Default: false) # CastDefenseReduction Defense reduction rate during skill cast. (Default: 0) # CastTime: Time to cast the skill in milliseconds. (Default: 0) # - Level Skill level. diff --git a/db/pre-re/skill_db.yml b/db/pre-re/skill_db.yml index d72540de50..dfd764632a 100644 --- a/db/pre-re/skill_db.yml +++ b/db/pre-re/skill_db.yml @@ -55,7 +55,7 @@ # NoNearNPC: Determines if the skill can be used near a NPC. (Optional) # AdditionalRange Number of cells from an NPC where the skill can be cast. (Optional) # Type: Type of NPC. -# CastCancel Cancel cast when hit. (Default: true) +# CastCancel Cancel cast when hit. (Default: false) # CastDefenseReduction Defense reduction rate during skill cast. (Default: 0) # CastTime: Time to cast the skill in milliseconds. (Default: 0) # - Level Skill level. diff --git a/db/re/skill_db.yml b/db/re/skill_db.yml index b17fd81244..295b9df07a 100644 --- a/db/re/skill_db.yml +++ b/db/re/skill_db.yml @@ -55,7 +55,7 @@ # NoNearNPC: Determines if the skill can be used near a NPC. (Optional) # AdditionalRange Number of cells from an NPC where the skill can be cast. (Optional) # Type: Type of NPC. -# CastCancel Cancel cast when hit. (Default: true) +# CastCancel Cancel cast when hit. (Default: false) # CastDefenseReduction Defense reduction rate during skill cast. (Default: 0) # CastTime: Time to cast the skill in milliseconds. (Default: 0) # - Level Skill level. diff --git a/db/skill_db.yml b/db/skill_db.yml index 28ec2ca234..abebd68c2e 100644 --- a/db/skill_db.yml +++ b/db/skill_db.yml @@ -55,7 +55,7 @@ # NoNearNPC: Determines if the skill can be used near a NPC. (Optional) # AdditionalRange Number of cells from an NPC where the skill can be cast. (Optional) # Type: Type of NPC. -# CastCancel Cancel cast when hit. (Default: true) +# CastCancel Cancel cast when hit. (Default: false) # CastDefenseReduction Defense reduction rate during skill cast. (Default: 0) # CastTime: Time to cast the skill in milliseconds. (Default: 0) # - Level Skill level. diff --git a/doc/yaml/db/skill_db.yml b/doc/yaml/db/skill_db.yml index 9efcb9311b..982b221c4f 100644 --- a/doc/yaml/db/skill_db.yml +++ b/doc/yaml/db/skill_db.yml @@ -38,7 +38,7 @@ # NoNearNPC: Determines if the skill can be used near a NPC. (Optional) # AdditionalRange Number of cells from an NPC where the skill can be cast. (Optional) # Type: Type of NPC. -# CastCancel Cancel cast when hit. (Default: true) +# CastCancel Cancel cast when hit. (Default: false) # CastDefenseReduction Defense reduction rate during skill cast. (Default: 0) # CastTime: Time to cast the skill in milliseconds. (Default: 0) # - Level Skill level. diff --git a/src/tool/csv2yaml.cpp b/src/tool/csv2yaml.cpp index ee4750f30c..0f87e3c8e9 100644 --- a/src/tool/csv2yaml.cpp +++ b/src/tool/csv2yaml.cpp @@ -231,7 +231,6 @@ std::unordered_map constants; static bool parse_item_constants_txt( const char* path ); static bool parse_mob_constants( char* split[], int columns, int current ); static bool parse_skill_constants_txt( char* split[], int columns, int current ); -static bool parse_skill_constants_yml(std::string path, std::string filename); static void init_random_option_constants(); bool fileExists( const std::string& path ); @@ -432,9 +431,8 @@ int do_init( int argc, char** argv ){ } sv_readdb( path_db_mode.c_str(), "mob_db.txt", ',', 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, -1, &parse_mob_constants, false ); sv_readdb( path_db_import.c_str(), "mob_db.txt", ',', 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, 31 + 2 * MAX_MVP_DROP + 2 * MAX_MOB_DROP, -1, &parse_mob_constants, false ); - if (fileExists(path_db + "/" + "skill_db.yml")) { - parse_skill_constants_yml(path_db_mode, "skill_db.yml"); - parse_skill_constants_yml(path_db_import + "/", "skill_db.yml"); + if (fileExists(skill_db.getDefaultLocation())) { + skill_db.load(); } else { sv_readdb(path_db_mode.c_str(), "skill_db.txt", ',', 18, 18, -1, parse_skill_constants_txt, false); sv_readdb(path_db_import.c_str(), "skill_db.txt", ',', 18, 18, -1, parse_skill_constants_txt, false); @@ -806,29 +804,34 @@ static bool parse_skill_constants_txt( char* split[], int columns, int current ) return true; } -static bool parse_skill_constants_yml(std::string path, std::string filename) { - YAML::Node rootNode; - - try { - rootNode = YAML::LoadFile(path + filename); - } catch (YAML::Exception &e) { - ShowError("Failed to read file from '" CL_WHITE "%s%s" CL_RESET "'.\n", path.c_str(), filename.c_str()); - ShowError("%s (Line %d: Column %d)\n", e.msg.c_str(), e.mark.line, e.mark.column); - return false; - } - - uint64 count = 0; - - for (const YAML::Node &body : rootNode["Body"]) { - aegis_skillnames[body["Id"].as()] = body["Name"].as(); - count++; - } - - ShowStatus("Done reading '" CL_WHITE "%" PRIu64 CL_RESET "' entries in '" CL_WHITE "%s%s" CL_RESET "'" CL_CLL "\n", count, path.c_str(), filename.c_str()); - - return true; +const std::string SkillDatabase::getDefaultLocation() { + return std::string(db_path) + "/skill_db.yml"; } +uint64 SkillDatabase::parseBodyNode(const YAML::Node &node) { + t_itemid nameid; + + if (!this->asUInt32(node, "Id", nameid)) + return 0; + + if (this->nodeExists(node, "Name")) { + std::string name; + + if (!this->asString(node, "Name", name)) + return 0; + + aegis_skillnames[nameid] = name; + } + + return 1; +} + +void SkillDatabase::clear() { + TypesafeCachedYamlDatabase::clear(); +} + +SkillDatabase skill_db; + /** * Split the string with ':' as separator and put each value for a skilllv * @param str: String to split