Skip to content

Commit 1e4dcab

Browse files
author
NoFantasy
committed
[1730] Restore custom way of assisting player in escortAi and followerAi by changing order of checks in MoveInLineOfSight
Restore custom way of assisting player in escortAi and followerAi by changing order of checks in MoveInLineOfSight git-svn-id: https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2@1730 5f9c896b-1e26-0410-94da-f77f675e2462
1 parent 90759da commit 1e4dcab

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

base/escort_ai.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,29 @@ void npc_escortAI::Aggro(Unit* pEnemy)
7474
//see followerAI
7575
bool npc_escortAI::AssistPlayerInCombat(Unit* pWho)
7676
{
77-
if (!pWho || !pWho->getVictim())
77+
if (!pWho->getVictim())
7878
return false;
7979

80-
//experimental (unknown) flag not present
80+
// experimental (unknown) flag not present
8181
if (!(m_creature->GetCreatureInfo()->type_flags & CREATURE_TYPEFLAGS_UNK13))
8282
return false;
8383

84-
//not a player
84+
// unit state prevents (similar check is done in CanInitiateAttack which also include checking unit_flags. We skip those here)
85+
if (m_creature->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED))
86+
return false;
87+
88+
// victim of pWho is not a player
8589
if (!pWho->getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
8690
return false;
8791

88-
//never attack friendly
92+
// never attack friendly
8993
if (m_creature->IsFriendlyTo(pWho))
9094
return false;
9195

92-
//too far away and no free sight?
96+
// too far away and no free sight?
9397
if (m_creature->IsWithinDistInMap(pWho, MAX_PLAYER_DISTANCE) && m_creature->IsWithinLOSInMap(pWho))
9498
{
95-
//already fighting someone?
99+
// already fighting someone?
96100
if (!m_creature->getVictim())
97101
{
98102
AttackStart(pWho);
@@ -111,11 +115,15 @@ bool npc_escortAI::AssistPlayerInCombat(Unit* pWho)
111115

112116
void npc_escortAI::MoveInLineOfSight(Unit* pWho)
113117
{
114-
if (m_creature->CanInitiateAttack() && pWho->isTargetableForAttack() && pWho->isInAccessablePlaceFor(m_creature))
118+
if (pWho->isTargetableForAttack() && pWho->isInAccessablePlaceFor(m_creature))
115119
{
120+
// AssistPlayerInCombat can start attack, so return if true
116121
if (HasEscortState(STATE_ESCORT_ESCORTING) && AssistPlayerInCombat(pWho))
117122
return;
118123

124+
if (!m_creature->CanInitiateAttack())
125+
return;
126+
119127
if (!m_creature->canFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
120128
return;
121129

base/follower_ai.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,29 @@ void FollowerAI::AttackStart(Unit* pWho)
4747
//The flag (type_flag) is unconfirmed, but used here for further research and is a good candidate.
4848
bool FollowerAI::AssistPlayerInCombat(Unit* pWho)
4949
{
50-
if (!pWho || !pWho->getVictim())
50+
if (!pWho->getVictim())
5151
return false;
5252

53-
//experimental (unknown) flag not present
53+
// experimental (unknown) flag not present
5454
if (!(m_creature->GetCreatureInfo()->type_flags & CREATURE_TYPEFLAGS_UNK13))
5555
return false;
5656

57-
//not a player
57+
// unit state prevents (similar check is done in CanInitiateAttack which also include checking unit_flags. We skip those here)
58+
if (m_creature->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED))
59+
return false;
60+
61+
// victim of pWho is not a player
5862
if (!pWho->getVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
5963
return false;
6064

61-
//never attack friendly
65+
// never attack friendly
6266
if (m_creature->IsFriendlyTo(pWho))
6367
return false;
6468

65-
//too far away and no free sight?
69+
// too far away and no free sight?
6670
if (m_creature->IsWithinDistInMap(pWho, MAX_PLAYER_DISTANCE) && m_creature->IsWithinLOSInMap(pWho))
6771
{
68-
//already fighting someone?
72+
// already fighting someone?
6973
if (!m_creature->getVictim())
7074
{
7175
AttackStart(pWho);
@@ -84,11 +88,15 @@ bool FollowerAI::AssistPlayerInCombat(Unit* pWho)
8488

8589
void FollowerAI::MoveInLineOfSight(Unit* pWho)
8690
{
87-
if (m_creature->CanInitiateAttack() && pWho->isTargetableForAttack() && pWho->isInAccessablePlaceFor(m_creature))
91+
if (pWho->isTargetableForAttack() && pWho->isInAccessablePlaceFor(m_creature))
8892
{
93+
// AssistPlayerInCombat can start attack, so return if true
8994
if (HasFollowState(STATE_FOLLOW_INPROGRESS) && AssistPlayerInCombat(pWho))
9095
return;
9196

97+
if (!m_creature->CanInitiateAttack())
98+
return;
99+
92100
if (!m_creature->canFly() && m_creature->GetDistanceZ(pWho) > CREATURE_Z_ATTACK_RANGE)
93101
return;
94102

0 commit comments

Comments
 (0)