diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 8f698afea..03eb0e888 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -515,9 +515,6 @@ Player::~Player () } CleanupChannels(); - for (PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) - delete itr->second; - //all mailed items should be deleted, also all mail should be deallocated for (PlayerMails::const_iterator itr = m_mail.begin(); itr != m_mail.end();++itr) delete *itr; @@ -2721,10 +2718,10 @@ void Player::SendInitialSpells() for (PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) { - if(itr->second->state == PLAYERSPELL_REMOVED) + if(itr->second.state == PLAYERSPELL_REMOVED) continue; - if(!itr->second->active || itr->second->disabled) + if(!itr->second.active || itr->second.disabled) continue; data << uint32(itr->first); @@ -2903,33 +2900,33 @@ 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(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; + 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) + if (itr->second.state != PLAYERSPELL_REMOVED && !itr->second.dependent && dependent) { - itr->second->dependent = dependent; - if (itr->second->state != PLAYERSPELL_NEW) - itr->second->state = PLAYERSPELL_CHANGED; + itr->second.dependent = dependent; + if (itr->second.state != PLAYERSPELL_NEW) + itr->second.state = PLAYERSPELL_CHANGED; dependent_set = true; } // update active state for known spell - if(itr->second->active != active && itr->second->state != PLAYERSPELL_REMOVED && !itr->second->disabled) + if(itr->second.active != active && itr->second.state != PLAYERSPELL_REMOVED && !itr->second.disabled) { - itr->second->active = active; + itr->second.active = active; 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; + itr->second.state = PLAYERSPELL_UNCHANGED; + else if(itr->second.state != PLAYERSPELL_NEW) + itr->second.state = PLAYERSPELL_CHANGED; if(active) { @@ -2957,24 +2954,23 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen return active; // learn (show in spell book if active now) } - if(itr->second->disabled != disabled && itr->second->state != PLAYERSPELL_REMOVED) + if(itr->second.disabled != disabled && itr->second.state != PLAYERSPELL_REMOVED) { - if(itr->second->state != PLAYERSPELL_NEW) - itr->second->state = PLAYERSPELL_CHANGED; - itr->second->disabled = disabled; + if(itr->second.state != PLAYERSPELL_NEW) + itr->second.state = PLAYERSPELL_CHANGED; + itr->second.disabled = disabled; if(disabled) return false; disabled_case = true; } - else switch(itr->second->state) + else switch(itr->second.state) { case PLAYERSPELL_UNCHANGED: // known saved spell return false; case PLAYERSPELL_REMOVED: // re-learning removed not saved spell { - delete itr->second; m_spells.erase(itr); state = PLAYERSPELL_CHANGED; break; // need re-add @@ -2983,7 +2979,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen { // can be in case spell loading but learned at some previous spell loading if(!IsInWorld() && !learning && !dependent_set) - itr->second->state = PLAYERSPELL_UNCHANGED; + itr->second.state = PLAYERSPELL_UNCHANGED; return false; } @@ -3017,24 +3013,24 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen learnSpell(prev_spell,true); } - PlayerSpell *newspell = new PlayerSpell; - newspell->state = state; - newspell->active = active; - newspell->dependent = dependent; - newspell->disabled = disabled; + PlayerSpell newspell; + newspell.state = state; + newspell.active = active; + newspell.dependent = dependent; + newspell.disabled = disabled; // replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible - if(newspell->active && !newspell->disabled && !SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0) + if(newspell.active && !newspell.disabled && !SpellMgr::canStackSpellRanks(spellInfo) && sSpellMgr.GetSpellRank(spellInfo->Id) != 0) { for( PlayerSpellMap::iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2 ) { - if(itr2->second->state == PLAYERSPELL_REMOVED) continue; + if(itr2->second.state == PLAYERSPELL_REMOVED) continue; SpellEntry const *i_spellInfo = sSpellStore.LookupEntry(itr2->first); if(!i_spellInfo) continue; if( sSpellMgr.IsRankSpellDueToSpell(spellInfo,itr2->first) ) { - if(itr2->second->active) + if(itr2->second.active) { if(sSpellMgr.IsHighRankOfSpell(spell_id,itr2->first)) { @@ -3047,9 +3043,9 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen } // mark old spell as disable (SMSG_SUPERCEDED_SPELL replace it in client by new) - itr2->second->active = false; - if(itr2->second->state != PLAYERSPELL_NEW) - itr2->second->state = PLAYERSPELL_CHANGED; + itr2->second.active = false; + if(itr2->second.state != PLAYERSPELL_NEW) + itr2->second.state = PLAYERSPELL_CHANGED; superceded_old = true; // new spell replace old in action bars and spell book. } else if(sSpellMgr.IsHighRankOfSpell(itr2->first,spell_id)) @@ -3063,9 +3059,9 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen } // 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; + newspell.active = false; + if(newspell.state != PLAYERSPELL_NEW) + newspell.state = PLAYERSPELL_CHANGED; } } } @@ -3075,7 +3071,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen m_spells[spell_id] = newspell; // return false if spell disabled - if (newspell->disabled) + if (newspell.disabled) return false; } @@ -3210,8 +3206,8 @@ void Player::learnSpell(uint32 spell_id, bool dependent) { PlayerSpellMap::iterator itr = m_spells.find(spell_id); - bool disabled = (itr != m_spells.end()) ? itr->second->disabled : false; - bool active = disabled ? itr->second->active : true; + bool disabled = (itr != m_spells.end()) ? itr->second.disabled : false; + bool active = disabled ? itr->second.active : true; bool learning = addSpell(spell_id,active,true,dependent,false); @@ -3222,7 +3218,7 @@ void Player::learnSpell(uint32 spell_id, bool dependent) for(SpellChainMapNext::const_iterator i = nextMap.lower_bound(spell_id); i != nextMap.upper_bound(spell_id); ++i) { PlayerSpellMap::iterator iter = m_spells.find(i->second); - if (iter != m_spells.end() && iter->second->disabled) + if (iter != m_spells.end() && iter->second.disabled) learnSpell(i->second,false); } } @@ -3242,7 +3238,7 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo if (itr == m_spells.end()) return; - if (itr->second->state == PLAYERSPELL_REMOVED || (disabled && itr->second->disabled)) + if (itr->second.state == PLAYERSPELL_REMOVED || (disabled && itr->second.disabled)) return; // unlearn non talent higher ranks (recursive) @@ -3256,24 +3252,21 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo if (itr == m_spells.end()) return; // already unleared - bool cur_active = itr->second->active; - bool cur_dependent = itr->second->dependent; + bool cur_active = itr->second.active; + bool cur_dependent = itr->second.dependent; if (disabled) { - itr->second->disabled = disabled; - if(itr->second->state != PLAYERSPELL_NEW) - itr->second->state = PLAYERSPELL_CHANGED; + itr->second.disabled = disabled; + if(itr->second.state != PLAYERSPELL_NEW) + itr->second.state = PLAYERSPELL_CHANGED; } else { - if(itr->second->state == PLAYERSPELL_NEW) - { - delete itr->second; + if(itr->second.state == PLAYERSPELL_NEW) m_spells.erase(itr); - } else - itr->second->state = PLAYERSPELL_REMOVED; + itr->second.state = PLAYERSPELL_REMOVED; } RemoveAurasDueToSpell(spell_id); @@ -3390,17 +3383,17 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo PlayerSpellMap::iterator prev_itr = m_spells.find(prev_id); if (prev_itr != m_spells.end()) { - if (prev_itr->second->dependent != cur_dependent) + if (prev_itr->second.dependent != cur_dependent) { - prev_itr->second->dependent = cur_dependent; - if (prev_itr->second->state != PLAYERSPELL_NEW) - prev_itr->second->state = PLAYERSPELL_CHANGED; + prev_itr->second.dependent = cur_dependent; + if (prev_itr->second.state != PLAYERSPELL_NEW) + prev_itr->second.state = PLAYERSPELL_CHANGED; } // now re-learn if need re-activate - if (cur_active && !prev_itr->second->active && learn_low_rank) + if (cur_active && !prev_itr->second.active && learn_low_rank) { - if (addSpell(prev_id,true,false,prev_itr->second->dependent,prev_itr->second->disabled)) + if (addSpell(prev_id,true,false,prev_itr->second.dependent,prev_itr->second.disabled)) { // downgrade spell ranks in spellbook and action bar WorldPacket data(SMSG_SUPERCEDED_SPELL, 4 + 4); @@ -3636,7 +3629,7 @@ bool Player::resetTalents(bool no_cost) { for(PlayerSpellMap::iterator itr = GetSpellMap().begin(); itr != GetSpellMap().end();) { - if(itr->second->state == PLAYERSPELL_REMOVED || itr->second->disabled) + if(itr->second.state == PLAYERSPELL_REMOVED || itr->second.disabled) { ++itr; continue; @@ -3892,15 +3885,15 @@ void Player::DestroyForPlayer( Player *target, bool anim ) const bool Player::HasSpell(uint32 spell) const { PlayerSpellMap::const_iterator itr = m_spells.find(spell); - return (itr != m_spells.end() && itr->second->state != PLAYERSPELL_REMOVED && - !itr->second->disabled); + return (itr != m_spells.end() && itr->second.state != PLAYERSPELL_REMOVED && + !itr->second.disabled); } bool Player::HasActiveSpell(uint32 spell) const { PlayerSpellMap::const_iterator itr = m_spells.find(spell); - return (itr != m_spells.end() && itr->second->state != PLAYERSPELL_REMOVED && - itr->second->active && !itr->second->disabled); + return (itr != m_spells.end() && itr->second.state != PLAYERSPELL_REMOVED && + itr->second.active && !itr->second.disabled); } TrainerSpellState Player::GetTrainerSpellState(TrainerSpell const* trainer_spell) const @@ -16654,21 +16647,18 @@ void Player::_SaveSpells() { for (PlayerSpellMap::iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end();) { - if (itr->second->state == PLAYERSPELL_REMOVED || itr->second->state == PLAYERSPELL_CHANGED) + 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); // add only changed/new not dependent spells - if (!itr->second->dependent && (itr->second->state == PLAYERSPELL_NEW || itr->second->state == PLAYERSPELL_CHANGED)) - 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.dependent && (itr->second.state == PLAYERSPELL_NEW || itr->second.state == PLAYERSPELL_CHANGED)) + 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) - { - delete itr->second; + if (itr->second.state == PLAYERSPELL_REMOVED) m_spells.erase(itr++); - } else { - itr->second->state = PLAYERSPELL_UNCHANGED; + itr->second.state = PLAYERSPELL_UNCHANGED; ++itr; } @@ -17857,7 +17847,7 @@ void Player::ProhibitSpellSchool(SpellSchoolMask idSchoolMask, uint32 unTimeMs ) time_t curTime = time(NULL); for(PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) { - if (itr->second->state == PLAYERSPELL_REMOVED) + if (itr->second.state == PLAYERSPELL_REMOVED) continue; uint32 unSpellId = itr->first; SpellEntry const *spellInfo = sSpellStore.LookupEntry(unSpellId); @@ -19162,7 +19152,7 @@ void Player::learnQuestRewardedSpells(Quest const* quest) // search other specialization for same prof for(PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) { - if(itr->second->state == PLAYERSPELL_REMOVED || itr->first==learned_0) + if(itr->second.state == PLAYERSPELL_REMOVED || itr->first==learned_0) continue; SpellEntry const *itrInfo = sSpellStore.LookupEntry(itr->first); diff --git a/src/game/Player.h b/src/game/Player.h index dae63b5fb..f35e614d6 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -95,6 +95,8 @@ struct PlayerSpell bool disabled : 1; // first rank has been learned in result talent learn but currently talent unlearned, save max learned ranks }; +typedef UNORDERED_MAP PlayerSpellMap; + // Spell modifier (used for modify other spells) struct SpellModifier { @@ -120,7 +122,6 @@ struct SpellModifier Spell const* lastAffected; }; -typedef UNORDERED_MAP PlayerSpellMap; typedef std::list SpellModList; struct SpellCooldown diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index e180c3d65..e8164ecc0 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -3141,7 +3141,7 @@ void Aura::HandleAuraModShapeshift(bool apply, bool Real) PlayerSpellMap const& sp_list = ((Player *)m_target)->GetSpellMap(); for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) { - if(itr->second->state == PLAYERSPELL_REMOVED) continue; + if(itr->second.state == PLAYERSPELL_REMOVED) continue; SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139) Rage_val += m_target->CalculateSpellDamage(spellInfo, EFFECT_INDEX_0, spellInfo->EffectBasePoints[EFFECT_INDEX_0], m_target) * 10; @@ -5852,7 +5852,7 @@ void Aura::HandleShapeshiftBoosts(bool apply) const PlayerSpellMap& sp_list = ((Player *)m_target)->GetSpellMap(); for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) { - if (itr->second->state == PLAYERSPELL_REMOVED) continue; + if (itr->second.state == PLAYERSPELL_REMOVED) continue; if (itr->first==spellId1 || itr->first==spellId2) continue; SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | (1<<7)))) diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index e993502c9..38ff5ccee 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -2292,7 +2292,7 @@ void Spell::EffectTriggerSpell(SpellEffectIndex effIndex) for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) { // only highest rank is shown in spell book, so simply check if shown in spell book - if (!itr->second->active || itr->second->disabled || itr->second->state == PLAYERSPELL_REMOVED) + if (!itr->second.active || itr->second.disabled || itr->second.state == PLAYERSPELL_REMOVED) continue; SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 943d73b49..5f14ffbde 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8470,7 +8470,7 @@ void Unit::ModifyAuraState(AuraState flag, bool apply) const PlayerSpellMap& sp_list = ((Player*)this)->GetSpellMap(); for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) { - if(itr->second->state == PLAYERSPELL_REMOVED) continue; + if(itr->second.state == PLAYERSPELL_REMOVED) continue; SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); if (!spellInfo || !IsPassiveSpell(itr->first)) continue; if (spellInfo->CasterAuraState == flag) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 285c1b830..a20263487 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 "9439" + #define REVISION_NR "9440" #endif // __REVISION_NR_H__