Advertisement
Guest User

Untitled

a guest
Dec 15th, 2012
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.27 KB | None | 0 0
  1. ///////////////////////////////
  2. //**** Created By EroniX ****//
  3. ///////////////////////////////
  4. //
  5. // #Files: - TransmogHandler.cpp
  6. //
  7. // - TransmogEngine.cpp
  8. // - TransmogEngine.h
  9. //
  10. // - TransmogMgr.cpp
  11. // - TransmogMgr.h
  12. //
  13. //
  14. // #Core Mods: - Player.cpp:
  15. // - #include "TransmogEngine.h"
  16. // - EquipItem:
  17. // - TransmogEngine::SetTransmogDisplay(this, slot);
  18. //
  19. // - RemoveItem:
  20. // - TransmogEngine::RemoveTransmog(this, slot);
  21. //
  22. // - Player.h:
  23. // - uint32 selectedSlotID;
  24. // - Loot* selectedInterface;
  25. //
  26. // - LootHandler.cpp:
  27. // - #include "TransmogEngine.h"
  28. // - HandleAutostoreLootItemOpcode:
  29. // if(TransmogEngine::IsActiveInterface(lguid) && player)
  30. // {
  31. // if(Creature* creature = player->GetMap()->GetCreature(lguid))
  32. // TransmogEngine::HandleInterfaceSelect(player, creature, player->selectedInterface, lootSlot);
  33. //
  34. // return;
  35. // }
  36. //
  37. // - HandleLootReleaseOpcode:
  38. // if(Player* player = GetPlayer())
  39. // if(TransmogEngine::IsActiveInterface(guid))
  40. // {
  41. // if(Creature* creature = GetPlayer()->GetMap()->GetCreature(guid))
  42. // TransmogEngine::SendInterfaceClose(player, guid);
  43. //
  44. // return;
  45. // }
  46.  
  47. #include "TransmogEngine.h"
  48. #include "TransmogMgr.h"
  49. #include "ObjectDefines.h"
  50. #include "ObjectMgr.h"
  51.  
  52. //////////////////////////////////////////////////////////////
  53. //******************* Interface Helpers ********************//
  54. //////////////////////////////////////////////////////////////
  55.  
  56. void TransmogEngine::AddInterfacePreparation(Player* player, Creature* creature, Loot* loot, uint8 slotID)
  57. {
  58. player->SetLootGUID(creature->GetGUID());
  59.  
  60. loot->loot_type = LOOT_PICKPOCKETING;
  61. loot->AddLooter(player->GetGUID());
  62.  
  63. player->selectedSlotID = slotID;
  64. player->selectedInterface = loot;
  65. }
  66.  
  67. void TransmogEngine::RemoveInterfacePreparation(Player* player)
  68. {
  69. player->SetLootGUID(0);
  70. player->selectedSlotID = 0;
  71. player->selectedInterface = NULL;
  72. }
  73.  
  74. void TransmogEngine::SendInterfaceClose(Player* player, uint64 creatureGUID)
  75. {
  76. if(player)
  77. {
  78. player->SendLootRelease(creatureGUID);
  79. TransmogEngine::RemoveInterfacePreparation(player);
  80. }
  81. }
  82.  
  83. void TransmogEngine::SendInterfaceOpen(Player* player, Creature* creature, Loot* loot)
  84. {
  85. WorldPacket data(SMSG_LOOT_RESPONSE, (9+50));
  86. data << uint64(creature->GetGUID());
  87. data << uint8(LOOT_PICKPOCKETING);
  88. data << LootView(*loot, player, OWNER_PERMISSION);
  89.  
  90. player->SendDirectMessage(&data);
  91. }
  92.  
  93. //////////////////////////////////////////////////////////////
  94. //********************** Checkers **************************//
  95. //////////////////////////////////////////////////////////////
  96.  
  97. bool TransmogEngine::IsInList(uint32 value, uint32 subClassTwoHand[4], uint8 length)
  98. {
  99. for(uint8 i = 0; i < length; i++)
  100. if(value == subClassTwoHand[i])
  101. return true;
  102.  
  103. return false;
  104. }
  105.  
  106. bool TransmogEngine::IsInList(Loot* loot, LootStoreItem storeitem)
  107. {
  108. for (std::vector<LootItem>::iterator i = loot->items.begin(); i != loot->items.end(); ++i)
  109. {
  110. LootItem itemsElement = *i;
  111. if(itemsElement.itemid == storeitem.itemid)
  112. return true;
  113. }
  114.  
  115. return false;
  116. }
  117.  
  118. bool TransmogEngine::IsActiveInterface(uint64 creatureGUID)
  119. {
  120. if(Creature* creature = ObjectAccessor::FindUnit(creatureGUID)->ToCreature())
  121. return (creature->GetEntry() == ENTRY);
  122.  
  123. return false;
  124. }
  125.  
  126. //////////////////////////////////////////////////////////////
  127. //********************* Set Display ************************//
  128. //////////////////////////////////////////////////////////////
  129.  
  130. bool TransmogEngine::RemoveAllTransmogDisplay(Player* player)
  131. {
  132. for(uint8 i = 0; i < TransmogableItemsCount; i++)
  133. TransmogEngine::RemoveTransmogDisplay(player, itemSlotTypes[i]);
  134.  
  135. return true;
  136. }
  137.  
  138. bool TransmogEngine::RemoveTransmogDisplay(Player* player, uint32 slotID)
  139. {
  140. if(Item* item = player->GetItemByPos(BAG, slotID))
  141. {
  142. TransmogEngine::TransmogDisplay(player, slotID, item->GetEntry());
  143. return true;
  144. }
  145.  
  146. return false;
  147. }
  148.  
  149. bool TransmogEngine::SetTransmogDisplay(Player* player, uint32 slotID)
  150. {
  151. if(Item* item = player->GetItemByPos(BAG, slotID))
  152. {
  153. uint32 itemEntry = TransmogMgr::GetEntry(item->GetGUIDLow());
  154. if(itemEntry == PROBLEM)
  155. return false;
  156.  
  157. TransmogDisplay(player, slotID, itemEntry);
  158. return true;
  159. }
  160.  
  161. return false;
  162. }
  163.  
  164. bool TransmogEngine::SetAllTransmogDisplay(Player* player)
  165. {
  166. for(uint8 i = 0; i < TransmogableItemsCount; i++)
  167. SetTransmogDisplay(player, itemSlotTypes[i]);
  168.  
  169. return true;
  170. }
  171.  
  172. bool TransmogEngine::TransmogDisplay(Player* player, int32 slotID, int32 itemENTRY)
  173. {
  174. player->SetUInt32Value(GetVisualId(slotID), itemENTRY);
  175. return true;
  176. }
  177.  
  178. //////////////////////////////////////////////////////////////
  179. //*********************** Set DB ***************************//
  180. //////////////////////////////////////////////////////////////
  181.  
  182. void TransmogEngine::RemoveAllTransmogDB(uint32 playerGUID)
  183. {
  184. CharacterDatabase.PExecute
  185. (
  186. "DELETE FROM character_transmog WHERE player_guid = %u", playerGUID
  187. );
  188. }
  189. void TransmogEngine::RemoveTransmogDB(uint32 itemGUID)
  190. {
  191. CharacterDatabase.PExecute
  192. (
  193. "DELETE FROM character_transmog WHERE item_guid = %u", itemGUID
  194. );
  195. }
  196.  
  197. void TransmogEngine::ReplaceTransmogDB(uint32 playerGUID, uint32 itemGUID, uint32 itemENTRY)
  198. {
  199. CharacterDatabase.PExecute
  200. (
  201. "REPLACE INTO character_transmog VALUES (%u, %u, %u)", playerGUID, itemGUID, itemENTRY
  202. );
  203. }
  204.  
  205. //////////////////////////////////////////////////////////////
  206. //******************** Interface ***************************//
  207. //////////////////////////////////////////////////////////////
  208.  
  209. void TransmogEngine::HandleInterfaceSelect(Player* player, Creature* creature, Loot* loot, uint8 lootSLOT)
  210. {
  211. QuestItem* qItem = NULL; QuestItem* ffaItem = NULL; QuestItem* condItem = NULL;
  212.  
  213. LootItem* lootITEM = loot->LootItemInSlot(lootSLOT, player, &qItem, &ffaItem, &condItem);
  214. if(!lootITEM)
  215. {
  216. creature->MonsterWhisper("You don't have any items at the slot that you selected", player->GetGUID(), true);
  217. TransmogEngine::SendInterfaceClose(player, player->GetLootGUID());
  218. TransmogEngine::GossipHelloMainMenu(player, creature);
  219. return;
  220. }
  221.  
  222. uint32 itemENTRY = lootITEM->itemid;
  223. const ItemTemplate* itemTemplate = sObjectMgr->GetItemTemplate(itemENTRY);
  224.  
  225. uint32 slotID = player->selectedSlotID;
  226. if(slotID > EQUIPMENT_SLOT_END)
  227. {
  228. TransmogEngine::SendInterfaceClose(player, player->GetLootGUID());
  229. player->PlayerTalkClass->SendCloseGossip();
  230. return;
  231. }
  232.  
  233. Item* item = player->GetItemByPos(BAG, slotID);
  234. if(!item)
  235. {
  236. creature->MonsterWhisper("You should equip an item before use this feature", player->GetGUID(), true);
  237. TransmogEngine::SendInterfaceClose(player, player->GetLootGUID());
  238. TransmogEngine::GossipHelloMainMenu(player, creature);
  239. return;
  240. }
  241.  
  242. if(!TransmogEngine::CheckItem(player, item, itemTemplate))
  243. {
  244. creature->MonsterWhisper("Your item is not compatible with the selected item", player->GetGUID(), true);
  245. TransmogEngine::SendInterfaceClose(player, player->GetLootGUID());
  246. TransmogEngine::GossipHelloMainMenu(player, creature);
  247. return;
  248. }
  249.  
  250. creature->MonsterWhisper("Transmogrification has been added succesfully", player->GetGUID(), true);
  251. TransmogEngine::SetTransmogItem(player, itemENTRY, slotID);
  252. TransmogEngine::GossipHelloMainMenu(player, creature);
  253. }
  254.  
  255. Loot* TransmogEngine::CreateInterface(Player* player, Item* oldItem)
  256. {
  257. uint32 addedCount = 0;
  258.  
  259. Loot* loot = new Loot();
  260. loot->clear();
  261. loot->items.reserve(MAX_NR_LOOT_ITEMS);
  262.  
  263. if(!player || !oldItem)
  264. return loot;
  265.  
  266. bool isFirst = false;
  267. for (uint8 i = INVENTORY_SLOT_BAG_START; (i < INVENTORY_SLOT_BAG_END) || (isFirst = (i == INVENTORY_SLOT_BAG_END)); i++)
  268. {
  269. Bag* bag = player->GetBagByPos(i);
  270. if(!bag && !isFirst) // If we don't have bag and that's not the first
  271. continue;
  272.  
  273. for (uint32 j = isFirst ? INVENTORY_SLOT_ITEM_START : 0; isFirst ? (j < INVENTORY_SLOT_ITEM_END) : (j < bag->GetBagSize()); j++)
  274. {
  275. if ((addedCount + 1) >= MAX_NR_LOOT_ITEMS)
  276. return loot;
  277.  
  278. Item* newItem = player->GetItemByPos(isFirst ? INVENTORY_SLOT_BAG_0 : i, j);
  279. if(!newItem)
  280. continue;
  281.  
  282. const ItemTemplate* newItemTemplate = newItem->GetTemplate();
  283. if(!newItemTemplate)
  284. continue;
  285.  
  286. if (!TransmogEngine::CheckItem(player, oldItem, newItemTemplate))
  287. continue;
  288.  
  289. LootStoreItem storeItem = LootStoreItem(newItem->GetEntry(), 100.0f, LOOT_MODE_DEFAULT, 0, 1, 1);
  290. if(!IsInList(loot, storeItem))
  291. {
  292. loot->items.push_back(LootItem(storeItem));
  293. addedCount++;
  294. }
  295. }
  296. }
  297.  
  298. return loot;
  299. }
  300.  
  301. //////////////////////////////////////////////////////////////
  302. //******************** Transmog Helpers ********************//
  303. //////////////////////////////////////////////////////////////
  304.  
  305. void TransmogEngine::SetTransmogItem(Player* player, uint32 itemENTRY, uint32 slotID)
  306. {
  307. if(!player)
  308. return;
  309.  
  310. if(Item* item = player->GetItemByPos(BAG, slotID))
  311. {
  312. uint32 playerGUID = player->GetGUIDLow();
  313. uint32 itemGUID = item->GetGUIDLow();
  314.  
  315. TransmogMgr::UpdateTransmog(playerGUID, itemGUID, itemENTRY);
  316. TransmogEngine::ReplaceTransmogDB(playerGUID, itemGUID, itemENTRY);
  317. TransmogEngine::TransmogDisplay(player, slotID, itemENTRY);
  318.  
  319. player->CastSpell(player, VANISH_VISUAL, true);
  320. }
  321. }
  322.  
  323. void TransmogEngine::RemoveTransmog(Player* player, uint32 slotID)
  324. {
  325. if(!player)
  326. return;
  327.  
  328. if(Item* item = player->GetItemByPos(BAG, slotID))
  329. {
  330. uint32 itemGUID = item->GetGUIDLow();
  331.  
  332. TransmogMgr::RemoveTransmogItem(itemGUID);
  333. TransmogEngine::RemoveTransmogDB(itemGUID);
  334. TransmogEngine::RemoveTransmogDisplay(player, slotID);
  335.  
  336. player->CastSpell(player, VANISH_VISUAL, true);
  337. }
  338. }
  339.  
  340. void TransmogEngine::RemoveAllTransmog(Player* player)
  341. {
  342. if(!player)
  343. return;
  344.  
  345. for(int32 i = 0; i < TransmogableItemsCount; i++)
  346. {
  347. uint32 slotID = itemSlotTypes[i];
  348.  
  349. if(Item* item = player->GetItemByPos(BAG, slotID))
  350. {
  351. uint32 playerGUID = player->GetGUIDLow();
  352.  
  353. TransmogMgr::RemoveTransmogPlayer(playerGUID);
  354. TransmogEngine::RemoveAllTransmogDB(playerGUID);
  355. TransmogEngine::RemoveAllTransmogDisplay(player);
  356.  
  357. player->CastSpell(player, VANISH_VISUAL, true);
  358. }
  359. }
  360. }
  361.  
  362. //////////////////////////////////////////////////////////////
  363. //******************** Handler Helpers ********************//
  364. //////////////////////////////////////////////////////////////
  365.  
  366. void TransmogEngine::GossipHelloMainMenu(Player* player, Creature* creature)
  367. {
  368. player->PlayerTalkClass->ClearMenus();
  369. uint32 playerGUID = player->GetGUIDLow();
  370.  
  371. for(int32 i = 0; i < TransmogableItemsCount; i++)
  372. {
  373. uint32 slotID = itemSlotTypes[i];
  374.  
  375. Item* item = player->GetItemByPos(BAG, slotID);
  376. if(!item)
  377. continue;
  378.  
  379. const ItemTemplate* itemTemplate = item->GetTemplate();
  380. if(!itemTemplate)
  381. continue;
  382.  
  383. std::string slotName = CreateColorString(COLOR_DARK_GREY, GetSlotName(slotID) + "\n");
  384. std::string itemName = CreateColorString(COLOR_GREY, item->GetTemplate()->Name1);
  385.  
  386. if(TransmogMgr::IsTransmogedItem(item->GetGUIDLow()))
  387. player->ADD_GOSSIP_ITEM(5, "[Remove]: " + slotName + itemName, GOSSIP_SENDER_MAIN, slotID);
  388. else
  389. player->ADD_GOSSIP_ITEM(5, "[Create]: " + slotName + itemName, GOSSIP_SENDER_MAIN, slotID);
  390. }
  391.  
  392. uint32 transmogsCount = TransmogMgr::GetTransmogsCount(playerGUID);
  393.  
  394. std::string removeOutPut = CreateColorString(COLOR_GREY, GetString(transmogsCount) + CreateColorString(COLOR_DARK_GREY, " Items"));
  395. std::string learnOutPut = CreateColorString(COLOR_DARK_GREY, "...");
  396.  
  397. player->ADD_GOSSIP_ITEM(5, "[Remove All]: " + removeOutPut, GOSSIP_SENDER_MAIN, MENU_TEXT + 0);
  398. player->ADD_GOSSIP_ITEM(5, "Learn More" + learnOutPut, GOSSIP_SENDER_MAIN, MENU_TEXT + 3);
  399.  
  400. player->SEND_GOSSIP_MENU(TEXT_MAIN, creature->GetGUID());
  401. }
  402.  
  403. std::string TransmogEngine::GetSlotName(uint32 slotID)
  404. {
  405. switch(slotID)
  406. {
  407. case HEAD: return "Head";
  408. case SHOULDERS: return "Shoulders";
  409. case CHEST: return "Chest";
  410. case WAIST: return "Waist";
  411. case LEGS: return "Legs";
  412. case FEET: return "Feet";
  413. case WRIST: return "Wrist";
  414. case HANDS: return "Hands";
  415. case BACK: return "Back";
  416. case MAIN_HAND: return "MainHand";
  417. case OFF_HAND: return "OffHand";
  418. default: return "Ranged";
  419. }
  420. }
  421.  
  422. //////////////////////////////////////////////////////////////
  423. //*********************** Helpers **************************//
  424. //////////////////////////////////////////////////////////////
  425.  
  426. std::string TransmogEngine::CreateColorString(uint32 color, std::string text)
  427. {
  428. std::stringstream ss;
  429. ss << "|cff";
  430. ss << colorCodes[color - 1];
  431. ss << text;
  432. ss << "|r";
  433.  
  434. return ss.str();
  435. }
  436.  
  437. std::string TransmogEngine::GetString(int32 value)
  438. {
  439. std::stringstream ss;
  440. std::string s;
  441. ss << value;
  442. s = ss.str();
  443.  
  444. return s;
  445. }
  446.  
  447. bool TransmogEngine::CheckItem(Player* itemOwner, Item* oldItem, const ItemTemplate* newItemTemplate)
  448. {
  449. if(!itemOwner || !oldItem || !newItemTemplate)
  450. return false;
  451.  
  452. const ItemTemplate* oldItemTemplate = oldItem->GetTemplate();
  453. if(!oldItemTemplate)
  454. return false;
  455.  
  456. uint32 oldItemGUID = oldItem->GetGUIDLow();
  457. const ItemTemplate* fakeItemTemplate = NULL;
  458.  
  459. bool isTransmoged = TransmogMgr::IsTransmogedItem(oldItemGUID);
  460. if(isTransmoged)
  461. fakeItemTemplate = sObjectMgr->GetItemTemplate(TransmogMgr::GetEntry(oldItemGUID));
  462.  
  463. uint32 newClass = newItemTemplate->Class;
  464. uint32 oldClass = oldItemTemplate->Class;
  465.  
  466. uint32 newSubClass = newItemTemplate->SubClass;
  467. uint32 oldSubClass = oldItemTemplate->SubClass;
  468.  
  469. uint32 newInventoryType = newItemTemplate->InventoryType;
  470. uint32 oldInventoryType = oldItemTemplate->InventoryType;
  471.  
  472. if(oldItemTemplate->DisplayInfoID == newItemTemplate->DisplayInfoID)
  473. return false;
  474.  
  475. if(isTransmoged)
  476. if(newItemTemplate->DisplayInfoID == fakeItemTemplate->DisplayInfoID)
  477. return false;
  478.  
  479. if (newClass != oldClass)
  480. return false;
  481.  
  482. if(newInventoryType == INVTYPE_RELIC || oldInventoryType == INVTYPE_RELIC)
  483. return false;
  484.  
  485. if (newClass == ITEM_CLASS_ARMOR)
  486. if(newSubClass == oldSubClass && newInventoryType == oldInventoryType)
  487. return true;
  488.  
  489. if (newClass == ITEM_CLASS_WEAPON)
  490. {
  491. uint32 subClassTwoHand[4] =
  492. { ITEM_SUBCLASS_WEAPON_AXE2, ITEM_SUBCLASS_WEAPON_MACE2, ITEM_SUBCLASS_WEAPON_SWORD2, ITEM_SUBCLASS_WEAPON_POLEARM };
  493.  
  494. if(TransmogEngine::IsInList(newSubClass, subClassTwoHand, 4) && TransmogEngine::IsInList(oldSubClass, subClassTwoHand, 4))
  495. return true;
  496.  
  497. uint32 subClassOneHand[4] =
  498. { ITEM_SUBCLASS_WEAPON_AXE, ITEM_SUBCLASS_WEAPON_MACE, ITEM_SUBCLASS_WEAPON_SWORD, ITEM_SUBCLASS_WEAPON_DAGGER };
  499.  
  500. if(TransmogEngine::IsInList(newSubClass, subClassOneHand, 4) && TransmogEngine::IsInList(oldSubClass, subClassOneHand, 4))
  501. return true;
  502.  
  503. uint32 subClassRanged[4] =
  504. { ITEM_SUBCLASS_WEAPON_BOW, ITEM_SUBCLASS_WEAPON_GUN, ITEM_SUBCLASS_WEAPON_CROSSBOW, 0 };
  505.  
  506. if(TransmogEngine::IsInList(newSubClass, subClassRanged, 3) && TransmogEngine::IsInList(oldSubClass, subClassRanged, 3))
  507. return true;
  508.  
  509. if(newSubClass == oldSubClass)
  510. if(newSubClass == ITEM_SUBCLASS_WEAPON_WAND || newSubClass == ITEM_SUBCLASS_WEAPON_THROWN || ITEM_SUBCLASS_WEAPON_STAFF)
  511. return true;
  512. }
  513.  
  514. return false;
  515. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement