Advertisement
Guest User

Proffesion NPC (Update)

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