void FollowerAI::UpdateAI(uint32 uiDiff) { if (HasFollowState(STATE_FOLLOW_INPROGRESS) && !me->GetVictim()) { if (m_uiUpdateFollowTimer <= uiDiff) { if (HasFollowState(STATE_FOLLOW_COMPLETE) && !HasFollowState(STATE_FOLLOW_POSTEVENT)) { TC_LOG_DEBUG("scripts", "FollowerAI is set completed, despawns."); me->DespawnOrUnsummon(); return; } bool bIsMaxRangeExceeded = true; if (Player* player = GetLeaderForFollower()) { if (HasFollowState(STATE_FOLLOW_RETURNING)) { TC_LOG_DEBUG("scripts", "FollowerAI is returning to leader."); RemoveFollowState(STATE_FOLLOW_RETURNING); me->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE); return; } if (Group* group = player->GetGroup()) { for (GroupReference* groupRef = group->GetFirstMember(); groupRef != NULL; groupRef = groupRef->next()) { Player* member = groupRef->GetSource(); if (member && me->IsWithinDistInMap(member, MAX_PLAYER_DISTANCE)) { bIsMaxRangeExceeded = false; break; } } } else { if (me->IsWithinDistInMap(player, MAX_PLAYER_DISTANCE)) bIsMaxRangeExceeded = false; } } if (bIsMaxRangeExceeded) { TC_LOG_DEBUG("scripts", "FollowerAI failed because player/group was to far away or not found"); me->DespawnOrUnsummon(); return; } m_uiUpdateFollowTimer = 1000; } else m_uiUpdateFollowTimer -= uiDiff; } UpdateFollowerAI(uiDiff); }
void FollowerAI::UpdateAI(const uint32 uiDiff) { if (HasFollowState(STATE_FOLLOW_INPROGRESS) && !m_creature->getVictim()) { if (m_uiUpdateFollowTimer < uiDiff) { if (HasFollowState(STATE_FOLLOW_COMPLETE) && !HasFollowState(STATE_FOLLOW_POSTEVENT)) { debug_log("SD2: FollowerAI is set completed, despawns."); m_creature->ForcedDespawn(); return; } bool bIsMaxRangeExceeded = true; if (Player* pPlayer = GetLeaderForFollower()) { if (HasFollowState(STATE_FOLLOW_RETURNING)) { debug_log("SD2: FollowerAI is returning to leader."); RemoveFollowState(STATE_FOLLOW_RETURNING); m_creature->GetMotionMaster()->MoveFollow(pPlayer, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE); return; } if (Group* pGroup = pPlayer->GetGroup()) { for(GroupReference* pRef = pGroup->GetFirstMember(); pRef != NULL; pRef = pRef->next()) { Player* pMember = pRef->getSource(); if (pMember && m_creature->IsWithinDistInMap(pMember, MAX_PLAYER_DISTANCE)) { bIsMaxRangeExceeded = false; break; } } } else { if (m_creature->IsWithinDistInMap(pPlayer, MAX_PLAYER_DISTANCE)) bIsMaxRangeExceeded = false; } } if (bIsMaxRangeExceeded) { debug_log("SD2: FollowerAI failed because player/group was to far away or not found"); m_creature->ForcedDespawn(); return; } m_uiUpdateFollowTimer = 1000; } else m_uiUpdateFollowTimer -= uiDiff; } UpdateFollowerAI(uiDiff); }
void FollowerAI::UpdateAI(const uint32 uiDiff) { if (HasFollowState(STATE_FOLLOW_INPROGRESS) && !m_creature->getVictim()) { if (m_uiUpdateFollowTimer < uiDiff) { if (HasFollowState(STATE_FOLLOW_COMPLETE) && !HasFollowState(STATE_FOLLOW_POSTEVENT)) { sLog.outDebug("FollowerAI is set completed, despawns."); m_creature->DisappearAndDie(); return; } bool bIsMaxRangeExceeded = true; if (Player* pPlayer = GetLeaderForFollower()) { if (HasFollowState(STATE_FOLLOW_RETURNING)) { sLog.outDebug("FollowerAI is returning to leader."); RemoveFollowState(STATE_FOLLOW_RETURNING); m_creature->GetMotionMaster()->MoveFollow(pPlayer, m_uiFollowDistance, PET_FOLLOW_ANGLE); return; } if (Group* pGroup = pPlayer->GetGroup()) { for(GroupReference* pRef = pGroup->GetFirstMember(); pRef != nullptr; pRef = pRef->next()) { Player* pMember = pRef->getSource(); if (pMember && m_creature->IsWithinDistInMap(pMember, MAX_PLAYER_DISTANCE)) { bIsMaxRangeExceeded = false; break; } } } else { if (m_creature->IsWithinDistInMap(pPlayer, MAX_PLAYER_DISTANCE)) bIsMaxRangeExceeded = false; } // allow postEvent to happen even if quest credit is already handled /*if (HasFollowState(STATE_FOLLOW_COMPLETE | STATE_FOLLOW_POSTEVENT)) bIsMaxRangeExceeded = false;*/ } if (bIsMaxRangeExceeded) { sLog.outDebug("FollowerAI failed because player/group was to far away or not found"); SetFollowPaused(false); m_creature->DisappearAndDie(); return; } m_uiUpdateFollowTimer = 300; } else m_uiUpdateFollowTimer -= uiDiff; } UpdateFollowerAI(uiDiff); }