[Cleanup] Cleanup Body Type Code (#4366)

* [Cleanup] Cleanup Body Type-based Code

* Update bodytypes.cpp

* Final

* Update body_type.cpp

* Cleanup

* Cleanup

* Formatting

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Alex King
2024-06-02 04:25:06 -04:00
committed by GitHub
parent 0c45d3b09e
commit 8640776a21
39 changed files with 324 additions and 250 deletions
+2
View File
@@ -1,5 +1,6 @@
#include "../client.h"
#include "find/aa.cpp"
#include "find/body_type.cpp"
#include "find/bug_category.cpp"
#include "find/character.cpp"
#include "find/class.cpp"
@@ -33,6 +34,7 @@ void command_find(Client *c, const Seperator *sep)
std::vector<Cmd> commands = {
Cmd{.cmd = "aa", .u = "aa [Search Criteria]", .fn = FindAA, .a = {"#findaa"}},
Cmd{.cmd = "body_type", .u = "body_type [Search Criteria]", .fn = FindBodyType, .a = {"#findbodytype"}},
Cmd{.cmd = "bug_category", .u = "bug_category [Search Criteria]", .fn = FindBugCategory, .a = {"#findbugcategory"}},
Cmd{.cmd = "character", .u = "character [Search Criteria]", .fn = FindCharacter, .a = {"#findcharacter"}},
Cmd{.cmd = "class", .u = "class [Search Criteria]", .fn = FindClass, .a = {"#findclass"}},
+62
View File
@@ -0,0 +1,62 @@
#include "../../client.h"
void FindBodyType(Client *c, const Seperator *sep)
{
if (sep->IsNumber(2)) {
const uint8 body_type_id = static_cast<uint8>(Strings::ToUnsignedInt(sep->arg[2]));
const std::string& body_type_name = BodyType::GetName(body_type_id);
if (Strings::EqualFold(body_type_name, "UNKNOWN BODY TYPE")) {
c->Message(
Chat::White,
fmt::format(
"Body Type {} does not exist.",
body_type_id
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Body Type {} | {}",
body_type_id,
body_type_name
).c_str()
);
return;
}
const std::string& search_criteria = Strings::ToLower(sep->argplus[2]);
uint32 found_count = 0;
for (const auto& e : body_type_names) {
const std::string& body_type_name_lower = Strings::ToLower(e.second);
if (!Strings::Contains(body_type_name_lower, search_criteria)) {
continue;
}
c->Message(
Chat::White,
fmt::format(
"Body Type {} | {}",
e.first,
e.second
).c_str()
);
found_count++;
}
c->Message(
Chat::White,
fmt::format(
"{} Body Type{} found matching '{}'.",
found_count,
found_count != 1 ? "s" : "",
sep->argplus[2]
).c_str()
);
}
+16 -12
View File
@@ -100,21 +100,25 @@ void command_npcedit(Client *c, const Seperator *sep)
}
} else if (!strcasecmp(sep->arg[1], "bodytype")) {
if (sep->IsNumber(2)) {
auto body_type_id = static_cast<uint8_t>(Strings::ToUnsignedInt(sep->arg[2]));
auto body_type_name = EQ::constants::GetBodyTypeName(static_cast<bodyType>(body_type_id));
const uint8 body_type_id = static_cast<uint8>(Strings::ToUnsignedInt(sep->arg[2]));
const std::string& body_type_name = BodyType::GetName(body_type_id);
if (Strings::EqualFold(body_type_name, "UNKNOWN BODY TYPE")) {
c->Message(
Chat::White,
fmt::format(
"Body Type {} does not exist.",
body_type_id
).c_str()
);
return;
}
n.bodytype = body_type_id;
d = fmt::format(
"{} is now using Body Type {}.",
"{} is now using Body Type {} ({}).",
npc_id_string,
(
!body_type_name.empty() ?
fmt::format(
"{} ({})",
body_type_name,
body_type_id
) :
std::to_string(body_type_id)
)
body_type_name,
body_type_id
);
} else {
c->Message(Chat::White, "Usage: #npcedit bodytype [Body Type ID] - Sets an NPC's Bodytype");