Rochet2

LearnAllSpells on char create

Jul 31st, 2012
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include "ScriptPch.h"
  2.  
  3. class TeachOnLogin : public PlayerScript
  4. {
  5. public:
  6.     TeachOnLogin() : PlayerScript("TeachOnLogin") { }
  7.    
  8.     void OnCreate(Player* player)
  9.     {
  10.         // HandleLearnAllMySpellsCommand Copy paste
  11.         ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(player->getClass());
  12.         if (!classEntry)
  13.             return;
  14.         uint32 family = classEntry->spellfamily;
  15.  
  16.         for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
  17.         {
  18.             SkillLineAbilityEntry const* entry = sSkillLineAbilityStore.LookupEntry(i);
  19.             if (!entry)
  20.                 continue;
  21.  
  22.             SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(entry->spellId);
  23.             if (!spellInfo)
  24.                 continue;
  25.  
  26.             // skip server-side/triggered spells
  27.             if (spellInfo->SpellLevel == 0)
  28.                 continue;
  29.  
  30.             // skip wrong class/race skills
  31.             if (!player->IsSpellFitByClassAndRace(spellInfo->Id))
  32.                 continue;
  33.  
  34.             // skip other spell families
  35.             if (spellInfo->SpellFamilyName != family)
  36.                 continue;
  37.  
  38.             // skip spells with first rank learned as talent (and all talents then also)
  39.             uint32 firstRank = sSpellMgr->GetFirstSpellInChain(spellInfo->Id);
  40.             if (GetTalentSpellCost(firstRank) > 0)
  41.                 continue;
  42.  
  43.             // skip broken spells
  44.             if (!SpellMgr::IsSpellValid(spellInfo, player, false))
  45.                 continue;
  46.  
  47.             player->learnSpell(spellInfo->Id, false);
  48.         }
  49.     }
  50. };
Add Comment
Please, Sign In to add comment