[7160] Implement (un-)learning skill level dependent spells at skill level change.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>

Some related cleanups using new functionality.
This commit is contained in:
yad02 2009-01-24 12:07:28 +03:00 committed by VladimirMangos
parent bbf8fd0742
commit 94d064be6f
3 changed files with 30 additions and 28 deletions

View file

@ -4866,6 +4866,11 @@ bool Player::UpdateFishingSkill()
return UpdateSkillPro(SKILL_FISHING,chance*10,gathering_skill_gain); return UpdateSkillPro(SKILL_FISHING,chance*10,gathering_skill_gain);
} }
// levels sync. with spell requirement for skill levels to learn
// bonus abilities in sSkillLineAbilityStore
// Used only to avoid scan DBC at each skill grow
static uint32 bonusSkillLevels[] = {75,150,225,300,375,450};
bool Player::UpdateSkillPro(uint16 SkillId, int32 Chance, uint32 step) bool Player::UpdateSkillPro(uint16 SkillId, int32 Chance, uint32 step)
{ {
sLog.outDebug("UpdateSkillPro(SkillId %d, Chance %3.1f%%)", SkillId, Chance/10.0); sLog.outDebug("UpdateSkillPro(SkillId %d, Chance %3.1f%%)", SkillId, Chance/10.0);
@ -4900,6 +4905,14 @@ bool Player::UpdateSkillPro(uint16 SkillId, int32 Chance, uint32 step)
new_value = MaxValue; new_value = MaxValue;
SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i),MAKE_SKILL_VALUE(new_value,MaxValue)); SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i),MAKE_SKILL_VALUE(new_value,MaxValue));
for(uint32* bsl = &bonusSkillLevels[0]; *bsl; ++bsl)
{
if((SkillValue < *bsl && new_value >= *bsl))
{
learnSkillRewardedSpells( SkillId, new_value);
break;
}
}
GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL); GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL);
sLog.outDebug("Player::UpdateSkillPro Chance=%3.1f%% taken", Chance/10.0); sLog.outDebug("Player::UpdateSkillPro Chance=%3.1f%% taken", Chance/10.0);
return true; return true;
@ -5076,6 +5089,7 @@ void Player::SetSkill(uint32 id, uint16 currVal, uint16 maxVal)
if(currVal) if(currVal)
{ {
SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i),MAKE_SKILL_VALUE(currVal,maxVal)); SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i),MAKE_SKILL_VALUE(currVal,maxVal));
learnSkillRewardedSpells(id, currVal);
GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL); GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL);
} }
else //remove else //remove
@ -5086,26 +5100,7 @@ void Player::SetSkill(uint32 id, uint16 currVal, uint16 maxVal)
SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i),0); SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i),0);
// remove spells that depend on this skill when removing the skill // remove spells that depend on this skill when removing the skill
for (PlayerSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next) learnSkillRewardedSpells(id, 0);
{
++next;
if(itr->second->state == PLAYERSPELL_REMOVED)
continue;
SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(itr->first);
SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(itr->first);
for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
{
if (_spell_idx->second->skillId == id)
{
// this may remove more than one spell (dependents)
removeSpell(itr->first);
next = m_spells.begin();
break;
}
}
}
} }
} }
else if(currVal) //add else if(currVal) //add
@ -5143,7 +5138,7 @@ void Player::SetSkill(uint32 id, uint16 currVal, uint16 maxVal)
(*i)->ApplyModifier(true); (*i)->ApplyModifier(true);
// Learn all spells for skill // Learn all spells for skill
learnSkillRewardedSpells(id); learnSkillRewardedSpells(id, currVal);
return; return;
} }
} }
@ -18327,7 +18322,7 @@ void Player::learnQuestRewardedSpells()
} }
} }
void Player::learnSkillRewardedSpells(uint32 skill_id ) void Player::learnSkillRewardedSpells(uint32 skill_id, uint32 skill_value )
{ {
uint32 raceMask = getRaceMask(); uint32 raceMask = getRaceMask();
uint32 classMask = getClassMask(); uint32 classMask = getClassMask();
@ -18345,8 +18340,14 @@ void Player::learnSkillRewardedSpells(uint32 skill_id )
if (sSpellStore.LookupEntry(pAbility->spellId)) if (sSpellStore.LookupEntry(pAbility->spellId))
{ {
// Ok need learn dependent spell // need unlearn spell
learnSpell(pAbility->spellId,true); if (skill_value < pAbility->req_skill_value)
removeSpell(pAbility->spellId);
// need learn
else if (!IsInWorld())
addSpell(pAbility->spellId,true,true,true,false);
else
learnSpell(pAbility->spellId,true);
} }
} }
} }
@ -18358,9 +18359,10 @@ void Player::learnSkillRewardedSpells()
if(!GetUInt32Value(PLAYER_SKILL_INDEX(i))) if(!GetUInt32Value(PLAYER_SKILL_INDEX(i)))
continue; continue;
uint32 pskill = GetUInt32Value(PLAYER_SKILL_INDEX(i)) & 0x0000FFFF; uint32 pskill = SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_INDEX(i)));
uint32 vskill = SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i)));
learnSkillRewardedSpells(pskill); learnSkillRewardedSpells(pskill, vskill);
} }
} }

View file

@ -1770,7 +1770,7 @@ class MANGOS_DLL_SPEC Player : public Unit
int16 GetSkillPermBonusValue(uint32 skill) const; int16 GetSkillPermBonusValue(uint32 skill) const;
int16 GetSkillTempBonusValue(uint32 skill) const; int16 GetSkillTempBonusValue(uint32 skill) const;
bool HasSkill(uint32 skill) const; bool HasSkill(uint32 skill) const;
void learnSkillRewardedSpells(uint32 id); void learnSkillRewardedSpells(uint32 id, uint32 value);
void learnSkillRewardedSpells(); void learnSkillRewardedSpells();
void SetDontMove(bool dontMove); void SetDontMove(bool dontMove);

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 "7159" #define REVISION_NR "7160"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__