Advertisement
cgm2k7

Npc-Profissão-Trinitycore

Nov 7th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.30 KB | None | 0 0
  1. /************************************
  2. *        Made by Sdyess             *
  3. *                                   *
  4. *      Edit By jameyboor            *
  5. *   Release by Ghostcrawler336      *
  6. *      Rewritten by Rochet2         *
  7. *                                   *
  8. *************************************
  9. */
  10.  
  11. #include "ScriptPCH.h"
  12. #include "Language.h"
  13. #include "Config.h"
  14.  
  15. bool CobrarProfession;
  16. int CobrarProfessionHONOR;
  17. int  IdEmblema;
  18. float  pValor;
  19. bool pProfissionVIP;
  20. uint32 nProfissionVIP;
  21. uint32 qProfissionVIP;
  22. uint32 qProfissionNormal;
  23. uint32 IdItemProfissionVIP;
  24.  
  25. using namespace std;
  26. struct MenuProfissao
  27. {
  28.     uint8 Menu, Submenu, Icone;
  29.     uint32 ValorProf, pSKILL;
  30.     string Nome, Confirmar;
  31. };
  32. MenuProfissao mpData[] =
  33. {
  34.     { 1, 2, 3, 0, 0, "|cff1C1C1C|TInterface/ICONS/achievement_general:30:30:-16:0|t[Profissoes Primarias]|r" },
  35.     { 1, 3, 3, 0, 0, "|cff90EE90|TInterface/ICONS/achievement_general:30:30:-16:0|t[Profissoes Secundarias]|r" },
  36.     // Profissões Primarias
  37.     { 2, 0, 3, pValor, 171, "|TInterface\\icons\\trade_alchemy:30:30:-16:0|t Alchemy.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_ALCHEMY 171
  38.     { 2, 0, 3, pValor, 164,"|TInterface\\icons\\INV_Ingot_05:30:30:-16:0|t Blacksmithing.", "|cff1E90FFTem certeza que quer essa profissao|r" }, // SKILL_BLACKSMITHING 164
  39.     { 2, 0, 3, pValor, 165,"|TInterface\\icons\\INV_Misc_LeatherScrap_02:30:30:-16:0|t Leatherworking.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_LEATHERWORKING 165
  40.     { 2, 0, 3, pValor, 197,"|TInterface\\icons\\INV_Fabric_Felcloth_Ebon:30:30:-16:0|t Tailoring.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_TAILORING 197
  41.     { 2, 0, 3, pValor, 202,"|TInterface\\icons\\inv_misc_wrench_01:30:30:-16:0|t Engineering.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_ENGINEERING 202
  42.     { 2, 0, 3, pValor, 333,"|TInterface\\icons\\trade_engraving:30:30:-16:0|t Enchanting.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_ENCHANTING 333
  43.     { 2, 0, 3, pValor, 755,"|TInterface\\icons\\inv_misc_gem_01:30:30:-16:0|t Jewelcrafting.", "|cff1E90FFTem certeza que quer essa profissao|r" }, // SKILL_JEWELCRAFTING 755
  44.     { 2, 0, 3, pValor, 773,"|TInterface\\icons\\INV_Scroll_08:30:30:-16:0|t Inscription.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_INSCRIPTION 773
  45.     { 2, 0, 3, pValor, 182, "|TInterface\\icons\\INV_Misc_Herb_07:30:30:-16:0|t Herbalism.", "|cff1E90FFTem certeza que quer essa profissao|r" }, // SKILL_HERBALISM 182
  46.     { 2, 0, 3, pValor, 186, "|TInterface\\icons\\trade_mining:30:30:-16:0|t Mining.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_MINING 186
  47.     { 2, 0, 3, pValor, 393, "|TInterface\\icons\\inv_misc_pelt_wolf_01:30:30:-16:0|t Skinning.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_SKINNING 393
  48.     { 2, 1, 3, 0, 0, "|cff0000FF|TInterface\\icons\\inv_misc_questionmark:20:20:-16:0|t<< Voltar" },
  49.     // Profissões Secundarias         
  50.     { 3, 0, 3, pValor, 185, "|TInterface/ICONS/INV_Misc_Food_15:30:30:-16:0|t Cooking.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_COOKING 185
  51.     { 3, 0, 3, pValor, 129, "|TInterface/ICONS/spell_holy_sealofsacrifice:30:30:-16:0|t First Aid.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_FIRST_AID 129
  52.     { 3, 0, 3, pValor, 356, "|TInterface/ICONS/Trade_Fishing:30:30:-16:0|t Fishing.", "|cff1E90FFTem certeza que quer essa profissao|r" }, //SKILL_FISHING 356
  53.     { 3, 1, 3, 0, 0, "|cff0000FF|TInterface\\icons\\inv_misc_questionmark:20:20:-16:0|t<< Voltar" },
  54.  
  55. };
  56. class npc_Profissoes : public CreatureScript
  57. {
  58. public:
  59.     npc_Profissoes() : CreatureScript("npc_Profissoes") {}
  60.  
  61.     void GetMenuProfissao(Player* player, Creature* creature, uint32 menuId)
  62.     {
  63.         player->PlayerTalkClass->ClearMenus();
  64.         std::ostringstream Bs;
  65.         bool epMENU = false;
  66.         for (uint8 i = 0; i < (sizeof(mpData) / sizeof(*mpData)); i++)
  67.         {
  68.             if (epMENU && mpData[i].Menu != menuId)
  69.                 break;
  70.             if (mpData[i].Menu == menuId )
  71.             {
  72.                 if (mpData[i].Submenu != 0)
  73.                     player->ADD_GOSSIP_ITEM(mpData[i].Icone, mpData[i].Nome, GOSSIP_SENDER_MAIN, i);
  74.                 else
  75.                     player->ADD_GOSSIP_ITEM_EXTENDED(mpData[i].Icone, mpData[i].Nome, GOSSIP_SENDER_MAIN, i, mpData[i].Confirmar, 0, false);
  76.                
  77.                 epMENU = true;
  78.             }
  79.         }
  80.         player->SEND_GOSSIP_MENU(907, creature->GetGUID());
  81.         return;
  82.     }
  83.     bool OnGossipHello(Player *pPlayer, Creature* _creature)
  84.     {
  85.         GetMenuProfissao(pPlayer, _creature, 1);
  86.         return true;
  87.     }
  88.     bool OnGossipSelect(Player* pPlayer, Creature* _creature, uint32 uiSender, uint32 SKILL)
  89.     {
  90.         pPlayer->PlayerTalkClass->ClearMenus();
  91.         uint8 ListaMenu;
  92.         switch (SKILL)
  93.         {
  94.         case -1:
  95.             break;
  96.         default:
  97.             ListaMenu = mpData[SKILL].Submenu;
  98.             break;
  99.         }
  100.         if (ListaMenu == 0)
  101.         {
  102.             if (pPlayer->HasSkill(mpData[SKILL].pSKILL)){
  103.                 pPlayer->GetSession()->SendNotification("|cffff0000ALERTA: Voce ja tem esta profissao!");
  104.             }else{
  105.                 CompleteLearnProfession(pPlayer, (SkillType)mpData[SKILL].pSKILL);
  106.             }
  107.             ListaMenu = mpData[SKILL].Menu;
  108.         }
  109.         GetMenuProfissao(pPlayer, _creature, ListaMenu);
  110.         return true;
  111.     }
  112.     bool IsSecondarySkill(SkillType skill) const
  113.     {
  114.         return skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
  115.     }
  116.     void CompleteLearnProfession(Player *pPlayer, SkillType skill)
  117.     {
  118.         if (PlayerAlreadyHasTwoProfessions(pPlayer) && !IsSecondarySkill(skill))
  119.             pPlayer->GetSession()->SendNotification("|cffff0000ALERTA: Voce ja tem o maximo de profissao permitida!");
  120.         else
  121.         {
  122.             if (CobrarProfession == 1)
  123.             {
  124.                 if (CobrarProfessionHONOR == 1){
  125.                     if (pPlayer->GetHonorPoints() < pValor)
  126.                     {
  127.                         pPlayer->GetSession()->SendNotification("|cffff0000ALERTA: Voce nao tem Honor Points suficiente!");
  128.                     }
  129.                     else
  130.                     {
  131.                         if (!LearnAllRecipesInProfession(pPlayer, skill))
  132.                             pPlayer->GetSession()->SendNotification("Internal error occured!");
  133.                             pPlayer->ModifyHonorPoints(-pValor);
  134.                             pPlayer->GetSession()->SendNotification("|cff32CD32PARABENS!: Profission atiquirida com sucesso!");
  135.                     }                  
  136.                 }
  137.                 else if (CobrarProfessionHONOR == 2)
  138.                 {
  139.                     if (pPlayer->HasItemCount(IdEmblema, pValor))
  140.                     {
  141.                         if (!LearnAllRecipesInProfession(pPlayer, skill))
  142.                             pPlayer->GetSession()->SendNotification("Internal error occured!");
  143.                         pPlayer->DestroyItemCount(IdEmblema, pValor, true);
  144.                         pPlayer->GetSession()->SendNotification("|cff32CD32PARABENS!: Profissao adiquirida com sucesso!");
  145.                     }
  146.                     else
  147.                     {
  148.                         pPlayer->GetSession()->SendNotification("|cffff0000ALERTA: Voce nao tem Item[Token] suficiente!");
  149.                     }
  150.                 }
  151.             }
  152.             else
  153.             {
  154.                 if (!LearnAllRecipesInProfession(pPlayer, skill))
  155.                     pPlayer->GetSession()->SendNotification("Internal error occured!");
  156.                 pPlayer->GetSession()->SendNotification("|cff32CD32PARABENS!: Profissao adiquirida com sucesso!");
  157.             }
  158.         }
  159.     }
  160.     bool LearnAllRecipesInProfession(Player* pPlayer, SkillType skill)
  161.     {
  162.         SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(skill);
  163.  
  164.         if (!SkillInfo)
  165.         {
  166.             sLog->outCommand(LANG_SET_SKILL_ERROR, "Profession NPC: received non-valid skill ID (LearnAllRecipesInProfession)");
  167.             return false;
  168.         }
  169.         const char* skill_name = SkillInfo->name[ChatHandler(pPlayer->GetSession()).GetSessionDbcLocale()];
  170.  
  171.         LearnSkillRecipesHelper(pPlayer, SkillInfo->id);
  172.  
  173.         pPlayer->SetSkill(SkillInfo->id, pPlayer->GetSkillStep(SkillInfo->id), 450, 450);
  174.         ChatHandler(pPlayer->GetSession()).PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES, skill_name);
  175.         return true;
  176.     }
  177.     bool PlayerAlreadyHasTwoProfessions(Player *pPlayer)
  178.     {
  179.         uint32 skillCount = 0;
  180.  
  181.         if (pPlayer->HasSkill(SKILL_MINING))
  182.             skillCount++;
  183.         if (pPlayer->HasSkill(SKILL_SKINNING))
  184.             skillCount++;
  185.         if (pPlayer->HasSkill(SKILL_HERBALISM))
  186.             skillCount++;
  187.  
  188.         if (skillCount >= 4)
  189.             return true;
  190.  
  191.         for (uint32 i = 1; i < sSkillLineStore.GetNumRows(); ++i)
  192.         {
  193.             SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(i);
  194.             if (!SkillInfo) continue;
  195.  
  196.             if (SkillInfo->categoryId == SKILL_CATEGORY_SECONDARY)  continue;
  197.  
  198.             if ((SkillInfo->categoryId != SKILL_CATEGORY_PROFESSION) || !SkillInfo->canLink) continue;
  199.  
  200.             const uint32 skillID = SkillInfo->id;
  201.             if (pPlayer->HasSkill(skillID))
  202.                 skillCount++;
  203.  
  204.             if (pProfissionVIP == 1 && (pPlayer->HasItemCount(IdItemProfissionVIP, 1, true))){
  205.                 if (skillCount >= qProfissionVIP) // Numero de profission player vip
  206.                     return true;
  207.             }
  208.             else
  209.             {
  210.                 if (skillCount >= qProfissionNormal) // Numero de profission de player normal
  211.                     return true;
  212.             }
  213.         }
  214.         return false;
  215.     }
  216.     void LearnSkillRecipesHelper(Player *player, uint32 skill_id)
  217.     {
  218.         uint32 classmask = player->getClassMask();
  219.         for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
  220.         {
  221.             SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
  222.             if (!skillLine) continue;
  223.             // wrong skill
  224.             if (skillLine->skillId != skill_id) continue;
  225.             // not high rank
  226.             if (skillLine->forward_spellid) continue;
  227.             // skip racial skills
  228.             if (skillLine->racemask != 0) continue;
  229.             // skip wrong class skills
  230.             if (skillLine->classmask && (skillLine->classmask & classmask) == 0) continue;
  231.  
  232.             SpellInfo const * spellInfo = sSpellMgr->GetSpellInfo(skillLine->spellId);
  233.             if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, player, false))
  234.                 continue;
  235.             player->LearnSpell(skillLine->spellId, false);
  236.         }
  237.     }
  238. };
  239.  
  240. class mod_npc_Profissoes_WorldScript : public WorldScript
  241. {
  242. public:
  243.     mod_npc_Profissoes_WorldScript() : WorldScript("mod_npcprofissio_WorldScript") { }
  244.  
  245.     void OnConfigLoad(bool /*reload*/)
  246.     {
  247.         CobrarProfession       = sConfigMgr->GetBoolDefault("Abilitar.Cobrar.Profession", true);
  248.         CobrarProfessionHONOR  = sConfigMgr->GetIntDefault("Cobrar.Profession_Honor.ou.Item", 0);
  249.         IdEmblema              = sConfigMgr->GetIntDefault("Id_Item", 0);
  250.         pValor                 = sConfigMgr->GetIntDefault("Valor_A_Cobrar", 0);
  251.         pProfissionVIP         = sConfigMgr->GetBoolDefault("ProfessionVIP", false);
  252.         qProfissionVIP         = sConfigMgr->GetIntDefault("QuantidadeProfessionVIP", 0);
  253.         qProfissionNormal      = sConfigMgr->GetIntDefault("QuantidadeProfessionNormal", 0);
  254.         IdItemProfissionVIP    = sConfigMgr->GetIntDefault("Id.ItemVIP", 0);
  255.     }
  256. };
  257.  
  258. void AddSC_npc_Profissoes()
  259. {
  260.     new npc_Profissoes();
  261.     new mod_npc_Profissoes_WorldScript();
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement