[Commands] Cleanup #findclass and #findrace Commands. (#2211)

- Cleanup messages and logic.
- Add bitmasks to player race messages.
This commit is contained in:
Kinglykrab 2022-05-27 14:46:53 -04:00 committed by GitHub
parent e6db71e31e
commit 123bc5f19a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 68 deletions

View File

@ -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]);
} else {
auto search_criteria = str_tolower(sep->argplus[1]);
int found_count = 0;
for (int class_id = WARRIOR; class_id <= MERCERNARY_MASTER; class_id++) {
for (uint16 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) {
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()
);
}

View File

@ -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<uint16>(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]);
} else {
auto 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++) {
for (uint16 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) {
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()
);
}

View File

@ -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) {

View File

@ -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);