[7178] Fixed character save fail at spell save in special case.

Case description: Spell save fail at attempt save into `character_spell` "new" spell loaded from DB
with exactly same settings after it learned from spell cast triggered by loading another spell from DB.
Reapeatable for shamans with known talent 16268.

Also speedup code with remove redundent Player::_removeSpell function.
This commit is contained in:
VladimirMangos 2009-01-25 19:31:12 +03:00
parent 0418aa5137
commit d8355f27f5
3 changed files with 16 additions and 19 deletions

View file

@ -2601,7 +2601,12 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
// not do anything if already known in expected state
if(itr->second->state != PLAYERSPELL_REMOVED && itr->second->active == active &&
itr->second->dependent == dependent && itr->second->disabled == disabled)
{
if(!IsInWorld() && !learning) // explicitly load from DB and then exist in it already and set correctly
itr->second->state = PLAYERSPELL_UNCHANGED;
return false;
}
// dependent spell known as not dependent, overwrite state
if (itr->second->state != PLAYERSPELL_REMOVED && !itr->second->dependent && dependent)
@ -2617,8 +2622,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
{
itr->second->active = active;
// !IsInWorld() && !learning == explicitly load from DB and then exist in it already and set correctly
if(!IsInWorld() && !learning && !dependent_set)
if(!IsInWorld() && !learning && !dependent_set) // explicitly load from DB and then exist in it already and set correctly
itr->second->state = PLAYERSPELL_UNCHANGED;
else if(itr->second->state != PLAYERSPELL_NEW)
itr->second->state = PLAYERSPELL_CHANGED;
@ -3341,18 +3345,6 @@ bool Player::resetTalents(bool no_cost)
return true;
}
bool Player::_removeSpell(uint16 spell_id)
{
PlayerSpellMap::iterator itr = m_spells.find(spell_id);
if (itr != m_spells.end())
{
delete itr->second;
m_spells.erase(itr);
return true;
}
return false;
}
Mail* Player::GetMail(uint32 id)
{
for(PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
@ -16005,9 +15997,8 @@ void Player::_SaveReputation()
void Player::_SaveSpells()
{
for (PlayerSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next)
for (PlayerSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end();)
{
++next;
if (itr->second->state == PLAYERSPELL_REMOVED || itr->second->state == PLAYERSPELL_CHANGED)
CharacterDatabase.PExecute("DELETE FROM character_spell WHERE guid = '%u' and spell = '%u'", GetGUIDLow(), itr->first);
@ -16016,9 +16007,16 @@ void Player::_SaveSpells()
CharacterDatabase.PExecute("INSERT INTO character_spell (guid,spell,active,disabled) VALUES ('%u', '%u', '%u', '%u')", GetGUIDLow(), itr->first, itr->second->active ? 1 : 0,itr->second->disabled ? 1 : 0);
if (itr->second->state == PLAYERSPELL_REMOVED)
_removeSpell(itr->first);
{
delete itr->second;
m_spells.erase(itr++);
}
else
{
itr->second->state = PLAYERSPELL_UNCHANGED;
++itr;
}
}
}