diff options
Diffstat (limited to 'src/game/Pet.cpp')
-rw-r--r-- | src/game/Pet.cpp | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index ca4035e81b8..dabc366b874 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -272,26 +272,12 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool // Load action bar data if (!is_temporary_summoned) { - // permanent controlled pets store state in DB - Tokens tokens = StrSplit(fields[14].GetString(), " "); - - if (tokens.size() != 20) + if(!m_charmInfo->LoadActionBar(fields[14].GetCppString())) { delete result; return false; } - int index; - Tokens::iterator iter; - for(iter = tokens.begin(), index = 0; index < 10; ++iter, ++index ) - { - m_charmInfo->GetActionBarEntry(index)->Type = atol((*iter).c_str()); - ++iter; - m_charmInfo->GetActionBarEntry(index)->SpellOrAction = atol((*iter).c_str()); - if(m_charmInfo->GetActionBarEntry(index)->Type == ACT_ENABLED && !IsAutocastableSpell(m_charmInfo->GetActionBarEntry(index)->SpellOrAction)) - m_charmInfo->GetActionBarEntry(index)->Type = ACT_PASSIVE; - } - _LoadSpells(); _LoadSpellCooldowns(); LearnPetPassives(); @@ -300,6 +286,8 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool } } + CleanupActionBar(); // remove unknown spells from action bar after load + delete result; sLog.outDebug("New Pet has guid %u", GetGUIDLow()); @@ -326,8 +314,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool } } - //InitLevelupSpellsForLevel(); - m_loading = false; SynchronizeLevelWithOwner(); @@ -414,8 +400,12 @@ void Pet::SavePetToDB(PetSaveMode mode) << curmana << ", " << GetPower(POWER_HAPPINESS) << ", '"; - for(uint32 i = 0; i < 10; ++i) - ss << uint32(m_charmInfo->GetActionBarEntry(i)->Type) << " " << uint32(m_charmInfo->GetActionBarEntry(i)->SpellOrAction) << " "; + for(uint32 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i) + { + ss << uint32(m_charmInfo->GetActionBarEntry(i)->Type) << " " + << uint32(m_charmInfo->GetActionBarEntry(i)->SpellOrAction) << " "; + }; + ss << "', " << time(NULL) << ", " << uint32(m_resetTalentsCost) << ", " @@ -1267,7 +1257,7 @@ bool Pet::addSpell(uint32 spell_id,ActiveStates active /*= ACT_DECIDE*/, PetSpel // skip unknown ranks if(!HasSpell(rankSpellId)) continue; - removeSpell(rankSpellId,false); + removeSpell(rankSpellId,false,false); } } } @@ -1288,7 +1278,7 @@ bool Pet::addSpell(uint32 spell_id,ActiveStates active /*= ACT_DECIDE*/, PetSpel ToggleAutocast(itr2->first, false); oldspell_id = itr2->first; - unlearnSpell(itr2->first,false); + unlearnSpell(itr2->first,false,false); break; } // ignore new lesser rank @@ -1303,7 +1293,7 @@ bool Pet::addSpell(uint32 spell_id,ActiveStates active /*= ACT_DECIDE*/, PetSpel if (IsPassiveSpell(spell_id)) CastSpell(this, spell_id, true); else - m_charmInfo->AddSpellToAB(oldspell_id, spell_id); + m_charmInfo->AddSpellToActionBar(spell_id); if(newspell.active == ACT_ENABLED) ToggleAutocast(spell_id, true); @@ -1367,7 +1357,7 @@ void Pet::InitLevelupSpellsForLevel() // will called first if level down if(spellEntry->spellLevel > level) - unlearnSpell(spellEntry->Id,false); + unlearnSpell(spellEntry->Id,true); // will called if level up else learnSpell(spellEntry->Id); @@ -1375,9 +1365,9 @@ void Pet::InitLevelupSpellsForLevel() } } -bool Pet::unlearnSpell(uint32 spell_id, bool learn_prev) +bool Pet::unlearnSpell(uint32 spell_id, bool learn_prev, bool clear_ab) { - if(removeSpell(spell_id,learn_prev)) + if(removeSpell(spell_id,learn_prev,clear_ab)) { if(!m_loading) { @@ -1390,7 +1380,7 @@ bool Pet::unlearnSpell(uint32 spell_id, bool learn_prev) return false; } -bool Pet::removeSpell(uint32 spell_id, bool learn_prev) +bool Pet::removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab) { PetSpellMap::iterator itr = m_spells.find(spell_id); if (itr == m_spells.end()) @@ -1421,29 +1411,35 @@ bool Pet::removeSpell(uint32 spell_id, bool learn_prev) 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 learn_prev = false; } // if remove last rank or non-ranked then update action bar at server and client if need - if(!learn_prev && m_charmInfo->AddSpellToAB(spell_id, 0)) + if (clear_ab && !learn_prev && m_charmInfo->RemoveSpellFromActionBar(spell_id)) { - // need update action bar for last removed rank - if (Unit* owner = GetOwner()) - if (owner->GetTypeId() == TYPEID_PLAYER) - ((Player*)owner)->PetSpellInitialize(); + if(!m_loading) + { + // need update action bar for last removed rank + if (Unit* owner = GetOwner()) + if (owner->GetTypeId() == TYPEID_PLAYER) + ((Player*)owner)->PetSpellInitialize(); + } } return true; } + +void Pet::CleanupActionBar() +{ + for(int i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i) + if(UnitActionBarEntry const* ab = m_charmInfo->GetActionBarEntry(i)) + if(ab->SpellOrAction && ab->IsActionBarForSpell() && !HasSpell(ab->SpellOrAction)) + m_charmInfo->SetActionBar(i,0,ACT_DISABLED); +} + void Pet::InitPetCreateSpells() { m_charmInfo->InitPetActionBar(); |