Advertisement
Erictemponi

NPC Professions

Jan 20th, 2016
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Made by: ???
  2.   Updated by: Erictemponi
  3. */
  4.  
  5. #include "ScriptMgr.h"
  6. #include "Cell.h"
  7. #include "CellImpl.h"
  8. #include "GameEventMgr.h"
  9. #include "GridNotifiers.h"
  10. #include "GridNotifiersImpl.h"
  11. #include "Unit.h"
  12. #include "GameObject.h"
  13. #include "ScriptedCreature.h"
  14. #include "ScriptedGossip.h"
  15. #include "InstanceScript.h"
  16. #include "CombatAI.h"
  17. #include "PassiveAI.h"
  18. #include "Chat.h"
  19. #include "DBCStructure.h"
  20. #include "DBCStores.h"
  21. #include "ObjectMgr.h"
  22. #include "SpellScript.h"
  23. #include "SpellAuraEffects.h"
  24. #include "Language.h"
  25.  
  26. class Professions_NPC : public CreatureScript
  27. {
  28. public:
  29.     Professions_NPC() : CreatureScript("Professions_NPC") {}
  30.  
  31.     void CreatureWhisperBasedOnBool(const char *text, Creature *_creature, Player *pPlayer, bool value)
  32.     {
  33.         if (value)
  34.             _creature->TextEmote(text, pPlayer);
  35.     }
  36.  
  37.     uint32 PlayerMaxLevel() const
  38.     {
  39.         return sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL);
  40.     }
  41.  
  42.     bool PlayerHasItemOrSpell(const Player *plr, uint32 itemId, uint32 spellId) const
  43.     {
  44.         return plr->HasItemCount(itemId, 1, true) || plr->HasSpell(spellId);
  45.     }
  46.  
  47.     bool OnGossipHello(Player *pPlayer, Creature* _creature)
  48.     {
  49.         pPlayer->ADD_GOSSIP_ITEM(9, "[Professions] ->", GOSSIP_SENDER_MAIN, 196);
  50.         pPlayer->PlayerTalkClass->SendGossipMenu(907, _creature->GetGUID());
  51.         return true;
  52.     }
  53.  
  54.     bool PlayerAlreadyHasTwoProfessions(const Player *pPlayer) const
  55.     {
  56.         uint32 skillCount = 0;
  57.  
  58.         if (pPlayer->HasSkill(SKILL_MINING))
  59.             skillCount++;
  60.         if (pPlayer->HasSkill(SKILL_SKINNING))
  61.             skillCount++;
  62.         if (pPlayer->HasSkill(SKILL_HERBALISM))
  63.             skillCount++;
  64.  
  65.         if (skillCount >= 2)
  66.             return true;
  67.  
  68.         for (uint32 i = 1; i < sSkillLineStore.GetNumRows(); ++i)
  69.         {
  70.             SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(i);
  71.             if (!SkillInfo)
  72.                 continue;
  73.  
  74.             if (SkillInfo->categoryId == SKILL_CATEGORY_SECONDARY)
  75.                 continue;
  76.  
  77.             if ((SkillInfo->categoryId != SKILL_CATEGORY_PROFESSION) || !SkillInfo->canLink)
  78.                 continue;
  79.  
  80.             const uint32 skillID = SkillInfo->id;
  81.             if (pPlayer->HasSkill(skillID))
  82.                 skillCount++;
  83.  
  84.             if (skillCount >= 2)
  85.                 return true;
  86.         }
  87.         return false;
  88.     }
  89.  
  90.     bool LearnAllRecipesInProfession(Player *pPlayer, SkillType skill)
  91.     {
  92.         ChatHandler handler(pPlayer->GetSession());
  93.         char* skill_name;
  94.  
  95.         SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(skill);
  96.         skill_name = SkillInfo->name[handler.GetSessionDbcLocale()];
  97.  
  98.         if (!SkillInfo)
  99.         {
  100.             TC_LOG_ERROR("server.loading", "Profession NPC: received non-valid skill ID (LearnAllRecipesInProfession)");
  101.         }
  102.  
  103.         LearnSkillRecipesHelper(pPlayer, SkillInfo->id);
  104.  
  105.         pPlayer->SetSkill(SkillInfo->id, pPlayer->GetSkillStep(SkillInfo->id), 450, 450);
  106.         handler.PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES, skill_name);
  107.  
  108.         return true;
  109.     }
  110.  
  111.     void LearnSkillRecipesHelper(Player *player, uint32 skill_id)
  112.     {
  113.         uint32 classmask = player->getClassMask();
  114.  
  115.         for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
  116.         {
  117.             SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
  118.             if (!skillLine)
  119.                 continue;
  120.  
  121.             // wrong skill
  122.             if (skillLine->skillId != skill_id)
  123.                 continue;
  124.  
  125.             // not high rank
  126.             if (skillLine->forward_spellid)
  127.                 continue;
  128.  
  129.             // skip racial skills
  130.             if (skillLine->racemask != 0)
  131.                 continue;
  132.  
  133.             // skip wrong class skills
  134.             if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
  135.                 continue;
  136.  
  137.             SpellInfo const * spellInfo = sSpellMgr->GetSpellInfo(skillLine->spellId);
  138.             if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, player, false))
  139.                 continue;
  140.  
  141.             player->LearnSpell(skillLine->spellId, false);
  142.         }
  143.     }
  144.  
  145.     bool IsSecondarySkill(SkillType skill) const
  146.     {
  147.         return skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
  148.     }
  149.  
  150.     void CompleteLearnProfession(Player *pPlayer, Creature *pCreature, SkillType skill)
  151.     {
  152.         if (PlayerAlreadyHasTwoProfessions(pPlayer) && !IsSecondarySkill(skill))
  153.             pCreature->TextEmote("You already know two professions!", pPlayer);
  154.         else
  155.         {
  156.             if (!LearnAllRecipesInProfession(pPlayer, skill))
  157.                 pCreature->TextEmote("Internal error occured!", pPlayer);
  158.         }
  159.     }
  160.  
  161.     bool OnGossipSelect(Player* pPlayer, Creature* _creature, uint32 uiSender, uint32 uiAction)
  162.     {
  163.         pPlayer->PlayerTalkClass->ClearMenus();
  164.  
  165.         if (uiSender == GOSSIP_SENDER_MAIN)
  166.         {
  167.  
  168.             switch (uiAction)
  169.             {
  170.             case 196:
  171.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\trade_alchemy:30|t Alchemy.", GOSSIP_SENDER_MAIN, 1);
  172.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\INV_Ingot_05:30|t Blacksmithing.", GOSSIP_SENDER_MAIN, 2);
  173.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\INV_Misc_LeatherScrap_02:30|t Leatherworking.", GOSSIP_SENDER_MAIN, 3);
  174.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\INV_Fabric_Felcloth_Ebon:30|t Tailoring.", GOSSIP_SENDER_MAIN, 4);
  175.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\inv_misc_wrench_01:30|t Engineering.", GOSSIP_SENDER_MAIN, 5);
  176.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\trade_engraving:30|t Enchanting.", GOSSIP_SENDER_MAIN, 6);
  177.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\inv_misc_gem_01:30|t Jewelcrafting.", GOSSIP_SENDER_MAIN, 7);
  178.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\INV_Scroll_08:30|t Inscription.", GOSSIP_SENDER_MAIN, 8);
  179.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\INV_Misc_Herb_07:30|t Herbalism.", GOSSIP_SENDER_MAIN, 9);
  180.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\inv_misc_pelt_wolf_01:30|t Skinning.", GOSSIP_SENDER_MAIN, 10);
  181.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_2, "|TInterface\\icons\\trade_mining:30|t Mining.", GOSSIP_SENDER_MAIN, 11);
  182.                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "|TInterface/ICONS/Thrown_1H_Harpoon_D_01Blue:30|t Nevermind!", GOSSIP_SENDER_MAIN, 12);
  183.                 pPlayer->PlayerTalkClass->SendGossipMenu(1, _creature->GetGUID());
  184.                 break;
  185.             case 1:
  186.                 if (pPlayer->HasSkill(SKILL_ALCHEMY))
  187.                 {
  188.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  189.                     break;
  190.                 }
  191.  
  192.                 CompleteLearnProfession(pPlayer, _creature, SKILL_ALCHEMY);
  193.  
  194.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  195.                 break;
  196.             case 2:
  197.                 if (pPlayer->HasSkill(SKILL_BLACKSMITHING))
  198.                 {
  199.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  200.                     break;
  201.                 }
  202.                 CompleteLearnProfession(pPlayer, _creature, SKILL_BLACKSMITHING);
  203.  
  204.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  205.                 break;
  206.             case 3:
  207.                 if (pPlayer->HasSkill(SKILL_LEATHERWORKING))
  208.                 {
  209.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  210.                     break;
  211.                 }
  212.                 CompleteLearnProfession(pPlayer, _creature, SKILL_LEATHERWORKING);
  213.  
  214.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  215.                 break;
  216.             case 4:
  217.                 if (pPlayer->HasSkill(SKILL_TAILORING))
  218.                 {
  219.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  220.                     break;
  221.                 }
  222.                 CompleteLearnProfession(pPlayer, _creature, SKILL_TAILORING);
  223.  
  224.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  225.                 break;
  226.             case 5:
  227.                 if (pPlayer->HasSkill(SKILL_ENGINEERING))
  228.                 {
  229.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  230.                     break;
  231.                 }
  232.                 CompleteLearnProfession(pPlayer, _creature, SKILL_ENGINEERING);
  233.  
  234.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  235.                 break;
  236.             case 6:
  237.                 if (pPlayer->HasSkill(SKILL_ENCHANTING))
  238.                 {
  239.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  240.                     break;
  241.                 }
  242.                 CompleteLearnProfession(pPlayer, _creature, SKILL_ENCHANTING);
  243.  
  244.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  245.                 break;
  246.             case 7:
  247.                 if (pPlayer->HasSkill(SKILL_JEWELCRAFTING))
  248.                 {
  249.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  250.                     break;
  251.                 }
  252.                 CompleteLearnProfession(pPlayer, _creature, SKILL_JEWELCRAFTING);
  253.  
  254.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  255.                 break;
  256.             case 8:
  257.                 if (pPlayer->HasSkill(SKILL_INSCRIPTION))
  258.                 {
  259.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  260.                     break;
  261.                 }
  262.                 CompleteLearnProfession(pPlayer, _creature, SKILL_INSCRIPTION);
  263.  
  264.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  265.                 break;
  266.             case 9:
  267.                 if (pPlayer->HasSkill(SKILL_HERBALISM))
  268.                 {
  269.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  270.                     break;
  271.                 }
  272.  
  273.                 CompleteLearnProfession(pPlayer, _creature, SKILL_HERBALISM);
  274.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  275.                 break;
  276.             case 10:
  277.                 if (pPlayer->HasSkill(SKILL_SKINNING))
  278.                 {
  279.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  280.                     break;
  281.                 }
  282.  
  283.                 CompleteLearnProfession(pPlayer, _creature, SKILL_SKINNING);
  284.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  285.                 break;
  286.             case 11:
  287.                 if (pPlayer->HasSkill(SKILL_MINING))
  288.                 {
  289.                     pPlayer->PlayerTalkClass->SendCloseGossip();
  290.                     break;
  291.                 }
  292.  
  293.                 CompleteLearnProfession(pPlayer, _creature, SKILL_MINING);
  294.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  295.                 break;
  296.             case 12:
  297.                 pPlayer->PlayerTalkClass->SendCloseGossip();
  298.                 break;
  299.             }
  300.  
  301.  
  302.         }
  303.         return true;
  304.     }
  305. };
  306.  
  307. void AddSC_Professions_NPC()
  308. {
  309.     new Professions_NPC();
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement