Merge remote-tracking branch 'origin/master'
Merge remote-tracking branch 'origin/master'

--- a/src/com/dryerzinia/pokemon/PokemonServer.java
+++ b/src/com/dryerzinia/pokemon/PokemonServer.java
@@ -27,12 +27,14 @@
 import java.net.SocketException;

 import java.util.ArrayList;

 import java.util.HashMap;

+import java.util.Iterator;

+import java.util.Map.Entry;

 import java.util.Timer;

 import java.util.TimerTask;

-import java.util.Map.Entry;

 import java.util.concurrent.ConcurrentHashMap;

 

 import com.dryerzinia.pokemon.map.Direction;

+import com.dryerzinia.pokemon.map.Level;

 import com.dryerzinia.pokemon.map.Pose;

 import com.dryerzinia.pokemon.net.ByteInputStream;

 import com.dryerzinia.pokemon.net.DatagramSocketStreamer;

@@ -44,14 +46,11 @@
 import com.dryerzinia.pokemon.net.msg.client.PlayerInfo;

 import com.dryerzinia.pokemon.net.msg.client.PlayerMovement;

 import com.dryerzinia.pokemon.net.msg.client.act.SendActMovedClientMessage;

-import com.dryerzinia.pokemon.net.msg.client.act.SendActTalkingToClientMessage;

-import com.dryerzinia.pokemon.net.msg.client.act.SendPerson;

 import com.dryerzinia.pokemon.net.msg.client.fight.SendFightClientMessage;

 import com.dryerzinia.pokemon.net.msg.server.ServerMessage;

-import com.dryerzinia.pokemon.obj.Actor;

 import com.dryerzinia.pokemon.obj.GameState;

+import com.dryerzinia.pokemon.obj.Player;

 import com.dryerzinia.pokemon.obj.tiles.Person;

-import com.dryerzinia.pokemon.obj.Player;

 import com.dryerzinia.pokemon.ui.Fight;

 import com.dryerzinia.pokemon.util.Database;

 import com.dryerzinia.pokemon.util.ResourceLoader;

@@ -232,20 +231,30 @@
     }

 

     /**

-     * TODO figure out what the fuck this is for

-     * @param x

-     * @param y

-     * @param level

-     * @return

-     */

-    public synchronized static boolean isPlayer(int x, int y, int level) {

-       for(PlayerInstanceData pid : players.values()) {

-            Player player = pid.getPlayer();

-            if(player.getPose().getX() + 4 == x

-            && player.getPose().getY() + 4 == y

-            && player.getPose().getLevel() == level)

-                return true;

-        }

+     * Return true if the given tile is occupied by any player.

+     * @param tileX

+     * @param tileY

+     * @param levelId

+     */

+    public synchronized static boolean isPlayerAtTile(

+    		int tileX, int tileY, int levelId) {

+    	

+    	Level level = GameState.getMap().getLevel(levelId);

+    	Iterator<Player> players = level.nearbyPlayerIterator();

+    	

+    	while (players.hasNext()) {

+    		Player player = players.next();

+    		Pose playerPose = player.getPose();

+    		

+    		int playerX = (int) playerPose.getX();

+    		int playerY = (int) playerPose.getY();

+    		int playerLvl = playerPose.getLevel();

+    		

+    		if (playerX == tileX && playerY == tileY && playerLvl == levelId) {

+    			return true;

+    		}

+    	}

+    	

         return false;

     }

 


--- a/src/com/dryerzinia/pokemon/obj/tiles/WanderingPerson.java
+++ b/src/com/dryerzinia/pokemon/obj/tiles/WanderingPerson.java
@@ -70,25 +70,25 @@
 

         	if (dir == Direction.UP) {

 

-        		if (!PokemonServer.isPlayer(x, y - 1, level)

+        		if (!PokemonServer.isPlayerAtTile(x, y - 1, level)

                         && g.canStepOn(x, y - 1))

                     canMove = true;

 

         	} else if (dir == Direction.DOWN) {

 

-        		if (!PokemonServer.isPlayer(x, y + 1, level)

+        		if (!PokemonServer.isPlayerAtTile(x, y + 1, level)

                         && g.canStepOn(x, y + 1))

                     canMove = true;

 

         	} else if (dir == Direction.LEFT) {

 

-        		if (!PokemonServer.isPlayer(x - 1, y, level)

+        		if (!PokemonServer.isPlayerAtTile(x - 1, y, level)

                         && g.canStepOn(x - 1, y))

                     canMove = true;

 

         	} else if (dir == Direction.RIGHT) {

 

-        		if (!PokemonServer.isPlayer(x + 1, y, level)

+        		if (!PokemonServer.isPlayerAtTile(x + 1, y, level)

                         && g.canStepOn(x + 1, y))

                     canMove = true;