diff --git a/data/sql/db-world/trasm_world_texts.sql b/data/sql/db-world/trasm_world_texts.sql index 8de1f17..a38084f 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, @STRING_ENTRY+14); INSERT INTO `acore_string` (`entry`, `content_default`) VALUES (@STRING_ENTRY+0, 'Item successfully transmogrified.'), (@STRING_ENTRY+1, 'Equipment slot is empty.'), @@ -19,8 +19,12 @@ 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.'), +(@STRING_ENTRY+14, 'The selected Item cannot be used for transmogrification of the target player.'); -DELETE FROM `command` WHERE `name` IN ('transmog'); +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', 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 set', 1, 'Syntax: .transmog add set $player $itemSet\nAdds items of an ItemSet to a player\'s appearance collection.'); diff --git a/src/Transmogrification.h b/src/Transmogrification.h index 1292450..4c63b8d 100644 --- a/src/Transmogrification.h +++ b/src/Transmogrification.h @@ -48,6 +48,8 @@ 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_UNSUITABLE = 11113, + LANG_CMD_TRANSMOG_ADD_FORBIDDEN = 11114, }; class Transmogrification diff --git a/src/cs_transmog.cpp b/src/cs_transmog.cpp index 3c5e3e1..bbb9b6c 100644 --- a/src/cs_transmog.cpp +++ b/src/cs_transmog.cpp @@ -30,9 +30,21 @@ public: ChatCommandTable GetCommands() const override { + static ChatCommandTable addCollectionTable = + { + { "set", HandleAddTransmogItemSet, SEC_MODERATOR, Console::No }, + { "", HandleAddTransmogItem, SEC_MODERATOR, Console::No }, + }; + + static ChatCommandTable transmogTable = + { + { "add", addCollectionTable }, + { "", HandleDisableTransMogVisual, SEC_PLAYER, Console::No }, + }; + static ChatCommandTable commandTable = { - { "transmog", HandleDisableTransMogVisual, SEC_PLAYER, Console::No }, + { "transmog", transmogTable }, }; return commandTable; @@ -56,6 +68,160 @@ 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_UNSUITABLE); + handler->SetSentErrorMessage(true); + return true; + } + + if (itemTemplate->Class != ITEM_CLASS_ARMOR && itemTemplate->Class != ITEM_CLASS_WEAPON) + { + handler->SendSysMessage(LANG_CMD_TRANSMOG_ADD_FORBIDDEN); + handler->SetSentErrorMessage(true); + 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 itemName = itemTemplate->Name1; + std::string nameLink = handler->playerLink(target->GetName()); + if (sTransmogrification->AddCollectedAppearance(accountId, itemId)) + { + + 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, itemName.c_str()); + } + + if (target != handler->GetPlayer()) + { + handler->PSendSysMessage(R"(|c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r has been added to the appearance collection of Player %s.)", itemQuality.c_str(), itemId, itemName.c_str(), nameLink); + } + + CharacterDatabase.Execute("INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId); + } + else + { + handler->PSendSysMessage(R"(Player %s already has item |c%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r in the appearance collection.)", nameLink, itemQuality.c_str(), itemId, itemName.c_str()); + handler->SetSentErrorMessage(true); + } + + 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; + } + + bool added = false; + uint32 error = 0; + uint32 accountId = target->GetSession()->GetAccountId(); + 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)) + { + error = LANG_CMD_TRANSMOG_ADD_UNSUITABLE; + continue; + } + if (itemTemplate->Class != ITEM_CLASS_ARMOR && itemTemplate->Class != ITEM_CLASS_WEAPON) + { + error = LANG_CMD_TRANSMOG_ADD_FORBIDDEN; + continue; + } + + if (sTransmogrification->AddCollectedAppearance(accountId, itemId)) + { + CharacterDatabase.Execute("INSERT INTO custom_unlocked_appearances (account_id, item_template_id) VALUES ({}, {})", accountId, itemId); + added = true; + } + } + } + } + + if (!added && error > 0) + { + handler->SendSysMessage(error); + handler->SetSentErrorMessage(true); + return true; + } + + int locale = handler->GetSessionDbcLocale(); + std::string setName = set->name[locale]; + std::string nameLink = handler->playerLink(target->GetName()); + + if (!added) + { + handler->PSendSysMessage("Player %s already has ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r in the appearance collection.", nameLink, uint32(itemSetId), setName.c_str(), localeNames[locale]); + handler->SetSentErrorMessage(true); + return true; + } + + if (!(target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value)) + { + 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]); + } + + if (target != handler->GetPlayer()) + { + handler->PSendSysMessage("ItemSet |cffffffff|Hitemset:%d|h[%s %s]|h|r has been added to the appearance collection of Player %s.", uint32(itemSetId), setName.c_str(), localeNames[locale], nameLink); + } + + return true; + } }; void AddSC_transmog_commandscript()