[7723] New AI call EnterCombat called at enter creature to combat (and re-enter if leave by some reason).

This commit is contained in:
VladimirMangos 2009-04-27 03:36:31 +04:00
parent f2f817883a
commit 73db1cbe01
10 changed files with 30 additions and 25 deletions

View file

@ -60,8 +60,8 @@ AggressorAI::MoveInLineOfSight(Unit *u)
} }
else if(sMapStore.LookupEntry(m_creature->GetMapId())->IsDungeon()) else if(sMapStore.LookupEntry(m_creature->GetMapId())->IsDungeon())
{ {
u->SetInCombatWith(m_creature);
m_creature->AddThreat(u, 0.0f); m_creature->AddThreat(u, 0.0f);
u->SetInCombatWith(m_creature);
} }
} }
} }
@ -152,13 +152,13 @@ AggressorAI::AttackStart(Unit *u)
if(m_creature->Attack(u,true)) if(m_creature->Attack(u,true))
{ {
m_creature->SetInCombatWith(u);
u->SetInCombatWith(m_creature);
m_creature->AddThreat(u, 0.0f);
// DEBUG_LOG("Creature %s tagged a victim to kill [guid=%u]", m_creature->GetName(), u->GetGUIDLow()); // DEBUG_LOG("Creature %s tagged a victim to kill [guid=%u]", m_creature->GetName(), u->GetGUIDLow());
i_victimGuid = u->GetGUID(); i_victimGuid = u->GetGUID();
m_creature->AddThreat(u, 0.0f);
m_creature->SetInCombatWith(u);
u->SetInCombatWith(m_creature);
m_creature->GetMotionMaster()->MoveChase(u); m_creature->GetMotionMaster()->MoveChase(u);
} }
} }

View file

@ -46,6 +46,9 @@ class MANGOS_DLL_SPEC CreatureAI
// Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter // Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter
virtual void MoveInLineOfSight(Unit *) {} virtual void MoveInLineOfSight(Unit *) {}
// Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
virtual void EnterCombat(Unit* /*enemy*/) {}
// Called for reaction at stopping attack at no attackers or targets // Called for reaction at stopping attack at no attackers or targets
virtual void EnterEvadeMode() {} virtual void EnterEvadeMode() {}

View file

@ -1118,7 +1118,7 @@ void CreatureEventAI::JustSummoned(Creature* pUnit)
} }
} }
void CreatureEventAI::Aggro(Unit *who) void CreatureEventAI::EnterCombat(Unit *enemy)
{ {
//Check for on combat start events //Check for on combat start events
if (!bEmptyList) if (!bEmptyList)
@ -1129,7 +1129,7 @@ void CreatureEventAI::Aggro(Unit *who)
{ {
case EVENT_T_AGGRO: case EVENT_T_AGGRO:
(*i).Enabled = true; (*i).Enabled = true;
ProcessEvent(*i, who); ProcessEvent(*i, enemy);
break; break;
//Reset all in combat timers //Reset all in combat timers
case EVENT_T_TIMER: case EVENT_T_TIMER:
@ -1164,17 +1164,12 @@ void CreatureEventAI::AttackStart(Unit *who)
if (!who) if (!who)
return; return;
bool inCombat = m_creature->isInCombat();
if (m_creature->Attack(who, MeleeEnabled)) if (m_creature->Attack(who, MeleeEnabled))
{ {
m_creature->AddThreat(who, 0.0f); m_creature->AddThreat(who, 0.0f);
m_creature->SetInCombatWith(who); m_creature->SetInCombatWith(who);
who->SetInCombatWith(m_creature); who->SetInCombatWith(m_creature);
if (!inCombat)
Aggro(who);
if (CombatMovementEnabled) if (CombatMovementEnabled)
{ {
m_creature->GetMotionMaster()->MoveChase(who, AttackDistance, AttackAngle); m_creature->GetMotionMaster()->MoveChase(who, AttackDistance, AttackAngle);
@ -1233,8 +1228,8 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
} }
else if (m_creature->GetMap()->IsDungeon()) else if (m_creature->GetMap()->IsDungeon())
{ {
who->SetInCombatWith(m_creature);
m_creature->AddThreat(who, 0.0f); m_creature->AddThreat(who, 0.0f);
who->SetInCombatWith(m_creature);
} }
} }
} }

View file

@ -257,11 +257,11 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI
void JustRespawned(); void JustRespawned();
void Reset(); void Reset();
void JustReachedHome(); void JustReachedHome();
void EnterCombat(Unit *enemy);
void EnterEvadeMode(); void EnterEvadeMode();
void JustDied(Unit* killer); void JustDied(Unit* killer);
void KilledUnit(Unit* victim); void KilledUnit(Unit* victim);
void JustSummoned(Creature* pUnit); void JustSummoned(Creature* pUnit);
void Aggro(Unit *who);
void AttackStart(Unit *who); void AttackStart(Unit *who);
void MoveInLineOfSight(Unit *who); void MoveInLineOfSight(Unit *who);
void SpellHit(Unit* pUnit, const SpellEntry* pSpell); void SpellHit(Unit* pUnit, const SpellEntry* pSpell);

View file

@ -137,11 +137,11 @@ void GuardAI::AttackStart(Unit *u)
// DEBUG_LOG("Creature %s tagged a victim to kill [guid=%u]", i_creature.GetName(), u->GetGUIDLow()); // DEBUG_LOG("Creature %s tagged a victim to kill [guid=%u]", i_creature.GetName(), u->GetGUIDLow());
if(m_creature->Attack(u,true)) if(m_creature->Attack(u,true))
{ {
i_victimGuid = u->GetGUID();
m_creature->AddThreat(u, 0.0f);
m_creature->SetInCombatWith(u); m_creature->SetInCombatWith(u);
u->SetInCombatWith(m_creature); u->SetInCombatWith(m_creature);
m_creature->AddThreat(u, 0.0f);
i_victimGuid = u->GetGUID();
m_creature->GetMotionMaster()->MoveChase(u); m_creature->GetMotionMaster()->MoveChase(u);
} }
} }

View file

@ -48,11 +48,12 @@ ReactorAI::AttackStart(Unit *p)
if(m_creature->Attack(p,true)) if(m_creature->Attack(p,true))
{ {
DEBUG_LOG("Tag unit GUID: %u (TypeId: %u) as a victim", p->GetGUIDLow(), p->GetTypeId()); DEBUG_LOG("Tag unit GUID: %u (TypeId: %u) as a victim", p->GetGUIDLow(), p->GetTypeId());
i_victimGuid = p->GetGUID();
m_creature->AddThreat(p, 0.0f);
m_creature->SetInCombatWith(p); m_creature->SetInCombatWith(p);
p->SetInCombatWith(m_creature); p->SetInCombatWith(m_creature);
m_creature->AddThreat(p, 0.0f);
i_victimGuid = p->GetGUID();
m_creature->GetMotionMaster()->MoveChase(p); m_creature->GetMotionMaster()->MoveChase(p);
} }
} }

View file

@ -1158,6 +1158,7 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask)
if(!unit->isInCombat() && unit->GetTypeId() != TYPEID_PLAYER && ((Creature*)unit)->AI()) if(!unit->isInCombat() && unit->GetTypeId() != TYPEID_PLAYER && ((Creature*)unit)->AI())
((Creature*)unit)->AI()->AttackedBy(m_caster); ((Creature*)unit)->AI()->AttackedBy(m_caster);
unit->AddThreat(m_caster, 0.0f);
unit->SetInCombatWith(m_caster); unit->SetInCombatWith(m_caster);
m_caster->SetInCombatWith(unit); m_caster->SetInCombatWith(unit);
@ -1165,7 +1166,6 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask)
{ {
m_caster->SetContestedPvP(attackedPlayer); m_caster->SetContestedPvP(attackedPlayer);
} }
unit->AddThreat(m_caster, 0.0f);
} }
} }
else else

View file

@ -8678,7 +8678,7 @@ void Unit::SetInCombatWith(Unit* enemy)
Unit* eOwner = enemy->GetCharmerOrOwnerOrSelf(); Unit* eOwner = enemy->GetCharmerOrOwnerOrSelf();
if(eOwner->IsPvP()) if(eOwner->IsPvP())
{ {
SetInCombatState(true); SetInCombatState(true,enemy);
return; return;
} }
@ -8688,14 +8688,14 @@ void Unit::SetInCombatWith(Unit* enemy)
Unit const* myOwner = GetCharmerOrOwnerOrSelf(); Unit const* myOwner = GetCharmerOrOwnerOrSelf();
if(((Player const*)eOwner)->duel->opponent == myOwner) if(((Player const*)eOwner)->duel->opponent == myOwner)
{ {
SetInCombatState(true); SetInCombatState(true,enemy);
return; return;
} }
} }
SetInCombatState(false); SetInCombatState(false,enemy);
} }
void Unit::SetInCombatState(bool PvP) void Unit::SetInCombatState(bool PvP, Unit* enemy)
{ {
// only alive units can be in combat // only alive units can be in combat
if(!isAlive()) if(!isAlive())
@ -8703,10 +8703,16 @@ void Unit::SetInCombatState(bool PvP)
if(PvP) if(PvP)
m_CombatTimer = 5000; m_CombatTimer = 5000;
bool creatureNotInCombat = GetTypeId()==TYPEID_UNIT && !HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT);
if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet()))
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);
if(creatureNotInCombat && ((Creature*)this)->AI())
((Creature*)this)->AI()->EnterCombat(enemy);
} }
void Unit::ClearInCombat() void Unit::ClearInCombat()

View file

@ -1018,7 +1018,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT); } bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT); }
bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); } bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }
void SetInCombatState(bool PvP); void SetInCombatState(bool PvP, Unit* enemy = NULL);
void SetInCombatWith(Unit* enemy); void SetInCombatWith(Unit* enemy);
void ClearInCombat(); void ClearInCombat();
uint32 GetCombatTimer() const { return m_CombatTimer; } uint32 GetCombatTimer() const { return m_CombatTimer; }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "7722" #define REVISION_NR "7723"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__