mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
[Commands] Add #findrecipe and #viewrecipe Commands. (#2401)
* [Commands] Add #findrecipe and #viewrecipe Commands. - Add #findrecipe [Search Critieria] command. - Add #viewrecipe [Recipe ID] command. - #findrecipe will show #viewrecipe saylinks if the user has access to that command. - #viewrecipe will show #summonitem saylinks if the user has access to that command. * Cleanup * Lexicon change. * Remove unnecessary .c_str() and
This commit is contained in:
@@ -146,6 +146,7 @@ int command_init(void)
|
||||
command_add("findfaction", "[Search Criteria] - Search for a faction", AccountStatus::Guide, command_findfaction) ||
|
||||
command_add("findnpctype", "[Search Criteria] - Search database NPC types", AccountStatus::GMAdmin, command_findnpctype) ||
|
||||
command_add("findrace", "[Search Criteria] - Search for a race", AccountStatus::Guide, command_findrace) ||
|
||||
command_add("findrecipe", "[Search Criteria] - Search for a recipe", AccountStatus::Guide, command_findrecipe) ||
|
||||
command_add("findskill", "[Search Criteria] - Search for a skill", AccountStatus::Guide, command_findskill) ||
|
||||
command_add("findspell", "[Search Criteria] - Search for a spell", AccountStatus::Guide, command_findspell) ||
|
||||
command_add("findtask", "[Search Criteria] - Search for a task", AccountStatus::Guide, command_findtask) ||
|
||||
@@ -341,6 +342,7 @@ int command_init(void)
|
||||
command_add("viewcurrencies", "View your or your target's currencies", AccountStatus::GMAdmin, command_viewcurrencies) ||
|
||||
command_add("viewnpctype", "[NPC ID] - Show stats for an NPC by NPC ID", AccountStatus::GMAdmin, command_viewnpctype) ||
|
||||
command_add("viewpetition", "[petition number] - View a petition", AccountStatus::ApprenticeGuide, command_viewpetition) ||
|
||||
command_add("viewrecipe", "[Recipe ID] - Show a recipe's entries", AccountStatus::GMAdmin, command_viewrecipe) ||
|
||||
command_add("viewzoneloot", "[item id] - Allows you to search a zone's loot for a specific item ID. (0 shows all loot in the zone)", AccountStatus::QuestTroupe, command_viewzoneloot) ||
|
||||
command_add("wc", "[wear slot] [material] - Sends an OP_WearChange for your target", AccountStatus::GMMgmt, command_wc) ||
|
||||
command_add("weather", "[0/1/2/3] (Off/Rain/Snow/Manual) - Change the weather", AccountStatus::QuestTroupe, command_weather) ||
|
||||
@@ -981,6 +983,7 @@ void command_bot(Client *c, const Seperator *sep)
|
||||
#include "gm_commands/findfaction.cpp"
|
||||
#include "gm_commands/findnpctype.cpp"
|
||||
#include "gm_commands/findrace.cpp"
|
||||
#include "gm_commands/findrecipe.cpp"
|
||||
#include "gm_commands/findskill.cpp"
|
||||
#include "gm_commands/findspell.cpp"
|
||||
#include "gm_commands/findtask.cpp"
|
||||
@@ -1174,6 +1177,7 @@ void command_bot(Client *c, const Seperator *sep)
|
||||
#include "gm_commands/viewcurrencies.cpp"
|
||||
#include "gm_commands/viewnpctype.cpp"
|
||||
#include "gm_commands/viewpetition.cpp"
|
||||
#include "gm_commands/viewrecipe.cpp"
|
||||
#include "gm_commands/viewzoneloot.cpp"
|
||||
#include "gm_commands/wc.cpp"
|
||||
#include "gm_commands/weather.cpp"
|
||||
|
||||
@@ -83,6 +83,7 @@ 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_findrecipe(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);
|
||||
@@ -291,6 +292,7 @@ void command_version(Client *c, const Seperator *sep);
|
||||
void command_viewcurrencies(Client *c, const Seperator *sep);
|
||||
void command_viewnpctype(Client *c, const Seperator *sep);
|
||||
void command_viewpetition(Client *c, const Seperator *sep);
|
||||
void command_viewrecipe(Client *c, const Seperator *sep);
|
||||
void command_viewzoneloot(Client *c, const Seperator *sep);
|
||||
void command_wc(Client *c, const Seperator *sep);
|
||||
void command_weather(Client *c, const Seperator *sep);
|
||||
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
#include "../client.h"
|
||||
#include "../command.h"
|
||||
#include "../../common/repositories/tradeskill_recipe_repository.h"
|
||||
|
||||
void command_findrecipe(Client *c, const Seperator *sep)
|
||||
{
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments) {
|
||||
c->Message(Chat::White, "Command Syntax: #findrecipe [Search Criteria]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sep->IsNumber(1)) {
|
||||
auto recipe_id = static_cast<uint16>(std::stoul(sep->arg[1]));
|
||||
auto r = TradeskillRecipeRepository::GetWhere(
|
||||
database,
|
||||
fmt::format("id = {}", recipe_id)
|
||||
);
|
||||
|
||||
if (r.empty() || !r[0].id) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Recipe ID {} could not be found.",
|
||||
Strings::Commify(std::to_string(recipe_id))
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
bool can_view_recipes = c->Admin() >= GetCommandStatus(c, "viewrecipe");
|
||||
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Recipe {} | {}{}",
|
||||
Strings::Commify(std::to_string(recipe_id)),
|
||||
r[0].name,
|
||||
can_view_recipes ? fmt::format(" | {}", Saylink::Silent(fmt::format("#viewrecipe {}", r[0].id), "View")) : ""
|
||||
).c_str()
|
||||
);
|
||||
} else {
|
||||
auto search_criteria = Strings::ToLower(sep->argplus[1]);
|
||||
int found_count = 0;
|
||||
|
||||
auto rl = TradeskillRecipeRepository::GetWhere(
|
||||
database,
|
||||
fmt::format("`name` LIKE '%{}%' ORDER BY `id` ASC", search_criteria)
|
||||
);
|
||||
|
||||
if (rl.empty() || !rl[0].id) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"No recipes were found matching '{}'.",
|
||||
search_criteria
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
bool can_view_recipes = c->Admin() >= GetCommandStatus(c, "viewrecipe");
|
||||
|
||||
for (const auto& r : rl) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Recipe {} | {}{}",
|
||||
Strings::Commify(std::to_string(r.id)),
|
||||
r.name,
|
||||
can_view_recipes ? fmt::format(" | {}", Saylink::Silent(fmt::format("#viewrecipe {}", r.id), "View")) : ""
|
||||
).c_str()
|
||||
);
|
||||
|
||||
if (found_count == 50) {
|
||||
break;
|
||||
}
|
||||
|
||||
found_count++;
|
||||
}
|
||||
|
||||
if (found_count == 50) {
|
||||
c->Message(Chat::White, "50 Recipes found, max reached.");
|
||||
} else {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"{} Recipe{} found.",
|
||||
found_count,
|
||||
found_count != 1 ? "s" : ""
|
||||
).c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
#include "../client.h"
|
||||
#include "../command.h"
|
||||
#include "../../common/repositories/tradeskill_recipe_repository.h"
|
||||
#include "../../common/repositories/tradeskill_recipe_entries_repository.h"
|
||||
|
||||
void command_viewrecipe(Client *c, const Seperator *sep)
|
||||
{
|
||||
int arguments = sep->argnum;
|
||||
if (!arguments || !sep->IsNumber(1)) {
|
||||
c->Message(Chat::White, "Command Syntax: #viewrecipe [Recipe ID]");
|
||||
return;
|
||||
}
|
||||
|
||||
auto recipe_id = static_cast<uint16>(std::stoul(sep->arg[1]));
|
||||
auto re = TradeskillRecipeEntriesRepository::GetWhere(
|
||||
database,
|
||||
fmt::format("recipe_id = {} ORDER BY id ASC", recipe_id)
|
||||
);
|
||||
auto r = TradeskillRecipeRepository::GetWhere(
|
||||
database,
|
||||
fmt::format("id = {}", recipe_id)
|
||||
);
|
||||
|
||||
if (re.empty() || r.empty() || !re[0].id || !r[0].id) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Recipe ID {} has no entries or could not be found.",
|
||||
Strings::Commify(std::to_string(recipe_id))
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Recipe {} | {}",
|
||||
Strings::Commify(std::to_string(recipe_id)),
|
||||
r[0].name
|
||||
).c_str()
|
||||
);
|
||||
|
||||
auto entry_number = 1;
|
||||
bool can_summon_items = c->Admin() >= GetCommandStatus(c, "summonitem");
|
||||
|
||||
for (const auto& e : re) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Entry {}{} | {}{}",
|
||||
entry_number,
|
||||
e.iscontainer > 0 ? " (Container)" : "",
|
||||
e.item_id > 1000 ? database.CreateItemLink(e.item_id) : EQ::constants::GetObjectTypeName(e.item_id),
|
||||
can_summon_items && e.item_id > 1000 ? fmt::format(" | {}", Saylink::Silent(fmt::format("#si {}", e.item_id), "Summon")) : ""
|
||||
).c_str()
|
||||
);
|
||||
|
||||
std::vector<std::string> emv;
|
||||
bool has_message = false;
|
||||
|
||||
if (e.componentcount) {
|
||||
emv.push_back(
|
||||
fmt::format(
|
||||
"Component: {}",
|
||||
e.componentcount
|
||||
)
|
||||
);
|
||||
|
||||
has_message = true;
|
||||
}
|
||||
|
||||
if (e.failcount) {
|
||||
emv.push_back(
|
||||
fmt::format(
|
||||
"Fail: {}",
|
||||
e.failcount
|
||||
)
|
||||
);
|
||||
|
||||
has_message = true;
|
||||
}
|
||||
|
||||
if (e.salvagecount) {
|
||||
emv.push_back(
|
||||
fmt::format(
|
||||
"Salvage: {}",
|
||||
e.salvagecount
|
||||
)
|
||||
);
|
||||
|
||||
has_message = true;
|
||||
}
|
||||
|
||||
if (e.successcount) {
|
||||
emv.push_back(
|
||||
fmt::format(
|
||||
"Success: {}",
|
||||
e.successcount
|
||||
)
|
||||
);
|
||||
|
||||
has_message = true;
|
||||
}
|
||||
|
||||
if (has_message) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"Entry {} Counts | {}",
|
||||
entry_number,
|
||||
Strings::Implode(" | ", emv)
|
||||
).c_str()
|
||||
);
|
||||
}
|
||||
|
||||
entry_number++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user