[Commands] Add #findfaction Command. (#1697)

- Add #findfaction [search criteria] command.
- Cleanup other #find command messages/logic.
- Add GetMaxFaction() helper method.
- Add races.h defines for races 725-732.
This commit is contained in:
Kinglykrab 2021-11-09 21:23:38 -05:00 committed by GitHub
parent 211196a722
commit 328a94e2d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 216 additions and 53 deletions

View File

@ -1603,6 +1603,14 @@ namespace PlayerAppearance
#define RACE_FALLEN_KNIGHT_722 722
#define RACE_SERVANT_OF_SHADOW_723 723
#define RACE_LUCLIN_724 724
#define RACE_XARIC_725 725
#define RACE_DERVISH_726 726
#define RACE_DERVISH_727 727
#define RACE_LUCLIN_728 728
#define RACE_LUCLIN_729 729
#define RACE_ORB_730 730
#define RACE_LUCLIN_731 731
#define RACE_PEGASUS_732 732
#define RACE_INTERACTIVE_OBJECT_2250 2250
#endif

View File

@ -220,6 +220,7 @@ int command_init(void)
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("findclass", "[search criteria] - Search for a class", 50, command_findclass) ||
command_add("findfaction", "[search criteria] - Search for a faction", 50, command_findfaction) ||
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) ||
@ -3639,21 +3640,33 @@ void command_showskills(Client *c, const Seperator *sep)
void command_findclass(Client *c, const Seperator *sep)
{
if (sep->arg[1][0] == 0) {
c->Message(Chat::White, "Usage: #findclass [search criteria]");
} else if (Seperator::IsNumber(sep->argplus[1])) {
int search_id = atoi(sep->argplus[1]);
std::string class_name = GetClassIDName(search_id);
if (class_name.length() > 0) {
int arguments = sep->argnum;
if (arguments == 0) {
c->Message(Chat::White, "Command Syntax: #findclass [search criteria]");
return;
}
if (sep->IsNumber(1)) {
int class_id = std::stoi(sep->arg[1]);
if (class_id >= WARRIOR && class_id <= MERCERNARY_MASTER) {
std::string class_name = GetClassIDName(class_id);
c->Message(
Chat::White,
fmt::format(
"Class {}: {}",
search_id,
class_id,
class_name
).c_str()
);
return;
} else {
c->Message(
Chat::White,
fmt::format(
"Class ID {} was not found.",
class_id
).c_str()
);
}
} else {
std::string search_criteria = str_tolower(sep->argplus[1]);
@ -3683,11 +3696,105 @@ void command_findclass(Client *c, const Seperator *sep)
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"
);
c->Message(
Chat::White,
fmt::format(
"{} Class(es) found.",
found_count
"{} found.",
class_message
).c_str()
);
}
}
}
void command_findfaction(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (arguments == 0) {
c->Message(Chat::White, "Command Syntax: #findfaction [search criteria]");
return;
}
if (sep->IsNumber(1)) {
int faction_id = std::stoi(sep->arg[1]);
auto faction_name = content_db.GetFactionName(faction_id);
if (!faction_name.empty()) {
c->Message(
Chat::White,
fmt::format(
"Faction {}: {}",
faction_id,
faction_name
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"Faction ID {} was not found.",
faction_id
).c_str()
);
}
} else {
std::string search_criteria = str_tolower(sep->argplus[1]);
int found_count = 0;
int max_faction_id = content_db.GetMaxFaction();
for (int faction_id = 0; faction_id < max_faction_id; faction_id++) {
std::string faction_name = content_db.GetFactionName(faction_id);
std::string faction_name_lower = str_tolower(faction_name);
if (faction_name.empty()) {
continue;
}
if (faction_name.find(search_criteria) == std::string::npos) {
continue;
}
c->Message(
Chat::White,
fmt::format(
"Faction {}: {}",
faction_id,
faction_name
).c_str()
);
found_count++;
if (found_count == 20) {
break;
}
}
if (found_count == 20) {
c->Message(Chat::White, "20 Factions found... max reached.");
} else {
auto faction_message = (
found_count > 0 ?
(
found_count == 1 ?
"A Faction was" :
fmt::format("{} Factions were", found_count)
) :
"No Factions were"
);
c->Message(
Chat::White,
fmt::format(
"{} found.",
faction_message
).c_str()
);
}
@ -3696,26 +3803,38 @@ void command_findclass(Client *c, const Seperator *sep)
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) {
int arguments = sep->argnum;
if (arguments == 0) {
c->Message(Chat::White, "Command Syntax: #findrace [search criteria]");
return;
}
if (sep->IsNumber(1)) {
int race_id = std::stoi(sep->arg[1]);
std::string race_name = GetRaceIDName(race_id);
if (race_id >= RACE_HUMAN_1 && race_id <= RACE_PEGASUS_732) {
c->Message(
Chat::White,
fmt::format(
"Race {}: {}",
search_id,
race_id,
race_name
).c_str()
);
return;
} else {
c->Message(
Chat::White,
fmt::format(
"Race ID {} was not found.",
race_id
).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 <= RT_PEGASUS_3; race_id++) {
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) {
@ -3736,14 +3855,25 @@ void command_findrace(Client *c, const Seperator *sep)
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"
);
c->Message(
Chat::White,
fmt::format(
"{} Race(s) found.",
found_count
"{} found.",
race_message
).c_str()
);
}
@ -3761,16 +3891,16 @@ void command_findskill(Client *c, const Seperator *sep)
std::map<EQ::skills::SkillType, std::string> skills = EQ::skills::GetSkillTypeMap();
if (sep->IsNumber(1)) {
int skill_id = atoi(sep->argplus[1]);
int skill_id = std::stoi(sep->arg[1]);
if (skill_id >= EQ::skills::Skill1HBlunt && skill_id < EQ::skills::SkillCount) {
for (auto skills_iter : skills) {
if (skill_id == skills_iter.first) {
for (auto skill : skills) {
if (skill_id == skill.first) {
c->Message(
Chat::White,
fmt::format(
"{}: {}",
skills_iter.first,
skills_iter.second
"Skill {}: {}",
skill.first,
skill.second
).c_str()
);
break;
@ -3789,8 +3919,8 @@ void command_findskill(Client *c, const Seperator *sep)
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);
for (auto skill : skills) {
std::string skill_name_lower = str_tolower(skill.second);
if (skill_name_lower.find(search_criteria) == std::string::npos) {
continue;
}
@ -3798,9 +3928,9 @@ void command_findskill(Client *c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"{}: {}",
skills_iter.first,
skills_iter.second
"Skill {}: {}",
skill.first,
skill.second
).c_str()
);
found_count++;
@ -3817,10 +3947,10 @@ void command_findskill(Client *c, const Seperator *sep)
found_count > 0 ?
(
found_count == 1 ?
"A skill was" :
fmt::format("{} skills were", found_count)
"A Skill was" :
fmt::format("{} Skills were", found_count)
) :
"No skills were"
"No Skills were"
);
c->Message(
@ -3837,30 +3967,43 @@ void command_findskill(Client *c, const Seperator *sep)
void command_findspell(Client *c, const Seperator *sep)
{
if (sep->arg[1][0] == 0) {
c->Message(Chat::White, "Usage: #findspell [search criteria]");
} else if (SPDAT_RECORDS <= 0) {
if (SPDAT_RECORDS <= 0) {
c->Message(Chat::White, "Spells not loaded");
} else if (Seperator::IsNumber(sep->argplus[1])) {
int spell_id = atoi(sep->argplus[1]);
return;
}
int arguments = sep->argnum;
if (arguments == 0) {
c->Message(Chat::White, "Command Syntax: #findspell [search criteria]");
return;
}
if (sep->IsNumber(1)) {
int spell_id = std::stoi(sep->arg[1]);
if (!IsValidSpell(spell_id)) {
c->Message(Chat::White, "Error: Invalid Spell");
c->Message(
Chat::White,
fmt::format(
"Spell ID {} was not found.",
spell_id
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"{}: {}",
"Spell {}: {}",
spell_id,
spells[spell_id].name
).c_str()
);
}
}
else {
} else {
std::string search_criteria = str_tolower(sep->argplus[1]);
int found_count = 0;
for (int i = 0; i < SPDAT_RECORDS; i++) {
auto current_spell = spells[i];
for (int spell_id = 0; spell_id < SPDAT_RECORDS; spell_id++) {
auto current_spell = spells[spell_id];
if (current_spell.name[0] != 0) {
std::string spell_name = current_spell.name;
std::string spell_name_lower = str_tolower(spell_name);
@ -3871,8 +4014,8 @@ void command_findspell(Client *c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"{}: {}",
i,
"Spell {}: {}",
spell_id,
spell_name
).c_str()
);
@ -3887,11 +4030,21 @@ void command_findspell(Client *c, const Seperator *sep)
if (found_count == 20) {
c->Message(Chat::White, "20 Spells found... max reached.");
} else {
auto spell_message = (
found_count > 0 ?
(
found_count == 1 ?
"A Spell was" :
fmt::format("{} Spells were", found_count)
) :
"No Spells were"
);
c->Message(
Chat::White,
fmt::format(
"{} Spell(s) found.",
found_count
"{} found.",
spell_message
).c_str()
);
}
@ -15842,12 +15995,12 @@ void command_findtask(Client *c, const Seperator *sep)
}
if (sep->IsNumber(1)) {
auto task_id = atoul(sep->argplus[1]);
auto task_id = std::stoul(sep->arg[1]);
auto task_name = task_manager->GetTaskName(task_id);
auto task_message = (
!task_name.empty() ?
fmt::format(
"{}: {}",
"Task {}: {}",
task_id,
task_name
).c_str() :
@ -15875,7 +16028,7 @@ void command_findtask(Client *c, const Seperator *sep)
c->Message(
Chat::White,
fmt::format(
"{}: {}",
"Task {}: {}",
task_id,
task_name
).c_str()

View File

@ -108,6 +108,7 @@ void command_face(Client *c, const Seperator *sep);
void command_faction(Client *c, const Seperator *sep);
void command_findaliases(Client *c, const Seperator *sep);
void command_findclass(Client *c, const Seperator *sep);
void command_findfaction(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);

View File

@ -407,6 +407,7 @@ public:
bool GetFactionIdsForNPC(uint32 nfl_id, std::list<struct NPCFaction*> *faction_list, int32* primary_faction = 0); // improve faction handling
bool SetCharacterFactionLevel(uint32 char_id, int32 faction_id, int32 value, uint8 temp, faction_map &val_list); // needed for factions Dec, 16 2001
bool LoadFactionData();
inline uint32 GetMaxFaction() { return max_faction; }
/* AAs New */
bool LoadAlternateAdvancementAbilities(std::unordered_map<int, std::unique_ptr<AA::Ability>> &abilities,