From 123bc5f19ab28426bb543e9df3b723688a2ec567 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Fri, 27 May 2022 14:46:53 -0400 Subject: [PATCH] [Commands] Cleanup #findclass and #findrace Commands. (#2211) - Cleanup messages and logic. - Add bitmasks to player race messages. --- zone/gm_commands/findclass.cpp | 72 ++++++++++++++++------------- zone/gm_commands/findrace.cpp | 82 +++++++++++++++++++--------------- zone/mob.cpp | 10 +++++ zone/mob.h | 1 + 4 files changed, 97 insertions(+), 68 deletions(-) diff --git a/zone/gm_commands/findclass.cpp b/zone/gm_commands/findclass.cpp index a220f5ded..01456db57 100755 --- a/zone/gm_commands/findclass.cpp +++ b/zone/gm_commands/findclass.cpp @@ -3,9 +3,8 @@ void command_findclass(Client *c, const Seperator *sep) { int arguments = sep->argnum; - - if (arguments == 0) { - c->Message(Chat::White, "Command Syntax: #findclass [search criteria]"); + if (!arguments) { + c->Message(Chat::White, "Command Syntax: #findclass [Search Criteria]"); return; } @@ -16,9 +15,17 @@ void command_findclass(Client *c, const Seperator *sep) c->Message( Chat::White, fmt::format( - "Class {}: {}", + "Class {} | {}{}", class_id, - class_name + class_name, + ( + c->IsPlayerClass(class_id) ? + fmt::format( + " ({})", + GetPlayerClassBit(class_id) + ) : + "" + ) ).c_str() ); } @@ -31,51 +38,52 @@ void command_findclass(Client *c, const Seperator *sep) ).c_str() ); } - } - else { - std::string search_criteria = str_tolower(sep->argplus[1]); - int found_count = 0; - for (int class_id = WARRIOR; class_id <= MERCERNARY_MASTER; class_id++) { - std::string class_name = GetClassIDName(class_id); - std::string class_name_lower = str_tolower(class_name); - if (search_criteria.length() > 0 && class_name_lower.find(search_criteria) == std::string::npos) { + } else { + auto search_criteria = str_tolower(sep->argplus[1]); + int found_count = 0; + for (uint16 class_id = WARRIOR; class_id <= MERCERNARY_MASTER; class_id++) { + std::string class_name = GetClassIDName(class_id); + auto class_name_lower = str_tolower(class_name); + if ( + search_criteria.length() && + class_name_lower.find(search_criteria) == std::string::npos + ) { continue; } c->Message( Chat::White, fmt::format( - "Class {}: {}", + "Class {} | {}{}", class_id, - class_name + class_name, + ( + c->IsPlayerClass(class_id) ? + fmt::format( + " ({})", + GetPlayerClassBit(class_id) + ) : + "" + ) ).c_str() ); + found_count++; - if (found_count == 20) { + if (found_count == 50) { break; } } - if (found_count == 20) { - c->Message(Chat::White, "20 Classes found... max reached."); - } - else { - auto class_message = ( - found_count > 0 ? - ( - found_count == 1 ? - "A Class was" : - fmt::format("{} Classes were", found_count) - ) : - "No Classes were" - ); - + if (found_count == 50) { + c->Message(Chat::White, "50 Classes found, max reached."); + } else { c->Message( Chat::White, fmt::format( - "{} found.", - class_message + "{} Class{} found.", + found_count, + found_count != 1 ? "es" : "" ).c_str() ); } diff --git a/zone/gm_commands/findrace.cpp b/zone/gm_commands/findrace.cpp index 413687160..06b5ccc56 100755 --- a/zone/gm_commands/findrace.cpp +++ b/zone/gm_commands/findrace.cpp @@ -3,26 +3,35 @@ void command_findrace(Client *c, const Seperator *sep) { int arguments = sep->argnum; - - if (arguments == 0) { - c->Message(Chat::White, "Command Syntax: #findrace [search criteria]"); + if (!arguments) { + c->Message(Chat::White, "Command Syntax: #findrace [Search Criteria]"); return; } if (sep->IsNumber(1)) { - int race_id = std::stoi(sep->arg[1]); + auto race_id = static_cast(std::stoul(sep->arg[1])); std::string race_name = GetRaceIDName(race_id); - if (race_id >= RACE_HUMAN_1 && race_id <= RACE_PEGASUS_732) { + if ( + race_id >= RACE_HUMAN_1 && + race_id <= RACE_PEGASUS_732 + ) { c->Message( Chat::White, fmt::format( - "Race {}: {}", + "Race {} | {}{}", race_id, - race_name + race_name, + ( + c->IsPlayerRace(race_id) ? + fmt::format( + " ({})", + GetPlayerRaceBit(race_id) + ) : + "" + ) ).c_str() ); - } - else { + } else { c->Message( Chat::White, fmt::format( @@ -31,51 +40,52 @@ void command_findrace(Client *c, const Seperator *sep) ).c_str() ); } - } - else { - std::string search_criteria = str_tolower(sep->argplus[1]); - int found_count = 0; - for (int race_id = RACE_HUMAN_1; race_id <= RACE_PEGASUS_732; race_id++) { - std::string race_name = GetRaceIDName(race_id); - std::string race_name_lower = str_tolower(race_name); - if (search_criteria.length() > 0 && race_name_lower.find(search_criteria) == std::string::npos) { + } else { + auto search_criteria = str_tolower(sep->argplus[1]); + int found_count = 0; + for (uint16 race_id = RACE_HUMAN_1; race_id <= RACE_PEGASUS_732; race_id++) { + std::string race_name = GetRaceIDName(race_id); + auto race_name_lower = str_tolower(race_name); + if ( + search_criteria.length() && + race_name_lower.find(search_criteria) == std::string::npos + ) { continue; } c->Message( Chat::White, fmt::format( - "Race {}: {}", + "Race {} | {}{}", race_id, - race_name + race_name, + ( + c->IsPlayerRace(race_id) ? + fmt::format( + " ({})", + GetPlayerRaceBit(race_id) + ) : + "" + ) ).c_str() ); + found_count++; - if (found_count == 20) { + if (found_count == 50) { break; } } - if (found_count == 20) { - c->Message(Chat::White, "20 Races found... max reached."); - } - else { - auto race_message = ( - found_count > 0 ? - ( - found_count == 1 ? - "A Race was" : - fmt::format("{} Races were", found_count) - ) : - "No Races were" - ); - + if (found_count == 50) { + c->Message(Chat::White, "50 Races found, max reached."); + } else { c->Message( Chat::White, fmt::format( - "{} found.", - race_message + "{} Race{} found.", + found_count, + found_count != 1 ? "s" : "" ).c_str() ); } diff --git a/zone/mob.cpp b/zone/mob.cpp index dc0032256..103989e4a 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -2854,6 +2854,16 @@ bool Mob::RandomizeFeatures(bool send_illusion, bool set_variables) return false; } +bool Mob::IsPlayerClass(uint16 in_class) { + if ( + in_class >= WARRIOR && + in_class <= BERSERKER + ) { + return true; + } + + return false; +} bool Mob::IsPlayerRace(uint16 in_race) { diff --git a/zone/mob.h b/zone/mob.h index 67aaa734a..269572d03 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -741,6 +741,7 @@ public: //Util static uint32 RandomTimer(int min, int max); static uint8 GetDefaultGender(uint16 in_race, uint8 in_gender = 0xFF); + static bool IsPlayerClass(uint16 in_class); static bool IsPlayerRace(uint16 in_race); EQ::skills::SkillType GetSkillByItemType(int ItemType); uint8 GetItemTypeBySkill(EQ::skills::SkillType skill);