From d8355f27f5a55a76275e72c22bd6f06a74d89ee0 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sun, 25 Jan 2009 19:31:12 +0300 Subject: [PATCH] [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. --- src/game/Player.cpp | 32 +++++++++++++++----------------- src/game/Player.h | 1 - src/shared/revision_nr.h | 2 +- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 350be0a6a..eb1322953 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -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; + } + } } diff --git a/src/game/Player.h b/src/game/Player.h index d6ec3e289..1bdf2718f 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -2287,7 +2287,6 @@ class MANGOS_DLL_SPEC Player : public Unit time_t m_lastHonorUpdateTime; void outDebugValues() const; - bool _removeSpell(uint16 spell_id); uint64 m_lootGuid; uint32 m_race; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 5bbf9d20e..1776583a5 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7177" + #define REVISION_NR "7178" #endif // __REVISION_NR_H__