Minor refactoring of auto-replacing player spell ranks

This commit is contained in:
Olion 2016-03-02 14:09:26 +02:00
parent b47f186c76
commit ed365bed34

View File

@ -2912,57 +2912,43 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
// replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible // replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible
if (newspell.active && !newspell.disabled) if (newspell.active && !newspell.disabled)
{ {
for (PlayerSpellMap::iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2) SpellChainMapNext const& nextMap = sSpellMgr.GetSpellChainNext();
for (SpellChainMapNext::const_iterator next_itr = nextMap.lower_bound(spell_id); next_itr != nextMap.upper_bound(spell_id); ++next_itr)
{ {
PlayerSpell &playerSpell2 = itr2->second; uint32 tested_spell_id = next_itr->second; // synonym just for the code clarity
if (m_spells.find(tested_spell_id) == m_spells.end())
continue;
if (playerSpell2.state == PLAYERSPELL_REMOVED) { continue; } PlayerSpell &lowerRank = m_spells[tested_spell_id];
SpellEntry const* i_spellInfo = sSpellStore.LookupEntry(itr2->first); if (lowerRank.state == PLAYERSPELL_REMOVED || !lowerRank.active)
if (!i_spellInfo) { continue; } continue;
if (sSpellMgr.IsRankSpellDueToSpell(spellInfo, itr2->first)) SpellEntry const *spell_old = sSpellStore.LookupEntry(tested_spell_id); // was checked for NULL in SpellMgr::LoadSpellChains()
{ SpellEntry const *spell_new = spellInfo;
if (playerSpell2.active) if (sSpellMgr.IsHighRankOfSpell(tested_spell_id, spell_id) && sSpellMgr.IsRankedSpellNonStackableInSpellBook(spell_old))
{
if (sSpellMgr.IsHighRankOfSpell(spell_id, itr2->first) &&
sSpellMgr.IsRankedSpellNonStackableInSpellBook(i_spellInfo))
{ {
spell_new = spell_old;
spell_old = spellInfo;
lowerRank = newspell;
}
else if (!(sSpellMgr.IsHighRankOfSpell(spell_id, tested_spell_id) && sSpellMgr.IsRankedSpellNonStackableInSpellBook(spell_new)))
continue;
if (IsInWorld()) // not send spell (re-/over-)learn packets at loading if (IsInWorld()) // not send spell (re-/over-)learn packets at loading
{ {
WorldPacket data(SMSG_SUPERCEDED_SPELL, (4)); WorldPacket data(SMSG_SUPERCEDED_SPELL, (4));
data << uint16(itr2->first); data << uint16(spell_old->Id);
data << uint16(spell_id); data << uint16(spell_new->Id);
GetSession()->SendPacket(&data); GetSession()->SendPacket(&data);
} }
// mark old spell as disable (SMSG_SUPERCEDED_SPELL replace it in client by new) // mark lower rank disabled (SMSG_SUPERCEDED_SPELL replaced it in client by new)
playerSpell2.active = false; lowerRank.active = false;
if (playerSpell2.state != PLAYERSPELL_NEW) if (lowerRank.state != PLAYERSPELL_NEW)
{ playerSpell2.state = PLAYERSPELL_CHANGED; } lowerRank.state = PLAYERSPELL_CHANGED;
canAddToSpellBook = false; canAddToSpellBook = false;
} }
else if (sSpellMgr.IsHighRankOfSpell(itr2->first, spell_id) &&
sSpellMgr.IsRankedSpellNonStackableInSpellBook(spellInfo))
{
if (IsInWorld()) // not send spell (re-/over-)learn packets at loading
{
WorldPacket data(SMSG_SUPERCEDED_SPELL, (4));
data << uint16(spell_id);
data << uint16(itr2->first);
GetSession()->SendPacket(&data);
}
// mark new spell as disable (not learned yet for client and will not learned)
newspell.active = false;
if (newspell.state != PLAYERSPELL_NEW)
{ newspell.state = PLAYERSPELL_CHANGED; }
canAddToSpellBook = false;
}
}
}
}
} }
m_spells[spell_id] = newspell; m_spells[spell_id] = newspell;