Advertisement
skillz79

Transmogrification.cpp

Aug 10th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.17 KB | None | 0 0
  1. #include "Transmogrification.h"
  2.  
  3. const char * Transmogrification::GetSlotName(uint8 slot, WorldSession* session) const
  4. {
  5.     switch (slot)
  6.     {
  7.     case EQUIPMENT_SLOT_HEAD      : return  "Head";// session->GetTrinityString(LANG_SLOT_NAME_HEAD);
  8.     case EQUIPMENT_SLOT_SHOULDERS : return  "Shoulders";// session->GetTrinityString(LANG_SLOT_NAME_SHOULDERS);
  9.     case EQUIPMENT_SLOT_BODY      : return  "Shirt";// session->GetTrinityString(LANG_SLOT_NAME_BODY);
  10.     case EQUIPMENT_SLOT_CHEST     : return  "Chest";// session->GetTrinityString(LANG_SLOT_NAME_CHEST);
  11.     case EQUIPMENT_SLOT_WAIST     : return  "Waist";// session->GetTrinityString(LANG_SLOT_NAME_WAIST);
  12.     case EQUIPMENT_SLOT_LEGS      : return  "Legs";// session->GetTrinityString(LANG_SLOT_NAME_LEGS);
  13.     case EQUIPMENT_SLOT_FEET      : return  "Feet";// session->GetTrinityString(LANG_SLOT_NAME_FEET);
  14.     case EQUIPMENT_SLOT_WRISTS    : return  "Wrists";// session->GetTrinityString(LANG_SLOT_NAME_WRISTS);
  15.     case EQUIPMENT_SLOT_HANDS     : return  "Hands";// session->GetTrinityString(LANG_SLOT_NAME_HANDS);
  16.     case EQUIPMENT_SLOT_BACK      : return  "Back";// session->GetTrinityString(LANG_SLOT_NAME_BACK);
  17.     case EQUIPMENT_SLOT_MAINHAND  : return  "Main hand";// session->GetTrinityString(LANG_SLOT_NAME_MAINHAND);
  18.     case EQUIPMENT_SLOT_OFFHAND   : return  "Off hand";// session->GetTrinityString(LANG_SLOT_NAME_OFFHAND);
  19.     case EQUIPMENT_SLOT_RANGED    : return  "Ranged";// session->GetTrinityString(LANG_SLOT_NAME_RANGED);
  20.     case EQUIPMENT_SLOT_TABARD    : return  "Tabard";// session->GetTrinityString(LANG_SLOT_NAME_TABARD);
  21.     default: return NULL;
  22.     }
  23. }
  24. std::string Transmogrification::GetItemIcon(uint32 entry, uint32 width, uint32 height, int x, int y)
  25. {
  26.     std::ostringstream ss;
  27.     ss << "|TInterface";
  28.     const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry);
  29.     const ItemDisplayInfoEntry* dispInfo = NULL;
  30.     if (temp)
  31.     {
  32.         dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
  33.         if (dispInfo)
  34.             ss << "/ICONS/" << dispInfo->inventoryIcon;
  35.     }
  36.     if (!temp && !dispInfo)
  37.         ss << "/InventoryItems/WoWUnknownItem01";
  38.     ss << ":" << width << ":" << height << ":" << x << ":" << y << "|t";
  39.     return ss.str();
  40. }
  41.  
  42. std::string Transmogrification::GetSlotIcon(uint8 slot, uint32 width, uint32 height, int x, int y)
  43. {
  44.     std::ostringstream ss;
  45.     ss << "|TInterface/PaperDoll/";
  46.     switch (slot)
  47.     {
  48.     case EQUIPMENT_SLOT_HEAD      : ss << "UI-PaperDoll-Slot-Head"; break;
  49.     case EQUIPMENT_SLOT_SHOULDERS : ss << "UI-PaperDoll-Slot-Shoulder"; break;
  50.     case EQUIPMENT_SLOT_BODY      : ss << "UI-PaperDoll-Slot-Shirt"; break;
  51.     case EQUIPMENT_SLOT_CHEST     : ss << "UI-PaperDoll-Slot-Chest"; break;
  52.     case EQUIPMENT_SLOT_WAIST     : ss << "UI-PaperDoll-Slot-Waist"; break;
  53.     case EQUIPMENT_SLOT_LEGS      : ss << "UI-PaperDoll-Slot-Legs"; break;
  54.     case EQUIPMENT_SLOT_FEET      : ss << "UI-PaperDoll-Slot-Feet"; break;
  55.     case EQUIPMENT_SLOT_WRISTS    : ss << "UI-PaperDoll-Slot-Wrists"; break;
  56.     case EQUIPMENT_SLOT_HANDS     : ss << "UI-PaperDoll-Slot-Hands"; break;
  57.     case EQUIPMENT_SLOT_BACK      : ss << "UI-PaperDoll-Slot-Chest"; break;
  58.     case EQUIPMENT_SLOT_MAINHAND  : ss << "UI-PaperDoll-Slot-MainHand"; break;
  59.     case EQUIPMENT_SLOT_OFFHAND   : ss << "UI-PaperDoll-Slot-SecondaryHand"; break;
  60.     case EQUIPMENT_SLOT_RANGED    : ss << "UI-PaperDoll-Slot-Ranged"; break;
  61.     case EQUIPMENT_SLOT_TABARD    : ss << "UI-PaperDoll-Slot-Tabard"; break;
  62.     default: ss << "UI-Backpack-EmptySlot";
  63.     }
  64.     ss << ":" << width << ":" << height << ":" << x << ":" << y << "|t";
  65.     return ss.str();
  66. }
  67. #ifdef PRESETS
  68. void Transmogrification::PresetTransmog(Player* player, Item* itemTransmogrified, uint32 fakeEntry, uint8 slot)
  69. {
  70.     if (!GetEnableSets())
  71.         return;
  72.     if (!player || !itemTransmogrified)
  73.         return;
  74.     if (slot >= EQUIPMENT_SLOT_END)
  75.         return;
  76.     if (!CanTransmogrifyItemWithItem(player, itemTransmogrified->GetTemplate(), sObjectMgr->GetItemTemplate(fakeEntry)))
  77.         return;
  78.  
  79.     // itemTransmogrified->ClearEnchantment(TRANSMOGRIFY_ENCHANTMENT_SLOT);
  80.     // player->SetVisibleItemSlot(slot, itemTransmogrified);
  81.  
  82.     // Custom
  83.     if (GetFakeEntry(itemTransmogrified->GetGUID()))
  84.         DeleteFakeEntry(player, slot, itemTransmogrified);
  85.  
  86.     // All okay, proceed
  87.     // itemTransmogrified->SetEnchantment(TRANSMOGRIFY_ENCHANTMENT_SLOT, newEntry, 0, 0);
  88.     // player->SetVisibleItemSlot(slot, itemTransmogrified);
  89.  
  90.     // Custom
  91.     SetFakeEntry(player, fakeEntry, slot, itemTransmogrified); // newEntry
  92.  
  93.  
  94.     itemTransmogrified->UpdatePlayedTime(player);
  95.  
  96.     itemTransmogrified->SetOwnerGUID(player->GetGUID());
  97.     itemTransmogrified->SetNotRefundable(player);
  98.     itemTransmogrified->ClearSoulboundTradeable(player);
  99. }
  100. bool Transmogrification::GetEnableSets() const
  101. {
  102.     return EnableSets;
  103. }
  104. uint8 Transmogrification::GetMaxSets() const
  105. {
  106.     return MaxSets;
  107. }
  108. float Transmogrification::GetSetCostModifier() const
  109. {
  110.     return SetCostModifier;
  111. }
  112. int32 Transmogrification::GetSetCopperCost() const
  113. {
  114.     return SetCopperCost;
  115. }
  116. void Transmogrification::LoadPlayerSets(uint64 pGUID)
  117. {
  118.     for (presetData::iterator it = presetById[pGUID].begin(); it != presetById[pGUID].end(); ++it)
  119.         it->second.clear();
  120.     presetById[pGUID].clear();
  121.  
  122.     presetByName[pGUID].clear();
  123.  
  124.     QueryResult result = CharacterDatabase.PQuery("SELECT `PresetID`, `SetName`, `SetData` FROM `custom_transmogrification_sets` WHERE Owner = %u", GUID_LOPART(pGUID));
  125.     if (result)
  126.     {
  127.         do
  128.         {
  129.             uint8 PresetID = (*result)[0].GetUInt8();
  130.             std::string SetName = (*result)[1].GetString();
  131.             std::istringstream SetData((*result)[2].GetString());
  132.             while (SetData.good())
  133.             {
  134.                 uint32 slot;
  135.                 uint32 entry;
  136.                 SetData >> slot >> entry;
  137.                 if(SetData.fail())
  138.                     break;
  139.                 if(slot >= EQUIPMENT_SLOT_END)
  140.                 {
  141.                     sLog->outError(LOG_FILTER_SQL, "Item entry (FakeEntry: %u, playerGUID: %u, slot: %u, presetId: %u) has invalid slot, ignoring.", entry, GUID_LOPART(pGUID), slot, uint32(PresetID));
  142.                     continue;
  143.                 }
  144.                 if (sObjectMgr->GetItemTemplate(entry))
  145.                     presetById[pGUID][PresetID][slot] = entry; // Transmogrification::Preset(presetName, fakeEntry);
  146.                 else
  147.                     sLog->outError(LOG_FILTER_SQL, "Item entry (FakeEntry: %u, playerGUID: %u, slot: %u, presetId: %u) does not exist, ignoring.", entry, GUID_LOPART(pGUID), uint32(slot), uint32(PresetID));
  148.             }
  149.  
  150.             if (!presetById[pGUID][PresetID].empty())
  151.             {
  152.                 presetByName[pGUID][PresetID] = SetName;
  153.                 // load all presets anyways
  154.                 //if (presetByName[pGUID].size() >= GetMaxSets())
  155.                 //    break;
  156.             }
  157.             else // should be deleted on startup, so  this never runs (shouldnt..)
  158.             {
  159.                 presetById[pGUID].erase(PresetID);
  160.                 CharacterDatabase.PExecute("DELETE FROM `custom_transmogrification_sets` WHERE Owner = %u AND PresetID = %u",  GUID_LOPART(pGUID), PresetID);
  161.             }
  162.         } while (result->NextRow());
  163.     }
  164. }
  165. void Transmogrification::UnloadPlayerSets(uint64 pGUID)
  166. {
  167.     for (presetData::iterator it = presetById[pGUID].begin(); it != presetById[pGUID].end(); ++it)
  168.         it->second.clear();
  169.     presetById[pGUID].clear();
  170.  
  171.     presetByName[pGUID].clear();
  172. }
  173. #endif
  174. std::string Transmogrification::GetItemLink(Item* item, WorldSession* session)
  175. {
  176.     int loc_idx = session->GetSessionDbLocaleIndex();
  177.     const ItemTemplate* temp = item->GetTemplate();
  178.     std::string name = temp->Name1;
  179.     if (ItemLocale const* il = sObjectMgr->GetItemLocale(temp->ItemId))
  180.         ObjectMgr::GetLocaleString(il->Name, loc_idx, name);
  181.  
  182.     if (int32 itemRandPropId = item->GetItemRandomPropertyId())
  183.     {
  184.         char* const* suffix = NULL;
  185.         if (itemRandPropId < 0)
  186.         {
  187.             const ItemRandomSuffixEntry* itemRandEntry = sItemRandomSuffixStore.LookupEntry(-item->GetItemRandomPropertyId());
  188.             if (itemRandEntry)
  189.                 suffix = itemRandEntry->nameSuffix;
  190.         }
  191.         else
  192.         {
  193.             const ItemRandomPropertiesEntry* itemRandEntry = sItemRandomPropertiesStore.LookupEntry(item->GetItemRandomPropertyId());
  194.             if (itemRandEntry)
  195.                 suffix = itemRandEntry->nameSuffix;
  196.         }
  197.         if (suffix)
  198.         {
  199.             std::string test(suffix[(name != temp->Name1) ? loc_idx : DEFAULT_LOCALE]);
  200.             if (!test.empty())
  201.             {
  202.                 name += ' ';
  203.                 name += test;
  204.             }
  205.         }
  206.     }
  207.  
  208.     std::ostringstream oss;
  209.     oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec <<
  210.         "|Hitem:" << temp->ItemId <<":" <<
  211.         item->GetEnchantmentId(PERM_ENCHANTMENT_SLOT) << ":" <<
  212.         item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT) << ":" <<
  213.         item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT_2) << ":" <<
  214.         item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT_3) << ":" <<
  215.         item->GetEnchantmentId(BONUS_ENCHANTMENT_SLOT) << ":" <<
  216.         item->GetItemRandomPropertyId() << ":" << item->GetItemSuffixFactor() << ":" <<
  217.         (uint32)item->GetOwner()->getLevel() << "|h[" << name << "]|h|r";
  218.  
  219.     return oss.str();
  220. }
  221. std::string Transmogrification::GetItemLink(uint32 entry, WorldSession* session)
  222. {
  223.     const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry);
  224.     int loc_idx = session->GetSessionDbLocaleIndex();
  225.     std::string name = temp->Name1;
  226.     if (ItemLocale const* il = sObjectMgr->GetItemLocale(entry))
  227.         ObjectMgr::GetLocaleString(il->Name, loc_idx, name);
  228.  
  229.     std::ostringstream oss;
  230.     oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec <<
  231.         "|Hitem:" << entry << ":0:0:0:0:0:0:0:0:0|h[" << name << "]|h|r";
  232.  
  233.     return oss.str();
  234. }
  235. uint32 Transmogrification::GetFakeEntry(uint64 itemGUID) const
  236. {
  237.     transmogData::const_iterator itr = dataMap.find(itemGUID);
  238.     if (itr == dataMap.end()) return 0;
  239.     transmogMap::const_iterator itr2 = entryMap.find(itr->second);
  240.     if (itr2 == entryMap.end()) return 0;
  241.     transmogData::const_iterator itr3 = itr2->second.find(itemGUID);
  242.     if (itr3 == itr2->second.end()) return 0;
  243.     return itr3->second;
  244. }
  245. void Transmogrification::DeleteFakeFromDB(uint64 itemGUID, SQLTransaction* trans)
  246. {
  247.     if (dataMap.find(itemGUID) != dataMap.end())
  248.     {
  249.         if (entryMap.find(dataMap[itemGUID]) != entryMap.end())
  250.             entryMap[dataMap[itemGUID]].erase(itemGUID);
  251.         dataMap.erase(itemGUID);
  252.     }
  253.     if (trans)
  254.         (*trans)->PAppend("DELETE FROM custom_transmogrification WHERE GUID = %u", GUID_LOPART(itemGUID));
  255.     else
  256.         CharacterDatabase.PExecute("DELETE FROM custom_transmogrification WHERE GUID = %u", GUID_LOPART(itemGUID));
  257. }
  258. void Transmogrification::DeleteFakeEntry(Player* player, uint8 slot, Item* itemTransmogrified, SQLTransaction* trans)
  259. {
  260.     //if (!GetFakeEntry(item))
  261.     //    return false;
  262.     DeleteFakeFromDB(itemTransmogrified->GetGUID(), trans);
  263.     player->SetVisibleItemSlot(slot, itemTransmogrified);
  264. }
  265. void Transmogrification::SetFakeEntry(Player* player, uint32 newEntry, uint8 slot, Item* itemTransmogrified)
  266. {
  267.     uint64 itemGUID = itemTransmogrified->GetGUID();
  268.     entryMap[player->GetGUID()][itemGUID] = newEntry;
  269.     dataMap[itemGUID] = player->GetGUID();
  270.     CharacterDatabase.PExecute("REPLACE INTO custom_transmogrification (GUID, FakeEntry, Owner) VALUES (%u, %u, %u)", GUID_LOPART(itemGUID), newEntry, player->GetGUIDLow());
  271.     player->SetVisibleItemSlot(slot, itemTransmogrified);
  272. }
  273. TransmogTrinityStrings Transmogrification::Transmogrify(Player* player, uint64 itemGUID, uint8 slot, /*uint32 newEntry, */bool no_cost)
  274. {
  275.     int32 cost = 0;
  276.     // slot of the transmogrified item
  277.     if (slot >= EQUIPMENT_SLOT_END)
  278.     {
  279.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: HandleTransmogrifyItems - Player (GUID: %u, name: %s) tried to transmogrify an item (lowguid: %u) with a wrong slot (%u) when transmogrifying items.", player->GetGUIDLow(), player->GetName().c_str(), GUID_LOPART(itemGUID), slot);
  280.         return LANG_ERR_TRANSMOG_INVALID_SLOT;
  281.     }
  282.  
  283.     /* // GET FROM itemTransmogrifier
  284.     // entry of the transmogrifier item, if it's not 0
  285.     if (newEntry)
  286.     {
  287.     ItemTemplate const* proto = sObjectMgr->GetItemTemplate(newEntry);
  288.     if (!proto)
  289.     {
  290.     TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: HandleTransmogrifyItems - Player (GUID: %u, name: %s) tried to transmogrify to an invalid item (entry: %u).", player->GetGUIDLow(), player->GetName().c_str(), newEntry);
  291.     return LANG_ERR_TRANSMOG_INVALID_SRC_ENTRY;
  292.     }
  293.     }
  294.     */
  295.  
  296.     Item* itemTransmogrifier = NULL;
  297.     // guid of the transmogrifier item, if it's not 0
  298.     if (itemGUID)
  299.     {
  300.         itemTransmogrifier = player->GetItemByGuid(itemGUID);
  301.         if (!itemTransmogrifier)
  302.         {
  303.             TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: HandleTransmogrifyItems - Player (GUID: %u, name: %s) tried to transmogrify with an invalid item (lowguid: %u).", player->GetGUIDLow(), player->GetName().c_str(), GUID_LOPART(itemGUID));
  304.             return LANG_ERR_TRANSMOG_MISSING_SRC_ITEM;
  305.         }
  306.     }
  307.  
  308.     // transmogrified item
  309.     Item* itemTransmogrified = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
  310.     if (!itemTransmogrified)
  311.     {
  312.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: HandleTransmogrifyItems - Player (GUID: %u, name: %s) tried to transmogrify an invalid item in a valid slot (slot: %u).", player->GetGUIDLow(), player->GetName().c_str(), slot);
  313.         return LANG_ERR_TRANSMOG_MISSING_DEST_ITEM;
  314.     }
  315.  
  316.     // uint16 tempDest;
  317.     //// has to be able to equip item transmogrified item
  318.     //if (!player->CanEquipItem(slot, tempDest, itemTransmogrified, true, true))
  319.     //{
  320.     //    TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: HandleTransmogrifyItems - Player (GUID: %u, name: %s) can't equip the item to be transmogrified (slot: %u, entry: %u).", player->GetGUIDLow(), player->GetName().c_str(), slot, itemTransmogrified->GetEntry());
  321.     //    return;
  322.     //}
  323.     //
  324.     //// has to be able to equip item transmogrifier item
  325.     //if (!player->CanEquipItem(slot, tempDest, itemTransmogrifier, true, true))
  326.     //{
  327.     //    TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: HandleTransmogrifyItems - Player (GUID: %u, name: %s) can't equip the transmogrifier item (slot: %u, entry: %u).", player->GetGUIDLow(), player->GetName().c_str(), slot, itemTransmogrifier->GetEntry());
  328.     //    return;
  329.     //}
  330.  
  331.     if (!itemTransmogrifier) // reset look newEntry
  332.     {
  333.         // itemTransmogrified->ClearEnchantment(TRANSMOGRIFY_ENCHANTMENT_SLOT);
  334.         // player->SetVisibleItemSlot(slot, itemTransmogrified);
  335.  
  336.         // Custom
  337.         DeleteFakeEntry(player, slot, itemTransmogrified);
  338.     }
  339.     else
  340.     {
  341.         if (!CanTransmogrifyItemWithItem(player, itemTransmogrified->GetTemplate(), itemTransmogrifier->GetTemplate()))
  342.         {
  343.             TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: HandleTransmogrifyItems - Player (GUID: %u, name: %s) failed CanTransmogrifyItemWithItem (%u with %u).", player->GetGUIDLow(), player->GetName().c_str(), itemTransmogrified->GetEntry(), itemTransmogrifier->GetEntry());
  344.             return LANG_ERR_TRANSMOG_INVALID_ITEMS;
  345.         }
  346.  
  347.         if (!no_cost)
  348.         {
  349.             cost = GetSpecialPrice(itemTransmogrified->GetTemplate());
  350.             cost *= GetScaledCostModifier();
  351.             cost += GetCopperCost();
  352.             if (!player->HasEnoughMoney(cost))
  353.                 return LANG_ERR_TRANSMOG_NOT_ENOUGH_MONEY;
  354.  
  355.             if (GetRequireToken())
  356.             {
  357.                 if (player->HasItemCount(GetTokenEntry(), GetTokenAmount()))
  358.                     player->DestroyItemCount(GetTokenEntry(), GetTokenAmount(), true);
  359.                 else
  360.                     return LANG_ERR_TRANSMOG_NOT_ENOUGH_TOKENS;
  361.             }
  362.         }
  363.  
  364.         // All okay, proceed
  365.         // itemTransmogrified->SetEnchantment(TRANSMOGRIFY_ENCHANTMENT_SLOT, newEntry, 0, 0);
  366.         // player->SetVisibleItemSlot(slot, itemTransmogrified);
  367.  
  368.         // Custom
  369.         SetFakeEntry(player, itemTransmogrifier->GetEntry(), slot, itemTransmogrified); // newEntry
  370.  
  371.         itemTransmogrified->UpdatePlayedTime(player);
  372.  
  373.         itemTransmogrified->SetOwnerGUID(player->GetGUID());
  374.         itemTransmogrified->SetNotRefundable(player);
  375.         itemTransmogrified->ClearSoulboundTradeable(player);
  376.  
  377.         if (itemTransmogrifier->GetTemplate()->Bonding == BIND_WHEN_EQUIPED || itemTransmogrifier->GetTemplate()->Bonding == BIND_WHEN_USE)
  378.             itemTransmogrifier->SetBinding(true);
  379.  
  380.         itemTransmogrifier->SetOwnerGUID(player->GetGUID());
  381.         itemTransmogrifier->SetNotRefundable(player);
  382.         itemTransmogrifier->ClearSoulboundTradeable(player);
  383.  
  384.         //cost += GetSpecialPrice(itemTransmogrified->GetTemplate());
  385.         //cost *= GetScaledCostModifier();
  386.         //cost += sT->GetCopperCost();
  387.     }
  388.  
  389.     // trusting the client, if it got here it has to have enough money
  390.     // ... unless client was modified
  391.     if (cost) // 0 cost if reverting look
  392.         player->ModifyMoney(-1*cost, false);
  393.     return LANG_ERR_TRANSMOG_OK;
  394. }
  395. bool Transmogrification::CanTransmogrifyItemWithItem(Player* player, ItemTemplate const* proto2, ItemTemplate const* proto1)
  396. {
  397.     //if (!transmogrifier || !transmogrified)
  398.     //    return false;
  399.  
  400.     //ItemTemplate const* proto1 = transmogrifier->GetTemplate(); // source
  401.     //ItemTemplate const* proto2 = transmogrified->GetTemplate(); // dest
  402.  
  403.     if (proto1->ItemId == proto2->ItemId)
  404.         return false;
  405.  
  406.     if (!SuitableForTransmogrification(player, proto2) || !SuitableForTransmogrification(player, proto1)) // if (!transmogrified->CanTransmogrify() || !transmogrifier->CanBeTransmogrified())
  407.         return false;
  408.  
  409.     if (proto1->InventoryType == INVTYPE_BAG ||
  410.         proto1->InventoryType == INVTYPE_RELIC ||
  411.         proto1->InventoryType == INVTYPE_BODY ||
  412.         proto1->InventoryType == INVTYPE_FINGER ||
  413.         proto1->InventoryType == INVTYPE_TRINKET ||
  414.         proto1->InventoryType == INVTYPE_AMMO ||
  415.         proto1->InventoryType == INVTYPE_QUIVER)
  416.         return false;
  417.  
  418.     //custom, TC doesnt check this? Checked by Inventory type check.
  419.     if (proto1->Class != proto2->Class)
  420.         return false;
  421.  
  422.     if (proto1->SubClass != proto2->SubClass && ((proto1->Class != ITEM_CLASS_WEAPON && !GetAllowMixedArmorTypes()) ||
  423.         (!GetAllowMixedWeaponTypes() || (!IsRangedWeapon(proto2->SubClass, proto2->Class) || !IsRangedWeapon(proto1->SubClass, proto1->Class)))))
  424.         return false;
  425.  
  426.     if (proto1->InventoryType != proto2->InventoryType &&
  427.         (proto1->Class != ITEM_CLASS_WEAPON || (proto2->InventoryType != INVTYPE_WEAPONMAINHAND && proto2->InventoryType != INVTYPE_WEAPONOFFHAND)) &&
  428.         (proto1->Class != ITEM_CLASS_ARMOR || (proto1->InventoryType != INVTYPE_CHEST && proto2->InventoryType != INVTYPE_ROBE && proto1->InventoryType != INVTYPE_ROBE && proto2->InventoryType != INVTYPE_CHEST) || true))
  429.         return false;
  430.  
  431.     return true;
  432. }
  433. bool Transmogrification::SuitableForTransmogrification(Player* player, ItemTemplate const* proto)
  434. {
  435.     // ItemTemplate const* proto = item->GetTemplate();
  436.     if (!player || !proto)
  437.         return false;
  438.  
  439.     if (proto->Class != ITEM_CLASS_ARMOR &&
  440.         proto->Class != ITEM_CLASS_WEAPON)
  441.         return false;
  442.  
  443.     if (proto->Class == ITEM_CLASS_WEAPON && proto->SubClass == ITEM_SUBCLASS_WEAPON_FISHING_POLE)
  444.         return false;
  445.  
  446.     if (IsAllowed(proto->ItemId))
  447.         return true;
  448.  
  449.     if (IsNotAllowed(proto->ItemId))
  450.         return false;
  451.  
  452.     if (!IsAllowedQuality(proto->Quality)) // (proto->Quality == ITEM_QUALITY_LEGENDARY)
  453.         return false;
  454.  
  455.     if (player->CanUseItem(proto) != EQUIP_ERR_OK)
  456.         return false;
  457.     return true;
  458. }
  459. /*
  460. bool Transmogrification::CanTransmogrify(Item const* item)
  461. {
  462. ItemTemplate const* proto = item->GetTemplate();
  463.  
  464. if (!proto)
  465. return false;
  466.  
  467. if (proto->Flags2 & ITEM_FLAGS_EXTRA_CANNOT_TRANSMOG)
  468. return false;
  469.  
  470. if (proto->Quality == ITEM_QUALITY_LEGENDARY)
  471. return false;
  472.  
  473. if (proto->Class != ITEM_CLASS_ARMOR &&
  474. proto->Class != ITEM_CLASS_WEAPON)
  475. return false;
  476.  
  477. if (proto->Class == ITEM_CLASS_WEAPON && proto->SubClass == ITEM_SUBCLASS_WEAPON_FISHING_POLE)
  478. return false;
  479.  
  480. if (proto->Flags2 & ITEM_FLAGS_EXTRA_CAN_TRANSMOG)
  481. return true;
  482.  
  483. if (item->GetItemRandomPropertyId() == 0)
  484. return false;
  485.  
  486. for (uint8 i = 0; i < MAX_ITEM_PROTO_STATS; ++i)
  487. if (proto->ItemStat[i].ItemStatValue != 0)
  488. return true;
  489.  
  490. return false;
  491. }
  492. bool Transmogrification::CanBeTransmogrified(Item const* item)
  493. {
  494. ItemTemplate const* proto = item->GetTemplate();
  495.  
  496. if (!proto)
  497. return false;
  498.  
  499. if (proto->Quality == ITEM_QUALITY_LEGENDARY)
  500. return false;
  501.  
  502. if (proto->Class != ITEM_CLASS_ARMOR &&
  503. proto->Class != ITEM_CLASS_WEAPON)
  504. return false;
  505.  
  506. if (proto->Class == ITEM_CLASS_WEAPON && proto->SubClass == ITEM_SUBCLASS_WEAPON_FISHING_POLE)
  507. return false;
  508.  
  509. if (proto->Flags2 & ITEM_FLAGS_EXTRA_CANNOT_BE_TRANSMOG)
  510. return false;
  511.  
  512. if (item->GetItemRandomPropertyId() == 0)
  513. return false;
  514.  
  515. for (uint8 i = 0; i < MAX_ITEM_PROTO_STATS; ++i)
  516. if (proto->ItemStat[i].ItemStatValue != 0)
  517. return true;
  518.  
  519. return false;
  520. }
  521. */
  522. uint32 Transmogrification::GetSpecialPrice(ItemTemplate const* proto) const
  523. {
  524.     uint32 cost = proto->SellPrice < 10000 ? 10000 : proto->SellPrice;
  525.     return cost;
  526. }
  527. bool Transmogrification::IsRangedWeapon(uint32 Class, uint32 SubClass) const
  528. {
  529.     return Class == ITEM_CLASS_WEAPON ||
  530.         SubClass == ITEM_SUBCLASS_WEAPON_BOW ||
  531.         SubClass == ITEM_SUBCLASS_WEAPON_GUN ||
  532.         SubClass == ITEM_SUBCLASS_WEAPON_CROSSBOW;
  533. }
  534. bool Transmogrification::IsAllowed(uint32 entry) const
  535. {
  536.     return Allowed.find(entry) != Allowed.end();
  537. }
  538. bool Transmogrification::IsNotAllowed(uint32 entry) const
  539. {
  540.     return NotAllowed.find(entry) != NotAllowed.end();
  541. }
  542. bool Transmogrification::GetEnableTransmogInfo() const
  543. {
  544.     return EnableTransmogInfo;
  545. }
  546. uint32 Transmogrification::GetTransmogNpcText() const
  547. {
  548.     return TransmogNpcText;
  549. }
  550. bool Transmogrification::GetEnableSetInfo() const
  551. {
  552.     return EnableSetInfo;
  553. }
  554. uint32 Transmogrification::GetSetNpcText() const
  555. {
  556.     return SetNpcText;
  557. }
  558. float Transmogrification::GetScaledCostModifier() const
  559. {
  560.     return ScaledCostModifier;
  561. }
  562. int32 Transmogrification::GetCopperCost() const
  563. {
  564.     return CopperCost;
  565. }
  566. bool Transmogrification::GetRequireToken() const
  567. {
  568.     return RequireToken;
  569. }
  570. uint32 Transmogrification::GetTokenEntry() const
  571. {
  572.     return TokenEntry;
  573. }
  574. uint32 Transmogrification::GetTokenAmount() const
  575. {
  576.     return TokenAmount;
  577. }
  578. bool Transmogrification::GetAllowMixedArmorTypes() const
  579. {
  580.     return AllowMixedArmorTypes;
  581. };
  582. bool Transmogrification::GetAllowMixedWeaponTypes() const
  583. {
  584.     return AllowMixedWeaponTypes;
  585. };
  586. bool Transmogrification::IsAllowedQuality(uint32 quality) const
  587. {
  588.     switch(quality)
  589.     {
  590.     case ITEM_QUALITY_POOR: return AllowPoor;
  591.     case ITEM_QUALITY_NORMAL: return AllowCommon;
  592.     case ITEM_QUALITY_UNCOMMON: return AllowUncommon;
  593.     case ITEM_QUALITY_RARE: return AllowRare;
  594.     case ITEM_QUALITY_EPIC: return AllowEpic;
  595.     case ITEM_QUALITY_LEGENDARY: return AllowLegendary;
  596.     case ITEM_QUALITY_ARTIFACT: return AllowArtifact;
  597.     case ITEM_QUALITY_HEIRLOOM: return AllowHeirloom;
  598.     default: return false;
  599.     }
  600. }
  601. void Transmogrification::LoadConfig(bool reload)
  602. {
  603. #ifdef PRESETS
  604.     EnableSetInfo = sConfigMgr->GetBoolDefault("Transmogrification.EnableSetInfo", true);
  605.     SetNpcText = uint32(sConfigMgr->GetIntDefault("Transmogrification.SetNpcText", 50001));
  606.  
  607.     EnableSets = sConfigMgr->GetBoolDefault("Transmogrification.EnableSets", true);
  608.     MaxSets = (uint8)sConfigMgr->GetIntDefault("Transmogrification.MaxSets", 10);
  609.     SetCostModifier = sConfigMgr->GetFloatDefault("Transmogrification.SetCostModifier", 3.0f);
  610.     SetCopperCost = sConfigMgr->GetIntDefault("Transmogrification.SetCopperCost", 0);
  611.  
  612.     if (MaxSets > MAX_OPTIONS)
  613.         MaxSets = MAX_OPTIONS;
  614.  
  615.     if (reload) // dont store presets for nothing
  616.     {
  617.         SessionMap const& sessions = sWorld->GetAllSessions();
  618.         for (SessionMap::const_iterator it = sessions.begin(); it != sessions.end(); ++it)
  619.         {
  620.             if (Player* player = it->second->GetPlayer())
  621.             {
  622.                 // skipping session check
  623.                 UnloadPlayerSets(player->GetGUID());
  624.                 if (GetEnableSets())
  625.                     LoadPlayerSets(player->GetGUID());
  626.             }
  627.         }
  628.     }
  629. #endif
  630.  
  631.     EnableTransmogInfo = sConfigMgr->GetBoolDefault("Transmogrification.EnableTransmogInfo", true);
  632.     TransmogNpcText = uint32(sConfigMgr->GetIntDefault("Transmogrification.TransmogNpcText", 50000));
  633.  
  634.     std::istringstream issAllowed(sConfigMgr->GetStringDefault("Transmogrification.Allowed", ""));
  635.     std::istringstream issNotAllowed(sConfigMgr->GetStringDefault("Transmogrification.NotAllowed", ""));
  636.     while(issAllowed.good())
  637.     {
  638.         uint32 entry;
  639.         issAllowed >> entry;
  640.         if(issAllowed.fail())
  641.             break;
  642.         Allowed.insert(entry);
  643.     }
  644.     while(issNotAllowed.good())
  645.     {
  646.         uint32 entry;
  647.         issNotAllowed >> entry;
  648.         if(issNotAllowed.fail())
  649.             break;
  650.         NotAllowed.insert(entry);
  651.     }
  652.  
  653.     ScaledCostModifier = sConfigMgr->GetFloatDefault("Transmogrification.ScaledCostModifier", 1.0f);
  654.     CopperCost = sConfigMgr->GetIntDefault("Transmogrification.CopperCost", 0);
  655.  
  656.     RequireToken = sConfigMgr->GetBoolDefault("Transmogrification.RequireToken", false);
  657.     TokenEntry = uint32(sConfigMgr->GetIntDefault("Transmogrification.TokenEntry", 49426));
  658.     TokenAmount = uint32(sConfigMgr->GetIntDefault("Transmogrification.TokenAmount", 1));
  659.  
  660.     AllowPoor = sConfigMgr->GetBoolDefault("Transmogrification.AllowPoor", true);
  661.     AllowCommon = sConfigMgr->GetBoolDefault("Transmogrification.AllowCommon", true);
  662.     AllowUncommon = sConfigMgr->GetBoolDefault("Transmogrification.AllowUncommon", true);
  663.     AllowRare = sConfigMgr->GetBoolDefault("Transmogrification.AllowRare", true);
  664.     AllowEpic = sConfigMgr->GetBoolDefault("Transmogrification.AllowEpic", true);
  665.     AllowLegendary = sConfigMgr->GetBoolDefault("Transmogrification.AllowLegendary", true);
  666.     AllowArtifact = sConfigMgr->GetBoolDefault("Transmogrification.AllowArtifact", true);
  667.     AllowHeirloom = sConfigMgr->GetBoolDefault("Transmogrification.AllowHeirloom", true);
  668.  
  669.     AllowMixedArmorTypes = sConfigMgr->GetBoolDefault("Transmogrification.AllowMixedArmorTypes", true);
  670.     AllowMixedWeaponTypes = sConfigMgr->GetBoolDefault("Transmogrification.AllowMixedWeaponTypes", true);
  671.  
  672.     if (!sObjectMgr->GetItemTemplate(TokenEntry))
  673.     {
  674.         sLog->outError(LOG_FILTER_SERVER_LOADING, "Transmogrification.TokenEntry (%u) does not exist. Using default.", TokenEntry);
  675.         TokenEntry = 49426;
  676.     }
  677. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement