From d6db35b84e8687297d580d5ca72ab39f05a33742 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Sun, 27 Nov 2022 18:56:40 -0500 Subject: [PATCH] [Commands] Cleanup #gearup Command. (#2589) # Notes - Cleanup messages and logic. - Add support for gearing up target client (with #gm on) and/or target bots. --- zone/command.cpp | 2 +- zone/gm_commands/gearup.cpp | 174 +++++++++++++++++++++--------------- 2 files changed, 104 insertions(+), 72 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 305eeb03d..d59b6f8f8 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -162,7 +162,7 @@ int command_init(void) command_add("fov", "Check wether you're behind or in your target's field of view", AccountStatus::QuestTroupe, command_fov) || command_add("freeze", "Freeze your target", AccountStatus::QuestTroupe, command_freeze) || command_add("gassign", "[Grid ID] - Assign targetted NPC to predefined wandering grid id", AccountStatus::GMAdmin, command_gassign) || - command_add("gearup", "Developer tool to quickly equip a character", AccountStatus::GMMgmt, command_gearup) || + command_add("gearup", "Developer tool to quickly equip yourself or your target", AccountStatus::GMMgmt, command_gearup) || command_add("gender", "[0/1/2] - Change your or your target's gender to male/female/neuter", AccountStatus::Guide, command_gender) || command_add("getplayerburiedcorpsecount", "Get your or your target's total number of buried player corpses.", AccountStatus::GMAdmin, command_getplayerburiedcorpsecount) || command_add("getvariable", "[Variable Name] - Get the value of a variable from the database", AccountStatus::GMMgmt, command_getvariable) || diff --git a/zone/gm_commands/gearup.cpp b/zone/gm_commands/gearup.cpp index c25a0dd60..950b83e3e 100755 --- a/zone/gm_commands/gearup.cpp +++ b/zone/gm_commands/gearup.cpp @@ -2,9 +2,26 @@ #include "../../common/http/httplib.h" #include "../../common/content/world_content_service.h" +#ifdef BOTS +#include "../bot.h" +#endif + void command_gearup(Client *c, const Seperator *sep) { - std::string tool_table_name = "tool_gearup_armor_sets"; + Mob* t = c; + if ( + c->GetTarget() && + ( + (c->GetTarget()->IsClient() && c->GetGM()) +#ifdef BOTS + || c->GetTarget()->IsBot() +#endif + ) + ) { + t = c->GetTarget(); + } + + const std::string tool_table_name = "tool_gearup_armor_sets"; if (!database.DoesTableExist(tool_table_name)) { c->Message( Chat::Yellow, @@ -41,8 +58,7 @@ void command_gearup(Client *c, const Seperator *sep) } } } - } - else { + } else { c->Message( Chat::Yellow, fmt::format( @@ -55,74 +71,97 @@ void command_gearup(Client *c, const Seperator *sep) c->Message( Chat::Yellow, fmt::format( - "Table [{}] installed. Sourced [{}] queries", - tool_table_name, sourced_queries + "Table [{}] installed. Sourced [{}] quer{}", + tool_table_name, + sourced_queries, + sourced_queries != 1 ? "ies" : "y" ).c_str() ); } - std::string expansion_arg = sep->arg[1]; + const std::string expansion_arg = sep->arg[1]; std::string expansion_filter; - if (expansion_arg.length() > 0) { - expansion_filter = fmt::format("and `expansion` = {}", expansion_arg); + if (!expansion_arg.empty()) { + expansion_filter = fmt::format(" AND `expansion` = {}", expansion_arg); } - auto results = database.QueryDatabase( - fmt::format( - SQL ( - select - item_id, - slot - from - {} - where - `class` = {} - and `level` = {} - {} - order by score desc, expansion desc - ), - tool_table_name, - c->GetClass(), - c->GetLevel(), - expansion_filter - ) + auto query = fmt::format( + "SELECT item_id, slot FROM {} WHERE " + "`class` = {} AND `level` = {}{} " + "ORDER BY score DESC, expansion DESC", + tool_table_name, + t->GetClass(), + t->GetLevel(), + expansion_filter ); + auto results = database.QueryDatabase(query); int items_equipped = 0; int items_already_have = 0; std::set equipped; - for (auto row = results.begin(); row != results.end(); ++row) { - int item_id = atoi(row[0]); - int slot_id = atoi(row[1]); + for (auto row : results) { + auto item_id = std::stoul(row[0]); + auto slot_id = static_cast(std::stoul(row[1])); if (equipped.find(slot_id) != equipped.end()) { if (slot_id == EQ::invslot::slotEar1) { slot_id = EQ::invslot::slotEar2; - } - if (slot_id == EQ::invslot::slotFinger1) { + } else if (slot_id == EQ::invslot::slotFinger1) { slot_id = EQ::invslot::slotFinger2; - } - if (slot_id == EQ::invslot::slotWrist1) { + } else if (slot_id == EQ::invslot::slotWrist1) { slot_id = EQ::invslot::slotWrist2; } } if (equipped.find(slot_id) == equipped.end()) { - const EQ::ItemData *item = database.GetItem(item_id); - bool has_item = (c->GetInv().HasItem(item_id, 1, invWhereWorn) != INVALID_INDEX); - bool can_wear_item = !c->CheckLoreConflict(item) && !has_item; + const auto *item = database.GetItem(item_id); + bool has_item = false; + if (t->IsClient()) { + has_item = t->CastToClient()->GetInv().HasItem(item_id, 1, invWhereWorn) != INVALID_INDEX; +#ifdef BOTS + } else if (t->IsBot()) { + has_item = t->CastToBot()->HasBotItem(item_id); +#endif + } + + bool can_wear_item = false; + if (t->IsClient()) { + can_wear_item = !t->CastToClient()->CheckLoreConflict(item) && !has_item; +#ifdef BOTS + } else if (t->IsBot()) { + can_wear_item = !t->CastToBot()->CheckLoreConflict(item) && !has_item; +#endif + } + if (!can_wear_item) { items_already_have++; } - if (c->CastToMob()->CanClassEquipItem(item_id) && can_wear_item) { + if ( + can_wear_item && + t->CanClassEquipItem(item_id) && + ( + t->CanRaceEquipItem(item_id) +#ifdef BOTS + || (t->IsBot() && !t->CanRaceEquipItem(item_id) && RuleB(Bots, AllowBotEquipAnyRaceGear)) +#endif + ) + ) { equipped.insert(slot_id); - c->SummonItem( - item_id, - 0, 0, 0, 0, 0, 0, 0, 0, - slot_id - ); + + if (t->IsClient()) { + t->CastToClient()->SummonItem( + item_id, + 0, 0, 0, 0, 0, 0, 0, 0, + slot_id + ); +#ifdef BOTS + } else if (t->IsBot()) { + t->CastToBot()->AddBotItem(slot_id, item_id); +#endif + } + items_equipped++; } } @@ -138,43 +177,36 @@ void command_gearup(Client *c, const Seperator *sep) ); if (expansion_arg.empty()) { - results = database.QueryDatabase( - fmt::format( - SQL ( - select - expansion - from - {} - where - class = {} - and level = {} - group by - expansion; - ), - tool_table_name, - c->GetClass(), - c->GetLevel() - ) + query = fmt::format( + "SELECT expansion FROM {} WHERE " + "class = {} AND level = {} " + "GROUP BY expansion", + tool_table_name, + t->GetClass(), + t->GetLevel() ); + results = database.QueryDatabase(query); - c->Message(Chat::White, "Choose armor from a specific era"); + c->Message(Chat::White, "Choose Armor by Expansion:"); std::string message; - for (auto row = results.begin(); row != results.end(); ++row) { - int expansion = atoi(row[0]); - message += "[" + Saylink::Silent( - fmt::format("#gearup {}", expansion), - Expansion::ExpansionName[expansion] - ) + "] "; + for (auto row : results) { + const auto expansion = std::stoi(row[0]); + message += fmt::format( + "[{}] ", + Saylink::Silent( + fmt::format("#gearup {}", expansion), + Expansion::ExpansionName[expansion] + ) + ); if (message.length() > 2000) { c->Message(Chat::White, message.c_str()); - message = ""; + message = std::string(); } } - if (message.length() > 0) { + + if (!message.empty()) { c->Message(Chat::White, message.c_str()); } } - } -