Browse Source

Better handling of pause timer to not interfere with out of combat with pets movement and in combat movement with other spawns

Image 2 years ago
parent
commit
b3389a0704

+ 6 - 1
EQ2/source/WorldServer/NPC.cpp

@@ -284,7 +284,12 @@ void NPC::InCombat(bool val){
 	}
 	if(!in_combat && val){
 		// if not a pet and no current run back location set then set one to the current location
-		if(!IsPet() && !GetRunbackLocation()) {
+		bool hadRunback = (GetRunbackLocation() != nullptr);
+		if(hadRunback) {
+			pause_timer.Disable();
+			ClearRunback();
+		}
+		if(!IsPet() && !hadRunback) {
 			StartRunback(true);
 		}
 	}

+ 5 - 5
EQ2/source/WorldServer/NPC_AI.cpp

@@ -72,7 +72,7 @@ void Brain::Think() {
 			if (m_body->GetTarget() != target) {
 				m_body->SetTarget(target);				
 			}
-			m_body->FaceTarget(target);
+			m_body->FaceTarget(target, false);
 			// target needs to be set before in combat is engaged
 
 			// If the NPC is not in combat then put them in combat
@@ -110,7 +110,7 @@ void Brain::Think() {
 
 				if(!m_body->IsCasting() && (!HasRecovered() || !ProcessSpell(target, distance))) {
 					LogWrite(NPC_AI__DEBUG, 7, "NPC_AI", "%s is attempting melee on %s.", m_body->GetName(), target->GetName());
-					m_body->FaceTarget(target);
+					m_body->FaceTarget(target, false);
 					ProcessMelee(target, distance);
 				}
 			}
@@ -162,7 +162,7 @@ void Brain::Think() {
 								m_body->SetHP(m_body->GetTotalHP());
 
 							m_body->ClearRunback();
-							
+
 							m_body->GetZone()->AddChangedSpawn(m_body);
 						break;
 						default: // captures case 1 up to case 5 to turn around / reset hp
@@ -677,7 +677,7 @@ void DumbFirePetBrain::Think() {
 			// Set the NPC's target to the most hated entity if it is not already.
 			if (GetBody()->GetTarget() != target) {
 				GetBody()->SetTarget(target);
-				GetBody()->FaceTarget(target);
+				GetBody()->FaceTarget(target, false);
 			}
 			// target needs to be identified before combat setting
 
@@ -692,7 +692,7 @@ void DumbFirePetBrain::Think() {
 
 			if(GetBody()->CheckLoS(target) && !GetBody()->IsCasting() && (!HasRecovered() || !ProcessSpell(target, distance))) {
 				LogWrite(NPC_AI__DEBUG, 7, "NPC_AI", "%s is attempting melee on %s.", GetBody()->GetName(), target->GetName());
-				GetBody()->FaceTarget(target);
+				GetBody()->FaceTarget(target, false);
 				ProcessMelee(target, distance);
 			}
 		}

+ 7 - 6
EQ2/source/WorldServer/Spawn.cpp

@@ -2697,7 +2697,7 @@ void Spawn::MoveToLocation(Spawn* spawn, float distance, bool immediate, bool ma
 	if(!spawn)
 		return;
 	SetRunningTo(spawn);
-	FaceTarget(spawn);
+	FaceTarget(spawn, false);
 
 	if (!IsPlayer() && distance > 0.0f)
 	{
@@ -3369,12 +3369,13 @@ void Spawn::FaceTarget(Spawn* target, bool disable_action_state){
 	if(!target)
 		return;
 	if(GetHP() > 0 && target->IsPlayer() && !EngagedInCombat()){
-		if(IsNPC()) {
-			((NPC*)this)->StartRunback();
-			((NPC*)this)->PauseMovement(30000);
-		}
-		if(disable_action_state)
+		if(!IsPet() && disable_action_state) {
+			if(IsNPC()) {
+				((NPC*)this)->StartRunback();
+				((NPC*)this)->PauseMovement(30000);
+			}
 			SetTempActionState(0);
+		}
 	}
 	FaceTarget(target->GetX(), target->GetZ());
 }