Advertisement
beimax76

Professions Npc

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