Loading...   

  • Created By Uleat On: 08:50 PM February 03, 2018
  • Link

 zone/mob_ai.cpp | 57 ++++++++++++++++++++++-----------------------------------
 1 file changed, 22 insertions(+), 35 deletions(-)

diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp
index 384f0993..83575256 100644
--- a/zone/mob_ai.cpp
+++ b/zone/mob_ai.cpp
@@ -974,10 +974,10 @@ void Mob::AI_Process() {
 				//make sure everybody knows were not moving, for appearance sake
 				if(IsMoving())
 				{
-					if(target)
-						SetHeading(CalculateHeadingToTarget(target->GetX(), target->GetY()));
-					SetCurrentSpeed(0);
-					moved=false;
+					if (target)
+						StopMoving(CalculateHeadingToTarget(target->GetX(), target->GetY()));
+					else
+						StopMoving();
 				}
 				//continue on to attack code, ensuring that we execute the engaged code
 				engaged = true;
@@ -1023,16 +1023,12 @@ void Mob::AI_Process() {
 			if (this->GetTarget()) {
 				/* If we are engaged, moving and following client, let's look for best Z more often */
 				float target_distance = DistanceNoZ(this->GetPosition(), this->GetTarget()->GetPosition());
-				this->FixZ();
-
 				if (target_distance <= 15 && !this->CheckLosFN(this->GetTarget())) {
-					Mob* target = this->GetTarget();
-
-					m_Position.x = target->GetX();
-					m_Position.y = target->GetY();
-					m_Position.z = target->GetZ();
-					m_Position.w = target->GetHeading();
-					SendPosition();
+					m_Position = GetTarget()->GetPosition();
+					StopMoving();
+				}
+				else {
+					this->FixZ();
 				}
 			}
 		}
@@ -1093,7 +1089,8 @@ void Mob::AI_Process() {
 			tether_range = tether_range > 0.0f ? tether_range * tether_range : pAggroRange * pAggroRange;
 
 			if (DistanceSquaredNoZ(m_Position, npcSpawnPoint) > tether_range) {
-				GMMove(npcSpawnPoint.x, npcSpawnPoint.y, npcSpawnPoint.z, npcSpawnPoint.w);
+				GMMove(npcSpawnPoint.x, npcSpawnPoint.y, npcSpawnPoint.z, npcSpawnPoint.w, false);
+				StopMoving();
 			}
 		}
 		else if (GetSpecialAbility(LEASH)) {
@@ -1101,7 +1098,8 @@ void Mob::AI_Process() {
 			leash_range = leash_range > 0.0f ? leash_range * leash_range : pAggroRange * pAggroRange;
 
 			if (DistanceSquaredNoZ(m_Position, npcSpawnPoint) > leash_range) {
-				GMMove(npcSpawnPoint.x, npcSpawnPoint.y, npcSpawnPoint.z, npcSpawnPoint.w);
+				GMMove(npcSpawnPoint.x, npcSpawnPoint.y, npcSpawnPoint.z, npcSpawnPoint.w, false);
+				StopMoving();
 				SetHP(GetMaxHP());
 				BuffFadeAll();
 				WipeHateList();
@@ -1117,21 +1115,13 @@ void Mob::AI_Process() {
 		{
 			if (AI_movement_timer->Check())
 			{
-				if (CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()) != m_Position.w)
-				{
-					SetHeading(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()));
-					SendPosition();
-				}
-				SetCurrentSpeed(0);
+				// old method calc'd heading once to check..twice if not facing...
+				// let's just force it on first calc and send that heading in StopMoving()
+				StopMoving(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()));
 			}
 			if (IsMoving())
 			{
-				if (CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()) != m_Position.w)
-				{
-					SetHeading(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY()));
-					SendPosition();
-				}
-				SetCurrentSpeed(0);
+				StopMoving(CalculateHeadingToTarget(GetTarget()->GetX(), GetTarget()->GetY())); // ditto
 			}
 
 			//casting checked above...
@@ -1295,6 +1285,7 @@ void Mob::AI_Process() {
 				if (!zone->watermap->InLiquid(targetPosition)) {
 					Mob *tar = hate_list.GetEntWithMostHateOnList(this);
 					if (tar == target) {
+						StopMoving();
 						WipeHateList();
 						Heal();
 						BuffFadeAll();
@@ -1303,6 +1294,7 @@ void Mob::AI_Process() {
 						return;
 					}
 					else if (tar != nullptr) {
+						StopMoving();
 						SetTarget(tar);
 						return;
 					}
@@ -1342,9 +1334,7 @@ void Mob::AI_Process() {
 
 					}
 					else if (IsMoving()) {
-						SetHeading(CalculateHeadingToTarget(target->GetX(), target->GetY()));
-						SetCurrentSpeed(0);
-
+						StopMoving(CalculateHeadingToTarget(target->GetX(), target->GetY()));
 					}
 				}
 			}
@@ -1440,9 +1430,7 @@ void Mob::AI_Process() {
 						{
 							if(moved)
 							{
-								this->FixZ();
-								SetCurrentSpeed(0);
-								moved = false;
+								StopMoving();
 							}
 						}
 
@@ -1498,8 +1486,7 @@ void Mob::AI_Process() {
 					}
 					else
 					{
-						moved = false;
-						SetCurrentSpeed(0);
+						StopMoving();
 					}
 				}
 			}

Raw Paste Data