Merge commit 'origin/master' into 310

Conflicts:
	src/game/Player.cpp
This commit is contained in:
tomrus88 2009-05-16 00:47:37 +04:00
commit 6734694a90
47 changed files with 740 additions and 524 deletions

View file

@ -58,11 +58,7 @@ m_declinedname(NULL)
Pet::~Pet()
{
if(m_uint32Values) // only for fully created Object
{
for (PetSpellMap::const_iterator i = m_spells.begin(); i != m_spells.end(); ++i)
delete i->second;
ObjectAccessor::Instance().RemoveObject(this);
}
delete m_declinedname;
}
@ -345,6 +341,8 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
}
m_loading = false;
SynchronizeLevelWithOwner();
return true;
}
@ -732,12 +730,11 @@ void Pet::GivePetXP(uint32 xp)
{
newXP -= nextLvlXP;
SetLevel( level + 1 );
GivePetLevel(level+1);
SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, objmgr.GetXPForLevel(level+1)/4);
level = getLevel();
nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP);
GivePetLevel(level);
}
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, newXP);
@ -940,7 +937,6 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
case HUNTER_PET:
{
SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, objmgr.GetXPForLevel(petlevel)/4);
learnLevelupSpells();
//these formula may not be correct; however, it is designed to be close to what it should be
//this makes dps 0.5 of pets level
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) );
@ -998,6 +994,9 @@ 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());
@ -1129,19 +1128,32 @@ void Pet::_LoadSpells()
void Pet::_SaveSpells()
{
for (PetSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next)
for (PetSpellMap::iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next)
{
++next;
if (itr->second->type == PETSPELL_FAMILY) continue; // prevent saving family passives to DB
if (itr->second->state == PETSPELL_REMOVED || itr->second->state == PETSPELL_CHANGED)
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
if (itr->second->state == PETSPELL_NEW || itr->second->state == PETSPELL_CHANGED)
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second->active);
if (itr->second->state == PETSPELL_REMOVED)
_removeSpell(itr->first);
else
itr->second->state = PETSPELL_UNCHANGED;
// prevent saving family passives to DB
if (itr->second.type == PETSPELL_FAMILY)
continue;
switch(itr->second.state)
{
case PETSPELL_REMOVED:
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
m_spells.erase(itr);
continue;
case PETSPELL_CHANGED:
CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first);
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second.active);
break;
case PETSPELL_NEW:
CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,active) VALUES ('%u', '%u', '%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second.active);
break;
case PETSPELL_UNCHANGED:
continue;
}
itr->second.state = PETSPELL_UNCHANGED;
}
}
@ -1272,7 +1284,7 @@ void Pet::_SaveAuras()
}
}
bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpellType type)
bool Pet::addSpell(uint32 spell_id,uint16 active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/)
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
if (!spellInfo)
@ -1292,16 +1304,15 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
PetSpellMap::iterator itr = m_spells.find(spell_id);
if (itr != m_spells.end())
{
if (itr->second->state == PETSPELL_REMOVED)
if (itr->second.state == PETSPELL_REMOVED)
{
delete itr->second;
m_spells.erase(itr);
state = PETSPELL_CHANGED;
}
else if (state == PETSPELL_UNCHANGED && itr->second->state != PETSPELL_UNCHANGED)
else if (state == PETSPELL_UNCHANGED && itr->second.state != PETSPELL_UNCHANGED)
{
// can be in case spell loading but learned at some previous spell loading
itr->second->state = PETSPELL_UNCHANGED;
itr->second.state = PETSPELL_UNCHANGED;
if(active == ACT_ENABLED)
ToggleAutocast(spell_id, true);
@ -1316,19 +1327,19 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
uint32 oldspell_id = 0;
PetSpell *newspell = new PetSpell;
newspell->state = state;
newspell->type = type;
PetSpell newspell;
newspell.state = state;
newspell.type = type;
if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here
{
if(IsPassiveSpell(spell_id))
newspell->active = ACT_PASSIVE;
newspell.active = ACT_PASSIVE;
else
newspell->active = ACT_DISABLED;
newspell.active = ACT_DISABLED;
}
else
newspell->active = active;
newspell.active = active;
// talent: unlearn all other talent ranks (high and low)
if(TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id))
@ -1353,13 +1364,13 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
{
for (PetSpellMap::const_iterator itr2 = m_spells.begin(); itr2 != m_spells.end(); ++itr2)
{
if(itr2->second->state == PETSPELL_REMOVED) continue;
if(itr2->second.state == PETSPELL_REMOVED) continue;
if(spellmgr.GetFirstSpellInChain(itr2->first) == chainstart)
{
newspell->active = itr2->second->active;
newspell.active = itr2->second.active;
if(newspell->active == ACT_ENABLED)
if(newspell.active == ACT_ENABLED)
ToggleAutocast(itr2->first, false);
oldspell_id = itr2->first;
@ -1376,7 +1387,7 @@ bool Pet::addSpell(uint32 spell_id, uint16 active, PetSpellState state, PetSpell
else if(state == PETSPELL_NEW)
m_charmInfo->AddSpellToAB(oldspell_id, spell_id);
if(newspell->active == ACT_ENABLED)
if(newspell.active == ACT_ENABLED)
ToggleAutocast(spell_id, true);
uint32 talentCost = GetTalentSpellCost(spell_id);
@ -1452,16 +1463,13 @@ bool Pet::removeSpell(uint32 spell_id)
if (itr == m_spells.end())
return false;
if(itr->second->state == PETSPELL_REMOVED)
if(itr->second.state == PETSPELL_REMOVED)
return false;
if(itr->second->state == PETSPELL_NEW)
{
delete itr->second;
if(itr->second.state == PETSPELL_NEW)
m_spells.erase(itr);
}
else
itr->second->state = PETSPELL_REMOVED;
itr->second.state = PETSPELL_REMOVED;
RemoveAurasDueToSpell(spell_id);
@ -1480,24 +1488,9 @@ bool Pet::removeSpell(uint32 spell_id)
return true;
}
bool Pet::_removeSpell(uint32 spell_id)
{
PetSpellMap::iterator itr = m_spells.find(spell_id);
if (itr != m_spells.end())
{
delete itr->second;
m_spells.erase(itr);
return true;
}
return false;
}
void Pet::InitPetCreateSpells()
{
m_charmInfo->InitPetActionBar();
for (PetSpellMap::const_iterator i = m_spells.begin(); i != m_spells.end(); ++i)
delete i->second;
m_spells.clear();
uint32 petspellid;
@ -1616,7 +1609,7 @@ bool Pet::resetTalents(bool no_cost)
{
for(PetSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end();)
{
if(itr->second->state == PETSPELL_REMOVED)
if(itr->second.state == PETSPELL_REMOVED)
{
++itr;
continue;
@ -1701,7 +1694,7 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
if(IsPassiveSpell(spellid))
return;
PetSpellMap::const_iterator itr = m_spells.find(spellid);
PetSpellMap::iterator itr = m_spells.find(spellid);
int i;
@ -1714,11 +1707,11 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
{
m_autospells.push_back(spellid);
if(itr->second->active != ACT_ENABLED)
if(itr->second.active != ACT_ENABLED)
{
itr->second->active = ACT_ENABLED;
if(itr->second->state != PETSPELL_NEW)
itr->second->state = PETSPELL_CHANGED;
itr->second.active = ACT_ENABLED;
if(itr->second.state != PETSPELL_NEW)
itr->second.state = PETSPELL_CHANGED;
}
}
}
@ -1731,11 +1724,11 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply)
if (i < m_autospells.size())
{
m_autospells.erase(itr2);
if(itr->second->active != ACT_DISABLED)
if(itr->second.active != ACT_DISABLED)
{
itr->second->active = ACT_DISABLED;
if(itr->second->state != PETSPELL_NEW)
itr->second->state = PETSPELL_CHANGED;
itr->second.active = ACT_DISABLED;
if(itr->second.state != PETSPELL_NEW)
itr->second.state = PETSPELL_CHANGED;
}
}
}
@ -1787,7 +1780,7 @@ bool Pet::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint3
bool Pet::HasSpell(uint32 spell) const
{
PetSpellMap::const_iterator itr = m_spells.find(spell);
return (itr != m_spells.end() && itr->second->state != PETSPELL_REMOVED );
return (itr != m_spells.end() && itr->second.state != PETSPELL_REMOVED );
}
// Get all passive spells in our skill line
@ -1853,3 +1846,29 @@ void Pet::learnSpellHighRank(uint32 spellid)
for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
learnSpellHighRank(itr->second);
}
void Pet::SynchronizeLevelWithOwner()
{
Unit* owner = GetOwner();
if (!owner || owner->GetTypeId() != TYPEID_PLAYER)
return;
switch(getPetType())
{
// always same level
case SUMMON_PET:
GivePetLevel(owner->getLevel());
break;
// can't be greater owner level
case HUNTER_PET:
if(getLevel() > owner->getLevel())
{
GivePetLevel(owner->getLevel());
SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, objmgr.GetXPForLevel(owner->getLevel())/4);
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP)-1);
}
break;
default:
break;
}
}