Browse Source

SetFollowTarget allows follow_distance as an optional field

By default we use combat distance on follow, now we will use follow_distance if set, otherwise combat distance

Fix #79
Image 4 years ago
parent
commit
363a3fe5a0

+ 2 - 1
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -4530,6 +4530,7 @@ int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
 
 	Spawn* spawn = lua_interface->GetSpawn(state);
 	Spawn* target = lua_interface->GetSpawn(state, 2);
+	int32 follow_distance = lua_interface->GetInt32Value(state, 3);
 
 	if (!spawn) {
 		lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
@@ -4538,7 +4539,7 @@ int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
 
 	// Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
 
-	spawn->SetFollowTarget(target);
+	spawn->SetFollowTarget(target, follow_distance);
 	return 0;
 }
 

+ 9 - 3
EQ2/source/WorldServer/Spawn.cpp

@@ -101,6 +101,7 @@ Spawn::Spawn(){
 	last_location_update = 0.0;
 	last_movement_update = Timer::GetCurrentTime2();
 	forceMapCheck = false;
+	m_followDistance = 0;
 }
 
 Spawn::~Spawn(){
@@ -2144,13 +2145,16 @@ void Spawn::ProcessMovement(bool isSpawnListLocked){
 				SetSpeed(speed);
 			}
 			MovementLocation* loc = GetCurrentRunningLocation();
-			if ((GetDistance(followTarget, true) <= rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat())) {
+			float dist = GetDistance(followTarget, true);
+			if ((!EngagedInCombat() && m_followDistance > 0 && dist <= m_followDistance) || 
+				(dist <= rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat())) {
 				ClearRunningLocations();
 				CalculateRunningLocation(true);
 			}
 			else if (loc) {
 				float distance = GetDistance(followTarget, loc->x, loc->y, loc->z);
-				if (distance > rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat()) {
+				if ( (!EngagedInCombat() && m_followDistance > 0 && distance > m_followDistance) ||
+					 ( EngagedInCombat() && distance > rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat())) {
 					MoveToLocation(followTarget, rule_manager.GetGlobalRule(R_Combat, MaxCombatRange)->GetFloat(), true, loc->mapped);
 					CalculateRunningLocation();
 				}
@@ -2809,14 +2813,16 @@ void Spawn::RemoveSpawnAccess(Spawn* spawn) {
 	}
 }
 
-void Spawn::SetFollowTarget(Spawn* spawn) {
+void Spawn::SetFollowTarget(Spawn* spawn, int32 follow_distance) {
 	if (spawn && spawn != this) {
 		m_followTarget = spawn->GetID();
+		m_followDistance = follow_distance;
 	}
 	else {
 		m_followTarget = 0;
 		if (following)
 			following = false;
+		m_followDistance = 0;
 	}
 }
 

+ 2 - 1
EQ2/source/WorldServer/Spawn.h

@@ -929,7 +929,7 @@ public:
 	Mutex m_requiredQuests;
 	Mutex m_requiredHistory;
 
-	void SetFollowTarget(Spawn* spawn);
+	void SetFollowTarget(Spawn* spawn, int32 followDistance=0);
 	Spawn* GetFollowTarget();
 
 	/// <summary>Sets a user defined variable</summary>
@@ -1037,6 +1037,7 @@ private:
 	bool			is_pet;
 	// m_followTarget = spawn to follow around
 	int32			m_followTarget;
+	int32			m_followDistance;
 	bool            req_quests_private;
 	int16           req_quests_override;
 	bool            req_quests_continued_access;