mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-21 18:58:21 +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:
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