void FollowerAI::SetFollowPaused(bool paused) { if (!HasFollowState(STATE_FOLLOW_INPROGRESS) || HasFollowState(STATE_FOLLOW_COMPLETE)) return; if (paused) { AddFollowState(STATE_FOLLOW_PAUSED); if (me->HasUnitState(UNIT_STATE_FOLLOW)) { me->ClearUnitState(UNIT_STATE_FOLLOW); me->StopMoving(); me->GetMotionMaster()->Clear(); me->GetMotionMaster()->MoveIdle(); } } else { RemoveFollowState(STATE_FOLLOW_PAUSED); if (Player* leader = GetLeaderForFollower()) me->GetMotionMaster()->MoveFollow(leader, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE); } }
void FollowerAI::SetFollowComplete(bool bWithEndEvent) { if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == FOLLOW_MOTION_TYPE) { m_creature->StopMoving(); m_creature->GetMotionMaster()->Clear(); m_creature->GetMotionMaster()->MoveIdle(); } if (bWithEndEvent) AddFollowState(STATE_FOLLOW_POSTEVENT); else { if (HasFollowState(STATE_FOLLOW_POSTEVENT)) RemoveFollowState(STATE_FOLLOW_POSTEVENT); } AddFollowState(STATE_FOLLOW_COMPLETE); }
void FollowerAI::SetFollowComplete(bool bWithEndEvent) { if (me->HasUnitState(UNIT_STATE_FOLLOW)) { me->ClearUnitState(UNIT_STATE_FOLLOW); me->StopMoving(); me->GetMotionMaster()->Clear(); me->GetMotionMaster()->MoveIdle(); } if (bWithEndEvent) AddFollowState(STATE_FOLLOW_POSTEVENT); else { if (HasFollowState(STATE_FOLLOW_POSTEVENT)) RemoveFollowState(STATE_FOLLOW_POSTEVENT); } AddFollowState(STATE_FOLLOW_COMPLETE); }
void FollowerAI::SetFollowPaused(bool bPaused) { if (!HasFollowState(STATE_FOLLOW_INPROGRESS) || HasFollowState(STATE_FOLLOW_COMPLETE)) return; if (bPaused) { AddFollowState(STATE_FOLLOW_PAUSED); if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == FOLLOW_MOTION_TYPE) { m_creature->StopMoving(); m_creature->GetMotionMaster()->Clear(); m_creature->GetMotionMaster()->MoveIdle(); } } else { RemoveFollowState(STATE_FOLLOW_PAUSED); if (Player* pLeader = GetLeaderForFollower()) m_creature->GetMotionMaster()->MoveFollow(pLeader, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE); } }
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(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)) { 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); }