1. #include "ScriptPCH.h"
  2. class npc_reforging : public CreatureScript
  3. {
  4. public:
  5. npc_reforging() : CreatureScript("npc_reforging")
  6. {
  7. }
  8. bool isEquiped(Player* player, uint8 slot, uint8 &count)
  9. {
  10. Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
  11. if (!item)
  12. return false;
  13. if ((slot == EQUIPMENT_SLOT_RANGED || slot == EQUIPMENT_SLOT_OFFHAND || slot == EQUIPMENT_SLOT_MAINHAND) && !requiredItem(slot, item))
  14. return false;
  15. ++count;
  16. return true;
  17. }
  18. bool requiredItem(uint8 slot, Item* item)
  19. {
  20. ItemTemplate const* pProto = item->GetTemplate();
  21. if (slot == EQUIPMENT_SLOT_RANGED)
  22. if (pProto->Class == 2 && (pProto->SubClass == 2 || pProto->SubClass == 3 || pProto->SubClass == 18 || pProto->SubClass == 19))
  23. return true;
  24. if (slot == EQUIPMENT_SLOT_OFFHAND)
  25. if ((pProto->Class == 2 && (pProto->SubClass == 0 || pProto->SubClass == 4 || pProto->SubClass == 7 || pProto->SubClass == 13 || pProto->SubClass == 15)) || (pProto->Class == 4 && pProto->SubClass == 6))
  26. return true;
  27. if (slot == EQUIPMENT_SLOT_MAINHAND)
  28. if (pProto->Class == 2 && (pProto->SubClass == 0 || pProto->SubClass == 1 || pProto->SubClass == 4 || pProto->SubClass == 5 || pProto->SubClass == 6 || pProto->SubClass == 7 || pProto->SubClass == 8 || pProto->SubClass == 10 || pProto->SubClass == 13 || pProto->SubClass == 15))
  29. return true;
  30. return false;
  31. }
  32. uint32 getCost(uint8 slot)
  33. {
  34. if (slot == EQUIPMENT_SLOT_RANGED || slot == EQUIPMENT_SLOT_OFFHAND || slot == EQUIPMENT_SLOT_MAINHAND)
  35. return 20000000;
  36. if (slot == EQUIPMENT_SLOT_WRISTS || slot == EQUIPMENT_SLOT_WAIST)
  37. return 5000000;
  38. return 10000000;
  39. }
  40. void reforge(Player* player, Creature* creature, uint8 slot, const char* code)
  41. {
  42. player->CLOSE_GOSSIP_MENU();
  43. if (!player->HasEnoughMoney(getCost(slot)))
  44. return;
  45. Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
  46. if (!item || ((slot == EQUIPMENT_SLOT_RANGED || slot == EQUIPMENT_SLOT_OFFHAND || slot == EQUIPMENT_SLOT_MAINHAND) && !requiredItem(slot, item)))
  47. {
  48. ChatHandler(player->GetSession()).PSendSysMessage("|cfff4b25eМастер перековки шепчет:|r |cfffcedbbМы ведь договаривались на другой предмет!? Если передумал, то давай с начала.|r");
  49. return;
  50. }
  51. uint32 entry = 0;
  52. if (code)
  53. sscanf(code, "%i", &entry);
  54. ItemTemplate const* mItem = item->GetTemplate();
  55. ItemTemplate const* wItem = sObjectMgr->GetItemTemplate(entry);
  56. if (!mItem || !wItem)
  57. {
  58. ChatHandler(player->GetSession()).PSendSysMessage("|cfff4b25eМастер перековки шепчет:|r |cfffcedbbЯ не нашёл предмета с таким номером. Попробуйте ещё раз.|r");
  59. return;
  60. }
  61. if (mItem->Class == wItem->Class && mItem->SubClass == wItem->SubClass)
  62. {
  63. player->SetVisibleItemSlot(slot, item);
  64. player->ModifyMoney(-int32(getCost(slot)));
  65. player->CastSpell(player, 44688, true);
  66. }
  67. else
  68. {
  69. ChatHandler(player->GetSession()).PSendSysMessage("|cfff4b25eМастер перековки шепчет:|r |cfffcedbbПрочтите информацию о перековке ещё раз. Видимо вы что-то не так поняли.|r");
  70. return;
  71. }
  72. }
  73. bool OnGossipHello(Player* player, Creature* creature)
  74. {
  75. uint8 count = 0;
  76. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Информация о перековке", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+14);
  77. if (isEquiped(player, EQUIPMENT_SLOT_HEAD, count))
  78. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Голова", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2, "Стоимость перековки:", 10000000, true);
  79. if (isEquiped(player, EQUIPMENT_SLOT_SHOULDERS, count))
  80. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Плечо", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3, "Стоимость перековки:", 10000000, true);
  81. if (isEquiped(player, EQUIPMENT_SLOT_BACK, count))
  82. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Спина", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4, "Стоимость перековки:", 10000000, true);
  83. if (isEquiped(player, EQUIPMENT_SLOT_CHEST, count))
  84. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Грудь", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+5, "Стоимость перековки:", 10000000, true);
  85. if (isEquiped(player, EQUIPMENT_SLOT_WRISTS, count))
  86. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Запястья", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+6, "Стоимость перековки:", 5000000, true);
  87. if (isEquiped(player, EQUIPMENT_SLOT_HANDS, count))
  88. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Кисти рук", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+7, "Стоимость перековки:", 10000000, true);
  89. if (isEquiped(player, EQUIPMENT_SLOT_WAIST, count))
  90. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Пояс", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+8, "Стоимость перековки:", 5000000, true);
  91. if (isEquiped(player, EQUIPMENT_SLOT_LEGS, count))
  92. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Ноги", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+9, "Стоимость перековки:", 10000000, true);
  93. if (isEquiped(player, EQUIPMENT_SLOT_FEET, count))
  94. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Ступни", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+10, "Стоимость перековки:", 10000000, true);
  95. if (isEquiped(player, EQUIPMENT_SLOT_MAINHAND, count))
  96. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Правая рука", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+11, "Стоимость перековки:", 20000000, true);
  97. if (isEquiped(player, EQUIPMENT_SLOT_OFFHAND, count))
  98. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Левая рука", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+12, "Стоимость перековки:", 20000000, true);
  99. if (isEquiped(player, EQUIPMENT_SLOT_RANGED, count))
  100. player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_INTERACT_1, "Левая рука", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+13, "Стоимость перековки:", 20000000, true);
  101. if (count > 0)
  102. player->SEND_GOSSIP_MENU(55000, creature->GetGUID());
  103. else
  104. ChatHandler(player->GetSession()).PSendSysMessage("|cfff4b25eМастер перековки шепчет:|r |cfffcedbbИз всех одетых на вас предметов я ни один не смогу перековать. Приходите позже, когда раздобудете других вещей.|r");
  105. return true;
  106. }
  107. bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
  108. {
  109. player->PlayerTalkClass->ClearMenus();
  110. if (sender != GOSSIP_SENDER_MAIN)
  111. return false;
  112. switch (action)
  113. {
  114. case GOSSIP_ACTION_INFO_DEF+14:
  115. player->SEND_GOSSIP_MENU(55002, creature->GetGUID());
  116. break;
  117. }
  118. return true;
  119. }
  120. bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code)
  121. {
  122. player->PlayerTalkClass->ClearMenus();
  123. if (sender != GOSSIP_SENDER_MAIN)
  124. return false;
  125. switch (action)
  126. {
  127. case GOSSIP_ACTION_INFO_DEF+2:
  128. reforge(player, creature, EQUIPMENT_SLOT_HEAD, code);
  129. break;
  130. case GOSSIP_ACTION_INFO_DEF+3:
  131. reforge(player, creature, EQUIPMENT_SLOT_SHOULDERS, code);
  132. break;
  133. case GOSSIP_ACTION_INFO_DEF+4:
  134. reforge(player, creature, EQUIPMENT_SLOT_BACK, code);
  135. break;
  136. case GOSSIP_ACTION_INFO_DEF+5:
  137. reforge(player, creature, EQUIPMENT_SLOT_CHEST, code);
  138. break;
  139. case GOSSIP_ACTION_INFO_DEF+6:
  140. reforge(player, creature, EQUIPMENT_SLOT_WRISTS, code);
  141. break;
  142. case GOSSIP_ACTION_INFO_DEF+7:
  143. reforge(player, creature, EQUIPMENT_SLOT_HANDS, code);
  144. break;
  145. case GOSSIP_ACTION_INFO_DEF+8:
  146. reforge(player, creature, EQUIPMENT_SLOT_WAIST, code);
  147. break;
  148. case GOSSIP_ACTION_INFO_DEF+9:
  149. reforge(player, creature, EQUIPMENT_SLOT_LEGS, code);
  150. break;
  151. case GOSSIP_ACTION_INFO_DEF+10:
  152. reforge(player, creature, EQUIPMENT_SLOT_FEET, code);
  153. break;
  154. case GOSSIP_ACTION_INFO_DEF+11:
  155. reforge(player, creature, EQUIPMENT_SLOT_MAINHAND, code);
  156. break;
  157. case GOSSIP_ACTION_INFO_DEF+12:
  158. reforge(player, creature, EQUIPMENT_SLOT_OFFHAND, code);
  159. break;
  160. case GOSSIP_ACTION_INFO_DEF+13:
  161. reforge(player, creature, EQUIPMENT_SLOT_RANGED, code);
  162. break;
  163. }
  164. return true;
  165. }
  166. };
  167. void AddSC_npc_reforging()
  168. {
  169. new npc_reforging;
  170. }