Advertisement
skillz79

Transmogrifier.cpp

Aug 10th, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.56 KB | None | 0 0
  1. /*
  2. 5.0
  3. Transmogrification 3.3.5a - Gossip menu
  4. By Rochet2
  5.  
  6. ScriptName for NPC:
  7. Creature_Transmogrify
  8.  
  9. TODO:
  10. Make DB saving even better (Deleting)? What about coding?
  11.  
  12. Fix the cost formula
  13. -- Too much data handling, use default costs
  14.  
  15. Are the qualities right?
  16. Blizzard might have changed the quality requirements.
  17. (TC handles it with stat checks)
  18.  
  19. Cant transmogrify rediculus items // Foereaper: would be fun to stab people with a fish
  20. -- Cant think of any good way to handle this easily, could rip flagged items from cata DB
  21. */
  22.  
  23. #include "Transmogrification.h"
  24. #define sT  sTransmogrification
  25. #define GTS session->GetTrinityString // dropped translation support, no one using?
  26.  
  27. class CS_Transmogrification : public CreatureScript
  28. {
  29. public:
  30.     CS_Transmogrification() : CreatureScript("Creature_Transmogrify") { }
  31.  
  32.     bool OnGossipHello(Player* player, Creature* creature)
  33.     {
  34.         WorldSession* session = player->GetSession();
  35.         if (sT->GetEnableTransmogInfo())
  36.             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Misc_Book_11:30:30:-18:0|tHow transmogrification works", EQUIPMENT_SLOT_END+9, 0);
  37.         for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
  38.         {
  39.             if (const char* slotName = sT->GetSlotName(slot, session))
  40.             {
  41.                 Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
  42.                 uint32 entry = newItem ? sT->GetFakeEntry(newItem->GetGUID()) : 0;
  43.                 std::string icon = entry ? sT->GetItemIcon(entry,30,30,-18,0) : sT->GetSlotIcon(slot, 30, 30, -18, 0);
  44.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, icon+std::string(slotName), EQUIPMENT_SLOT_END, slot);
  45.             }
  46.         }
  47. #ifdef PRESETS
  48.         if (sT->GetEnableSets())
  49.             player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG,"|TInterface/RAIDFRAME/UI-RAIDFRAME-MAINASSIST:30:30:-18:0|tManage sets", EQUIPMENT_SLOT_END+4, 0);
  50. #endif
  51.         player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Enchant_Disenchant:30:30:-18:0|tRemove all transmogrifications", EQUIPMENT_SLOT_END+2, 0, "Remove transmogrifications from all equipped items?", 0, false);
  52.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", EQUIPMENT_SLOT_END+1, 0);
  53.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  54.         return true;
  55.     }
  56.  
  57.     bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
  58.     {
  59.         player->PlayerTalkClass->ClearMenus();
  60.         WorldSession* session = player->GetSession();
  61.         switch(sender)
  62.         {
  63.         case EQUIPMENT_SLOT_END: // Show items you can use
  64.             ShowTransmogItems(player, creature, action);
  65.             break;
  66.         case EQUIPMENT_SLOT_END+1: // Main menu
  67.             OnGossipHello(player, creature);
  68.             break;
  69.         case EQUIPMENT_SLOT_END+2: // Remove Transmogrifications
  70.             {
  71.                 bool removed = false;
  72.                 SQLTransaction trans = CharacterDatabase.BeginTransaction();
  73.                 for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
  74.                 {
  75.                     if (Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
  76.                     {
  77.                         if (!sT->GetFakeEntry(newItem->GetGUID()))
  78.                             continue;
  79.                         sT->DeleteFakeEntry(player, slot, newItem, &trans);
  80.                         removed = true;
  81.                     }
  82.                 }
  83.                 if (removed)
  84.                 {
  85.                     session->SendAreaTriggerMessage(GTS(LANG_ERR_UNTRANSMOG_OK));
  86.                     CharacterDatabase.CommitTransaction(trans);
  87.                 }
  88.                 else
  89.                     session->SendNotification(LANG_ERR_UNTRANSMOG_NO_TRANSMOGS);
  90.                 OnGossipHello(player, creature);
  91.             } break;
  92.         case EQUIPMENT_SLOT_END+3: // Remove Transmogrification from single item
  93.             {
  94.                 if (Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, action))
  95.                 {
  96.                     if (sT->GetFakeEntry(newItem->GetGUID()))
  97.                     {
  98.                         sT->DeleteFakeEntry(player, action, newItem);
  99.                         session->SendAreaTriggerMessage(GTS(LANG_ERR_UNTRANSMOG_OK));
  100.                     }
  101.                     else
  102.                         session->SendNotification(LANG_ERR_UNTRANSMOG_NO_TRANSMOGS);
  103.                 }
  104.                 OnGossipSelect(player, creature, EQUIPMENT_SLOT_END, action);
  105.             } break;
  106. #ifdef PRESETS
  107.         case EQUIPMENT_SLOT_END+4: // Presets menu
  108.             {
  109.                 if (!sT->GetEnableSets())
  110.                 {
  111.                     OnGossipHello(player, creature);
  112.                     return true;
  113.                 }
  114.                 if (sT->GetEnableSetInfo())
  115.                     player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Misc_Book_11:30:30:-18:0|tHow sets work", EQUIPMENT_SLOT_END+10, 0);
  116.                 for (Transmogrification::presetIdMap::const_iterator it = sT->presetByName[player->GetGUID()].begin(); it != sT->presetByName[player->GetGUID()].end(); ++it)
  117.                     player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Misc_Statue_02:30:30:-18:0|t"+it->second, EQUIPMENT_SLOT_END+6, it->first);
  118.  
  119.                 if (sT->presetByName[player->GetGUID()].size() < sT->GetMaxSets())
  120.                     player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/GuildBankFrame/UI-GuildBankFrame-NewTab:30:30:-18:0|tSave set", EQUIPMENT_SLOT_END+8, 0);
  121.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+1, 0);
  122.                 player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  123.             } break;
  124.         case EQUIPMENT_SLOT_END+5: // Use preset
  125.             {
  126.                 if (!sT->GetEnableSets())
  127.                 {
  128.                     OnGossipHello(player, creature);
  129.                     return true;
  130.                 }
  131.                 // action = presetID
  132.                 for (Transmogrification::slotMap::const_iterator it = sT->presetById[player->GetGUID()][action].begin(); it != sT->presetById[player->GetGUID()][action].end(); ++it)
  133.                 {
  134.                     if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, it->first))
  135.                         sT->PresetTransmog(player, item, it->second, it->first);
  136.                 }
  137.                 OnGossipSelect(player, creature, EQUIPMENT_SLOT_END+6, action);
  138.             } break;
  139.         case EQUIPMENT_SLOT_END+6: // view preset
  140.             {
  141.                 if (!sT->GetEnableSets())
  142.                 {
  143.                     OnGossipHello(player, creature);
  144.                     return true;
  145.                 }
  146.                 // action = presetID
  147.                 for (Transmogrification::slotMap::const_iterator it = sT->presetById[player->GetGUID()][action].begin(); it != sT->presetById[player->GetGUID()][action].end(); ++it)
  148.                     player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(it->second, 30, 30, -18, 0)+sT->GetItemLink(it->second, session), sender, action);
  149.  
  150.                 player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Misc_Statue_02:30:30:-18:0|tUse set", EQUIPMENT_SLOT_END+5, action, "Using this set for transmogrify will bind transmogrified items to you and make them non-refundable and non-tradeable.\nDo you wish to continue?\n\n"+sT->presetByName[player->GetGUID()][action], 0, false);
  151.                 player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-LeaveItem-Opaque:30:30:-18:0|tDelete set", EQUIPMENT_SLOT_END+7, action, "Are you sure you want to delete "+sT->presetByName[player->GetGUID()][action]+"?", 0, false);
  152.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+4, 0);
  153.                 player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  154.             } break;
  155.         case EQUIPMENT_SLOT_END+7: // Delete preset
  156.             {
  157.                 if (!sT->GetEnableSets())
  158.                 {
  159.                     OnGossipHello(player, creature);
  160.                     return true;
  161.                 }
  162.                 // action = presetID
  163.                 CharacterDatabase.PExecute("DELETE FROM `custom_transmogrification_sets` WHERE Owner = %u AND PresetID = %u",  player->GetGUIDLow(), action);
  164.                 sT->presetById[player->GetGUID()][action].clear();
  165.                 sT->presetById[player->GetGUID()].erase(action);
  166.                 sT->presetByName[player->GetGUID()].erase(action);
  167.  
  168.                 OnGossipSelect(player, creature, EQUIPMENT_SLOT_END+4, 0);
  169.             } break;
  170.         case EQUIPMENT_SLOT_END+8: // Save preset
  171.             {
  172.                 if (!sT->GetEnableSets() || sT->presetByName[player->GetGUID()].size() >= sT->GetMaxSets())
  173.                 {
  174.                     OnGossipHello(player, creature);
  175.                     return true;
  176.                 }
  177.                 uint32 cost = 0;
  178.                 bool canSave = false;
  179.                 for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
  180.                 {
  181.                     if (!sT->GetSlotName(slot, session))
  182.                         continue;
  183.                     if (Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
  184.                     {
  185.                         uint32 entry = sT->GetFakeEntry(newItem->GetGUID());
  186.                         if (!entry)
  187.                             continue;
  188.                         const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry);
  189.                         if (!temp)
  190.                             continue;
  191.                         if (!sT->SuitableForTransmogrification(player, temp)) // no need to check?
  192.                             continue;
  193.                         cost += sT->GetSpecialPrice(temp);
  194.                         canSave = true;
  195.                         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(entry, 30, 30, -18, 0)+sT->GetItemLink(entry, session), EQUIPMENT_SLOT_END+8, 0);
  196.                     }
  197.                 }
  198.                 if (canSave)
  199.                     player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, "|TInterface/GuildBankFrame/UI-GuildBankFrame-NewTab:30:30:-18:0|tSave set", 0, 0, "Insert set name", cost*sT->GetSetCostModifier()+sT->GetSetCopperCost(), true);
  200.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", sender, action);
  201.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+4, 0);
  202.                 player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  203.             } break;
  204.         case EQUIPMENT_SLOT_END+10: // Set info
  205.             {
  206.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+4, 0);
  207.                 player->SEND_GOSSIP_MENU(sT->GetSetNpcText(), creature->GetGUID());
  208.             } break;
  209. #endif
  210.         case EQUIPMENT_SLOT_END+9: // Transmog info
  211.             {
  212.                 player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+1, 0);
  213.                 player->SEND_GOSSIP_MENU(sT->GetTransmogNpcText(), creature->GetGUID());
  214.             } break;
  215.         default: // Transmogrify
  216.             {
  217.                 if (!sender && !action)
  218.                 {
  219.                     OnGossipHello(player, creature);
  220.                     return true;
  221.                 }
  222.                 // sender = slot, action = display
  223.                 TransmogTrinityStrings res = sT->Transmogrify(player, MAKE_NEW_GUID(action, 0, HIGHGUID_ITEM), sender);
  224.                 if (res == LANG_ERR_TRANSMOG_OK)
  225.                     session->SendAreaTriggerMessage(GTS(LANG_ERR_TRANSMOG_OK));
  226.                 else
  227.                     session->SendNotification(res);
  228.                 // OnGossipSelect(player, creature, EQUIPMENT_SLOT_END, sender);
  229.                 // ShowTransmogItems(player, creature, sender);
  230.                 player->CLOSE_GOSSIP_MENU(); // Wait for SetMoney to get fixed, issue #10053
  231.             } break;
  232.         }
  233.         return true;
  234.     }
  235.  
  236. #ifdef PRESETS
  237.     bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code)
  238.     {
  239.         player->PlayerTalkClass->ClearMenus();
  240.         if (sender || action)
  241.             return true; // should never happen
  242.         if (!sT->GetEnableSets())
  243.         {
  244.             OnGossipHello(player, creature);
  245.             return true;
  246.         }
  247.         std::string name(code);
  248.         if (name.find('"') != std::string::npos || name.find('\\') != std::string::npos)
  249.             player->GetSession()->SendNotification(LANG_PRESET_ERR_INVALID_NAME);
  250.         else
  251.         {
  252.             for (uint8 presetID = 0; presetID < sT->GetMaxSets(); ++presetID) // should never reach over max
  253.             {
  254.                 if (sT->presetByName[player->GetGUID()].find(presetID) != sT->presetByName[player->GetGUID()].end())
  255.                     continue; // Just remember never to use presetByName[pGUID][presetID] when finding etc!
  256.  
  257.                 int32 cost = 0;
  258.                 std::map<uint8, uint32> items;
  259.                 for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
  260.                 {
  261.                     if (!sT->GetSlotName(slot, player->GetSession()))
  262.                         continue;
  263.                     if (Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
  264.                     {
  265.                         uint32 entry = sT->GetFakeEntry(newItem->GetGUID());
  266.                         if (!entry)
  267.                             continue;
  268.                         const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry);
  269.                         if (!temp)
  270.                             continue;
  271.                         if (!sT->SuitableForTransmogrification(player, temp))
  272.                             continue;
  273.                         cost += sT->GetSpecialPrice(temp);
  274.                         items[slot] = entry;
  275.                     }
  276.                 }
  277.                 if (items.empty())
  278.                     break; // no transmogrified items were found to be saved
  279.                 cost *= sT->GetSetCostModifier();
  280.                 cost += sT->GetSetCopperCost();
  281.                 if (!player->HasEnoughMoney(cost))
  282.                 {
  283.                     player->GetSession()->SendNotification(LANG_ERR_TRANSMOG_NOT_ENOUGH_MONEY);
  284.                     break;
  285.                 }
  286.  
  287.                 std::ostringstream ss;
  288.                 for (std::map<uint8, uint32>::iterator it = items.begin(); it != items.end(); ++it)
  289.                 {
  290.                     ss << uint32(it->first) << ' ' << it->second << ' ';
  291.                     sT->presetById[player->GetGUID()][presetID][it->first] = it->second;
  292.                 }
  293.                 sT->presetByName[player->GetGUID()][presetID] = name; // Make sure code doesnt mess up SQL!
  294.                 CharacterDatabase.PExecute("REPLACE INTO `custom_transmogrification_sets` (`Owner`, `PresetID`, `SetName`, `SetData`) VALUES (%u, %u, \"%s\", \"%s\")",  player->GetGUIDLow(), uint32(presetID), name.c_str(), ss.str().c_str());
  295.                 if (cost)
  296.                     player->ModifyMoney(cost);
  297.                 break;
  298.             }
  299.         }
  300.         //OnGossipSelect(player, creature, EQUIPMENT_SLOT_END+4, 0);
  301.         player->CLOSE_GOSSIP_MENU(); // Wait for SetMoney to get fixed, issue #10053
  302.         return true;
  303.     }
  304. #endif
  305.  
  306.     void ShowTransmogItems(Player* player, Creature* creature, uint8 slot) // Only checks bags while can use an item from anywhere in inventory
  307.     {
  308.         WorldSession* session = player->GetSession();
  309.         Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
  310.         if (oldItem)
  311.         {
  312.             uint32 limit = 0;
  313.             uint32 price = sT->GetSpecialPrice(oldItem->GetTemplate());
  314.             price *= sT->GetScaledCostModifier();
  315.             price += sT->GetCopperCost();
  316.             std::ostringstream ss;
  317.             ss << std::endl;
  318.             if (sT->GetRequireToken())
  319.                 ss << std::endl << std::endl << sT->GetTokenAmount() << " x " << sT->GetItemLink(sT->GetTokenEntry(), session);
  320.  
  321.             for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
  322.             {
  323.                 if (limit > MAX_OPTIONS)
  324.                     break;
  325.                 Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
  326.                 if (!newItem)
  327.                     continue;
  328.                 if (!sT->CanTransmogrifyItemWithItem(player, oldItem->GetTemplate(), newItem->GetTemplate()))
  329.                     continue;
  330.                 if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
  331.                     continue;
  332.                 ++limit;
  333.                 player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0)+sT->GetItemLink(newItem, session), slot, newItem->GetGUIDLow(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n"+sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10)+sT->GetItemLink(newItem, session)+ss.str(), price, false);
  334.             }
  335.  
  336.             for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
  337.             {
  338.                 Bag* bag = player->GetBagByPos(i);
  339.                 if (!bag)
  340.                     continue;
  341.                 for (uint32 j = 0; j < bag->GetBagSize(); ++j)
  342.                 {
  343.                     if (limit > MAX_OPTIONS)
  344.                         break;
  345.                     Item* newItem = player->GetItemByPos(i, j);
  346.                     if (!newItem)
  347.                         continue;
  348.                     if (!sT->CanTransmogrifyItemWithItem(player, oldItem->GetTemplate(), newItem->GetTemplate()))
  349.                         continue;
  350.                     if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
  351.                         continue;
  352.                     ++limit;
  353.                     player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0)+sT->GetItemLink(newItem, session), slot, newItem->GetGUIDLow(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n"+sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10)+sT->GetItemLink(newItem, session)+ss.str(), price, false);
  354.                 }
  355.             }
  356.         }
  357.  
  358.         player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Enchant_Disenchant:30:30:-18:0|tRemove transmogrification", EQUIPMENT_SLOT_END+3, slot, "Remove transmogrification from the slot?", 0, false);
  359.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", EQUIPMENT_SLOT_END, slot);
  360.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+1, 0);
  361.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  362.     }
  363. };
  364.  
  365. class PS_Transmogrification : public PlayerScript
  366. {
  367. public:
  368.     PS_Transmogrification() : PlayerScript("Player_Transmogrify") { }
  369.  
  370.     void OnLogin(Player* player)
  371.     {
  372.         uint64 playerGUID = player->GetGUID();
  373.         sT->entryMap.erase(playerGUID);
  374.         QueryResult result = CharacterDatabase.PQuery("SELECT GUID, FakeEntry FROM custom_transmogrification WHERE Owner = %u", player->GetGUIDLow());
  375.         if (result)
  376.         {
  377.             do
  378.             {
  379.                 uint64 itemGUID = MAKE_NEW_GUID((*result)[0].GetUInt32(), 0, HIGHGUID_ITEM);
  380.                 uint32 fakeEntry = (*result)[1].GetUInt32();
  381.                 if (sObjectMgr->GetItemTemplate(fakeEntry))
  382.                 {
  383.                     sT->dataMap[itemGUID] = playerGUID;
  384.                     sT->entryMap[playerGUID][itemGUID] = fakeEntry;
  385.                 }
  386.                 else
  387.                 {
  388.                     sLog->outError(LOG_FILTER_SQL, "Item entry (Entry: %u, itemGUID: %u, playerGUID: %u) does not exist, ignoring.", fakeEntry, GUID_LOPART(itemGUID), player->GetGUIDLow());
  389.                     // CharacterDatabase.PExecute("DELETE FROM custom_transmogrification WHERE FakeEntry = %u", fakeEntry);
  390.                 }
  391.             } while (result->NextRow());
  392.  
  393.             for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
  394.             {
  395.                 if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
  396.                     player->SetVisibleItemSlot(slot, item);
  397.             }
  398.         }
  399.  
  400. #ifdef PRESETS
  401.         if (sT->GetEnableSets())
  402.             sT->LoadPlayerSets(playerGUID);
  403. #endif
  404.     }
  405.  
  406.     void OnLogout(Player* player)
  407.     {
  408.         uint32 pGUID = player->GetGUID();
  409.         for (Transmogrification::transmogData::const_iterator it = sT->entryMap[pGUID].begin(); it != sT->entryMap[pGUID].end(); ++it)
  410.             sT->dataMap.erase(it->first);
  411.         sT->entryMap.erase(pGUID);
  412.  
  413. #ifdef PRESETS
  414.         if (sT->GetEnableSets())
  415.             sT->UnloadPlayerSets(pGUID);
  416. #endif
  417.     }
  418. };
  419.  
  420. class WS_Transmogrification : public WorldScript
  421. {
  422. public:
  423.     WS_Transmogrification() : WorldScript("WS_Transmogrification") { }
  424.  
  425.     void OnConfigLoad(bool reload)
  426.     {
  427.         sT->LoadConfig(reload);
  428.     }
  429.  
  430.     void OnStartup()
  431.     {
  432.         sT->LoadConfig(false);
  433.         sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Deleting non-existing transmogrification entries...");
  434.         CharacterDatabase.Execute("DELETE FROM custom_transmogrification WHERE NOT EXISTS (SELECT 1 FROM item_instance WHERE item_instance.guid = custom_transmogrification.GUID)");
  435.  
  436. #ifdef PRESETS
  437.         // Clean even if disabled
  438.         // Dont delete even if player has more presets than should
  439.         CharacterDatabase.Execute("DELETE FROM `custom_transmogrification_sets` WHERE NOT EXISTS(SELECT 1 FROM characters WHERE characters.guid = custom_transmogrification_sets.Owner)");
  440. #endif
  441.     }
  442. };
  443.  
  444. void AddSC_CPWS_Transmogrification()
  445. {
  446.     new CS_Transmogrification();
  447.     new PS_Transmogrification();
  448.     new WS_Transmogrification();
  449. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement