Skip to content

Commit

Permalink
implement nico's work
Browse files Browse the repository at this point in the history
first part only, used to learn spell, need to remove from sql file bad entries (or missing if needed)
  • Loading branch information
unknown authored and unknown committed Jul 15, 2011
1 parent f393d9a commit 966ecb2
Show file tree
Hide file tree
Showing 8 changed files with 2,054 additions and 562 deletions.
1,978 changes: 1,978 additions & 0 deletions addition/99999_mangos_spell_info.sql

Large diffs are not rendered by default.

230 changes: 4 additions & 226 deletions src/game/Level3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2329,235 +2329,13 @@ bool ChatHandler::HandleLearnAllMySpellsCommand(char* /*args*/)

player->learnDefaultSpells();

ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(player->getClass());

if(!clsEntry)
return true;

uint32 family = clsEntry->spellfamily;

for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
{
CreatureInfo const *cinfo = sObjectMgr.GetCreatureTemplate(id);
if(!cinfo)
continue;

if((cinfo->npcflag & UNIT_NPC_FLAG_TRAINER) || (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_CLASS)
|| (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_PROFESSION))
{
TrainerSpellData const* cSpells = sObjectMgr.GetNpcTrainerSpells(cinfo->Entry);
TrainerSpellData const* tSpells = sObjectMgr.GetNpcTrainerTemplateSpells(cinfo->trainerId);

if (!cSpells && !tSpells)
continue;

if (cSpells)
{
for(TrainerSpellMap::const_iterator itr = cSpells->spellList.begin(); itr != cSpells->spellList.end(); ++itr)
{
TrainerSpell const* tSpell = &itr->second;

SpellEntry const* spellInfo1 = sSpellStore.LookupEntry(tSpell->spell);
if (!spellInfo1)
continue;

SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(tSpell->learnedSpell);
if (!spellInfo2)
continue;

if (player->GetTrainerSpellState(tSpell, true) != TRAINER_SPELL_GREEN)
continue;

if (sSpellMgr.IsProfessionSpell(tSpell->learnedSpell))
continue;

if (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_WEAPON) {}
else if (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_PROFICIENCY) {}
else if(spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL
&& spellInfo1->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL) {}
else if (spellInfo1->SpellFamilyName != family || spellInfo2->SpellFamilyName != family)
continue;

if(tSpell->IsCastable())
{
if (!player->isWtfSpell(tSpell->learnedSpell))
player->learnSpell(tSpell->learnedSpell, false, true);
}
else
{
if (!player->isWtfSpell(tSpell->spell))
player->learnSpell(tSpell->spell, false, true);
}
}
}

if (tSpells)
{
for(TrainerSpellMap::const_iterator itr = tSpells->spellList.begin(); itr != tSpells->spellList.end(); ++itr)
{
TrainerSpell const* tSpell = &itr->second;

SpellEntry const* spellInfo1 = sSpellStore.LookupEntry(tSpell->spell);
if (!spellInfo1)
continue;

SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(tSpell->learnedSpell);
if (!spellInfo2)
continue;

if (player->GetTrainerSpellState(tSpell, true) != TRAINER_SPELL_GREEN)
continue;

if (sSpellMgr.IsProfessionSpell(tSpell->learnedSpell))
continue;

if (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_WEAPON) {}
else if (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_PROFICIENCY) {}
else if(spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL
&& spellInfo1->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL) {}
else if (spellInfo1->SpellFamilyName != family || spellInfo2->SpellFamilyName != family)
continue;

if(tSpell->IsCastable())
{
if (!player->isWtfSpell(tSpell->learnedSpell))
player->learnSpell(tSpell->learnedSpell, false, true);
}
else
{
if (!player->isWtfSpell(tSpell->spell))
player->learnSpell(tSpell->spell, false, true);
}
}
}
}

if(cinfo->npcflag & UNIT_NPC_FLAG_QUESTGIVER)
{
QuestRelationsMapBounds bounds = sObjectMgr.GetCreatureQuestRelationsMapBounds(id);
for(QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
Quest const *pQuest = sObjectMgr.GetQuestTemplate(itr->second);

if (!pQuest)
continue;

SpellEntry const* spellInfo1 = sSpellStore.LookupEntry(pQuest->GetSrcSpell());
if (spellInfo1)
{
if (player->IsSpellFitByClassAndRace(spellInfo1->Id) && !player->isWtfSpell(spellInfo1->Id))
{
if ( (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL && spellInfo1->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL)
|| (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_TRADE_SKILL) ) {}
else if (spellInfo1->SpellFamilyName == family)
player->learnSpell(spellInfo1->Id, false, true);
else if ( ((cinfo->npcflag & UNIT_NPC_FLAG_TRAINER) || (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_CLASS)
|| (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_PROFESSION)) && (cinfo->trainer_class == player->getClass()) )
player->learnSpell(spellInfo1->Id, false, true);
}
}

SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(pQuest->GetRewSpell());
if (spellInfo2)
{
if (player->IsSpellFitByClassAndRace(spellInfo2->Id) && !player->isWtfSpell(spellInfo2->Id))
{
if ( (spellInfo2->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL && spellInfo2->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL)
|| (spellInfo2->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_TRADE_SKILL) ) {}
else if (spellInfo2->SpellFamilyName == family)
player->learnSpell(spellInfo2->Id, false, true);
else if ( ((cinfo->npcflag & UNIT_NPC_FLAG_TRAINER) || (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_CLASS)
|| (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_PROFESSION)) && (cinfo->trainer_class == player->getClass()) )
player->learnSpell(spellInfo2->Id, false, true);
}
}

SpellEntry const* spellInfo3 = sSpellStore.LookupEntry(pQuest->GetRewSpellCast());
if (spellInfo3)
{
bool learn = false;
for(int j = 0; j < 3; j++)
{
if(spellInfo3->Effect[j] == SPELL_EFFECT_LEARN_SPELL)
{
learn = true;
SpellEntry const* spellInfo4 = sSpellStore.LookupEntry(spellInfo3->EffectTriggerSpell[j]);
if (spellInfo4)
{
if (player->IsSpellFitByClassAndRace(spellInfo4->Id) && !player->isWtfSpell(spellInfo4->Id))
{
if ( (spellInfo4->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL && spellInfo4->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL)
|| (spellInfo4->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_TRADE_SKILL) ) {}
else if (spellInfo4->SpellFamilyName == family)
player->learnSpell(spellInfo4->Id, false, true);
else if ( ((cinfo->npcflag & UNIT_NPC_FLAG_TRAINER) || (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_CLASS)
|| (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_PROFESSION)) && (cinfo->trainer_class == player->getClass()) )
player->learnSpell(spellInfo4->Id, false, true);
}
}
}
}
if (!learn)
{
if (player->IsSpellFitByClassAndRace(spellInfo3->Id) && !player->isWtfSpell(spellInfo3->Id))
{
if ( (spellInfo3->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL && spellInfo3->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL)
|| (spellInfo3->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_TRADE_SKILL) ) {}
else if (spellInfo3->SpellFamilyName == family)
player->learnSpell(spellInfo3->Id, false, true);
else if ( ((cinfo->npcflag & UNIT_NPC_FLAG_TRAINER) || (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_CLASS)
|| (cinfo->npcflag & UNIT_NPC_FLAG_TRAINER_PROFESSION)) && (cinfo->trainer_class == player->getClass()) )
player->learnSpell(spellInfo3->Id, false, true);
}
}
}
}
}
}

for (uint32 id = 0; id < sItemStorage.MaxEntry; ++id)
SpellInfoMap const & spellInfo = sObjectMgr.GetSpellInfoMap();
for (SpellInfoMap::const_iterator itr = spellInfo.begin(); itr != spellInfo.end(); ++itr)
{
ItemPrototype const *pProto = sObjectMgr.GetItemPrototype(id);
if(!pProto || pProto->Stackable > 1 || pProto->Class==ITEM_CLASS_WEAPON || pProto->Class==ITEM_CLASS_ARMOR)
if (itr->second._class != player->getClass())
continue;

for (int i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
{
bool learn = false;
SpellEntry const* spellInfo1 = sSpellStore.LookupEntry(pProto->Spells[i].SpellId);
if (spellInfo1)
{
bool learn = false;
for(int j = 0; j < 3; j++)
{
if(spellInfo1->Effect[j] == SPELL_EFFECT_LEARN_SPELL)
{
learn = true;
SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo1->EffectTriggerSpell[j]);
if (spellInfo2)
{
if (player->IsSpellFitByClassAndRace(spellInfo2->Id) && !player->isWtfSpell(spellInfo2->Id))
{
if ( (spellInfo2->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL && spellInfo2->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL)
|| (spellInfo2->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_TRADE_SKILL) ) {}
else if (spellInfo2->SpellFamilyName == family)
player->learnSpell(spellInfo2->Id, false, true);
}
}
}
}
if (!learn)
{
if (player->IsSpellFitByClassAndRace(spellInfo1->Id) && !player->isWtfSpell(spellInfo1->Id))
{
if ( (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL && spellInfo1->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SKILL)
|| (spellInfo1->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_TRADE_SKILL) ) {}
else if (spellInfo1->SpellFamilyName == family)
player->learnSpell(spellInfo1->Id, false, true);
}
}
}
}
player->learnSpell(itr->second.id, false);
}

player->learnSpell(33388, false);
Expand Down
44 changes: 44 additions & 0 deletions src/game/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,50 @@ void ObjectMgr::LoadItemSetPrototypes()
sLog.outString( ">> Loaded %u Items in Sets", count );
}

void ObjectMgr::LoadSpellInfo()
{
uint32 count = 0;
QueryResult *result = WorldDatabase.Query("SELECT id, class, name_en, name_en2, name_fr, learn_level, rank, prev_rank, next_rank FROM spell_info");

if (!result)
{
BarGoLink bar(1);

bar.step();

sLog.outString();
sLog.outErrorDb(">> Loaded 0 Spells Info . DB table `spell_info` is empty.");
return;
}

BarGoLink bar(result->GetRowCount());

do
{
Field *fields = result->Fetch();
bar.step();

SpellInfo spellinfo;
spellinfo.id = fields[0].GetUInt32();
spellinfo._class = fields[1].GetUInt8();
//spellinfo.name_en = fields[2].GetCppString();
spellinfo.name_en2 = fields[3].GetCppString();
//spellinfo.name_fr = fields[4].GetCppString();
spellinfo.learn_level = fields[5].GetUInt32();
spellinfo.rank = fields[6].GetUInt8();
spellinfo.prev_rank = fields[7].GetUInt8();
spellinfo.next_rank = fields[8].GetUInt8();

m_SpellInfoMap[count] = spellinfo;

++count;
} while (result->NextRow());

delete result;
sLog.outString();
sLog.outString( ">> Loaded %u Spells Info", count );
}

void ObjectMgr::LoadItemConverts()
{
m_ItemConvert.clear(); // needed for reload case
Expand Down
18 changes: 18 additions & 0 deletions src/game/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ struct ShortItemSet

typedef UNORDERED_MAP<uint32, ShortItemSet > ItemSetMap;

struct SpellInfo
{
uint32 id;
uint8 _class;
//std::string name_en;
std::string name_en2;
//std::string name_fr;
uint32 learn_level;
uint8 rank;
uint8 prev_rank;
uint8 next_rank;
};

typedef UNORDERED_MAP<uint32, SpellInfo > SpellInfoMap;

struct SpellClickInfo
{
uint32 spellId;
Expand Down Expand Up @@ -758,6 +773,7 @@ class ObjectMgr
void LoadGameobjects();
void LoadItemPrototypes();
void LoadItemSetPrototypes();
void LoadSpellInfo();
void LoadItemConverts();
void LoadItemExpireConverts();
void LoadItemRequiredTarget();
Expand Down Expand Up @@ -1042,6 +1058,7 @@ class ObjectMgr
bool DeleteGameTele(const std::string& name);

ItemSetMap const& GetItemSetMap() const { return m_ItemSetMap; }
SpellInfoMap const& GetSpellInfoMap() const { return m_SpellInfoMap; }

uint32 GetNpcGossip(uint32 entry) const
{
Expand Down Expand Up @@ -1227,6 +1244,7 @@ class ObjectMgr

GameTeleMap m_GameTeleMap;
ItemSetMap m_ItemSetMap;
SpellInfoMap m_SpellInfoMap;

SpellClickInfoMap mSpellClickInfoMap;

Expand Down
7 changes: 1 addition & 6 deletions src/game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3513,13 +3513,8 @@ bool Player::IsNeedCastPassiveLikeSpellAtLearn(SpellEntry const* spellInfo) cons
return need_cast && (!spellInfo->CasterAuraState || HasAuraState(AuraState(spellInfo->CasterAuraState)));
}

void Player::learnSpell(uint32 spell_id, bool dependent, bool debug)
void Player::learnSpell(uint32 spell_id, bool dependent)
{
/*if (debug)
{
SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
sLog.outString("%u %s %s", spellInfo->Id, spellInfo->SpellName[2], spellInfo->Rank[2]);
}*/
PlayerSpellMap::iterator itr = m_spells.find(spell_id);

bool disabled = (itr != m_spells.end()) ? itr->second.disabled : false;
Expand Down
3 changes: 1 addition & 2 deletions src/game/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1647,14 +1647,13 @@ class MANGOS_DLL_SPEC Player : public Unit
void SendProficiency(ItemClass itemClass, uint32 itemSubclassMask);
void SendInitialSpells();
bool addSpell(uint32 spell_id, bool active, bool learning, bool dependent, bool disabled);
void learnSpell(uint32 spell_id, bool dependent, bool debug = false);
void learnSpell(uint32 spell_id, bool dependent);
void removeSpell(uint32 spell_id, bool disabled = false, bool learn_low_rank = true, bool sendUpdate = true);
void resetSpells();
void learnDefaultSpells();
void learnQuestRewardedSpells();
void learnQuestRewardedSpells(Quest const* quest);
void learnSpellHighRank(uint32 spellid);
bool isWtfSpell(uint32 spell_id);
void choseMount(uint32 *Mount, uint32 max);

uint32 GetFreeTalentPoints() const { return GetUInt32Value(PLAYER_CHARACTER_POINTS1); }
Expand Down
Loading

0 comments on commit 966ecb2

Please sign in to comment.