From 7cac2e2bc3ebd28a8ddfe06af053fb882cf68224 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Sun, 28 Nov 2021 00:09:07 -0500 Subject: [PATCH] [Commands] Add #viewcurrencies Command. (#1844) * [Commands] Add #viewcurrencies Command. - Add #viewcurrencies command to view your or your target's currencies (Money, Crystals, Alternate Currency, LDoN, and PVP). - Add GetLDoNThemeName() helper method. * Update viewcurrencies.cpp * Cleanup name of map method. * Cleanup. --- common/emu_constants.cpp | 22 +++++ common/emu_constants.h | 3 + zone/CMakeLists.txt | 1 + zone/client_packet.cpp | 30 +++--- zone/command.cpp | 1 + zone/command.h | 3 +- zone/gm_commands/viewcurrencies.cpp | 137 ++++++++++++++++++++++++++++ 7 files changed, 181 insertions(+), 16 deletions(-) create mode 100644 zone/gm_commands/viewcurrencies.cpp diff --git a/common/emu_constants.cpp b/common/emu_constants.cpp index 8658cc419..a6a45c0d3 100644 --- a/common/emu_constants.cpp +++ b/common/emu_constants.cpp @@ -198,6 +198,28 @@ std::string EQ::constants::GetLanguageName(int language_id) return std::string(); } +const std::map& EQ::constants::GetLDoNThemeMap() +{ + static const std::map ldon_theme_map = { + { LDoNThemes::Unused, "Unused" }, + { LDoNThemes::GUK, "Deepest Guk" }, + { LDoNThemes::MIR, "Miragul's Menagerie" }, + { LDoNThemes::MMC, "Mistmoore Catacombs" }, + { LDoNThemes::RUJ, "Rujarkian Hills" }, + { LDoNThemes::TAK, "Takish-Hiz" }, + }; + return ldon_theme_map; +} + +std::string EQ::constants::GetLDoNThemeName(uint32 theme_id) +{ + if (theme_id >= LDoNThemes::Unused && theme_id <= LDoNThemes::TAK) { + auto ldon_themes = EQ::constants::GetLDoNThemeMap(); + return ldon_themes[theme_id]; + } + return std::string(); +} + const std::map& EQ::constants::GetFlyModeMap() { static const std::map flymode_map = { diff --git a/common/emu_constants.h b/common/emu_constants.h index 322b91ba0..c2157d78f 100644 --- a/common/emu_constants.h +++ b/common/emu_constants.h @@ -235,6 +235,9 @@ namespace EQ extern const std::map& GetLanguageMap(); std::string GetLanguageName(int language_id); + extern const std::map& GetLDoNThemeMap(); + std::string GetLDoNThemeName(uint32 theme_id); + extern const std::map& GetFlyModeMap(); std::string GetFlyModeName(uint8 flymode_id); diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index e9740a71d..b3dcb597a 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -547,6 +547,7 @@ SET(gm_commands gm_commands/untraindiscs.cpp gm_commands/uptime.cpp gm_commands/version.cpp + gm_commands/viewcurrencies.cpp gm_commands/viewnpctype.cpp gm_commands/viewpetition.cpp gm_commands/viewzoneloot.cpp diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 0975c1df3..ddb2d04f6 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -1936,14 +1936,6 @@ void Client::Handle_OP_AdventureMerchantPurchase(const EQApplicationPacket *app) } Adventure_Purchase_Struct* aps = (Adventure_Purchase_Struct*)app->pBuffer; - /* - Get item apc->itemid (can check NPC if thats necessary), ldon point theme check only if theme is not 0 (I am not sure what 1-5 are though for themes) - if(ldon_points_available >= item ldonpointcost) - { - give item (67 00 00 00 for the packettype using opcode 0x02c5) - ldon_points_available -= ldonpointcost; - } - */ uint32 merchantid = 0; Mob* tmp = entity_list.GetMob(aps->npcid); if (tmp == 0 || !tmp->IsNPC() || ((tmp->GetClass() != ADVENTUREMERCHANT) && @@ -2000,39 +1992,47 @@ void Client::Handle_OP_AdventureMerchantPurchase(const EQApplicationPacket *app) } if (item->LDoNTheme <= LDoNThemeBits::TAKBit) { + uint32 ldon_theme; if (item->LDoNTheme & LDoNThemeBits::TAKBit) { if (m_pp.ldon_points_tak < item_cost) { cannot_afford = true; - merchant_type = fmt::format("Deepest Guk Point{}", item_cost != 1 ? "s" : ""); + ldon_theme = LDoNThemes::TAK; } } else if (item->LDoNTheme & LDoNThemeBits::RUJBit) { if (m_pp.ldon_points_ruj < item_cost) { cannot_afford = true; - merchant_type = fmt::format("Miragul's Menagerie Point{}", item_cost != 1 ? "s" : ""); + ldon_theme = LDoNThemes::RUJ; } } else if (item->LDoNTheme & LDoNThemeBits::MMCBit) { if (m_pp.ldon_points_mmc < item_cost) { cannot_afford = true; - merchant_type = fmt::format("Mistmoore Catacombs Point{}", item_cost != 1 ? "s" : ""); + ldon_theme = LDoNThemes::MMC; } } else if (item->LDoNTheme & LDoNThemeBits::MIRBit) { if (m_pp.ldon_points_mir < item_cost) { cannot_afford = true; - merchant_type = fmt::format("Rujarkian Hills Point{}", item_cost != 1 ? "s" : ""); + ldon_theme = LDoNThemes::MIR; } } else if (item->LDoNTheme & LDoNThemeBits::GUKBit) { if (m_pp.ldon_points_guk < item_cost) { cannot_afford = true; - merchant_type = fmt::format("Takish-Hiz Point{}", item_cost != 1 ? "s" : ""); + ldon_theme = LDoNThemes::GUK; } } - + merchant_type = fmt::format( + "{} Point{}", + EQ::constants::GetLDoNThemeName(ldon_theme), + item_cost != 1 ? "s" : "" + ); } } else if (aps->Type == DiscordMerchant) { if (GetPVPPoints() < item_cost) { cannot_afford = true; - merchant_type = fmt::format("PVP Point{}", item_cost != 1 ? "s" : ""); + merchant_type = fmt::format( + "PVP Point{}", + item_cost != 1 ? "s" : "" + ); } } else if (aps->Type == NorrathsKeepersMerchant) { if (GetRadiantCrystals() < item_cost) { diff --git a/zone/command.cpp b/zone/command.cpp index 815336719..1149f09e5 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -384,6 +384,7 @@ int command_init(void) command_add("untraindiscs", "- Untrains all disciplines from your target.", AccountStatus::GMCoder, command_untraindiscs) || command_add("uptime", "[zone server id] - Get uptime of worldserver, or zone server if argument provided", AccountStatus::Steward, command_uptime) || command_add("version", "- Display current version of EQEmu server", AccountStatus::Player, command_version) || + 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("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) || diff --git a/zone/command.h b/zone/command.h index 9ff50140f..d9113a5d5 100644 --- a/zone/command.h +++ b/zone/command.h @@ -307,8 +307,10 @@ void command_untraindisc(Client *c, const Seperator *sep); void command_untraindiscs(Client *c, const Seperator *sep); void command_uptime(Client *c, const Seperator *sep); 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_viewzoneloot(Client *c, const Seperator *sep); void command_wc(Client *c, const Seperator *sep); void command_weather(Client *c, const Seperator *sep); void command_who(Client *c, const Seperator *sep); @@ -325,7 +327,6 @@ void command_zone(Client *c, const Seperator *sep); void command_zone_instance(Client *c, const Seperator *sep); void command_zonebootup(Client *c, const Seperator *sep); void command_zonelock(Client *c, const Seperator *sep); -void command_viewzoneloot(Client *c, const Seperator *sep); void command_zoneshutdown(Client *c, const Seperator *sep); void command_zonestatus(Client *c, const Seperator *sep); void command_zopp(Client *c, const Seperator *sep); diff --git a/zone/gm_commands/viewcurrencies.cpp b/zone/gm_commands/viewcurrencies.cpp new file mode 100644 index 000000000..c66393c6f --- /dev/null +++ b/zone/gm_commands/viewcurrencies.cpp @@ -0,0 +1,137 @@ +#include "../client.h" + +void command_viewcurrencies(Client *c, const Seperator *sep) +{ + Client *target = c; + if (c->GetTarget() && c->GetTarget()->IsClient()) { + target = c->GetTarget()->CastToClient(); + } + + auto target_string = ( + c == target ? + "Yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ); + + auto platinum = ( + target->GetMoney(3, 0) + + target->GetMoney(3, 1) + + target->GetMoney(3, 2) + + target->GetMoney(3, 3) + ); + + auto gold = ( + target->GetMoney(2, 0) + + target->GetMoney(2, 1) + + target->GetMoney(2, 2) + ); + + auto silver = ( + target->GetMoney(1, 0) + + target->GetMoney(1, 1) + + target->GetMoney(1, 2) + ); + + auto copper = ( + target->GetMoney(0, 0) + + target->GetMoney(0, 1) + + target->GetMoney(0, 2) + ); + + if ( + platinum || + gold || + silver || + copper + ) { + c->Message( + Chat::White, + fmt::format( + "Money for {} | {}", + target_string, + ConvertMoneyToString( + platinum, + gold, + silver, + copper + ) + ).c_str() + ); + } + + auto ebon_crystals = target->GetEbonCrystals(); + if (ebon_crystals) { + c->Message( + Chat::White, + fmt::format( + "{} for {} | {}", + database.CreateItemLink(RuleI(Zone, EbonCrystalItemID)), + target_string, + ebon_crystals + ).c_str() + ); + } + + auto radiant_crystals = target->GetRadiantCrystals(); + if (radiant_crystals) { + c->Message( + Chat::White, + fmt::format( + "{} for {} | {}", + database.CreateItemLink(RuleI(Zone, RadiantCrystalItemID)), + target_string, + radiant_crystals + ).c_str() + ); + } + + for (const auto& alternate_currency : zone->AlternateCurrencies) { + auto currency_value = target->GetAlternateCurrencyValue(alternate_currency.id); + if (currency_value) { + c->Message( + Chat::White, + fmt::format( + "{} for {} | {}", + database.CreateItemLink(alternate_currency.item_id), + target_string, + currency_value + ).c_str() + ); + } + } + + for ( + uint32 ldon_currency_id = LDoNThemes::GUK; + ldon_currency_id <= LDoNThemes::TAK; + ldon_currency_id++ + ) { + auto ldon_currency_value = target->GetLDoNPointsTheme(ldon_currency_id); + if (ldon_currency_value) { + c->Message( + Chat::White, + fmt::format( + "{} for {} | {}", + EQ::constants::GetLDoNThemeName(ldon_currency_id), + target_string, + ldon_currency_value + ).c_str() + ); + } + } + + auto pvp_points = target->GetPVPPoints(); + if (pvp_points) { + c->Message( + Chat::White, + fmt::format( + "PVP Points for {} | {}", + target_string, + pvp_points + ).c_str() + ); + } +}