*Disable charmed/possessed creature AI.

*Use general react states to replace charminfo react states.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-03-05 18:48:56 -06:00
parent 769c835f26
commit 8787c00ca3
17 changed files with 103 additions and 96 deletions

View File

@@ -149,7 +149,7 @@ bool IsPassiveStackableSpell( uint32 spellId )
Unit::Unit()
: WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this)
, m_IsInNotifyList(false), m_Notified(false), m_AI_enabled(false)
, m_IsInNotifyList(false), m_Notified(false), IsAIEnabled(false)
{
m_objectType |= TYPEMASK_UNIT;
m_objectTypeId = TYPEID_UNIT;
@@ -627,7 +627,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
}
//Script Event damage taken
if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() )
if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->IsAIEnabled )
{
((Creature *)pVictim)->AI()->DamageTaken(this, damage);
@@ -778,7 +778,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
if(!getVictim())
/*{
// if have target and damage pVictim just call AI reaction
if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI())
if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsAIEnabled)
((Creature*)pVictim)->AI()->AttackedBy(this);
}
else*/
@@ -8283,7 +8283,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
m_attacking = victim;
m_attacking->_addAttacker(this);
//if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->AI())
//if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->IsAIEnabled)
// ((Creature*)m_attacking)->AI()->AttackedBy(this);
if(GetTypeId()==TYPEID_UNIT)
@@ -9831,7 +9831,7 @@ void Unit::CombatStart(Unit* target)
target->SetStandState(PLAYER_STATE_NONE);
if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER
&& !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->AI())
&& !((Creature*)target)->HasReactState(REACT_PASSIVE) && ((Creature*)target)->IsAIEnabled)
((Creature*)target)->AI()->AttackStart(this);
SetInCombatWith(target);
@@ -10454,7 +10454,7 @@ void Unit::TauntApply(Unit* taunter)
return;
SetInFront(taunter);
if (((Creature*)this)->AI())
if (((Creature*)this)->IsAIEnabled)
((Creature*)this)->AI()->AttackStart(taunter);
m_ThreatManager.tauntApply(taunter);
@@ -10478,7 +10478,7 @@ void Unit::TauntFadeOut(Unit *taunter)
if(m_ThreatManager.isThreatListEmpty())
{
if(((Creature*)this)->AI())
if(((Creature*)this)->IsAIEnabled)
((Creature*)this)->AI()->EnterEvadeMode();
return;
}
@@ -10489,7 +10489,7 @@ void Unit::TauntFadeOut(Unit *taunter)
if (target && target != taunter)
{
SetInFront(target);
if (((Creature*)this)->AI())
if (((Creature*)this)->IsAIEnabled)
((Creature*)this)->AI()->AttackStart(target);
}
}
@@ -11225,21 +11225,43 @@ void Unit::CleanupsBeforeDelete()
RemoveFromWorld();
}
CharmInfo* Unit::InitCharmInfo(Unit *charm)
CharmInfo* Unit::InitCharmInfo()
{
if(!m_charmInfo)
m_charmInfo = new CharmInfo(charm);
m_charmInfo = new CharmInfo(this);
return m_charmInfo;
}
void Unit::DeleteCharmInfo()
{
if(!m_charmInfo)
return;
delete m_charmInfo;
m_charmInfo = NULL;
}
CharmInfo::CharmInfo(Unit* unit)
: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0), m_barInit(false)
: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_petnumber(0), m_barInit(false)
{
for(int i =0; i<4; ++i)
{
m_charmspells[i].spellId = 0;
m_charmspells[i].active = ACT_DISABLED;
}
if(m_unit->GetTypeId() == TYPEID_UNIT)
{
m_oldReactState = ((Creature*)m_unit)->GetReactState();
((Creature*)m_unit)->SetReactState(REACT_PASSIVE);
}
}
CharmInfo::~CharmInfo()
{
if(m_unit->GetTypeId() == TYPEID_UNIT)
{
((Creature*)m_unit)->SetReactState(m_oldReactState);
}
}
void CharmInfo::InitPetActionBar()
@@ -12084,7 +12106,7 @@ void Unit::SetFeared(bool apply, uint64 casterGUID, uint32 spellID)
// attack caster if can
Unit* caster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL);
if(caster && caster != getVictim() && ((Creature*)this)->AI())
if(caster && caster != getVictim() && ((Creature*)this)->IsAIEnabled)
((Creature*)this)->AI()->AttackStart(caster);
}
}
@@ -12768,7 +12790,7 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss)
((Player*)pVictim)->GetSession()->SendPacket(&data);
}
// Call KilledUnit for creatures
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI())
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsAIEnabled)
((Creature*)this)->AI()->KilledUnit(pVictim);
// last damage from non duel opponent or opponent controlled creature
@@ -12791,11 +12813,11 @@ void Unit::Kill(Unit *pVictim, bool durabilityLoss)
}
// Call KilledUnit for creatures, this needs to be called after the lootable flag is set
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI())
if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->IsAIEnabled)
((Creature*)this)->AI()->KilledUnit(pVictim);
// Call creature just died function
if (cVictim->AI())
if (cVictim->IsAIEnabled)
cVictim->AI()->JustDied(this);
// Dungeon specific stuff, only applies to players killing creatures
@@ -13059,7 +13081,7 @@ void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess)
if(GetTypeId() == TYPEID_UNIT)
{
((Creature*)this)->InitPossessedAI();
((Creature*)this)->AI()->OnCharmed(true);
StopMoving();
GetMotionMaster()->Clear(false);
GetMotionMaster()->MoveIdle();
@@ -13074,8 +13096,7 @@ void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess)
// Pets already have a properly initialized CharmInfo, don't overwrite it.
if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet())
{
CharmInfo *charmInfo = InitCharmInfo(this);
charmInfo->SetReactState(REACT_DEFENSIVE);
CharmInfo *charmInfo = InitCharmInfo();
if(possess)
charmInfo->InitPossessCreateSpells();
else
@@ -13145,8 +13166,8 @@ void Unit::RemoveCharmedOrPossessedBy(Unit *charmer)
if(!((Creature*)this)->isPet())
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
((Creature*)this)->DisablePossessedAI();
if(isAlive() && ((Creature*)this)->AI())
((Creature*)this)->AI()->OnCharmed(false);
if(isAlive() && ((Creature*)this)->IsAIEnabled)
{
if(charmer && !IsFriendlyTo(charmer))
{
@@ -13192,6 +13213,11 @@ void Unit::RemoveCharmedOrPossessedBy(Unit *charmer)
}
}
if(GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet())
{
DeleteCharmInfo();
}
if(possess || charmer->GetTypeId() == TYPEID_PLAYER)
{
// Remove pet spell action bar