Advertisement
Guest User

error

a guest
Aug 8th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.65 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->MonsterWhisper(text, pPlayer->GetGUID());
  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.                         pPlayer->ADD_GOSSIP_ITEM(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 = ChatHandler(player->GetSession());
  71.                         char* skill_name;
  72.  
  73.                         SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(skill);
  74.                         skill_name = SkillInfo->name[ChatHandler(player->GetSession()).GetSessionDbcLocal()];
  75.  
  76.                         if (!SkillInfo)
  77.                         {
  78.                         sLog->outError(LOG_FILTER_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->MonsterWhisper("You already know two professions!", pPlayer->GetGUID());
  132.                         else
  133.                         {
  134.                                 if (!LearnAllRecipesInProfession(pPlayer, skill))
  135.                                         pCreature->MonsterWhisper("Internal error occured!", pPlayer->GetGUID());
  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.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Alchemy", GOSSIP_SENDER_MAIN, 1);
  150.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Blacksmithing", GOSSIP_SENDER_MAIN, 2);
  151.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Leatherworking", GOSSIP_SENDER_MAIN, 3);
  152.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Tailoring", GOSSIP_SENDER_MAIN, 4);
  153.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Engineering", GOSSIP_SENDER_MAIN, 5);
  154.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Enchanting", GOSSIP_SENDER_MAIN, 6);
  155.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Jewelcrafting", GOSSIP_SENDER_MAIN, 7);
  156.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Inscription", GOSSIP_SENDER_MAIN, 8);
  157.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Cooking", GOSSIP_SENDER_MAIN, 9);
  158.                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "First Aid", GOSSIP_SENDER_MAIN, 10);
  159.                                                                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Herbalism", GOSSIP_SENDER_MAIN, 11);
  160.                                                                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Skinning", GOSSIP_SENDER_MAIN, 12);
  161.                                                                                                 pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Mining", GOSSIP_SENDER_MAIN, 13);
  162.  
  163.                                                 pPlayer->PlayerTalkClass->SendGossipMenu(907, _creature->GetGUID());
  164.                                                 break;
  165.                                         case 1:
  166.                                                 if(pPlayer->HasSkill(SKILL_ALCHEMY))
  167.                                                 {
  168.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  169.                                                         break;
  170.                                                 }
  171.  
  172.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_ALCHEMY);
  173.  
  174.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  175.                                                 break;
  176.                                         case 2:
  177.                                                 if(pPlayer->HasSkill(SKILL_BLACKSMITHING))
  178.                                                 {
  179.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  180.                                                         break;
  181.                                                 }
  182.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_BLACKSMITHING);
  183.  
  184.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  185.                                                 break;
  186.                                         case 3:
  187.                                                 if(pPlayer->HasSkill(SKILL_LEATHERWORKING))
  188.                                                 {
  189.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  190.                                                         break;
  191.                                                 }
  192.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_LEATHERWORKING);
  193.  
  194.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  195.                                                 break;
  196.                                         case 4:
  197.                                                 if(pPlayer->HasSkill(SKILL_TAILORING))
  198.                                                 {
  199.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  200.                                                         break;
  201.                                                 }
  202.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_TAILORING);
  203.  
  204.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  205.                                                 break;
  206.                                         case 5:
  207.                                                 if(pPlayer->HasSkill(SKILL_ENGINEERING))
  208.                                                 {
  209.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  210.                                                         break;
  211.                                                 }
  212.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_ENGINEERING);
  213.  
  214.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  215.                                                 break;
  216.                                         case 6:
  217.                                                 if(pPlayer->HasSkill(SKILL_ENCHANTING))
  218.                                                 {
  219.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  220.                                                         break;
  221.                                                 }
  222.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_ENCHANTING);
  223.  
  224.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  225.                                                 break;
  226.                                         case 7:
  227.                                                 if(pPlayer->HasSkill(SKILL_JEWELCRAFTING))
  228.                                                 {
  229.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  230.                                                         break;
  231.                                                 }
  232.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_JEWELCRAFTING);
  233.  
  234.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  235.                                                 break;
  236.                                         case 8:
  237.                                                 if(pPlayer->HasSkill(SKILL_INSCRIPTION))
  238.                                                 {
  239.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  240.                                                         break;
  241.                                                 }
  242.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_INSCRIPTION);
  243.  
  244.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  245.                                                 break;
  246.                                         case 9:
  247.                                                 if(pPlayer->HasSkill(SKILL_COOKING))
  248.                                                 {
  249.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  250.                                                         break;
  251.                                                 }
  252.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_COOKING);
  253.  
  254.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  255.                                                 break;
  256.                                         case 10:
  257.                                                 if(pPlayer->HasSkill(SKILL_FIRST_AID))
  258.                                                 {
  259.                                                         pPlayer->PlayerTalkClass->SendCloseGossip();
  260.                                                         break;
  261.                                                 }
  262.                                                 CompleteLearnProfession(pPlayer, _creature, SKILL_FIRST_AID);
  263.  
  264.                                                 pPlayer->PlayerTalkClass->SendCloseGossip();
  265.                                                 break;
  266.                                                                                 case 11:
  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 12:
  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 13:
  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.                                 }
  297.  
  298.        
  299.                         }
  300.                         return true;
  301.                 }
  302. };
  303.  
  304. void AddSC_Professions_NPC()
  305. {
  306.     new Professions_NPC();
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement