Untitled


SUBMITTED BY: Guest

DATE: Aug. 9, 2013, 3:13 p.m.

FORMAT: Text only

SIZE: 7.3 kB

HITS: 2188

  1. #include "ScriptPCH.h"
  2. #include "Language.h"
  3. class Professions_NPC : public CreatureScript
  4. {
  5. public:
  6. Professions_NPC () : CreatureScript("Professions_NPC") {}
  7. bool OnGossipHello(Player *pPlayer, Creature* _creature)
  8. {
  9. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Alchemy", GOSSIP_SENDER_MAIN, SKILL_ALCHEMY);
  10. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Blacksmithing", GOSSIP_SENDER_MAIN, SKILL_BLACKSMITHING);
  11. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Leatherworking", GOSSIP_SENDER_MAIN, SKILL_LEATHERWORKING);
  12. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Tailoring", GOSSIP_SENDER_MAIN, SKILL_TAILORING);
  13. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Engineering", GOSSIP_SENDER_MAIN, SKILL_ENGINEERING);
  14. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Enchanting", GOSSIP_SENDER_MAIN, SKILL_ENCHANTING);
  15. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Jewelcrafting", GOSSIP_SENDER_MAIN, SKILL_JEWELCRAFTING);
  16. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Inscription", GOSSIP_SENDER_MAIN, SKILL_INSCRIPTION);
  17. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Cooking", GOSSIP_SENDER_MAIN, SKILL_COOKING);
  18. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "First Aid", GOSSIP_SENDER_MAIN, SKILL_FIRST_AID);
  19. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Herbalism", GOSSIP_SENDER_MAIN, SKILL_HERBALISM);
  20. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Skinning", GOSSIP_SENDER_MAIN, SKILL_SKINNING);
  21. pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Mining", GOSSIP_SENDER_MAIN, SKILL_MINING);
  22. pPlayer->PlayerTalkClass->SendGossipMenu(907, _creature->GetGUID());
  23. return true;
  24. }
  25. bool OnGossipSelect(Player* pPlayer, Creature* _creature, uint32 uiSender, uint32 SKILL)
  26. {
  27. pPlayer->PlayerTalkClass->ClearMenus();
  28. if (uiSender == GOSSIP_SENDER_MAIN)
  29. {
  30. if(pPlayer->HasSkill(SKILL))
  31. pPlayer->GetSession()->SendNotification("You already have that skill");
  32. else
  33. CompleteLearnProfession(pPlayer, (SkillType)SKILL);
  34. }
  35. OnGossipHello(pPlayer, _creature);
  36. return true;
  37. }
  38. bool IsSecondarySkill(SkillType skill) const
  39. {
  40. return skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
  41. }
  42. void CompleteLearnProfession(Player *pPlayer, SkillType skill)
  43. {
  44. if (PlayerAlreadyHasTwoProfessions(pPlayer) && !IsSecondarySkill(skill))
  45. pPlayer->GetSession()->SendNotification("You already know two professions!");
  46. else
  47. {
  48. if (!LearnAllRecipesInProfession(pPlayer, skill))
  49. pPlayer->GetSession()->SendNotification("Internal error occured!");
  50. }
  51. }
  52. bool LearnAllRecipesInProfession(Player* pPlayer, SkillType skill)
  53. {
  54. const char* skill_name;
  55. SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(skill);
  56. skill_name = SkillInfo->name[ChatHandler(pPlayer->GetSession()).GetSessionDbcLocale()];
  57. if (!SkillInfo)
  58. {
  59. sLog->outError(LOG_FILTER_PLAYER_SKILLS, "Profession NPC: received non-valid skill ID (LearnAllRecipesInProfession)");
  60. return false;
  61. }
  62. LearnSkillRecipesHelper(pPlayer, SkillInfo->id);
  63. pPlayer->SetSkill(SkillInfo->id, pPlayer->GetSkillStep(SkillInfo->id), 450, 450);
  64. ChatHandler(pPlayer->GetSession()).PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES, skill_name);
  65. return true;
  66. }
  67. bool PlayerAlreadyHasTwoProfessions(Player *pPlayer)
  68. {
  69. uint32 skillCount = 0;
  70. if (pPlayer->HasSkill(SKILL_MINING))
  71. skillCount++;
  72. if (pPlayer->HasSkill(SKILL_SKINNING))
  73. skillCount++;
  74. if (pPlayer->HasSkill(SKILL_HERBALISM))
  75. skillCount++;
  76. if (skillCount >= 2)
  77. return true;
  78. for (uint32 i = 1; i < sSkillLineStore.GetNumRows(); ++i)
  79. {
  80. SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(i);
  81. if (!SkillInfo)
  82. continue;
  83. if (SkillInfo->categoryId == SKILL_CATEGORY_SECONDARY)
  84. continue;
  85. if ((SkillInfo->categoryId != SKILL_CATEGORY_PROFESSION) || !SkillInfo->canLink)
  86. continue;
  87. const uint32 skillID = SkillInfo->id;
  88. if (pPlayer->HasSkill(skillID))
  89. skillCount++;
  90. if (skillCount >= 2)
  91. return true;
  92. }
  93. return false;
  94. }
  95. void LearnSkillRecipesHelper(Player *player, uint32 skill_id)
  96. {
  97. uint32 classmask = player->getClassMask();
  98. for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
  99. {
  100. SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
  101. if (!skillLine)
  102. continue;
  103. // wrong skill
  104. if (skillLine->skillId != skill_id)
  105. continue;
  106. // not high rank
  107. if (skillLine->forward_spellid)
  108. continue;
  109. // skip racial skills
  110. if (skillLine->racemask != 0)
  111. continue;
  112. // skip wrong class skills
  113. if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
  114. continue;
  115. SpellInfo const * spellInfo = sSpellMgr->GetSpellInfo(skillLine->spellId);
  116. if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, player, false))
  117. continue;
  118. player->learnSpell(skillLine->spellId, false);
  119. }
  120. }
  121. };
  122. void AddSC_Professions_NPC()
  123. {
  124. new Professions_NPC();
  125. }

comments powered by Disqus