From 0cbc5aac08fe42fd52eba5b3f08b4a79bd810921 Mon Sep 17 00:00:00 2001
From: Zoey76 <zoey_76@msn.com>
Date: Mon, 18 May 2015 17:27:06 -0300
Subject: [PATCH] Players shouldn't use pathfinding to go to targets (sadly)

They should stop when they hit the first obstacle.

Reported by: @maneco2
---
 .../handlers/actionhandlers/L2NpcAction.java  | 22 +++++++------
 .../actionhandlers/L2PcInstanceAction.java    | 31 +++++++++----------
 2 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2NpcAction.java b/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2NpcAction.java
index e8289aae83..e486bdada6 100644
--- a/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2NpcAction.java
+++ b/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2NpcAction.java
@@ -19,18 +19,18 @@
 package handlers.actionhandlers;
 
 import com.l2jserver.Config;
+import com.l2jserver.gameserver.GeoData;
 import com.l2jserver.gameserver.ai.CtrlIntention;
 import com.l2jserver.gameserver.enums.InstanceType;
 import com.l2jserver.gameserver.handler.IActionHandler;
 import com.l2jserver.gameserver.model.L2Object;
-import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.Location;
 import com.l2jserver.gameserver.model.actor.L2Npc;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.entity.L2Event;
 import com.l2jserver.gameserver.model.events.EventDispatcher;
 import com.l2jserver.gameserver.model.events.EventType;
 import com.l2jserver.gameserver.model.events.impl.character.npc.OnNpcFirstTalk;
-import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
 import com.l2jserver.gameserver.network.serverpackets.MoveToPawn;
 import com.l2jserver.util.Rnd;
 
@@ -79,23 +79,27 @@ public class L2NpcAction implements IActionHandler
 		else if (interact)
 		{
 			// Check if the activeChar is attackable (without a forced attack) and isn't dead
-			if (target.isAutoAttackable(activeChar) && !((L2Character) target).isAlikeDead())
+			if (target.isAutoAttackable(activeChar) && !((L2Npc) target).isAlikeDead())
 			{
-				// Check the height difference
-				if (Math.abs(activeChar.getZ() - target.getZ()) < 400) // this max heigth difference might need some tweaking
+				if (GeoData.getInstance().canSeeTarget(activeChar, target))
 				{
-					// Set the L2PcInstance Intention to AI_INTENTION_ATTACK
 					activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
-					// activeChar.startAttack(this);
 				}
 				else
 				{
-					// Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
-					activeChar.sendPacket(ActionFailed.STATIC_PACKET);
+					final Location destination = GeoData.getInstance().moveCheck(activeChar, target);
+					activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
 				}
 			}
 			else if (!target.isAutoAttackable(activeChar))
 			{
+				if (GeoData.getInstance().canSeeTarget(activeChar, target))
+				{
+					final Location destination = GeoData.getInstance().moveCheck(activeChar, target);
+					activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
+					return true;
+				}
+				
 				// Calculate the distance between the L2PcInstance and the L2Npc
 				if (!((L2Npc) target).canInteract(activeChar))
 				{
diff --git a/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2PcInstanceAction.java b/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2PcInstanceAction.java
index 3573be85db..bdc126d141 100644
--- a/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2PcInstanceAction.java
+++ b/L2J_DataPack/dist/game/data/scripts/handlers/actionhandlers/L2PcInstanceAction.java
@@ -25,7 +25,6 @@ import com.l2jserver.gameserver.enums.PrivateStoreType;
 import com.l2jserver.gameserver.handler.IActionHandler;
 import com.l2jserver.gameserver.model.L2Object;
 import com.l2jserver.gameserver.model.Location;
-import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.entity.TvTEvent;
 import com.l2jserver.gameserver.network.SystemMessageId;
@@ -33,6 +32,8 @@ import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
 
 public class L2PcInstanceAction implements IActionHandler
 {
+	private static final int CURSED_WEAPON_VICTIM_MIN_LEVEL = 21;
+	
 	/**
 	 * Manage actions when a player click on this L2PcInstance.<BR>
 	 * <BR>
@@ -83,50 +84,48 @@ public class L2PcInstanceAction implements IActionHandler
 		}
 		else if (interact)
 		{
+			final L2PcInstance player = target.getActingPlayer();
 			// Check if this L2PcInstance has a Private Store
-			if (((L2PcInstance) target).getPrivateStoreType() != PrivateStoreType.NONE)
+			if (player.getPrivateStoreType() != PrivateStoreType.NONE)
 			{
-				activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
+				activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, player);
 			}
 			else
 			{
 				// Check if this L2PcInstance is autoAttackable
-				if (target.isAutoAttackable(activeChar))
+				if (player.isAutoAttackable(activeChar))
 				{
-					// activeChar with lvl < 21 can't attack a cursed weapon holder
-					// And a cursed weapon holder can't attack activeChars with lvl < 21
-					if ((((L2PcInstance) target).isCursedWeaponEquipped() && (activeChar.getLevel() < 21)) || (activeChar.isCursedWeaponEquipped() && (((L2Character) target).getLevel() < 21)))
+					if ((player.isCursedWeaponEquipped() && (activeChar.getLevel() < CURSED_WEAPON_VICTIM_MIN_LEVEL)) //
+						|| (activeChar.isCursedWeaponEquipped() && (player.getLevel() < CURSED_WEAPON_VICTIM_MIN_LEVEL)))
 					{
 						activeChar.sendPacket(ActionFailed.STATIC_PACKET);
 					}
 					else
 					{
-						if (GeoData.getInstance().canSeeTarget(activeChar, target))
+						if (GeoData.getInstance().canSeeTarget(activeChar, player))
 						{
-							activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
-							activeChar.onActionRequest();
+							activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
 						}
 						else
 						{
-							final Location destination = GeoData.getInstance().moveCheck(activeChar.getX(), activeChar.getY(), activeChar.getZ(), target.getX(), target.getY(), target.getZ(), activeChar.getInstanceId());
+							final Location destination = GeoData.getInstance().moveCheck(activeChar, player);
 							activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
-							activeChar.onActionRequest();
 						}
+						activeChar.onActionRequest();
 					}
 				}
 				else
 				{
 					// This Action Failed packet avoids activeChar getting stuck when clicking three or more times
 					activeChar.sendPacket(ActionFailed.STATIC_PACKET);
-					if (GeoData.getInstance().canSeeTarget(activeChar, target))
+					if (GeoData.getInstance().canSeeTarget(activeChar, player))
 					{
-						activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, target);
+						activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player);
 					}
 					else
 					{
-						final Location destination = GeoData.getInstance().moveCheck(activeChar.getX(), activeChar.getY(), activeChar.getZ(), target.getX(), target.getY(), target.getZ(), activeChar.getInstanceId());
+						final Location destination = GeoData.getInstance().moveCheck(activeChar, player);
 						activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, destination);
-						activeChar.onActionRequest();
 					}
 				}
 			}
-- 
GitLab