From 8d8301fbd7a844c25aab9ea8f9a7dc52266e5101 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Sat, 6 Nov 2021 17:35:43 -0400 Subject: [PATCH] [Commands] Add #findskill [search criteria] Command. (#1674) * [Commands] Add #findskill [search criteria] Command. - Allows you to search for skills by ID or partial name. * Add error message. * Update command.cpp * Update command.cpp * Update command.cpp --- zone/command.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ zone/command.h | 1 + 2 files changed, 87 insertions(+) diff --git a/zone/command.cpp b/zone/command.cpp index 5f22ab2fa..cb084020f 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -221,6 +221,7 @@ int command_init(void) command_add("findclass", "[search criteria] - Search for a class", 50, command_findclass) || command_add("findnpctype", "[search criteria] - Search database NPC types", 100, command_findnpctype) || command_add("findrace", "[search criteria] - Search for a race", 50, command_findrace) || + command_add("findskill", "[search criteria] - Search for a skill", 50, command_findskill) || command_add("findspell", "[search criteria] - Search for a spell", 50, command_findspell) || command_add("findtask", "[search criteria] - Search for a task", 50, command_findtask) || command_add("findzone", "[search criteria] - Search database zones", 100, command_findzone) || @@ -2882,6 +2883,91 @@ void command_findrace(Client *c, const Seperator *sep) } } +void command_findskill(Client *c, const Seperator *sep) +{ + int arguments = sep->argnum; + + if (arguments == 0) { + c->Message(Chat::White, "Command Syntax: #findskill [search criteria]"); + return; + } + + std::map skills = EQ::skills::GetSkillTypeMap(); + if (sep->IsNumber(1)) { + int skill_id = atoi(sep->argplus[1]); + if (skill_id >= EQ::skills::Skill1HBlunt && skill_id < EQ::skills::SkillCount) { + for (auto skills_iter : skills) { + if (skill_id == skills_iter.first) { + c->Message( + Chat::White, + fmt::format( + "{}: {}", + skills_iter.first, + skills_iter.second + ).c_str() + ); + break; + } + } + } else { + c->Message( + Chat::White, + fmt::format( + "Skill ID {} was not found.", + skill_id + ).c_str() + ); + } + } else { + std::string search_criteria = str_tolower(sep->argplus[1]); + if (!search_criteria.empty()) { + int found_count = 0; + for (auto skills_iter : skills) { + std::string skill_name_lower = str_tolower(skills_iter.second); + if (skill_name_lower.find(search_criteria) == std::string::npos) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "{}: {}", + skills_iter.first, + skills_iter.second + ).c_str() + ); + found_count++; + + if (found_count == 20) { + break; + } + } + + if (found_count == 20) { + c->Message(Chat::White, "20 Skills were found, max reached."); + } else { + auto skill_message = ( + found_count > 0 ? + ( + found_count == 1 ? + "A skill was" : + fmt::format("{} skills were", found_count) + ) : + "No skills were" + ); + + c->Message( + Chat::White, + fmt::format( + "{} found.", + skill_message + ).c_str() + ); + } + } + } +} + void command_findspell(Client *c, const Seperator *sep) { if (sep->arg[1][0] == 0) { diff --git a/zone/command.h b/zone/command.h index 7bac28308..dec5cd076 100644 --- a/zone/command.h +++ b/zone/command.h @@ -109,6 +109,7 @@ void command_findaliases(Client *c, const Seperator *sep); void command_findclass(Client *c, const Seperator *sep); void command_findnpctype(Client *c, const Seperator *sep); void command_findrace(Client *c, const Seperator *sep); +void command_findskill(Client *c, const Seperator *sep); void command_findspell(Client *c, const Seperator *sep); void command_findtask(Client *c, const Seperator *sep); void command_findzone(Client *c, const Seperator *sep);