From 0b2493beb8eafde5a39ab2d8f26adb4f42b5b1a4 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:58:59 -0400 Subject: [PATCH] [Cleanup] Cleanup Object Type Code (#4375) * [Cleanup] Cleanup Object Type Code * Move to object.cpp/object.h --- common/emu_constants.cpp | 78 ----------- common/emu_constants.h | 67 --------- .../command_subsettings_repository.h | 1 + zone/gm_commands/find.cpp | 2 + zone/gm_commands/find/object_type.cpp | 65 +++++++++ zone/gm_commands/show/recipe.cpp | 4 +- zone/object.cpp | 10 ++ zone/object.h | 131 ++++++++++++++++++ 8 files changed, 211 insertions(+), 147 deletions(-) create mode 100644 zone/gm_commands/find/object_type.cpp diff --git a/common/emu_constants.cpp b/common/emu_constants.cpp index b7bc01fc3..51704fea6 100644 --- a/common/emu_constants.cpp +++ b/common/emu_constants.cpp @@ -296,84 +296,6 @@ std::string EQ::constants::GetSpawnAnimationName(uint8 animation_id) return EQ::constants::GetSpawnAnimationMap().find(animation_id)->second; } -const std::map& EQ::constants::GetObjectTypeMap() -{ - static const std::map object_type_map = { - { ObjectTypes::SmallBag, "Small Bag" }, - { ObjectTypes::LargeBag, "Large Bag" }, - { ObjectTypes::Quiver, "Quiver" }, - { ObjectTypes::BeltPouch, "Belt Pouch" }, - { ObjectTypes::WristPouch, "Wrist Pouch" }, - { ObjectTypes::Backpack, "Backpack" }, - { ObjectTypes::SmallChest, "Small Chest" }, - { ObjectTypes::LargeChest, "Large Chest" }, - { ObjectTypes::Bandolier, "Bandolier" }, - { ObjectTypes::Medicine, "Medicine" }, - { ObjectTypes::Tinkering, "Tinkering" }, - { ObjectTypes::Lexicon, "Lexicon" }, - { ObjectTypes::PoisonMaking, "Mortar and Pestle" }, - { ObjectTypes::Quest, "Quest" }, - { ObjectTypes::MixingBowl, "Mixing Bowl" }, - { ObjectTypes::Baking, "Baking" }, - { ObjectTypes::Tailoring, "Tailoring" }, - { ObjectTypes::Blacksmithing, "Blacksmithing" }, - { ObjectTypes::Fletching, "Fletching" }, - { ObjectTypes::Brewing, "Brewing" }, - { ObjectTypes::JewelryMaking, "Jewelry Making" }, - { ObjectTypes::Pottery, "Pottery" }, - { ObjectTypes::Kiln, "Kiln" }, - { ObjectTypes::KeyMaker, "Key Maker" }, - { ObjectTypes::ResearchWIZ, "Lexicon" }, - { ObjectTypes::ResearchMAG, "Lexicon" }, - { ObjectTypes::ResearchNEC, "Lexicon" }, - { ObjectTypes::ResearchENC, "Lexicon" }, - { ObjectTypes::Unknown, "Unknown" }, - { ObjectTypes::ResearchPractice, "Lexicon" }, - { ObjectTypes::Alchemy, "Alchemy" }, - { ObjectTypes::HighElfForge, "High Elf Forge" }, - { ObjectTypes::DarkElfForge, "Dark Elf Forge" }, - { ObjectTypes::OgreForge, "Ogre Forge" }, - { ObjectTypes::DwarfForge, "Dwarf Forge" }, - { ObjectTypes::GnomeForge, "Gnome Forge" }, - { ObjectTypes::BarbarianForge, "Barbarian Forge" }, - { ObjectTypes::IksarForge, "Iksar Forge" }, - { ObjectTypes::HumanForgeOne, "Human Forge" }, - { ObjectTypes::HumanForgeTwo, "Human Forge" }, - { ObjectTypes::HalflingTailoringOne, "Halfling Tailoring" }, - { ObjectTypes::HalflingTailoringTwo, "Halfling Tailoring" }, - { ObjectTypes::EruditeTailoring, "Erudite Tailoring" }, - { ObjectTypes::WoodElfTailoring, "Wood Elf Tailoring" }, - { ObjectTypes::WoodElfFletching, "Wood Elf Fletching" }, - { ObjectTypes::IksarPottery, "Iksar Pottery" }, - { ObjectTypes::Fishing, "Fishing" }, - { ObjectTypes::TrollForge, "Troll Forge" }, - { ObjectTypes::WoodElfForge, "Wood Elf Forge" }, - { ObjectTypes::HalflingForge, "Halfling Forge" }, - { ObjectTypes::EruditeForge, "Erudite Forge" }, - { ObjectTypes::Merchant, "Merchant" }, - { ObjectTypes::FroglokForge, "Froglok Forge" }, - { ObjectTypes::Augmenter, "Augmenter" }, - { ObjectTypes::Churn, "Churn" }, - { ObjectTypes::TransformationMold, "Transformation Mold" }, - { ObjectTypes::DetransformationMold, "Detransformation Mold" }, - { ObjectTypes::Unattuner, "Unattuner" }, - { ObjectTypes::TradeskillBag, "Tradeskill Bag" }, - { ObjectTypes::CollectibleBag, "Collectible Bag" }, - { ObjectTypes::NoDeposit, "No Deposit" } - }; - - return object_type_map; -} - -std::string EQ::constants::GetObjectTypeName(int object_type) -{ - if (!EQ::ValueWithin(object_type, ObjectTypes::SmallBag, ObjectTypes::NoDeposit)) { - return std::string(); - } - - return EQ::constants::GetObjectTypeMap().find(object_type)->second; -} - const std::map &EQ::constants::GetWeatherTypeMap() { static const std::map weather_type_map = { diff --git a/common/emu_constants.h b/common/emu_constants.h index af33b56e3..f06fcb47c 100644 --- a/common/emu_constants.h +++ b/common/emu_constants.h @@ -337,70 +337,6 @@ namespace EQ Looting }; - enum ObjectTypes : int { - SmallBag, - LargeBag, - Quiver, - BeltPouch, - WristPouch, - Backpack, - SmallChest, - LargeChest, - Bandolier, - Medicine, - Tinkering, - Lexicon, - PoisonMaking, - Quest, - MixingBowl, - Baking, - Tailoring, - Blacksmithing, - Fletching, - Brewing, - JewelryMaking, - Pottery, - Kiln, - KeyMaker, - ResearchWIZ, - ResearchMAG, - ResearchNEC, - ResearchENC, - Unknown, - ResearchPractice, - Alchemy, - HighElfForge, - DarkElfForge, - OgreForge, - DwarfForge, - GnomeForge, - BarbarianForge, - IksarForge, - HumanForgeOne, - HumanForgeTwo, - HalflingTailoringOne, - HalflingTailoringTwo, - EruditeTailoring, - WoodElfTailoring, - WoodElfFletching, - IksarPottery, - Fishing, - TrollForge, - WoodElfForge, - HalflingForge, - EruditeForge, - Merchant, - FroglokForge, - Augmenter, - Churn, - TransformationMold, - DetransformationMold, - Unattuner, - TradeskillBag, - CollectibleBag, - NoDeposit - }; - enum WeatherTypes : uint8 { None, Raining, @@ -453,9 +389,6 @@ namespace EQ extern const std::map& GetSpawnAnimationMap(); std::string GetSpawnAnimationName(uint8 animation_id); - extern const std::map& GetObjectTypeMap(); - std::string GetObjectTypeName(int object_type); - extern const std::map& GetWeatherTypeMap(); std::string GetWeatherTypeName(uint8 weather_type); diff --git a/common/repositories/command_subsettings_repository.h b/common/repositories/command_subsettings_repository.h index b580a7115..c11012f14 100644 --- a/common/repositories/command_subsettings_repository.h +++ b/common/repositories/command_subsettings_repository.h @@ -61,6 +61,7 @@ public: {.parent_command = "find", .sub_command = "item", .access_level = AccountStatus::QuestTroupe, .top_level_aliases = "fi|finditem|itemsearch"}, {.parent_command = "find", .sub_command = "language", .access_level = AccountStatus::QuestTroupe, .top_level_aliases = "findlanguage"}, {.parent_command = "find", .sub_command = "npc_type", .access_level = AccountStatus::QuestTroupe, .top_level_aliases = "fn|findnpc|findnpctype"}, + {.parent_command = "find", .sub_command = "object_type", .access_level = AccountStatus::QuestTroupe, .top_level_aliases = "findobjecttype"}, {.parent_command = "find", .sub_command = "race", .access_level = AccountStatus::QuestTroupe, .top_level_aliases = "findrace"}, {.parent_command = "find", .sub_command = "recipe", .access_level = AccountStatus::QuestTroupe, .top_level_aliases = "findrecipe"}, {.parent_command = "find", .sub_command = "skill", .access_level = AccountStatus::QuestTroupe, .top_level_aliases = "findskill"}, diff --git a/zone/gm_commands/find.cpp b/zone/gm_commands/find.cpp index c362df2e5..bc51cb1f0 100644 --- a/zone/gm_commands/find.cpp +++ b/zone/gm_commands/find.cpp @@ -12,6 +12,7 @@ #include "find/item.cpp" #include "find/language.cpp" #include "find/npctype.cpp" +#include "find/object_type.cpp" #include "find/race.cpp" #include "find/recipe.cpp" #include "find/skill.cpp" @@ -52,6 +53,7 @@ void command_find(Client *c, const Seperator *sep) "#findnpctype" } }, + Cmd{.cmd = "object_type", .u = "object_type [Search Criteria]", .fn = FindObjectType, .a = {"#findobjecttype"}}, Cmd{.cmd = "race", .u = "race [Search Criteria]", .fn = FindRace, .a = {"#findrace"}}, Cmd{.cmd = "recipe", .u = "recipe [Search Criteria]", .fn = FindRecipe, .a = {"#findrecipe"}}, Cmd{.cmd = "skill", .u = "skill [Search Criteria]", .fn = FindSkill, .a = {"#findskill"}}, diff --git a/zone/gm_commands/find/object_type.cpp b/zone/gm_commands/find/object_type.cpp new file mode 100644 index 000000000..39a94fd5e --- /dev/null +++ b/zone/gm_commands/find/object_type.cpp @@ -0,0 +1,65 @@ +#include "../../client.h" + +void FindObjectType(Client *c, const Seperator *sep) +{ + if (sep->IsNumber(2)) { + const uint32 object_type = Strings::ToUnsignedInt(sep->arg[2]); + const std::string& object_type_name = ObjectType::GetName(object_type); + if (Strings::EqualFold(object_type_name, "UNKNOWN OBJECT TYPE")) { + + c->Message( + Chat::White, + fmt::format( + "Object Type {} does not exist.", + object_type + ).c_str() + ); + + return; + } + + c->Message( + Chat::White, + fmt::format( + "Object Type {} | {}", + object_type, + ObjectType::GetName(object_type) + ).c_str() + ); + + return; + } + + const std::string& search_criteria = Strings::ToLower(sep->argplus[2]); + + uint32 found_count = 0; + + for (const auto& e : object_types) { + const std::string& object_type_name_lower = Strings::ToLower(e.second); + if (!Strings::Contains(object_type_name_lower, search_criteria)) { + continue; + } + + c->Message( + Chat::White, + fmt::format( + "Object Type {} | {}", + e.first, + e.second + ).c_str() + ); + + found_count++; + } + + c->Message( + Chat::White, + fmt::format( + "{} Object Type{} found matching '{}'.", + found_count, + found_count != 1 ? "s" : "", + sep->argplus[2] + ).c_str() + ); +} + diff --git a/zone/gm_commands/show/recipe.cpp b/zone/gm_commands/show/recipe.cpp index 9d8025a43..acbe08d82 100644 --- a/zone/gm_commands/show/recipe.cpp +++ b/zone/gm_commands/show/recipe.cpp @@ -54,8 +54,8 @@ void ShowRecipe(Client *c, const Seperator *sep) e.iscontainer > 0 ? " (Container)" : "", ( e.item_id > 1000 ? - database.CreateItemLink(e.item_id) : - EQ::constants::GetObjectTypeName(e.item_id) + database.CreateItemLink(static_cast(e.item_id)) : + ObjectType::GetName(static_cast(e.item_id)) ), ( can_summon_items && e.item_id > 1000 ? diff --git a/zone/object.cpp b/zone/object.cpp index 5e0337853..f740bf93c 100644 --- a/zone/object.cpp +++ b/zone/object.cpp @@ -1293,3 +1293,13 @@ void Object::FixZ() } } } + +std::string ObjectType::GetName(uint32 object_type) +{ + return IsValid(object_type) ? object_types[object_type] : "UNKNOWN OBJECT TYPE"; +} + +bool ObjectType::IsValid(uint32 object_type) +{ + return object_types.find(object_type) != object_types.end(); +} diff --git a/zone/object.h b/zone/object.h index 114efd7e9..5e66c3d19 100644 --- a/zone/object.h +++ b/zone/object.h @@ -250,4 +250,135 @@ protected: void FixZ(); }; +namespace ObjectType { + constexpr uint32 SmallBag = 0; + constexpr uint32 LargeBag = 1; + constexpr uint32 Quiver = 2; + constexpr uint32 BeltPouch = 3; + constexpr uint32 WristPouch = 4; + constexpr uint32 Backpack = 5; + constexpr uint32 SmallChest = 6; + constexpr uint32 LargeChest = 7; + constexpr uint32 Bandolier = 8; + constexpr uint32 Medicine = 9; + constexpr uint32 Tinkering = 10; + constexpr uint32 Lexicon = 11; + constexpr uint32 PoisonMaking = 12; + constexpr uint32 Quest = 13; + constexpr uint32 MixingBowl = 14; + constexpr uint32 Baking = 15; + constexpr uint32 Tailoring = 16; + constexpr uint32 Blacksmithing = 17; + constexpr uint32 Fletching = 18; + constexpr uint32 Brewing = 19; + constexpr uint32 JewelryMaking = 20; + constexpr uint32 Pottery = 21; + constexpr uint32 Kiln = 22; + constexpr uint32 KeyMaker = 23; + constexpr uint32 ResearchWIZ = 24; + constexpr uint32 ResearchMAG = 25; + constexpr uint32 ResearchNEC = 26; + constexpr uint32 ResearchENC = 27; + constexpr uint32 Unknown = 28; + constexpr uint32 ResearchPractice = 29; + constexpr uint32 Alchemy = 30; + constexpr uint32 HighElfForge = 31; + constexpr uint32 DarkElfForge = 32; + constexpr uint32 OgreForge = 33; + constexpr uint32 DwarfForge = 34; + constexpr uint32 GnomeForge = 35; + constexpr uint32 BarbarianForge = 36; + constexpr uint32 IksarForge = 37; + constexpr uint32 HumanForgeOne = 38; + constexpr uint32 HumanForgeTwo = 39; + constexpr uint32 HalflingTailoringOne = 40; + constexpr uint32 HalflingTailoringTwo = 41; + constexpr uint32 EruditeTailoring = 42; + constexpr uint32 WoodElfTailoring = 43; + constexpr uint32 WoodElfFletching = 44; + constexpr uint32 IksarPottery = 45; + constexpr uint32 Fishing = 46; + constexpr uint32 TrollForge = 47; + constexpr uint32 WoodElfForge = 48; + constexpr uint32 HalflingForge = 49; + constexpr uint32 EruditeForge = 50; + constexpr uint32 Merchant = 51; + constexpr uint32 FroglokForge = 52; + constexpr uint32 Augmenter = 53; + constexpr uint32 Churn = 54; + constexpr uint32 TransformationMold = 55; + constexpr uint32 DetransformationMold = 56; + constexpr uint32 Unattuner = 57; + constexpr uint32 TradeskillBag = 58; + constexpr uint32 CollectibleBag = 59; + constexpr uint32 NoDeposit = 60; + + std::string GetName(uint32 object_type); + bool IsValid(uint32 object_type); +} + +static std::map object_types = { + { ObjectType::SmallBag, "Small Bag" }, + { ObjectType::LargeBag, "Large Bag" }, + { ObjectType::Quiver, "Quiver" }, + { ObjectType::BeltPouch, "Belt Pouch" }, + { ObjectType::WristPouch, "Wrist Pouch" }, + { ObjectType::Backpack, "Backpack" }, + { ObjectType::SmallChest, "Small Chest" }, + { ObjectType::LargeChest, "Large Chest" }, + { ObjectType::Bandolier, "Bandolier" }, + { ObjectType::Medicine, "Medicine" }, + { ObjectType::Tinkering, "Tinkering" }, + { ObjectType::Lexicon, "Lexicon" }, + { ObjectType::PoisonMaking, "Mortar and Pestle" }, + { ObjectType::Quest, "Quest" }, + { ObjectType::MixingBowl, "Mixing Bowl" }, + { ObjectType::Baking, "Baking" }, + { ObjectType::Tailoring, "Tailoring" }, + { ObjectType::Blacksmithing, "Blacksmithing" }, + { ObjectType::Fletching, "Fletching" }, + { ObjectType::Brewing, "Brewing" }, + { ObjectType::JewelryMaking, "Jewelry Making" }, + { ObjectType::Pottery, "Pottery" }, + { ObjectType::Kiln, "Kiln" }, + { ObjectType::KeyMaker, "Key Maker" }, + { ObjectType::ResearchWIZ, "Lexicon" }, + { ObjectType::ResearchMAG, "Lexicon" }, + { ObjectType::ResearchNEC, "Lexicon" }, + { ObjectType::ResearchENC, "Lexicon" }, + { ObjectType::Unknown, "Unknown" }, + { ObjectType::ResearchPractice, "Lexicon" }, + { ObjectType::Alchemy, "Alchemy" }, + { ObjectType::HighElfForge, "High Elf Forge" }, + { ObjectType::DarkElfForge, "Dark Elf Forge" }, + { ObjectType::OgreForge, "Ogre Forge" }, + { ObjectType::DwarfForge, "Dwarf Forge" }, + { ObjectType::GnomeForge, "Gnome Forge" }, + { ObjectType::BarbarianForge, "Barbarian Forge" }, + { ObjectType::IksarForge, "Iksar Forge" }, + { ObjectType::HumanForgeOne, "Human Forge" }, + { ObjectType::HumanForgeTwo, "Human Forge" }, + { ObjectType::HalflingTailoringOne, "Halfling Tailoring" }, + { ObjectType::HalflingTailoringTwo, "Halfling Tailoring" }, + { ObjectType::EruditeTailoring, "Erudite Tailoring" }, + { ObjectType::WoodElfTailoring, "Wood Elf Tailoring" }, + { ObjectType::WoodElfFletching, "Wood Elf Fletching" }, + { ObjectType::IksarPottery, "Iksar Pottery" }, + { ObjectType::Fishing, "Fishing" }, + { ObjectType::TrollForge, "Troll Forge" }, + { ObjectType::WoodElfForge, "Wood Elf Forge" }, + { ObjectType::HalflingForge, "Halfling Forge" }, + { ObjectType::EruditeForge, "Erudite Forge" }, + { ObjectType::Merchant, "Merchant" }, + { ObjectType::FroglokForge, "Froglok Forge" }, + { ObjectType::Augmenter, "Augmenter" }, + { ObjectType::Churn, "Churn" }, + { ObjectType::TransformationMold, "Transformation Mold" }, + { ObjectType::DetransformationMold, "Detransformation Mold" }, + { ObjectType::Unattuner, "Unattuner" }, + { ObjectType::TradeskillBag, "Tradeskill Bag" }, + { ObjectType::CollectibleBag, "Collectible Bag" }, + { ObjectType::NoDeposit, "No Deposit" } +}; + #endif