diff --git a/data/sql/db-world/trasm_world_texts.sql b/data/sql/db-world/trasm_world_texts.sql index 0772ba1..7d2b882 100644 --- a/data/sql/db-world/trasm_world_texts.sql +++ b/data/sql/db-world/trasm_world_texts.sql @@ -22,7 +22,8 @@ INSERT INTO `acore_string` (`entry`, `content_default`) VALUES (@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', 'transmog add'); +DELETE FROM `command` WHERE `name` IN ('transmog', 'transmog add', 'transmog add set'); INSERT INTO `command` (`name`, `security`, `help`) VALUES ('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.'); +('transmog add', 1, 'Syntax: .transmog add $player $item\nAdds an item to a player\'s appearance collection.'), +('transmog add set', 1, 'Syntax: .transmog add set $player $itemSet\nAdds items of an ItemSet to a player\'s appearance collection.'); diff --git a/src/cs_transmog.cpp b/src/cs_transmog.cpp index 8b2db14..0c36a07 100644 --- a/src/cs_transmog.cpp +++ b/src/cs_transmog.cpp @@ -30,9 +30,15 @@ public: ChatCommandTable GetCommands() const override { + static ChatCommandTable addCollectionTable = + { + { "set", HandleAddTransmogItemSet, SEC_MODERATOR, Console::No }, + { "", HandleAddTransmogItem, SEC_MODERATOR, Console::No }, + }; + static ChatCommandTable transmogTable = { - { "add", HandleAddTransmogItem, SEC_MODERATOR, Console::No }, + { "add", addCollectionTable }, { "", HandleDisableTransMogVisual, SEC_PLAYER, Console::No }, }; @@ -63,7 +69,7 @@ public: return true; } - static bool HandleAddTransmogItem(ChatHandler* handler, Optional player, ItemTemplate const* itemTemplate) + static bool HandleAddTransmogItem(ChatHandler* handler, Optional player, ItemTemplate const* itemTemplate) { if (!sTransmogrification->GetUseCollectionSystem()) return true; @@ -100,18 +106,80 @@ public: 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); - } + 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; } + + static bool HandleAddTransmogItemSet(ChatHandler* handler, Optional player, Variant, uint32> itemSetId) + { + if (!sTransmogrification->GetUseCollectionSystem()) + return true; + + if (!*itemSetId) + { + handler->PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND, uint32(itemSetId)); + handler->SetSentErrorMessage(true); + return false; + } + + if (!player) + player = PlayerIdentifier::FromTargetOrSelf(handler); + if (!player || !player->IsConnected()) + return false; + + Player* target = player->GetConnectedPlayer(); + ItemSetEntry const* set = sItemSetStore.LookupEntry(uint32(itemSetId)); + + if (!set) + { + handler->PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND, uint32(itemSetId)); + handler->SetSentErrorMessage(true); + return false; + } + + uint32 itemId; + for (uint32 i = 0; i < MAX_ITEM_SET_ITEMS; ++i) + { + itemId = set->itemId[i]; + if (itemId) + { + ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId); + if (itemTemplate) + { + if (!sTransmogrification->GetTrackUnusableItems() && !sTransmogrification->SuitableForTransmogrification(target, itemTemplate)) + continue; + if (itemTemplate->Class != ITEM_CLASS_ARMOR && itemTemplate->Class != ITEM_CLASS_WEAPON) + continue; + + uint32 accountId = target->GetSession()->GetAccountId(); + 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) + CharacterDatabase.Execute("INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId); + })); + } + } + } + + if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value)) + { + int locale = handler->GetSessionDbcLocale(); + std::string setName = set->name[locale]; + ChatHandler(target->GetSession()).PSendSysMessage("ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r has been added to your appearance collection.", uint32(itemSetId), setName.c_str(), localeNames[locale]); + } + + return true; + } }; void AddSC_transmog_commandscript()