From f8fd0e036416d12ca83b131835abafcf1ee9d6f5 Mon Sep 17 00:00:00 2001 From: Gozzim <80704304+Gozzim@users.noreply.github.com> Date: Sun, 15 May 2022 18:07:27 +0200 Subject: [PATCH] feat: Add appearance collection add item command --- data/sql/db-world/trasm_world_texts.sql | 10 +++-- src/Transmogrification.h | 1 + src/cs_transmog.cpp | 58 ++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/data/sql/db-world/trasm_world_texts.sql b/data/sql/db-world/trasm_world_texts.sql index 8de1f17..0772ba1 100644 --- a/data/sql/db-world/trasm_world_texts.sql +++ b/data/sql/db-world/trasm_world_texts.sql @@ -5,7 +5,7 @@ INSERT INTO `npc_text` (`ID`, `text0_0`) VALUES (@TEXT_ID+1, 'You can save your own transmogrification sets.\r\n\r\nTo save, first you must transmogrify your equipped items.\r\nThen when you go to the set management menu and go to save set menu,\r\nall items you have transmogrified are displayed so you see what you are saving.\r\nIf you think the set is fine, you can click to save the set and name it as you wish.\r\n\r\nTo use a set you can click the saved set in the set management menu and then select use set.\r\nIf the set has a transmogrification for an item that is already transmogrified, the old transmogrification is lost.\r\nNote that same transmogrification restrictions apply when trying to use a set as in normal transmogrification.\r\n\r\nTo delete a set you can go to the set\'s menu and select delete set.'); SET @STRING_ENTRY := 11100; -DELETE FROM `acore_string` WHERE `entry` IN (@STRING_ENTRY+0,@STRING_ENTRY+1,@STRING_ENTRY+2,@STRING_ENTRY+3,@STRING_ENTRY+4,@STRING_ENTRY+5,@STRING_ENTRY+6,@STRING_ENTRY+7,@STRING_ENTRY+8,@STRING_ENTRY+9,@STRING_ENTRY+10, @STRING_ENTRY+11, @STRING_ENTRY+12); +DELETE FROM `acore_string` WHERE `entry` IN (@STRING_ENTRY+0,@STRING_ENTRY+1,@STRING_ENTRY+2,@STRING_ENTRY+3,@STRING_ENTRY+4,@STRING_ENTRY+5,@STRING_ENTRY+6,@STRING_ENTRY+7,@STRING_ENTRY+8,@STRING_ENTRY+9,@STRING_ENTRY+10, @STRING_ENTRY+11, @STRING_ENTRY+12, @STRING_ENTRY+13); INSERT INTO `acore_string` (`entry`, `content_default`) VALUES (@STRING_ENTRY+0, 'Item successfully transmogrified.'), (@STRING_ENTRY+1, 'Equipment slot is empty.'), @@ -19,8 +19,10 @@ INSERT INTO `acore_string` (`entry`, `content_default`) VALUES (@STRING_ENTRY+9, 'No transmogrification found.'), (@STRING_ENTRY+10, 'Invalid name inserted.'), (@STRING_ENTRY+11, 'Showing transmogrifieded items, relog to update the current area.'), -(@STRING_ENTRY+12, 'Hiding transmogrifieded items, relog to update the current area.'); +(@STRING_ENTRY+12, 'Hiding transmogrifieded items, relog to update the current area.'), +(@STRING_ENTRY+13, 'The selected Item is not suitable for transmogrification.'); -DELETE FROM `command` WHERE `name` IN ('transmog'); +DELETE FROM `command` WHERE `name` IN ('transmog', 'transmog add'); INSERT INTO `command` (`name`, `security`, `help`) VALUES -('transmog', 0, 'Syntax: .transmog \nAllows seeing transmogrified items and the transmogrifier NPC.'); +('transmog', 0, 'Syntax: .transmog \nAllows seeing transmogrified items and the transmogrifier NPC.'), +('transmog add', 1, 'Syntax: .transmog add $player $item\nAdds an item to a player\'s appearance collection.'); diff --git a/src/Transmogrification.h b/src/Transmogrification.h index 8787961..ebad395 100644 --- a/src/Transmogrification.h +++ b/src/Transmogrification.h @@ -47,6 +47,7 @@ enum TransmogAcoreStrings // Language.h might have same entries, appears when ex #endif LANG_CMD_TRANSMOG_SHOW = 11111, LANG_CMD_TRANSMOG_HIDE = 11112, + LANG_CMD_TRANSMOG_ADD = 11113, }; class Transmogrification diff --git a/src/cs_transmog.cpp b/src/cs_transmog.cpp index 3c5e3e1..8b2db14 100644 --- a/src/cs_transmog.cpp +++ b/src/cs_transmog.cpp @@ -30,9 +30,15 @@ public: ChatCommandTable GetCommands() const override { + static ChatCommandTable transmogTable = + { + { "add", HandleAddTransmogItem, SEC_MODERATOR, Console::No }, + { "", HandleDisableTransMogVisual, SEC_PLAYER, Console::No }, + }; + static ChatCommandTable commandTable = { - { "transmog", HandleDisableTransMogVisual, SEC_PLAYER, Console::No }, + { "transmog", transmogTable }, }; return commandTable; @@ -56,6 +62,56 @@ public: player->UpdateObjectVisibility(); return true; } + + static bool HandleAddTransmogItem(ChatHandler* handler, Optional player, ItemTemplate const* itemTemplate) + { + if (!sTransmogrification->GetUseCollectionSystem()) + return true; + + if (!sObjectMgr->GetItemTemplate(itemTemplate->ItemId)) + { + handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemTemplate->ItemId); + handler->SetSentErrorMessage(true); + return false; + } + + if (!player) + player = PlayerIdentifier::FromTargetOrSelf(handler); + if (!player || !player->IsConnected()) + return false; + + Player* target = player->GetConnectedPlayer(); + + if (!sTransmogrification->GetTrackUnusableItems() && !sTransmogrification->SuitableForTransmogrification(target, itemTemplate)) + { + handler->SendSysMessage(LANG_CMD_TRANSMOG_ADD); + handler->SetSentErrorMessage(true); + return true; + } + + if (itemTemplate->Class != ITEM_CLASS_ARMOR && itemTemplate->Class != ITEM_CLASS_WEAPON) + return true; + + uint32 itemId = itemTemplate->ItemId; + uint32 accountId = target->GetSession()->GetAccountId(); + std::stringstream tempStream; + tempStream << std::hex << ItemQualityColors[itemTemplate->Quality]; + std::string itemQuality = tempStream.str(); + std::string query = "SELECT account_id, item_template_id FROM custom_unlocked_appearances WHERE account_id = " + std::to_string(accountId) + " AND item_template_id = " + std::to_string(itemId); + target->GetSession()->GetQueryProcessor().AddCallback(CharacterDatabase.AsyncQuery(query).WithCallback([=](QueryResult result) + { + if (!result) + { + if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value)) + { + ChatHandler(target->GetSession()).PSendSysMessage(R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to your appearance collection.)", itemQuality.c_str(), itemId, itemTemplate->Name1.c_str()); + } + CharacterDatabase.Execute("INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId); + } + })); + + return true; + } }; void AddSC_transmog_commandscript()