[8426] Use upper/lower iterator pairs as result instead 2 function calls.

This commit is contained in:
VladimirMangos 2009-08-27 10:51:23 +04:00
parent fdb2842f60
commit 5d50bb16b8
9 changed files with 139 additions and 173 deletions

View file

@ -1208,18 +1208,18 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
} }
case ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM: case ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM:
// miscvalue1 = item_id // miscvalue1 = item_id
if(!miscvalue1) if (!miscvalue1)
continue; continue;
if(miscvalue1 != achievementCriteria->equip_item.itemID) if (miscvalue1 != achievementCriteria->equip_item.itemID)
continue; continue;
SetCriteriaProgress(achievementCriteria, 1); SetCriteriaProgress(achievementCriteria, 1);
break; break;
case ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT: case ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT:
// miscvalue1 = go entry // miscvalue1 = go entry
if(!miscvalue1) if (!miscvalue1)
continue; continue;
if(miscvalue1 != achievementCriteria->use_gameobject.goEntry) if (miscvalue1 != achievementCriteria->use_gameobject.goEntry)
continue; continue;
SetCriteriaProgress(achievementCriteria, 1, PROGRESS_ACCUMULATE); SetCriteriaProgress(achievementCriteria, 1, PROGRESS_ACCUMULATE);
@ -1234,7 +1234,7 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
break; break;
case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS: case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS:
{ {
if(miscvalue1 && miscvalue1 != achievementCriteria->learn_skillline_spell.skillLine) if (miscvalue1 && miscvalue1 != achievementCriteria->learn_skillline_spell.skillLine)
continue; continue;
uint32 spellCount = 0; uint32 spellCount = 0;
@ -1242,9 +1242,8 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
spellIter != GetPlayer()->GetSpellMap().end(); spellIter != GetPlayer()->GetSpellMap().end();
++spellIter) ++spellIter)
{ {
for(SkillLineAbilityMap::const_iterator skillIter = spellmgr.GetBeginSkillLineAbilityMap(spellIter->first); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(spellIter->first);
skillIter != spellmgr.GetEndSkillLineAbilityMap(spellIter->first); for(SkillLineAbilityMap::const_iterator skillIter = bounds.first; skillIter != bounds.second; ++skillIter)
++skillIter)
{ {
if(skillIter->second->skillId == achievementCriteria->learn_skillline_spell.skillLine) if(skillIter->second->skillId == achievementCriteria->learn_skillline_spell.skillLine)
spellCount++; spellCount++;
@ -1255,17 +1254,17 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
} }
case ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL: case ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL:
// AchievementMgr::UpdateAchievementCriteria might also be called on login - skip in this case // AchievementMgr::UpdateAchievementCriteria might also be called on login - skip in this case
if(!miscvalue1) if (!miscvalue1)
continue; continue;
if(achievementCriteria->win_duel.duelCount) if (achievementCriteria->win_duel.duelCount)
{ {
// those requirements couldn't be found in the dbc // those requirements couldn't be found in the dbc
AchievementCriteriaDataSet const* data = achievementmgr.GetCriteriaDataSet(achievementCriteria); AchievementCriteriaDataSet const* data = achievementmgr.GetCriteriaDataSet(achievementCriteria);
if(!data) if (!data)
continue; continue;
if(!data->Meets(GetPlayer(),unit)) if (!data->Meets(GetPlayer(),unit))
continue; continue;
} }
@ -1301,7 +1300,7 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
} }
case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE: case ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE:
{ {
if(miscvalue1 && miscvalue1 != achievementCriteria->learn_skill_line.skillLine) if (miscvalue1 && miscvalue1 != achievementCriteria->learn_skill_line.skillLine)
continue; continue;
uint32 spellCount = 0; uint32 spellCount = 0;
@ -1309,14 +1308,11 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
spellIter != GetPlayer()->GetSpellMap().end(); spellIter != GetPlayer()->GetSpellMap().end();
++spellIter) ++spellIter)
{ {
for(SkillLineAbilityMap::const_iterator skillIter = spellmgr.GetBeginSkillLineAbilityMap(spellIter->first); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(spellIter->first);
skillIter != spellmgr.GetEndSkillLineAbilityMap(spellIter->first); for(SkillLineAbilityMap::const_iterator skillIter = bounds.first; skillIter != bounds.second; ++skillIter)
++skillIter) if (skillIter->second->skillId == achievementCriteria->learn_skill_line.skillLine)
{
if(skillIter->second->skillId == achievementCriteria->learn_skill_line.skillLine)
spellCount++; spellCount++;
} }
}
SetCriteriaProgress(achievementCriteria, spellCount); SetCriteriaProgress(achievementCriteria, spellCount);
break; break;
} }

View file

@ -1331,12 +1331,12 @@ valid examples:
c = reader.peek(); c = reader.peek();
} }
GlyphPropertiesEntry const* glyph = sGlyphPropertiesStore.LookupEntry(glyphId); GlyphPropertiesEntry const* glyph = sGlyphPropertiesStore.LookupEntry(glyphId);
if(!glyph) if (!glyph)
return false; return false;
linkedSpell = sSpellStore.LookupEntry(glyph->SpellId); linkedSpell = sSpellStore.LookupEntry(glyph->SpellId);
if(!linkedSpell) if (!linkedSpell)
return false; return false;
} }
else else
@ -1349,10 +1349,10 @@ valid examples:
break; break;
case 'h': case 'h':
// if h is next element in sequence, this one must contain the linked text :) // if h is next element in sequence, this one must contain the linked text :)
if(*validSequenceIterator == 'h') if (*validSequenceIterator == 'h')
{ {
// links start with '[' // links start with '['
if(reader.get() != '[') if (reader.get() != '[')
{ {
#ifdef MANGOS_DEBUG #ifdef MANGOS_DEBUG
sLog.outBasic("ChatHandler::isValidChatMessage link caption doesn't start with '['"); sLog.outBasic("ChatHandler::isValidChatMessage link caption doesn't start with '['");
@ -1365,18 +1365,16 @@ valid examples:
if (linkedSpell) if (linkedSpell)
{ {
// spells with that flag have a prefix of "$PROFESSION: " // spells with that flag have a prefix of "$PROFESSION: "
if(linkedSpell->Attributes & SPELL_ATTR_TRADESPELL) if (linkedSpell->Attributes & SPELL_ATTR_TRADESPELL)
{ {
// lookup skillid // lookup skillid
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(linkedSpell->Id); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(linkedSpell->Id);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(linkedSpell->Id); if (bounds.first == bounds.second)
if(lower == upper)
{ {
return false; return false;
} }
SkillLineAbilityEntry const *skillInfo = lower->second; SkillLineAbilityEntry const *skillInfo = bounds.first->second;
if (!skillInfo) if (!skillInfo)
{ {
@ -1384,7 +1382,7 @@ valid examples:
} }
SkillLineEntry const *skillLine = sSkillLineStore.LookupEntry(skillInfo->skillId); SkillLineEntry const *skillLine = sSkillLineStore.LookupEntry(skillInfo->skillId);
if(!skillLine) if (!skillLine)
{ {
return false; return false;
} }
@ -1392,7 +1390,7 @@ valid examples:
for(uint8 i=0; i<MAX_LOCALE; ++i) for(uint8 i=0; i<MAX_LOCALE; ++i)
{ {
uint32 skillLineNameLength = strlen(skillLine->name[i]); uint32 skillLineNameLength = strlen(skillLine->name[i]);
if(skillLineNameLength > 0 && strncmp(skillLine->name[i], buffer, skillLineNameLength) == 0) if (skillLineNameLength > 0 && strncmp(skillLine->name[i], buffer, skillLineNameLength) == 0)
{ {
// found the prefix, remove it to perform spellname validation below // found the prefix, remove it to perform spellname validation below
// -2 = strlen(": ") // -2 = strlen(": ")
@ -1404,22 +1402,22 @@ valid examples:
bool foundName = false; bool foundName = false;
for(uint8 i=0; i<MAX_LOCALE; ++i) for(uint8 i=0; i<MAX_LOCALE; ++i)
{ {
if(*linkedSpell->SpellName[i] && strcmp(linkedSpell->SpellName[i], buffer) == 0) if (*linkedSpell->SpellName[i] && strcmp(linkedSpell->SpellName[i], buffer) == 0)
{ {
foundName = true; foundName = true;
break; break;
} }
} }
if(!foundName) if (!foundName)
return false; return false;
} }
else if(linkedQuest) else if (linkedQuest)
{ {
if (linkedQuest->GetTitle() != buffer) if (linkedQuest->GetTitle() != buffer)
{ {
QuestLocale const *ql = objmgr.GetQuestLocale(linkedQuest->GetQuestId()); QuestLocale const *ql = objmgr.GetQuestLocale(linkedQuest->GetQuestId());
if(!ql) if (!ql)
{ {
#ifdef MANOGS_DEBUG #ifdef MANOGS_DEBUG
sLog.outBasic("ChatHandler::isValidChatMessage default questname didn't match and there is no locale"); sLog.outBasic("ChatHandler::isValidChatMessage default questname didn't match and there is no locale");
@ -1430,13 +1428,13 @@ valid examples:
bool foundName = false; bool foundName = false;
for(uint8 i=0; i<ql->Title.size(); i++) for(uint8 i=0; i<ql->Title.size(); i++)
{ {
if(ql->Title[i] == buffer) if (ql->Title[i] == buffer)
{ {
foundName = true; foundName = true;
break; break;
} }
} }
if(!foundName) if (!foundName)
{ {
#ifdef MANOGS_DEBUG #ifdef MANOGS_DEBUG
sLog.outBasic("ChatHandler::isValidChatMessage no quest locale title matched") sLog.outBasic("ChatHandler::isValidChatMessage no quest locale title matched")
@ -1447,11 +1445,11 @@ valid examples:
} }
else if(linkedItem) else if(linkedItem)
{ {
if(strcmp(linkedItem->Name1, buffer) != 0) if (strcmp(linkedItem->Name1, buffer) != 0)
{ {
ItemLocale const *il = objmgr.GetItemLocale(linkedItem->ItemId); ItemLocale const *il = objmgr.GetItemLocale(linkedItem->ItemId);
if(!il) if (!il)
{ {
#ifdef MANGOS_DEBUG #ifdef MANGOS_DEBUG
sLog.outBasic("ChatHandler::isValidChatMessage linked item name doesn't is wrong and there is no localization"); sLog.outBasic("ChatHandler::isValidChatMessage linked item name doesn't is wrong and there is no localization");
@ -1462,13 +1460,13 @@ valid examples:
bool foundName = false; bool foundName = false;
for(uint8 i=0; i<il->Name.size(); ++i) for(uint8 i=0; i<il->Name.size(); ++i)
{ {
if(il->Name[i] == buffer) if (il->Name[i] == buffer)
{ {
foundName = true; foundName = true;
break; break;
} }
} }
if(!foundName) if (!foundName)
{ {
#ifdef MANGOS_DEBUG #ifdef MANGOS_DEBUG
sLog.outBasic("ChatHandler::isValidChatMessage linked item name wasn't found in any localization"); sLog.outBasic("ChatHandler::isValidChatMessage linked item name wasn't found in any localization");
@ -1477,18 +1475,18 @@ valid examples:
} }
} }
} }
else if(linkedAchievement) else if (linkedAchievement)
{ {
bool foundName = false; bool foundName = false;
for(uint8 i=0; i<MAX_LOCALE; ++i) for(uint8 i=0; i<MAX_LOCALE; ++i)
{ {
if(*linkedAchievement->name[i], strcmp(linkedAchievement->name[i], buffer) == 0) if (*linkedAchievement->name[i], strcmp(linkedAchievement->name[i], buffer) == 0)
{ {
foundName = true; foundName = true;
break; break;
} }
} }
if(!foundName) if (!foundName)
return false; return false;
} }
// that place should never be reached - if nothing linked has been set in |H // that place should never be reached - if nothing linked has been set in |H

View file

@ -2028,10 +2028,8 @@ void ObjectMgr::LoadItemRequiredTarget()
if (pItemProto->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_USE || if (pItemProto->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_USE ||
pItemProto->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_NO_DELAY_USE) pItemProto->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_NO_DELAY_USE)
{ {
SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(pSpellInfo->Id); SpellScriptTargetBounds bounds = spellmgr.GetSpellScriptTargetBounds(pSpellInfo->Id);
SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(pSpellInfo->Id); if (bounds.first != bounds.second)
if (lower != upper)
break; break;
for (int j = 0; j < 3; ++j) for (int j = 0; j < 3; ++j)

View file

@ -2999,7 +2999,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
// cast talents with SPELL_EFFECT_LEARN_SPELL (other dependent spells will learned later as not auto-learned) // cast talents with SPELL_EFFECT_LEARN_SPELL (other dependent spells will learned later as not auto-learned)
// note: all spells with SPELL_EFFECT_LEARN_SPELL isn't passive // note: all spells with SPELL_EFFECT_LEARN_SPELL isn't passive
if( talentCost > 0 && IsSpellHaveEffect(spellInfo,SPELL_EFFECT_LEARN_SPELL) ) if (talentCost > 0 && IsSpellHaveEffect(spellInfo,SPELL_EFFECT_LEARN_SPELL))
{ {
// ignore stance requirement for talent learn spell (stance set for spell only for client spell description show) // ignore stance requirement for talent learn spell (stance set for spell only for client spell description show)
CastSpell(this, spell_id, true); CastSpell(this, spell_id, true);
@ -3007,10 +3007,10 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
// also cast passive spells (including all talents without SPELL_EFFECT_LEARN_SPELL) with additional checks // also cast passive spells (including all talents without SPELL_EFFECT_LEARN_SPELL) with additional checks
else if (IsPassiveSpell(spell_id)) else if (IsPassiveSpell(spell_id))
{ {
if(IsNeedCastPassiveSpellAtLearn(spellInfo)) if (IsNeedCastPassiveSpellAtLearn(spellInfo))
CastSpell(this, spell_id, true); CastSpell(this, spell_id, true);
} }
else if( IsSpellHaveEffect(spellInfo,SPELL_EFFECT_SKILL_STEP) ) else if (IsSpellHaveEffect(spellInfo,SPELL_EFFECT_SKILL_STEP))
{ {
CastSpell(this, spell_id, true); CastSpell(this, spell_id, true);
return false; return false;
@ -3020,7 +3020,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
m_usedTalentCount += talentCost; m_usedTalentCount += talentCost;
// update free primary prof.points (if any, can be none in case GM .learn prof. learning) // update free primary prof.points (if any, can be none in case GM .learn prof. learning)
if(uint32 freeProfs = GetFreePrimaryProfessionPoints()) if (uint32 freeProfs = GetFreePrimaryProfessionPoints())
{ {
if(spellmgr.IsPrimaryProfessionFirstRankSpell(spell_id)) if(spellmgr.IsPrimaryProfessionFirstRankSpell(spell_id))
SetFreePrimaryProfessions(freeProfs-1); SetFreePrimaryProfessions(freeProfs-1);
@ -3031,20 +3031,19 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
SpellLearnSkillNode const* spellLearnSkill = spellmgr.GetSpellLearnSkill(spell_id); SpellLearnSkillNode const* spellLearnSkill = spellmgr.GetSpellLearnSkill(spell_id);
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spell_id); SkillLineAbilityMapBounds skill_bounds = spellmgr.GetSkillLineAbilityMapBounds(spell_id);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spell_id);
if(spellLearnSkill) if (spellLearnSkill)
{ {
uint32 skill_value = GetPureSkillValue(spellLearnSkill->skill); uint32 skill_value = GetPureSkillValue(spellLearnSkill->skill);
uint32 skill_max_value = GetPureMaxSkillValue(spellLearnSkill->skill); uint32 skill_max_value = GetPureMaxSkillValue(spellLearnSkill->skill);
if(skill_value < spellLearnSkill->value) if (skill_value < spellLearnSkill->value)
skill_value = spellLearnSkill->value; skill_value = spellLearnSkill->value;
uint32 new_skill_max_value = spellLearnSkill->maxvalue == 0 ? maxskill : spellLearnSkill->maxvalue; uint32 new_skill_max_value = spellLearnSkill->maxvalue == 0 ? maxskill : spellLearnSkill->maxvalue;
if(skill_max_value < new_skill_max_value) if (skill_max_value < new_skill_max_value)
skill_max_value = new_skill_max_value; skill_max_value = new_skill_max_value;
SetSkill(spellLearnSkill->skill,skill_value,skill_max_value); SetSkill(spellLearnSkill->skill,skill_value,skill_max_value);
@ -3052,16 +3051,16 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
else else
{ {
// not ranked skills // not ranked skills
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) for(SkillLineAbilityMap::const_iterator _spell_idx = skill_bounds.first; _spell_idx != skill_bounds.second; ++_spell_idx)
{ {
SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(_spell_idx->second->skillId); SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(_spell_idx->second->skillId);
if(!pSkill) if (!pSkill)
continue; continue;
if(HasSkill(pSkill->id)) if (HasSkill(pSkill->id))
continue; continue;
if(_spell_idx->second->learnOnGetSkill == ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL || if (_spell_idx->second->learnOnGetSkill == ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL ||
// lockpicking/runeforging special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL // lockpicking/runeforging special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
(pSkill->id==SKILL_LOCKPICKING || pSkill->id==SKILL_RUNEFORGING) && _spell_idx->second->max_value==0 ) (pSkill->id==SKILL_LOCKPICKING || pSkill->id==SKILL_RUNEFORGING) && _spell_idx->second->max_value==0 )
{ {
@ -3084,24 +3083,23 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen
} }
// learn dependent spells // learn dependent spells
SpellLearnSpellMap::const_iterator spell_begin = spellmgr.GetBeginSpellLearnSpell(spell_id); SpellLearnSpellMapBounds spell_bounds = spellmgr.GetSpellLearnSpellMapBounds(spell_id);
SpellLearnSpellMap::const_iterator spell_end = spellmgr.GetEndSpellLearnSpell(spell_id);
for(SpellLearnSpellMap::const_iterator itr2 = spell_begin; itr2 != spell_end; ++itr2) for(SpellLearnSpellMap::const_iterator itr2 = spell_bounds.first; itr2 != spell_bounds.second; ++itr2)
{ {
if(!itr2->second.autoLearned) if (!itr2->second.autoLearned)
{ {
if(!IsInWorld() || !itr2->second.active) // at spells loading, no output, but allow save if (!IsInWorld() || !itr2->second.active) // at spells loading, no output, but allow save
addSpell(itr2->second.spell,itr2->second.active,true,true,false); addSpell(itr2->second.spell,itr2->second.active,true,true,false);
else // at normal learning else // at normal learning
learnSpell(itr2->second.spell,true); learnSpell(itr2->second.spell,true);
} }
} }
if(!GetSession()->PlayerLoading()) if (!GetSession()->PlayerLoading())
{ {
// not ranked skills // not ranked skills
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) for(SkillLineAbilityMap::const_iterator _spell_idx = skill_bounds.first; _spell_idx != skill_bounds.second; ++_spell_idx)
{ {
GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE,_spell_idx->second->skillId); GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE,_spell_idx->second->skillId);
GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS,_spell_idx->second->skillId); GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS,_spell_idx->second->skillId);
@ -3236,19 +3234,19 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank)
prevSkill = spellmgr.GetSpellLearnSkill(spellmgr.GetFirstSpellInChain(prev_spell)); prevSkill = spellmgr.GetSpellLearnSkill(spellmgr.GetFirstSpellInChain(prev_spell));
} }
if(!prevSkill) // not found prev skill setting, remove skill if (!prevSkill) // not found prev skill setting, remove skill
SetSkill(spellLearnSkill->skill,0,0); SetSkill(spellLearnSkill->skill,0,0);
else // set to prev. skill setting values else // set to prev. skill setting values
{ {
uint32 skill_value = GetPureSkillValue(prevSkill->skill); uint32 skill_value = GetPureSkillValue(prevSkill->skill);
uint32 skill_max_value = GetPureMaxSkillValue(prevSkill->skill); uint32 skill_max_value = GetPureMaxSkillValue(prevSkill->skill);
if(skill_value > prevSkill->value) if (skill_value > prevSkill->value)
skill_value = prevSkill->value; skill_value = prevSkill->value;
uint32 new_skill_max_value = prevSkill->maxvalue == 0 ? GetMaxSkillValueForLevel() : prevSkill->maxvalue; uint32 new_skill_max_value = prevSkill->maxvalue == 0 ? GetMaxSkillValueForLevel() : prevSkill->maxvalue;
if(skill_max_value > new_skill_max_value) if (skill_max_value > new_skill_max_value)
skill_max_value = new_skill_max_value; skill_max_value = new_skill_max_value;
SetSkill(prevSkill->skill,skill_value,skill_max_value); SetSkill(prevSkill->skill,skill_value,skill_max_value);
@ -3259,22 +3257,21 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank)
else else
{ {
// not ranked skills // not ranked skills
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spell_id); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(spell_id);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spell_id);
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) for(SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
{ {
SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(_spell_idx->second->skillId); SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(_spell_idx->second->skillId);
if(!pSkill) if (!pSkill)
continue; continue;
if(_spell_idx->second->learnOnGetSkill == ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL || if (_spell_idx->second->learnOnGetSkill == ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL ||
// lockpicking/runeforging special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL // lockpicking/runeforging special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
(pSkill->id==SKILL_LOCKPICKING || pSkill->id==SKILL_RUNEFORGING) && _spell_idx->second->max_value==0 ) (pSkill->id==SKILL_LOCKPICKING || pSkill->id==SKILL_RUNEFORGING) && _spell_idx->second->max_value==0 )
{ {
// not reset skills for professions and racial abilities // not reset skills for professions and racial abilities
if( (pSkill->categoryId==SKILL_CATEGORY_SECONDARY || pSkill->categoryId==SKILL_CATEGORY_PROFESSION) && if ((pSkill->categoryId==SKILL_CATEGORY_SECONDARY || pSkill->categoryId==SKILL_CATEGORY_PROFESSION) &&
(IsProfessionSkill(pSkill->id) || _spell_idx->second->racemask!=0) ) (IsProfessionSkill(pSkill->id) || _spell_idx->second->racemask!=0))
continue; continue;
SetSkill(pSkill->id, 0, 0 ); SetSkill(pSkill->id, 0, 0 );
@ -3283,43 +3280,42 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank)
} }
// remove dependent spells // remove dependent spells
SpellLearnSpellMap::const_iterator spell_begin = spellmgr.GetBeginSpellLearnSpell(spell_id); SpellLearnSpellMapBounds spell_bounds = spellmgr.GetSpellLearnSpellMapBounds(spell_id);
SpellLearnSpellMap::const_iterator spell_end = spellmgr.GetEndSpellLearnSpell(spell_id);
for(SpellLearnSpellMap::const_iterator itr2 = spell_begin; itr2 != spell_end; ++itr2) for(SpellLearnSpellMap::const_iterator itr2 = spell_bounds.first; itr2 != spell_bounds.second; ++itr2)
removeSpell(itr2->second.spell, disabled); removeSpell(itr2->second.spell, disabled);
// activate lesser rank in spellbook/action bar, and cast it if need // activate lesser rank in spellbook/action bar, and cast it if need
bool prev_activate = false; bool prev_activate = false;
if(uint32 prev_id = spellmgr.GetPrevSpellInChain (spell_id)) if (uint32 prev_id = spellmgr.GetPrevSpellInChain (spell_id))
{ {
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id); SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
// if talent then lesser rank also talent and need learn // if talent then lesser rank also talent and need learn
if(talentCosts) if (talentCosts)
{ {
if(learn_low_rank) if(learn_low_rank)
learnSpell (prev_id,false); learnSpell (prev_id,false);
} }
// if ranked non-stackable spell: need activate lesser rank and update dendence state // if ranked non-stackable spell: need activate lesser rank and update dendence state
else if(cur_active && !SpellMgr::canStackSpellRanks(spellInfo) && spellmgr.GetSpellRank(spellInfo->Id) != 0) else if (cur_active && !SpellMgr::canStackSpellRanks(spellInfo) && spellmgr.GetSpellRank(spellInfo->Id) != 0)
{ {
// need manually update dependence state (learn spell ignore like attempts) // need manually update dependence state (learn spell ignore like attempts)
PlayerSpellMap::iterator prev_itr = m_spells.find(prev_id); PlayerSpellMap::iterator prev_itr = m_spells.find(prev_id);
if (prev_itr != m_spells.end()) 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; prev_itr->second->dependent = cur_dependent;
if(prev_itr->second->state != PLAYERSPELL_NEW) if (prev_itr->second->state != PLAYERSPELL_NEW)
prev_itr->second->state = PLAYERSPELL_CHANGED; prev_itr->second->state = PLAYERSPELL_CHANGED;
} }
// now re-learn if need re-activate // 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 // downgrade spell ranks in spellbook and action bar
WorldPacket data(SMSG_SUPERCEDED_SPELL, 4 + 4); WorldPacket data(SMSG_SUPERCEDED_SPELL, 4 + 4);
@ -5043,20 +5039,19 @@ bool Player::UpdateCraftSkill(uint32 spellid)
{ {
sLog.outDebug("UpdateCraftSkill spellid %d", spellid); sLog.outDebug("UpdateCraftSkill spellid %d", spellid);
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellid); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(spellid);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellid);
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) for(SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
{ {
if(_spell_idx->second->skillId) if (_spell_idx->second->skillId)
{ {
uint32 SkillValue = GetPureSkillValue(_spell_idx->second->skillId); uint32 SkillValue = GetPureSkillValue(_spell_idx->second->skillId);
// Alchemy Discoveries here // Alchemy Discoveries here
SpellEntry const* spellEntry = sSpellStore.LookupEntry(spellid); SpellEntry const* spellEntry = sSpellStore.LookupEntry(spellid);
if(spellEntry && spellEntry->Mechanic==MECHANIC_DISCOVERY) if (spellEntry && spellEntry->Mechanic==MECHANIC_DISCOVERY)
{ {
if(uint32 discoveredSpell = GetSkillDiscoverySpell(_spell_idx->second->skillId, spellid, this)) if (uint32 discoveredSpell = GetSkillDiscoverySpell(_spell_idx->second->skillId, spellid, this))
learnSpell(discoveredSpell,false); learnSpell(discoveredSpell,false);
} }
@ -18584,19 +18579,18 @@ bool Player::IsSpellFitByClassAndRace( uint32 spell_id ) const
uint32 racemask = getRaceMask(); uint32 racemask = getRaceMask();
uint32 classmask = getClassMask(); uint32 classmask = getClassMask();
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spell_id); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(spell_id);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spell_id); if (bounds.first==bounds.second)
if(lower==upper)
return true; return true;
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) for(SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
{ {
// skip wrong race skills // skip wrong race skills
if( _spell_idx->second->racemask && (_spell_idx->second->racemask & racemask) == 0) if (_spell_idx->second->racemask && (_spell_idx->second->racemask & racemask) == 0)
continue; continue;
// skip wrong class skills // skip wrong class skills
if( _spell_idx->second->classmask && (_spell_idx->second->classmask & classmask) == 0) if (_spell_idx->second->classmask && (_spell_idx->second->classmask & classmask) == 0)
continue; continue;
return true; return true;

View file

@ -114,22 +114,19 @@ void LoadSkillDiscoveryTable()
SkillDiscoveryStore[reqSkillOrSpell].push_back( SkillDiscoveryEntry(spellId, reqSkillValue, chance) ); SkillDiscoveryStore[reqSkillOrSpell].push_back( SkillDiscoveryEntry(spellId, reqSkillValue, chance) );
} }
else if( reqSkillOrSpell == 0 ) // skill case else if (reqSkillOrSpell == 0) // skill case
{ {
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellId); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(spellId);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellId);
if(lower==upper) if (bounds.first==bounds.second)
{ {
sLog.outErrorDb("Spell (ID: %u) not listed in `SkillLineAbility.dbc` but listed with `reqSpell`=0 in `skill_discovery_template` table",spellId); sLog.outErrorDb("Spell (ID: %u) not listed in `SkillLineAbility.dbc` but listed with `reqSpell`=0 in `skill_discovery_template` table",spellId);
continue; continue;
} }
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) for(SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
{
SkillDiscoveryStore[-int32(_spell_idx->second->skillId)].push_back( SkillDiscoveryEntry(spellId, reqSkillValue, chance) ); SkillDiscoveryStore[-int32(_spell_idx->second->skillId)].push_back( SkillDiscoveryEntry(spellId, reqSkillValue, chance) );
} }
}
else else
{ {
sLog.outErrorDb("Spell (ID: %u) have negative value in `reqSpell` field in `skill_discovery_template` table",spellId); sLog.outErrorDb("Spell (ID: %u) have negative value in `reqSpell` field in `skill_discovery_template` table",spellId);
@ -143,21 +140,21 @@ void LoadSkillDiscoveryTable()
sLog.outString(); sLog.outString();
sLog.outString( ">> Loaded %u skill discovery definitions", count ); sLog.outString( ">> Loaded %u skill discovery definitions", count );
if(!ssNonDiscoverableEntries.str().empty()) if (!ssNonDiscoverableEntries.str().empty())
sLog.outErrorDb("Some items can't be successfully discovered: have in chance field value < 0.000001 in `skill_discovery_template` DB table . List:\n%s",ssNonDiscoverableEntries.str().c_str()); sLog.outErrorDb("Some items can't be successfully discovered: have in chance field value < 0.000001 in `skill_discovery_template` DB table . List:\n%s",ssNonDiscoverableEntries.str().c_str());
// report about empty data for explicit discovery spells // report about empty data for explicit discovery spells
for(uint32 spell_id = 1; spell_id < sSpellStore.GetNumRows(); ++spell_id) for(uint32 spell_id = 1; spell_id < sSpellStore.GetNumRows(); ++spell_id)
{ {
SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell_id); SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell_id);
if(!spellEntry) if (!spellEntry)
continue; continue;
// skip not explicit discovery spells // skip not explicit discovery spells
if (!IsExplicitDiscoverySpell(spellEntry)) if (!IsExplicitDiscoverySpell(spellEntry))
continue; continue;
if(SkillDiscoveryStore.find(spell_id)==SkillDiscoveryStore.end()) if (SkillDiscoveryStore.find(spell_id)==SkillDiscoveryStore.end())
sLog.outErrorDb("Spell (ID: %u) is 100%% chance random discovery ability but not have data in `skill_discovery_template` table",spell_id); sLog.outErrorDb("Spell (ID: %u) is 100%% chance random discovery ability but not have data in `skill_discovery_template` table",spell_id);
} }
} }
@ -170,9 +167,8 @@ uint32 GetExplicitDiscoverySpell(uint32 spellId, Player* player)
if (tab == SkillDiscoveryStore.end()) if (tab == SkillDiscoveryStore.end())
return 0; return 0;
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellId); SkillLineAbilityMapBounds bounds = spellmgr.GetSkillLineAbilityMapBounds(spellId);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellId); uint32 skillvalue = bounds.first != bounds.second ? player->GetSkillValue(bounds.first->second->skillId) : 0;
uint32 skillvalue = lower != upper ? player->GetSkillValue(lower->second->skillId) : 0;
float full_chance = 0; float full_chance = 0;
for(SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter) for(SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)

View file

@ -3966,15 +3966,15 @@ SpellCastResult Spell::CheckCast(bool strict)
} }
// Spell casted only on battleground // Spell casted only on battleground
if((m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_BATTLEGROUND) && m_caster->GetTypeId() == TYPEID_PLAYER) if ((m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_BATTLEGROUND) && m_caster->GetTypeId() == TYPEID_PLAYER)
if(!((Player*)m_caster)->InBattleGround()) if(!((Player*)m_caster)->InBattleGround())
return SPELL_FAILED_ONLY_BATTLEGROUNDS; return SPELL_FAILED_ONLY_BATTLEGROUNDS;
// do not allow spells to be cast in arenas // do not allow spells to be cast in arenas
// - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
// - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
if( (m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA) || if ((m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA) ||
GetSpellRecoveryTime(m_spellInfo) > 15 * MINUTE * IN_MILISECONDS && !(m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_USABLE_IN_ARENA) ) GetSpellRecoveryTime(m_spellInfo) > 15 * MINUTE * IN_MILISECONDS && !(m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_USABLE_IN_ARENA))
if(MapEntry const* mapEntry = sMapStore.LookupEntry(m_caster->GetMapId())) if(MapEntry const* mapEntry = sMapStore.LookupEntry(m_caster->GetMapId()))
if(mapEntry->IsBattleArena()) if(mapEntry->IsBattleArena())
return SPELL_FAILED_NOT_IN_ARENA; return SPELL_FAILED_NOT_IN_ARENA;
@ -3985,21 +3985,21 @@ SpellCastResult Spell::CheckCast(bool strict)
SpellCastResult locRes= spellmgr.GetSpellAllowedInLocationError(m_spellInfo,m_caster->GetMapId(),zone,area, SpellCastResult locRes= spellmgr.GetSpellAllowedInLocationError(m_spellInfo,m_caster->GetMapId(),zone,area,
m_caster->GetTypeId() == TYPEID_PLAYER ? ((Player*)m_caster) : NULL); m_caster->GetTypeId() == TYPEID_PLAYER ? ((Player*)m_caster) : NULL);
if(locRes != SPELL_CAST_OK) if (locRes != SPELL_CAST_OK)
return locRes; return locRes;
// not let players cast spells at mount (and let do it to creatures) // not let players cast spells at mount (and let do it to creatures)
if( m_caster->IsMounted() && m_caster->GetTypeId()==TYPEID_PLAYER && !m_IsTriggeredSpell && if (m_caster->IsMounted() && m_caster->GetTypeId()==TYPEID_PLAYER && !m_IsTriggeredSpell &&
!IsPassiveSpell(m_spellInfo->Id) && !(m_spellInfo->Attributes & SPELL_ATTR_CASTABLE_WHILE_MOUNTED) ) !IsPassiveSpell(m_spellInfo->Id) && !(m_spellInfo->Attributes & SPELL_ATTR_CASTABLE_WHILE_MOUNTED))
{ {
if(m_caster->isInFlight()) if (m_caster->isInFlight())
return SPELL_FAILED_NOT_FLYING; return SPELL_FAILED_NOT_FLYING;
else else
return SPELL_FAILED_NOT_MOUNTED; return SPELL_FAILED_NOT_MOUNTED;
} }
// always (except passive spells) check items (focus object can be required for any type casts) // always (except passive spells) check items (focus object can be required for any type casts)
if(!IsPassiveSpell(m_spellInfo->Id)) if (!IsPassiveSpell(m_spellInfo->Id))
{ {
SpellCastResult castResult = CheckItems(); SpellCastResult castResult = CheckItems();
if(castResult != SPELL_CAST_OK) if(castResult != SPELL_CAST_OK)
@ -4007,7 +4007,7 @@ SpellCastResult Spell::CheckCast(bool strict)
} }
//ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
if(m_UniqueTargetInfo.empty()) // skip second CheckCast apply (for delayed spells for example) if (m_UniqueTargetInfo.empty()) // skip second CheckCast apply (for delayed spells for example)
{ {
for(uint8 j = 0; j < 3; ++j) for(uint8 j = 0; j < 3; ++j)
{ {
@ -4016,9 +4016,8 @@ SpellCastResult Spell::CheckCast(bool strict)
m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT_COORDINATES || m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT_COORDINATES ||
m_spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT_COORDINATES ) m_spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT_COORDINATES )
{ {
SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(m_spellInfo->Id); SpellScriptTargetBounds bounds = spellmgr.GetSpellScriptTargetBounds(m_spellInfo->Id);
SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(m_spellInfo->Id); if(bounds.first==bounds.second)
if(lower==upper)
sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = TARGET_SCRIPT or TARGET_SCRIPT_COORDINATES, but does not have record in `spell_script_target`",m_spellInfo->Id); sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = TARGET_SCRIPT or TARGET_SCRIPT_COORDINATES, but does not have record in `spell_script_target`",m_spellInfo->Id);
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex); SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex);
@ -4027,7 +4026,7 @@ SpellCastResult Spell::CheckCast(bool strict)
Creature* creatureScriptTarget = NULL; Creature* creatureScriptTarget = NULL;
GameObject* goScriptTarget = NULL; GameObject* goScriptTarget = NULL;
for(SpellScriptTarget::const_iterator i_spellST = lower; i_spellST != upper; ++i_spellST) for(SpellScriptTarget::const_iterator i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST)
{ {
switch(i_spellST->second.type) switch(i_spellST->second.type)
{ {
@ -4035,7 +4034,7 @@ SpellCastResult Spell::CheckCast(bool strict)
{ {
GameObject* p_GameObject = NULL; GameObject* p_GameObject = NULL;
if(i_spellST->second.targetEntry) if (i_spellST->second.targetEntry)
{ {
CellPair p(MaNGOS::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); CellPair p(MaNGOS::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY()));
Cell cell(p); Cell cell(p);
@ -4048,7 +4047,7 @@ SpellCastResult Spell::CheckCast(bool strict)
CellLock<GridReadGuard> cell_lock(cell, p); CellLock<GridReadGuard> cell_lock(cell, p);
cell_lock->Visit(cell_lock, object_checker, *m_caster->GetMap()); cell_lock->Visit(cell_lock, object_checker, *m_caster->GetMap());
if(p_GameObject) if (p_GameObject)
{ {
// remember found target and range, next attempt will find more near target with another entry // remember found target and range, next attempt will find more near target with another entry
creatureScriptTarget = NULL; creatureScriptTarget = NULL;
@ -4056,10 +4055,10 @@ SpellCastResult Spell::CheckCast(bool strict)
range = go_check.GetLastRange(); range = go_check.GetLastRange();
} }
} }
else if( focusObject ) // Focus Object else if (focusObject) // Focus Object
{ {
float frange = m_caster->GetDistance(focusObject); float frange = m_caster->GetDistance(focusObject);
if(range >= frange) if (range >= frange)
{ {
creatureScriptTarget = NULL; creatureScriptTarget = NULL;
goScriptTarget = focusObject; goScriptTarget = focusObject;

View file

@ -1693,16 +1693,15 @@ bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const
bool SpellMgr::IsSkillBonusSpell(uint32 spellId) const bool SpellMgr::IsSkillBonusSpell(uint32 spellId) const
{ {
SkillLineAbilityMap::const_iterator lower = GetBeginSkillLineAbilityMap(spellId); SkillLineAbilityMapBounds bounds = GetSkillLineAbilityMapBounds(spellId);
SkillLineAbilityMap::const_iterator upper = GetEndSkillLineAbilityMap(spellId);
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) for(SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
{ {
SkillLineAbilityEntry const *pAbility = _spell_idx->second; SkillLineAbilityEntry const *pAbility = _spell_idx->second;
if (!pAbility || pAbility->learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL) if (!pAbility || pAbility->learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL)
continue; continue;
if(pAbility->req_skill_value > 0) if (pAbility->req_skill_value > 0)
return true; return true;
} }
@ -1964,7 +1963,7 @@ void SpellMgr::LoadSpellLearnSpells()
// 0 1 2 // 0 1 2
QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell"); QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
if(!result) if (!result)
{ {
barGoLink bar( 1 ); barGoLink bar( 1 );
bar.step(); bar.step();
@ -1990,19 +1989,19 @@ void SpellMgr::LoadSpellLearnSpells()
node.active = fields[2].GetBool(); node.active = fields[2].GetBool();
node.autoLearned= false; node.autoLearned= false;
if(!sSpellStore.LookupEntry(spell_id)) if (!sSpellStore.LookupEntry(spell_id))
{ {
sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id); sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id);
continue; continue;
} }
if(!sSpellStore.LookupEntry(node.spell)) if (!sSpellStore.LookupEntry(node.spell))
{ {
sLog.outErrorDb("Spell %u listed in `spell_learn_spell` learning not existed spell %u",spell_id,node.spell); sLog.outErrorDb("Spell %u listed in `spell_learn_spell` learning not existed spell %u",spell_id,node.spell);
continue; continue;
} }
if(GetTalentSpellCost(node.spell)) if (GetTalentSpellCost(node.spell))
{ {
sLog.outErrorDb("Spell %u listed in `spell_learn_spell` attempt learning talent spell %u, skipped",spell_id,node.spell); sLog.outErrorDb("Spell %u listed in `spell_learn_spell` attempt learning talent spell %u, skipped",spell_id,node.spell);
continue; continue;
@ -2021,7 +2020,7 @@ void SpellMgr::LoadSpellLearnSpells()
{ {
SpellEntry const* entry = sSpellStore.LookupEntry(spell); SpellEntry const* entry = sSpellStore.LookupEntry(spell);
if(!entry) if (!entry)
continue; continue;
for(int i = 0; i < 3; ++i) for(int i = 0; i < 3; ++i)
@ -2033,7 +2032,7 @@ void SpellMgr::LoadSpellLearnSpells()
dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself) dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself)
// ignore learning not existed spells (broken/outdated/or generic learnig spell 483 // ignore learning not existed spells (broken/outdated/or generic learnig spell 483
if(!sSpellStore.LookupEntry(dbc_node.spell)) if (!sSpellStore.LookupEntry(dbc_node.spell))
continue; continue;
// talent or passive spells or skill-step spells auto-casted and not need dependent learning, // talent or passive spells or skill-step spells auto-casted and not need dependent learning,
@ -2041,13 +2040,12 @@ void SpellMgr::LoadSpellLearnSpells()
// other required explicit dependent learning // other required explicit dependent learning
dbc_node.autoLearned = entry->EffectImplicitTargetA[i]==TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(spell) || IsSpellHaveEffect(entry,SPELL_EFFECT_SKILL_STEP); dbc_node.autoLearned = entry->EffectImplicitTargetA[i]==TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(spell) || IsSpellHaveEffect(entry,SPELL_EFFECT_SKILL_STEP);
SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell); SpellLearnSpellMapBounds db_node_bounds = GetSpellLearnSpellMapBounds(spell);
SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell);
bool found = false; bool found = false;
for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr) for(SpellLearnSpellMap::const_iterator itr = db_node_bounds.first; itr != db_node_bounds.second; ++itr)
{ {
if(itr->second.spell == dbc_node.spell) if (itr->second.spell == dbc_node.spell)
{ {
sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.", sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.",
spell,dbc_node.spell); spell,dbc_node.spell);
@ -2056,7 +2054,7 @@ void SpellMgr::LoadSpellLearnSpells()
} }
} }
if(!found) // add new spell-spell pair if not found if (!found) // add new spell-spell pair if not found
{ {
mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node)); mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node));
++dbc_count; ++dbc_count;

View file

@ -545,6 +545,7 @@ struct SpellTargetEntry
}; };
typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget; typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
typedef std::pair<SpellScriptTarget::const_iterator,SpellScriptTarget::const_iterator> SpellScriptTargetBounds;
// coordinates for spells (accessed using SpellMgr functions) // coordinates for spells (accessed using SpellMgr functions)
struct SpellTargetPosition struct SpellTargetPosition
@ -666,8 +667,10 @@ struct SpellLearnSpellNode
}; };
typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap; typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
typedef std::pair<SpellLearnSpellMap::const_iterator,SpellLearnSpellMap::const_iterator> SpellLearnSpellMapBounds;
typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap; typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
typedef std::pair<SkillLineAbilityMap::const_iterator,SkillLineAbilityMap::const_iterator> SkillLineAbilityMapBounds;
typedef std::multimap<uint32, uint32> PetLevelupSpellSet; typedef std::multimap<uint32, uint32> PetLevelupSpellSet;
typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap; typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap;
@ -883,22 +886,16 @@ class SpellMgr
return mSpellLearnSpells.find(spell_id) != mSpellLearnSpells.end(); return mSpellLearnSpells.find(spell_id) != mSpellLearnSpells.end();
} }
SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const SpellLearnSpellMapBounds GetSpellLearnSpellMapBounds(uint32 spell_id) const
{ {
return mSpellLearnSpells.lower_bound(spell_id); return SpellLearnSpellMapBounds(mSpellLearnSpells.lower_bound(spell_id),mSpellLearnSpells.upper_bound(spell_id));
}
SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
{
return mSpellLearnSpells.upper_bound(spell_id);
} }
bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
{ {
SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1); SpellLearnSpellMapBounds bounds = GetSpellLearnSpellMapBounds(spell_id1);
SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1); for(SpellLearnSpellMap::const_iterator i = bounds.first; i != bounds.second; ++i)
for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i) if (i->second.spell==spell_id2)
if(i->second.spell==spell_id2)
return true; return true;
return false; return false;
} }
@ -912,27 +909,17 @@ class SpellMgr
// Spell script targets // Spell script targets
SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const SpellScriptTargetBounds GetSpellScriptTargetBounds(uint32 spell_id) const
{ {
return mSpellScriptTarget.lower_bound(spell_id); return SpellScriptTargetBounds(mSpellScriptTarget.lower_bound(spell_id),mSpellScriptTarget.upper_bound(spell_id));
}
SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
{
return mSpellScriptTarget.upper_bound(spell_id);
} }
// Spell correctess for client using // Spell correctess for client using
static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true); static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const SkillLineAbilityMapBounds GetSkillLineAbilityMapBounds(uint32 spell_id) const
{ {
return mSkillLineAbilityMap.lower_bound(spell_id); return SkillLineAbilityMapBounds(mSkillLineAbilityMap.lower_bound(spell_id),mSkillLineAbilityMap.upper_bound(spell_id));
}
SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
{
return mSkillLineAbilityMap.upper_bound(spell_id);
} }
PetAura const* GetPetAura(uint32 spell_id, uint8 eff) PetAura const* GetPetAura(uint32 spell_id, uint8 eff)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "8425" #define REVISION_NR "8426"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__