mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 17:51:28 +00:00
[Commands] Add #findclass [search criteria] command. (#1384)
* [Commands] Add #findclass [search criteria] command. - Allows GMs to find a class by name or ID. - Modify some verbiage in command messages that were improper. * Update find functions to use strings instead of chars.
This commit is contained in:
parent
a0063997e1
commit
d162f25536
192
zone/command.cpp
192
zone/command.cpp
@ -212,6 +212,7 @@ int command_init(void)
|
|||||||
command_add("face", "- Change the face of your target", 80, command_face) ||
|
command_add("face", "- Change the face of your target", 80, command_face) ||
|
||||||
command_add("faction", "[Find (criteria | all ) | Review (criteria | all) | Reset (id)] - Resets Player's Faction", 80, command_faction) ||
|
command_add("faction", "[Find (criteria | all ) | Review (criteria | all) | Reset (id)] - Resets Player's Faction", 80, command_faction) ||
|
||||||
command_add("findaliases", "[search criteria]- Searches for available command aliases, by alias or command", 0, command_findaliases) ||
|
command_add("findaliases", "[search criteria]- Searches for available command aliases, by alias or command", 0, command_findaliases) ||
|
||||||
|
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("findnpctype", "[search criteria] - Search database NPC types", 100, command_findnpctype) ||
|
||||||
command_add("findrace", "[search criteria] - Search for a race", 50, command_findrace) ||
|
command_add("findrace", "[search criteria] - Search for a race", 50, command_findrace) ||
|
||||||
command_add("findspell", "[search criteria] - Search for a spell", 50, command_findspell) ||
|
command_add("findspell", "[search criteria] - Search for a spell", 50, command_findspell) ||
|
||||||
@ -2689,34 +2690,101 @@ void command_showskills(Client *c, const Seperator *sep)
|
|||||||
c->Message(Chat::White, "Skill [%d] is at [%d] - %u", i, t->GetSkill(i), t->GetRawSkill(i));
|
c->Message(Chat::White, "Skill [%d] is at [%d] - %u", i, t->GetSkill(i), t->GetRawSkill(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
void command_findrace(Client *c, const Seperator *sep)
|
void command_findclass(Client *c, const Seperator *sep)
|
||||||
{
|
{
|
||||||
if (sep->arg[1][0] == 0) {
|
if (sep->arg[1][0] == 0) {
|
||||||
c->Message(Chat::White, "Usage: #findrace [race name]");
|
c->Message(Chat::White, "Usage: #findclass [search criteria]");
|
||||||
} else if (Seperator::IsNumber(sep->argplus[1])) {
|
} else if (Seperator::IsNumber(sep->argplus[1])) {
|
||||||
int search_id = atoi(sep->argplus[1]);
|
int search_id = atoi(sep->argplus[1]);
|
||||||
std::string race_name = GetRaceIDName(search_id);
|
std::string class_name = GetClassIDName(search_id);
|
||||||
if (race_name != std::string("")) {
|
if (class_name.length() > 0) {
|
||||||
c->Message(Chat::White, "Race %d: %s", search_id, race_name.c_str());
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Class {}: {}",
|
||||||
|
search_id,
|
||||||
|
class_name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const char *search_criteria = sep->argplus[1];
|
std::string search_criteria = str_tolower(sep->argplus[1]);
|
||||||
int found_count = 0;
|
int found_count = 0;
|
||||||
char race_name[64];
|
for (int class_id = WARRIOR; class_id <= MERCERNARY_MASTER; class_id++) {
|
||||||
char search_string[65];
|
std::string class_name = GetClassIDName(class_id);
|
||||||
strn0cpy(search_string, search_criteria, sizeof(search_string));
|
std::string class_name_lower = str_tolower(class_name);
|
||||||
strupr(search_string);
|
if (search_criteria.length() > 0 && class_name_lower.find(search_criteria) == std::string::npos) {
|
||||||
char *string_location;
|
continue;
|
||||||
for (int race_id = RACE_HUMAN_1; race_id <= RT_PEGASUS_3; race_id++) {
|
|
||||||
strn0cpy(race_name, GetRaceIDName(race_id), sizeof(race_name));
|
|
||||||
strupr(race_name);
|
|
||||||
string_location = strstr(race_name, search_string);
|
|
||||||
if (string_location != nullptr) {
|
|
||||||
c->Message(Chat::White, "Race %d: %s", race_id, GetRaceIDName(race_id));
|
|
||||||
found_count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Class {}: {}",
|
||||||
|
class_id,
|
||||||
|
class_name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
found_count++;
|
||||||
|
|
||||||
|
if (found_count == 20) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found_count == 20) {
|
||||||
|
c->Message(Chat::White, "20 Classes found... max reached.");
|
||||||
|
} else {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"{} Class(es) found.",
|
||||||
|
found_count
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void command_findrace(Client *c, const Seperator *sep)
|
||||||
|
{
|
||||||
|
if (sep->arg[1][0] == 0) {
|
||||||
|
c->Message(Chat::White, "Usage: #findrace [search criteria]");
|
||||||
|
} else if (Seperator::IsNumber(sep->argplus[1])) {
|
||||||
|
int search_id = atoi(sep->argplus[1]);
|
||||||
|
std::string race_name = GetRaceIDName(search_id);
|
||||||
|
if (race_name.length() > 0) {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Race {}: {}",
|
||||||
|
search_id,
|
||||||
|
race_name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::string search_criteria = str_tolower(sep->argplus[1]);
|
||||||
|
int found_count = 0;
|
||||||
|
for (int race_id = RACE_HUMAN_1; race_id <= RT_PEGASUS_3; 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) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Race {}: {}",
|
||||||
|
race_id,
|
||||||
|
race_name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
found_count++;
|
||||||
|
|
||||||
if (found_count == 20) {
|
if (found_count == 20) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2724,51 +2792,77 @@ void command_findrace(Client *c, const Seperator *sep)
|
|||||||
if (found_count == 20) {
|
if (found_count == 20) {
|
||||||
c->Message(Chat::White, "20 Races found... max reached.");
|
c->Message(Chat::White, "20 Races found... max reached.");
|
||||||
} else {
|
} else {
|
||||||
c->Message(Chat::White, "%i Race(s) found.", found_count);
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"{} Race(s) found.",
|
||||||
|
found_count
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void command_findspell(Client *c, const Seperator *sep)
|
void command_findspell(Client *c, const Seperator *sep)
|
||||||
{
|
{
|
||||||
if (sep->arg[1][0] == 0)
|
if (sep->arg[1][0] == 0) {
|
||||||
c->Message(Chat::White, "Usage: #FindSpell [spellname]");
|
c->Message(Chat::White, "Usage: #findspell [search criteria]");
|
||||||
else if (SPDAT_RECORDS <= 0)
|
} else if (SPDAT_RECORDS <= 0) {
|
||||||
c->Message(Chat::White, "Spells not loaded");
|
c->Message(Chat::White, "Spells not loaded");
|
||||||
else if (Seperator::IsNumber(sep->argplus[1])) {
|
} else if (Seperator::IsNumber(sep->argplus[1])) {
|
||||||
int spellid = atoi(sep->argplus[1]);
|
int spell_id = atoi(sep->argplus[1]);
|
||||||
if (spellid <= 0 || spellid >= SPDAT_RECORDS) {
|
if (!IsValidSpell(spell_id)) {
|
||||||
c->Message(Chat::White, "Error: Number out of range");
|
c->Message(Chat::White, "Error: Invalid Spell");
|
||||||
}
|
} else {
|
||||||
else {
|
c->Message(
|
||||||
c->Message(Chat::White, " %i: %s", spellid, spells[spellid].name);
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"{}: {}",
|
||||||
|
spell_id,
|
||||||
|
spells[spell_id].name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int count=0;
|
std::string search_criteria = str_tolower(sep->argplus[1]);
|
||||||
//int iSearchLen = strlen(sep->argplus[1])+1;
|
int found_count = 0;
|
||||||
char sName[64];
|
for (int i = 0; i < SPDAT_RECORDS; i++) {
|
||||||
char sCriteria[65];
|
auto current_spell = spells[i];
|
||||||
strn0cpy(sCriteria, sep->argplus[1], 64);
|
if (current_spell.name[0] != 0) {
|
||||||
strupr(sCriteria);
|
std::string spell_name = current_spell.name;
|
||||||
for (int i=0; i<SPDAT_RECORDS; i++) {
|
std::string spell_name_lower = str_tolower(spell_name);
|
||||||
if (spells[i].name[0] != 0) {
|
if (search_criteria.length() > 0 && spell_name_lower.find(search_criteria) == std::string::npos) {
|
||||||
strcpy(sName, spells[i].name);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
strupr(sName);
|
c->Message(
|
||||||
char* pdest = strstr(sName, sCriteria);
|
Chat::White,
|
||||||
if ((pdest != nullptr) && (count <=20)) {
|
fmt::format(
|
||||||
c->Message(Chat::White, " %i: %s", i, spells[i].name);
|
"{}: {}",
|
||||||
count++;
|
i,
|
||||||
}
|
spell_name
|
||||||
else if (count > 20)
|
).c_str()
|
||||||
|
);
|
||||||
|
found_count++;
|
||||||
|
|
||||||
|
if (found_count == 20) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count > 20)
|
}
|
||||||
c->Message(Chat::White, "20 spells found... max reached.");
|
|
||||||
else
|
if (found_count == 20) {
|
||||||
c->Message(Chat::White, "%i spells found.", count);
|
c->Message(Chat::White, "20 Spells found... max reached.");
|
||||||
|
} else {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"{} Spell(s) found.",
|
||||||
|
found_count
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -104,6 +104,7 @@ void command_equipitem(Client *c, const Seperator *sep);
|
|||||||
void command_face(Client *c, const Seperator *sep);
|
void command_face(Client *c, const Seperator *sep);
|
||||||
void command_faction(Client *c, const Seperator *sep);
|
void command_faction(Client *c, const Seperator *sep);
|
||||||
void command_findaliases(Client *c, const Seperator *sep);
|
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_findnpctype(Client *c, const Seperator *sep);
|
||||||
void command_findrace(Client *c, const Seperator *sep);
|
void command_findrace(Client *c, const Seperator *sep);
|
||||||
void command_findspell(Client *c, const Seperator *sep);
|
void command_findspell(Client *c, const Seperator *sep);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user