Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include "Language.h"
  3.  
  4.  
  5. #define TXT_BAD_SKILL "Profession NPC: received non-valid skill ID (LearnAllRecipesInProfession)"
  6. #define TXT_ERR_SKILL "you already have that skill"
  7. #define TXT_PROBLEM "Internal error occured!"
  8. #define TXT_ERR_MAX "you already know two professions!"
  9. class npc_profession : public CreatureScript
  10. {
  11. public:
  12. npc_profession() : CreatureScript("npc_profession") {}
  13.  
  14. bool LearnAllRecipesInProfession(Player* player, SkillType skill)
  15. {
  16. SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(skill);
  17.  
  18. uint16 skill_level = 225;
  19.  
  20. if (!SkillInfo)
  21. {
  22. sLog->TC_LOG_ERROR("entitles.player.skills", TXT_BAD_SKILL);
  23. return (false);
  24. }
  25. if (skill == SKILL_ENGINEERING)
  26. skill_level = 150;
  27. player->SetSkill(SkillInfo->id, player->GetSkillStep(SkillInfo->id), skill_level, skill_level);
  28. return (true);
  29. }
  30.  
  31. bool ForgotSkill(Player* player, SkillType skill)
  32. {
  33. if (!player->HasSkill(skill))
  34. return (false);
  35. SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(skill);
  36. if (!SkillInfo)
  37. {
  38. sLog->TC_LOG_ERROR("entitles.player.skills", TXT_BAD_SKILL);
  39. return (false);
  40. }
  41. player->SetSkill(SkillInfo->id, player->GetSkillStep(SkillInfo->id), 0, 0);
  42. return (true);
  43. }
  44.  
  45. bool PlayerAlreadyHasTwoProfessions(Player *player)
  46. {
  47. uint32 skillCount = player->HasSkill(SKILL_MINING) + player->HasSkill(SKILL_SKINNING)
  48. + player->HasSkill(SKILL_HERBALISM)+ player->HasSkill(SKILL_ENGINEERING);
  49. if (skillCount >= 2)
  50. return true;
  51. return false;
  52. }
  53.  
  54. void CompleteLearnProfession(Player *player, SkillType skill)
  55. {
  56. if (PlayerAlreadyHasTwoProfessions(player))
  57. player->GetSession()->SendNotification(TXT_ERR_MAX);
  58. else if (!LearnAllRecipesInProfession(player, skill))
  59. player->GetSession()->SendNotification(TXT_PROBLEM);
  60. }
  61.  
  62. bool OnGossipHello(Player *player, Creature* me)
  63. {
  64. player->PlayerTalkClass->ClearMenus();
  65. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TRAINER, "Engineering", GOSSIP_SENDER_MAIN, SKILL_ENGINEERING);
  66. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TRAINER, "Herbalism", GOSSIP_SENDER_MAIN, SKILL_HERBALISM);
  67. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TRAINER, "Skinning", GOSSIP_SENDER_MAIN, SKILL_SKINNING);
  68. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TRAINER, "Mining", GOSSIP_SENDER_MAIN, SKILL_MINING);
  69. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_INTERACT_1, "Unlearn All", CUSTOM_OPTION_UNLEARN, 0);
  70. player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, TXT_KTHXBY, CUSTOM_OPTION_EXIT, 0);
  71. player->PlayerTalkClass->SendGossipMenu(907, me->GetGUID());
  72. return (true);
  73. }
  74.  
  75. bool OnGossipSelect(Player* Player, Creature* me, uint32 uiSender, uint32 skill)
  76. {
  77. Player->PlayerTalkClass->ClearMenus();
  78.  
  79. if (uiSender == CUSTOM_OPTION_UNLEARN)
  80. {
  81. ForgotSkill(Player, SKILL_ENGINEERING);
  82. ForgotSkill(Player, SKILL_HERBALISM);
  83. ForgotSkill(Player, SKILL_SKINNING);
  84. ForgotSkill(Player, SKILL_MINING);
  85. }
  86. else if (uiSender == GOSSIP_SENDER_MAIN)
  87. {
  88. if(Player->HasSkill(skill))
  89. Player->GetSession()->SendNotification(TXT_ERR_SKILL);
  90. else
  91. CompleteLearnProfession(Player, (SkillType)skill);
  92. }
  93. if (uiSender == CUSTOM_OPTION_EXIT)
  94. Player->PlayerTalkClass->SendCloseGossip();
  95. else
  96. OnGossipHello(Player, me);
  97. return (true);
  98. }
  99. };
  100.  
  101. void AddSC_cyclone_customs()
  102. {
  103. new npc_profession();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement