Merge commit 'origin/master' into 310

Hope it works with live 3.1.2.9901 client
This commit is contained in:
tomrus88 2009-05-20 10:47:48 +04:00
commit ebb03b7b9f
32 changed files with 1709 additions and 2123 deletions

View file

@ -340,6 +340,8 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
}
}
InitLevelupSpellsForLevel();
m_loading = false;
SynchronizeLevelWithOwner();
@ -653,6 +655,9 @@ bool Pet::CanTakeMoreActiveSpells(uint32 spellid)
for (PetSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
{
if(itr->second.state == PETSPELL_REMOVED)
continue;
if(IsPassiveSpell(itr->first))
continue;
@ -746,6 +751,7 @@ void Pet::GivePetLevel(uint32 level)
return;
InitStatsForLevel(level);
InitLevelupSpellsForLevel();
InitTalentForLevel();
}
@ -847,7 +853,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
else if (getLevel() <= cFamily->minScaleLevel)
scale = cFamily->minScale;
else
scale = cFamily->minScale + (getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale);
scale = cFamily->minScale + float(getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale);
SetFloatValue(OBJECT_FIELD_SCALE_X, scale);
}
@ -994,9 +1000,6 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
SetModifierValue(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(createResistance[i]));
if(cinfo->family)
learnLevelupSpells();
UpdateAllStats();
SetHealth(GetMaxHealth());
@ -1118,7 +1121,7 @@ void Pet::_LoadSpells()
{
Field *fields = result->Fetch();
addSpell(fields[0].GetUInt32(), fields[1].GetUInt16(), PETSPELL_UNCHANGED);
addSpell(fields[0].GetUInt32(), ActiveStates(fields[1].GetUInt16()), PETSPELL_UNCHANGED);
}
while( result->NextRow() );
@ -1284,7 +1287,7 @@ void Pet::_SaveAuras()
}
}
bool Pet::addSpell(uint32 spell_id,uint16 active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/)
bool Pet::addSpell(uint32 spell_id,ActiveStates active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/)
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
if (!spellInfo)
@ -1356,26 +1359,33 @@ bool Pet::addSpell(uint32 spell_id,uint16 active /*= ACT_DECIDE*/, PetSpellState
// skip unknown ranks
if(!HasSpell(rankSpellId))
continue;
removeSpell(rankSpellId);
removeSpell(rankSpellId,false);
}
}
}
else if(uint32 chainstart = spellmgr.GetFirstSpellInChain(spell_id))
else if(spellmgr.GetSpellRank(spell_id)!=0)
{
for (PetSpellMap::const_iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2)
{
if(itr2->second.state == PETSPELL_REMOVED) continue;
if(spellmgr.GetFirstSpellInChain(itr2->first) == chainstart)
if( spellmgr.IsRankSpellDueToSpell(spellInfo,itr2->first) )
{
newspell.active = itr2->second.active;
// replace by new high rank
if(spellmgr.IsHighRankOfSpell(spell_id,itr2->first))
{
newspell.active = itr2->second.active;
if(newspell.active == ACT_ENABLED)
ToggleAutocast(itr2->first, false);
if(newspell.active == ACT_ENABLED)
ToggleAutocast(itr2->first, false);
oldspell_id = itr2->first;
unlearnSpell(itr2->first);
break;
oldspell_id = itr2->first;
unlearnSpell(itr2->first,false);
break;
}
// ignore new lesser rank
else if(spellmgr.IsHighRankOfSpell(itr2->first,spell_id))
return false;
}
}
}
@ -1384,7 +1394,7 @@ bool Pet::addSpell(uint32 spell_id,uint16 active /*= ACT_DECIDE*/, PetSpellState
if (IsPassiveSpell(spell_id))
CastSpell(this, spell_id, true);
else if(state == PETSPELL_NEW)
else
m_charmInfo->AddSpellToAB(oldspell_id, spell_id);
if(newspell.active == ACT_ENABLED)
@ -1422,26 +1432,33 @@ bool Pet::learnSpell(uint32 spell_id)
return true;
}
void Pet::learnLevelupSpells()
void Pet::InitLevelupSpellsForLevel()
{
PetLevelupSpellSet const *levelupSpells = spellmgr.GetPetLevelupSpellList(GetCreatureInfo()->family);
uint32 family = GetCreatureInfo()->family;
if(!family)
return;
PetLevelupSpellSet const *levelupSpells = spellmgr.GetPetLevelupSpellList(family);
if(!levelupSpells)
return;
uint32 level = getLevel();
for(PetLevelupSpellSet::const_iterator itr = levelupSpells->begin(); itr != levelupSpells->end(); ++itr)
// PetLevelupSpellSet ordered by levels, process in reversed order
for(PetLevelupSpellSet::const_reverse_iterator itr = levelupSpells->rbegin(); itr != levelupSpells->rend(); ++itr)
{
if(itr->first <= level)
learnSpell(itr->second);
// will called first if level down
if(itr->first > level)
unlearnSpell(itr->second,true); // will learn prev rank if any
// will called if level up
else
unlearnSpell(itr->second);
learnSpell(itr->second); // will unlearn prev rank if any
}
}
bool Pet::unlearnSpell(uint32 spell_id)
bool Pet::unlearnSpell(uint32 spell_id, bool learn_prev)
{
if(removeSpell(spell_id))
if(removeSpell(spell_id,learn_prev))
{
if(GetOwner()->GetTypeId() == TYPEID_PLAYER)
{
@ -1457,7 +1474,7 @@ bool Pet::unlearnSpell(uint32 spell_id)
return false;
}
bool Pet::removeSpell(uint32 spell_id)
bool Pet::removeSpell(uint32 spell_id, bool learn_prev)
{
PetSpellMap::iterator itr = m_spells.find(spell_id);
if (itr == m_spells.end())
@ -1485,6 +1502,27 @@ bool Pet::removeSpell(uint32 spell_id)
SetFreeTalentPoints(free_points > 0 ? free_points : 0);
}
if (learn_prev)
{
if (uint32 prev_id = spellmgr.GetPrevSpellInChain (spell_id))
{
// replace to next spell
if(!talentCost && !IsPassiveSpell(prev_id))
m_charmInfo->AddSpellToAB(spell_id, prev_id);
learnSpell(prev_id);
}
else
{
m_charmInfo->AddSpellToAB(spell_id, 0);
// need update action bar for last removed rank
if (Unit* owner = GetOwner())
if (owner->GetTypeId() == TYPEID_PLAYER)
((Player*)owner)->PetSpellInitialize();
}
}
return true;
}
@ -1620,7 +1658,7 @@ bool Pet::resetTalents(bool no_cost)
// unlearn if first rank is talent or learned by talent
if (itrFirstId == talentInfo->RankID[j] || spellmgr.IsSpellLearnToSpell(talentInfo->RankID[j],itrFirstId))
{
removeSpell(itr->first);
removeSpell(itr->first,false);
itr = m_spells.begin();
continue;
}