Skip to content

Commit 5f75835

Browse files
author
NoFantasy
committed
[1364] Add function AssistPlayerInCombat() for escortAI and followerAI. m_creature will then assist a player being attacked by another creature, if escort/follow is active.
Add function AssistPlayerInCombat() for escortAI and followerAI. m_creature will then assist a player being attacked by another creature, if escort/follow is active. git-svn-id: https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2@1364 5f9c896b-1e26-0410-94da-f77f675e2462
1 parent 0c15e0f commit 5f75835

4 files changed

Lines changed: 106 additions & 40 deletions

File tree

base/escort_ai.cpp

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,69 @@ void npc_escortAI::Aggro(Unit* pEnemy)
7373
{
7474
}
7575

76-
void npc_escortAI::MoveInLineOfSight(Unit* pWho)
76+
//see followerAI
77+
bool npc_escortAI::AssistPlayerInCombat(Unit* pWho)
7778
{
78-
if (IsBeingEscorted && !m_bIsActiveAttacker)
79-
return;
79+
if (!pWho || !pWho->getVictim())
80+
return false;
81+
82+
//experimental (unknown) flag not present
83+
if (!(m_creature->GetCreatureInfo()->type_flags & CREATURE_TYPEFLAGS_UNK13))
84+
return false;
85+
86+
//not a player
87+
if (!pWho->getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
88+
return false;
89+
90+
//never attack friendly
91+
if (m_creature->IsFriendlyTo(pWho))
92+
return false;
93+
94+
//too far away and no free sight?
95+
if (m_creature->IsWithinDistInMap(pWho, MAX_PLAYER_DISTANCE) && m_creature->IsWithinLOSInMap(pWho))
96+
{
97+
//already fighting someone?
98+
if (!m_creature->getVictim())
99+
{
100+
AttackStart(pWho);
101+
return true;
102+
}
103+
else
104+
{
105+
pWho->SetInCombatWith(m_creature);
106+
m_creature->AddThreat(pWho, 0.0f);
107+
return true;
108+
}
109+
}
110+
111+
return false;
112+
}
80113

81-
if (!m_creature->hasUnitState(UNIT_STAT_STUNNED) && pWho->isTargetableForAttack() &&
82-
m_creature->IsHostileTo(pWho) && pWho->isInAccessablePlaceFor(m_creature))
114+
void npc_escortAI::MoveInLineOfSight(Unit* pWho)
115+
{
116+
if (!m_creature->hasUnitState(UNIT_STAT_STUNNED) && pWho->isTargetableForAttack() && pWho->isInAccessablePlaceFor(m_creature))
83117
{
118+
if (IsBeingEscorted && AssistPlayerInCombat(pWho))
119+
return;
120+
84121
if (!m_creature->canFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
85122
return;
86123

87-
float attackRadius = m_creature->GetAttackDistance(pWho);
88-
if (m_creature->IsWithinDistInMap(pWho, attackRadius) && m_creature->IsWithinLOSInMap(pWho))
124+
if (m_creature->IsHostileTo(pWho))
89125
{
90-
if (!m_creature->getVictim())
91-
{
92-
AttackStart(pWho);
93-
pWho->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
94-
}
95-
else if (m_creature->GetMap()->IsDungeon())
126+
float fAttackRadius = m_creature->GetAttackDistance(pWho);
127+
if (m_creature->IsWithinDistInMap(pWho, fAttackRadius) && m_creature->IsWithinLOSInMap(pWho))
96128
{
97-
pWho->SetInCombatWith(m_creature);
98-
m_creature->AddThreat(pWho, 0.0f);
129+
if (!m_creature->getVictim())
130+
{
131+
pWho->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
132+
AttackStart(pWho);
133+
}
134+
else if (m_creature->GetMap()->IsDungeon())
135+
{
136+
pWho->SetInCombatWith(m_creature);
137+
m_creature->AddThreat(pWho, 0.0f);
138+
}
99139
}
100140
}
101141
}

base/escort_ai.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ struct MANGOS_DLL_DECL npc_escortAI : public ScriptedAI
8181
bool IsOnHold;
8282

8383
private:
84+
bool AssistPlayerInCombat(Unit* pWho);
85+
8486
uint64 m_uiPlayerGUID;
8587
uint32 m_uiWPWaitTimer;
8688
uint32 m_uiPlayerCheckTimer;

base/follower_ai.cpp

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,60 @@ void FollowerAI::AttackStart(Unit* pWho)
4545
}
4646
}
4747

48+
//This part provides assistance to a player that are attacked by pWho, even if out of normal aggro range
49+
//It will cause m_creature to attack pWho that are attacking _any_ player (which has been confirmed may happen also on offi)
50+
//The flag (type_flag) is unconfirmed, but used here for further research and is a good candidate.
51+
bool FollowerAI::AssistPlayerInCombat(Unit* pWho)
52+
{
53+
if (!pWho || !pWho->getVictim())
54+
return false;
55+
56+
//experimental (unknown) flag not present
57+
if (!(m_creature->GetCreatureInfo()->type_flags & CREATURE_TYPEFLAGS_UNK13))
58+
return false;
59+
60+
//not a player
61+
if (!pWho->getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
62+
return false;
63+
64+
//never attack friendly
65+
if (m_creature->IsFriendlyTo(pWho))
66+
return false;
67+
68+
//too far away and no free sight?
69+
if (m_creature->IsWithinDistInMap(pWho, MAX_PLAYER_DISTANCE) && m_creature->IsWithinLOSInMap(pWho))
70+
{
71+
//already fighting someone?
72+
if (!m_creature->getVictim())
73+
{
74+
AttackStart(pWho);
75+
return true;
76+
}
77+
else
78+
{
79+
pWho->SetInCombatWith(m_creature);
80+
m_creature->AddThreat(pWho, 0.0f);
81+
return true;
82+
}
83+
}
84+
85+
return false;
86+
}
87+
4888
void FollowerAI::MoveInLineOfSight(Unit* pWho)
4989
{
50-
if (!m_creature->hasUnitState(UNIT_STAT_STUNNED) && pWho->isTargetableForAttack() &&
51-
m_creature->IsHostileTo(pWho) && pWho->isInAccessablePlaceFor(m_creature))
90+
if (!m_creature->hasUnitState(UNIT_STAT_STUNNED) && pWho->isTargetableForAttack() && pWho->isInAccessablePlaceFor(m_creature))
5291
{
92+
if (HasFollowState(STATE_FOLLOW_INPROGRESS) && AssistPlayerInCombat(pWho))
93+
return;
94+
5395
if (!m_creature->canFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
5496
return;
5597

56-
//This part provides assistance to a player that are attacked by pWho, even if out of normal aggro range
57-
//It will cause m_creature to attack pWho that are attacking _any_ player (which has been confirmed may happen also on offi)
58-
//The flag (type_flag) is unconfirmed, but used here for further research and is a good candidate.
59-
if (m_creature->hasUnitState(UNIT_STAT_FOLLOW) &&
60-
m_creature->GetCreatureInfo()->type_flags & CREATURE_TYPEFLAGS_UNK13 &&
61-
pWho->getVictim() &&
62-
pWho->getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself() &&
63-
m_creature->IsWithinDistInMap(pWho, MAX_PLAYER_DISTANCE) &&
64-
m_creature->IsWithinLOSInMap(pWho))
65-
{
66-
if (!m_creature->getVictim())
67-
{
68-
AttackStart(pWho);
69-
}
70-
else
71-
{
72-
pWho->SetInCombatWith(m_creature);
73-
m_creature->AddThreat(pWho, 0.0f);
74-
}
75-
}
76-
else
98+
if (m_creature->IsHostileTo(pWho))
7799
{
78-
float attackRadius = m_creature->GetAttackDistance(pWho);
79-
if (m_creature->IsWithinDistInMap(pWho, attackRadius) && m_creature->IsWithinLOSInMap(pWho))
100+
float fAttackRadius = m_creature->GetAttackDistance(pWho);
101+
if (m_creature->IsWithinDistInMap(pWho, fAttackRadius) && m_creature->IsWithinLOSInMap(pWho))
80102
{
81103
if (!m_creature->getVictim())
82104
{

base/follower_ai.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class MANGOS_DLL_DECL FollowerAI : public ScriptedAI
5656
void AddFollowState(uint32 uiFollowState) { m_uiFollowState |= uiFollowState; }
5757
void RemoveFollowState(uint32 uiFollowState) { m_uiFollowState &= ~uiFollowState; }
5858

59+
bool AssistPlayerInCombat(Unit* pWho);
60+
5961
uint64 m_uiLeaderGUID;
6062
uint32 m_uiUpdateFollowTimer;
6163
uint32 m_uiFollowState;

0 commit comments

Comments
 (0)