Merge branch 'master' into 310

Conflicts:
	src/game/Player.cpp
This commit is contained in:
tomrus88 2009-05-28 10:16:02 +04:00
commit f6e2b55e2c
25 changed files with 382 additions and 240 deletions

View file

@ -10281,28 +10281,18 @@ void CharmInfo::InitPetActionBar()
// the first 3 SpellOrActions are attack, follow and stay
for(uint32 i = 0; i < 3; ++i)
{
PetActionBar[i].Type = ACT_COMMAND;
PetActionBar[i].SpellOrAction = COMMAND_ATTACK - i;
PetActionBar[i + 7].Type = ACT_REACTION;
PetActionBar[i + 7].SpellOrAction = COMMAND_ATTACK - i;
}
for(uint32 i=0; i < 4; ++i)
{
PetActionBar[i + 3].Type = ACT_DISABLED;
PetActionBar[i + 3].SpellOrAction = 0;
SetActionBar(i,COMMAND_ATTACK - i,ACT_COMMAND);
SetActionBar(i + 7,COMMAND_ATTACK - i,ACT_REACTION);
}
for(uint32 i = 0; i < 4; ++i)
SetActionBar(i,0,ACT_DISABLED);
}
void CharmInfo::InitEmptyActionBar()
{
for(uint32 x = 1; x < 10; ++x)
{
PetActionBar[x].Type = ACT_PASSIVE;
PetActionBar[x].SpellOrAction = 0;
}
PetActionBar[0].Type = ACT_COMMAND;
PetActionBar[0].SpellOrAction = COMMAND_ATTACK;
SetActionBar(0,COMMAND_ATTACK,ACT_COMMAND);
for(uint32 x = 1; x < MAX_UNIT_ACTION_BAR_INDEX; ++x)
SetActionBar(x,0,ACT_PASSIVE);
}
void CharmInfo::InitPossessCreateSpells()
@ -10317,7 +10307,7 @@ void CharmInfo::InitPossessCreateSpells()
if (IsPassiveSpell(((Creature*)m_unit)->m_spells[x]))
m_unit->CastSpell(m_unit, ((Creature*)m_unit)->m_spells[x], true);
else
AddSpellToAB(0, ((Creature*)m_unit)->m_spells[x], ACT_PASSIVE);
AddSpellToActionBar(((Creature*)m_unit)->m_spells[x], ACT_PASSIVE);
}
}
@ -10362,39 +10352,56 @@ void CharmInfo::InitCharmCreateSpells()
else
newstate = ACT_PASSIVE;
AddSpellToAB(0, spellId, newstate);
AddSpellToActionBar(spellId, newstate);
}
}
}
bool CharmInfo::AddSpellToAB(uint32 oldid, uint32 newid, ActiveStates newstate)
bool CharmInfo::AddSpellToActionBar(uint32 spell_id, ActiveStates newstate)
{
// new spell already listed for example in case prepered switch to lesser rank in Pet::removeSpell
for(uint8 i = 0; i < 10; ++i)
if (PetActionBar[i].Type == ACT_DISABLED || PetActionBar[i].Type == ACT_ENABLED || PetActionBar[i].Type == ACT_PASSIVE)
if (newid && PetActionBar[i].SpellOrAction == newid)
return true;
uint32 first_id = spellmgr.GetFirstSpellInChain(spell_id);
// old spell can be leasted for example in case learn high rank
for(uint8 i = 0; i < 10; ++i)
// new spell rank can be already listed
for(uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if (PetActionBar[i].Type == ACT_DISABLED || PetActionBar[i].Type == ACT_ENABLED || PetActionBar[i].Type == ACT_PASSIVE)
if (PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
{
if (PetActionBar[i].SpellOrAction == oldid)
if (spellmgr.GetFirstSpellInChain(PetActionBar[i].SpellOrAction) == first_id)
{
PetActionBar[i].SpellOrAction = newid;
if (!oldid)
{
if (newstate == ACT_DECIDE)
PetActionBar[i].Type = ACT_DISABLED;
else
PetActionBar[i].Type = newstate;
}
PetActionBar[i].SpellOrAction = spell_id;
return true;
}
}
}
// or use empty slot in other case
for(uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if (!PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
{
SetActionBar(i,spell_id,newstate == ACT_DECIDE ? ACT_DISABLED : newstate);
return true;
}
}
return false;
}
bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id)
{
uint32 first_id = spellmgr.GetFirstSpellInChain(spell_id);
for(uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if (PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
{
if (spellmgr.GetFirstSpellInChain(PetActionBar[i].SpellOrAction) == first_id)
{
SetActionBar(i,0,ACT_DISABLED);
return true;
}
}
}
return false;
}
@ -10421,6 +10428,50 @@ void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow)
m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0);
}
bool CharmInfo::LoadActionBar( std::string data )
{
Tokens tokens = StrSplit(data, " ");
if (tokens.size() != MAX_UNIT_ACTION_BAR_INDEX*2)
return false;
int index;
Tokens::iterator iter;
for(iter = tokens.begin(), index = 0; index < MAX_UNIT_ACTION_BAR_INDEX; ++iter, ++index )
{
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
PetActionBar[index].Type = atol((*iter).c_str());
++iter;
PetActionBar[index].SpellOrAction = atol((*iter).c_str());
// check correctness
if(PetActionBar[index].IsActionBarForSpell() && !sSpellStore.LookupEntry(PetActionBar[index].SpellOrAction))
SetActionBar(index,0,ACT_DISABLED);
}
return true;
}
void CharmInfo::BuildActionBar( WorldPacket* data )
{
for(uint32 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
*data << uint16(PetActionBar[i].SpellOrAction);
*data << uint16(PetActionBar[i].Type);
}
}
void CharmInfo::SetSpellAutocast( uint32 spell_id, bool state )
{
for(int i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if(spell_id == PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
{
PetActionBar[i].Type = state ? ACT_ENABLED : ACT_DISABLED;
break;
}
}
}
bool Unit::isFrozen() const
{
return HasAuraState(AURA_STATE_FROZEN);