PetAI - Overhaul / bug fix

* Aggressive pets now use aggro radius check based on level diff of target
  * Aggro radius limited to max 45 yards (per wowwiki)
  * Pets no longer "dance" when fighting a creature
  * Pets returning will defend themselves (if not passive) if owner didn't click "follow"
  * Pets at stay will properly pick up their owner's attackers that pass within range
  * Fix "no empty line at end of file" warning in PetAI
  * Fix typo in GetAggroRange()
  * Fix spell "Eyes of the Beast" - player can move pet freely
  * Code style cleanup

  * Update commit comment

Closes #8398, #7455
This commit is contained in:
MrSmite committed 2012-12-07 22:13:57 -05:00
1 parent b9442f3773
commit 777b287dff
12 files changed
+343 -162

No files matched your search

+58 -44
View File
@@ -551,18 +551,22 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
if (IsAIEnabled)
GetAI()->DamageDealt(victim, damage, damagetype);
if (victim->GetTypeId() == TYPEID_PLAYER)
if (victim->GetTypeId() == TYPEID_PLAYER && this != victim)
{
if (victim->ToPlayer()->GetCommandStatus(CHEAT_GOD))
return 0;
// Signal to pets that their owner was attacked
Pet* pet = victim->ToPlayer()->GetPet();
if (pet && pet->isAlive())
pet->AI()->OwnerDamagedBy(this);
pet->AI()->OwnerAttackedBy(this);
if (victim->ToPlayer()->GetCommandStatus(CHEAT_GOD))
return 0;
}
// Signal the pet it was attacked so the AI can respond if needed
if (victim->GetTypeId() == TYPEID_UNIT && this != victim && victim->isPet() && victim->isAlive())
victim->ToPet()->AI()->AttackedBy(this);
if (damagetype != NODAMAGE)
{
// interrupting auras with AURA_INTERRUPT_FLAG_DAMAGE before checking !damage (absorbed damage breaks that type of auras)
@@ -13948,17 +13952,17 @@ void Unit::DeleteCharmInfo()
}
CharmInfo::CharmInfo(Unit* unit)
: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_petnumber(0), m_barInit(false),
m_isCommandAttack(false), m_isAtStay(false), m_isFollowing(false), m_isReturning(false),
m_stayX(0.0f), m_stayY(0.0f), m_stayZ(0.0f)
: _unit(unit), _CommandState(COMMAND_FOLLOW), _petnumber(0), _barInit(false),
_isCommandAttack(false), _isAtStay(false), _isFollowing(false), _isReturning(false),
_stayX(0.0f), _stayY(0.0f), _stayZ(0.0f)
{
for (uint8 i = 0; i < MAX_SPELL_CHARM; ++i)
m_charmspells[i].SetActionAndType(0, ACT_DISABLED);
_charmspells[i].SetActionAndType(0, ACT_DISABLED);
if (m_unit->GetTypeId() == TYPEID_UNIT)
if (_unit->GetTypeId() == TYPEID_UNIT)
{
m_oldReactState = m_unit->ToCreature()->GetReactState();
m_unit->ToCreature()->SetReactState(REACT_PASSIVE);
_oldReactState = _unit->ToCreature()->GetReactState();
_unit->ToCreature()->SetReactState(REACT_PASSIVE);
}
}
@@ -13968,9 +13972,9 @@ CharmInfo::~CharmInfo()
void CharmInfo::RestoreState()
{
if (m_unit->GetTypeId() == TYPEID_UNIT)
if (Creature* creature = m_unit->ToCreature())
creature->SetReactState(m_oldReactState);
if (_unit->GetTypeId() == TYPEID_UNIT)
if (Creature* creature = _unit->ToCreature())
creature->SetReactState(_oldReactState);
}
void CharmInfo::InitPetActionBar()
@@ -14001,16 +14005,16 @@ void CharmInfo::InitEmptyActionBar(bool withAttack)
void CharmInfo::InitPossessCreateSpells()
{
InitEmptyActionBar();
if (m_unit->GetTypeId() == TYPEID_UNIT)
if (_unit->GetTypeId() == TYPEID_UNIT)
{
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
{
uint32 spellId = m_unit->ToCreature()->m_spells[i];
uint32 spellId = _unit->ToCreature()->m_spells[i];
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (spellInfo && !(spellInfo->Attributes & SPELL_ATTR0_CASTABLE_WHILE_DEAD))
{
if (spellInfo->IsPassive())
m_unit->CastSpell(m_unit, spellInfo, true);
_unit->CastSpell(_unit, spellInfo, true);
else
AddSpellToActionBar(spellInfo, ACT_PASSIVE);
}
@@ -14020,7 +14024,7 @@ void CharmInfo::InitPossessCreateSpells()
void CharmInfo::InitCharmCreateSpells()
{
if (m_unit->GetTypeId() == TYPEID_PLAYER) // charmed players don't have spells
if (_unit->GetTypeId() == TYPEID_PLAYER) // charmed players don't have spells
{
InitEmptyActionBar();
return;
@@ -14030,23 +14034,23 @@ void CharmInfo::InitCharmCreateSpells()
for (uint32 x = 0; x < MAX_SPELL_CHARM; ++x)
{
uint32 spellId = m_unit->ToCreature()->m_spells[x];
uint32 spellId = _unit->ToCreature()->m_spells[x];
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo || spellInfo->Attributes & SPELL_ATTR0_CASTABLE_WHILE_DEAD)
{
m_charmspells[x].SetActionAndType(spellId, ACT_DISABLED);
_charmspells[x].SetActionAndType(spellId, ACT_DISABLED);
continue;
}
if (spellInfo->IsPassive())
{
m_unit->CastSpell(m_unit, spellInfo, true);
m_charmspells[x].SetActionAndType(spellId, ACT_PASSIVE);
_unit->CastSpell(_unit, spellInfo, true);
_charmspells[x].SetActionAndType(spellId, ACT_PASSIVE);
}
else
{
m_charmspells[x].SetActionAndType(spellId, ACT_DISABLED);
_charmspells[x].SetActionAndType(spellId, ACT_DISABLED);
ActiveStates newstate = ACT_PASSIVE;
@@ -14123,17 +14127,17 @@ void CharmInfo::ToggleCreatureAutocast(SpellInfo const* spellInfo, bool apply)
return;
for (uint32 x = 0; x < MAX_SPELL_CHARM; ++x)
if (spellInfo->Id == m_charmspells[x].GetAction())
m_charmspells[x].SetType(apply ? ACT_ENABLED : ACT_DISABLED);
if (spellInfo->Id == _charmspells[x].GetAction())
_charmspells[x].SetType(apply ? ACT_ENABLED : ACT_DISABLED);
}
void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow)
{
m_petnumber = petnumber;
_petnumber = petnumber;
if (statwindow)
m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, m_petnumber);
_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, _petnumber);
else
m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0);
_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0);
}
void CharmInfo::LoadPetActionBar(const std::string& data)
@@ -17579,58 +17583,68 @@ uint32 Unit::GetResistance(SpellSchoolMask mask) const
void CharmInfo::SetIsCommandAttack(bool val)
{
m_isCommandAttack = val;
_isCommandAttack = val;
}
bool CharmInfo::IsCommandAttack()
{
return m_isCommandAttack;
return _isCommandAttack;
}
void CharmInfo::SetIsCommandFollow(bool val)
{
_isCommandFollow = val;
}
bool CharmInfo::IsCommandFollow()
{
return _isCommandFollow;
}
void CharmInfo::SaveStayPosition()
{
//! At this point a new spline destination is enabled because of Unit::StopMoving()
G3D::Vector3 const stayPos = m_unit->movespline->FinalDestination();
m_stayX = stayPos.x;
m_stayY = stayPos.y;
m_stayZ = stayPos.z;
G3D::Vector3 const stayPos = _unit->movespline->FinalDestination();
_stayX = stayPos.x;
_stayY = stayPos.y;
_stayZ = stayPos.z;
}
void CharmInfo::GetStayPosition(float &x, float &y, float &z)
{
x = m_stayX;
y = m_stayY;
z = m_stayZ;
x = _stayX;
y = _stayY;
z = _stayZ;
}
void CharmInfo::SetIsAtStay(bool val)
{
m_isAtStay = val;
_isAtStay = val;
}
bool CharmInfo::IsAtStay()
{
return m_isAtStay;
return _isAtStay;
}
void CharmInfo::SetIsFollowing(bool val)
{
m_isFollowing = val;
_isFollowing = val;
}
bool CharmInfo::IsFollowing()
{
return m_isFollowing;
return _isFollowing;
}
void CharmInfo::SetIsReturning(bool val)
{
m_isReturning = val;
_isReturning = val;
}
bool CharmInfo::IsReturning()
{
return m_isReturning;
return _isReturning;
}
void Unit::SetInFront(Unit const* target)