Code:
* Following
**/
public void playerWalk(int x, int y) {
PathFinder.getPathFinder().findRoute(c, x, y, true, 1, 1);
}
public void followPlayer(int i) {
if(Server.playerHandler.players[c.followId] == null || Server.playerHandler.players[c.followId].isDead) {
c.followId = 0;
return;
}
if (c.freezeTimer > 0) {
return;
}
if (c.inWG()) {
c.followId = 0;
return;
}
if (c.inDuelArena()) {
c.followId = 0;
return;
}
if (c.inJail() && c.Jail == true) {
c.sendMessage("You cannot follow in jail!");
c.followId = 0;
return;
}
if (c.Jail == true) {
c.sendMessage("You cannot follow in jail!");
c.followId = 0;
return;
}
if (c.isDead || c.playerLevel[3] <= 0)
return;
if(c.freezeTimer > 0 || c.isDead || c.playerLevel[3] <= 0)
return;
int otherX = Server.playerHandler.players[c.followId].getX();
int otherY = Server.playerHandler.players[c.followId].getY();
boolean withinDistance = c.goodDistance(otherX, otherY, c.getX(), c.getY(), 1);
boolean goodDistance = c.goodDistance(otherX, otherY, c.getX(), c.getY(), 1);
boolean hallyDistance = c.goodDistance(otherX, otherY, c.getX(), c.getY(), 2);
boolean bowDistance = c.goodDistance(otherX, otherY, c.getX(), c.getY(), 8);
boolean rangeWeaponDistance = c.goodDistance(otherX, otherY, c.getX(), c.getY(), 4);
boolean sameSpot = c.absX == otherX && c.absY == otherY;
if(!c.goodDistance(otherX, otherY, c.getX(), c.getY(), 25)) {
c.followId = 0;
return;
}
if(c.goodDistance(otherX, otherY, c.getX(), c.getY(), 1)) {
if (otherX != c.getX() && otherY != c.getY()) {
stopDiagonal(otherX, otherY);//This is what causes Clipping through walls needa rewrite this
return;
}
}
if((c.usingBow || c.mageFollow || (c.playerIndex > 0 && c.autocastId > 0)) && bowDistance && !sameSpot) {
return;
}
if(c.getCombat().usingHally() && hallyDistance && !sameSpot) {
return;
}
if(c.usingRangeWeapon && rangeWeaponDistance && !sameSpot) {
return;
}
c.faceUpdate(c.followId+32768);
int absX = c.getX();
int absY = c.getY();
if (otherX == c.absX && otherY == c.absY) {
int r = Misc.random(3);
switch (r) {
case 0:
walkTo(0,-1);
break;
case 1:
walkTo(0,1);
break;
case 2:
walkTo(1,0);
break;
case 3:
walkTo(-1,0);
break;
}
} else if(c.isRunning2 && !withinDistance) {
if(otherY > c.getY() && otherX == c.getX()) {
playerWalk(otherX, otherY - 1);
} else if(otherY < c.getY() && otherX == c.getX()) {
playerWalk(otherX, otherY + 1);
} else if(otherX > c.getX() && otherY == c.getY()) {
playerWalk(otherX - 1, otherY);
} else if(otherX < c.getX() && otherY == c.getY()) {
playerWalk(otherX + 1, otherY);
} else if(otherX < c.getX() && otherY < c.getY()) {
playerWalk(otherX + 1, otherY + 1);
} else if(otherX > c.getX() && otherY > c.getY()) {
playerWalk(otherX - 1, otherY - 1);
} else if(otherX < c.getX() && otherY > c.getY()) {
playerWalk(otherX + 1, otherY - 1);
} else if(otherX > c.getX() && otherY < c.getY()) {
playerWalk(otherX + 1, otherY - 1);
}
} else {
if(otherY > c.getY() && otherX == c.getX()) {
playerWalk(otherX, otherY - 1);
} else if(otherY < c.getY() && otherX == c.getX()) {
playerWalk(otherX, otherY + 1);
} else if(otherX > c.getX() && otherY == c.getY()) {
playerWalk(otherX - 1, otherY);
} else if(otherX < c.getX() && otherY == c.getY()) {
playerWalk(otherX + 1, otherY);
} else if(otherX < c.getX() && otherY < c.getY()) {
playerWalk(otherX + 1, otherY + 1);
} else if(otherX > c.getX() && otherY > c.getY()) {
playerWalk(otherX - 1, otherY - 1);
} else if(otherX < c.getX() && otherY > c.getY()) {
playerWalk(otherX + 1, otherY - 1);
} else if(otherX > c.getX() && otherY < c.getY()) {
playerWalk(otherX - 1, otherY + 1);
}
}
c.faceUpdate(c.followId+32768);
}
public void followNpc() { //old one
if (Server.npcHandler.npcs[c.followId2] == null
|| Server.npcHandler.npcs[c.followId2].isDead) {
c.followId2 = 0;
return;
}
if (c.freezeTimer > 0) {
return;
}
if (c.inWG()) {
c.followId = 0;
return;
}
if (c.inDuelArena()) {
c.followId = 0;
return;
}
if (c.inJail() && c.Jail == true) {
c.sendMessage("You cannot follow in jail!");
c.followId = 0;
return;
}
if (c.Jail == true) {
c.sendMessage("You cannot follow in jail!");
c.followId = 0;
return;
}
if (c.isDead || c.playerLevel[3] <= 0)
return;
int otherX = Server.npcHandler.npcs[c.followId2].getX();
int otherY = Server.npcHandler.npcs[c.followId2].getY();
boolean withinDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 2);
boolean goodDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 1);
boolean hallyDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 2);
boolean bowDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 8);
boolean rangeWeaponDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 4);
boolean sameSpot = c.absX == otherX && c.absY == otherY;
if (!c.goodDistance(otherX, otherY, c.getX(), c.getY(), 25)) {
c.followId2 = 0;
return;
}
if (c.goodDistance(otherX, otherY, c.getX(), c.getY(), 1)) {
if (otherX != c.getX() && otherY != c.getY()) {
stopDiagonal(otherX, otherY);
return;
}
}
if ((c.usingBow || c.mageFollow || (c.npcIndex > 0 && c.autocastId > 0))
&& bowDistance && !sameSpot) {
return;
}
if (c.getCombat().usingHally() && hallyDistance && !sameSpot) {
return;
}
if (c.usingRangeWeapon && rangeWeaponDistance && !sameSpot) {
return;
}
c.faceUpdate(c.followId2);
if (otherX == c.absX && otherY == c.absY) {
int r = Misc.random(3);
switch (r) {
case 0:
walkTo(0, -1);
break;
case 1:
walkTo(0, 1);
break;
case 2:
walkTo(1, 0);
break;
case 3:
walkTo(-1, 0);
break;
}
} else if (c.isRunning2 && !withinDistance) {
if (otherY > c.getY() && otherX == c.getX()) {
walkTo(0,
getMove(c.getY(), otherY - 1)
+ getMove(c.getY(), otherY - 1));
} else if (otherY < c.getY() && otherX == c.getX()) {
walkTo(0,
getMove(c.getY(), otherY + 1)
+ getMove(c.getY(), otherY + 1));
} else if (otherX > c.getX() && otherY == c.getY()) {
walkTo(getMove(c.getX(), otherX - 1)
+ getMove(c.getX(), otherX - 1), 0);
} else if (otherX < c.getX() && otherY == c.getY()) {
walkTo(getMove(c.getX(), otherX + 1)
+ getMove(c.getX(), otherX + 1), 0);
} else if (otherX < c.getX() && otherY < c.getY()) {
walkTo(getMove(c.getX(), otherX + 1)
+ getMove(c.getX(), otherX + 1),
getMove(c.getY(), otherY + 1)
+ getMove(c.getY(), otherY + 1));
} else if (otherX > c.getX() && otherY > c.getY()) {
walkTo(getMove(c.getX(), otherX - 1)
+ getMove(c.getX(), otherX - 1),
getMove(c.getY(), otherY - 1)
+ getMove(c.getY(), otherY - 1));
} else if (otherX < c.getX() && otherY > c.getY()) {
walkTo(getMove(c.getX(), otherX + 1)
+ getMove(c.getX(), otherX + 1),
getMove(c.getY(), otherY - 1)
+ getMove(c.getY(), otherY - 1));
} else if (otherX > c.getX() && otherY < c.getY()) {
walkTo(getMove(c.getX(), otherX + 1)
+ getMove(c.getX(), otherX + 1),
getMove(c.getY(), otherY - 1)
+ getMove(c.getY(), otherY - 1));
}
} else {
if (otherY > c.getY() && otherX == c.getX()) {
walkTo(0, getMove(c.getY(), otherY - 1));
} else if (otherY < c.getY() && otherX == c.getX()) {
walkTo(0, getMove(c.getY(), otherY + 1));
} else if (otherX > c.getX() && otherY == c.getY()) {
walkTo(getMove(c.getX(), otherX - 1), 0);
} else if (otherX < c.getX() && otherY == c.getY()) {
walkTo(getMove(c.getX(), otherX + 1), 0);
} else if (otherX < c.getX() && otherY < c.getY()) {
walkTo(getMove(c.getX(), otherX + 1),
getMove(c.getY(), otherY + 1));
} else if (otherX > c.getX() && otherY > c.getY()) {
walkTo(getMove(c.getX(), otherX - 1),
getMove(c.getY(), otherY - 1));
} else if (otherX < c.getX() && otherY > c.getY()) {
walkTo(getMove(c.getX(), otherX + 1),
getMove(c.getY(), otherY - 1));
} else if (otherX > c.getX() && otherY < c.getY()) {
walkTo(getMove(c.getX(), otherX - 1),
getMove(c.getY(), otherY + 1));
}
}
c.faceUpdate(c.followId2);
}
public int getRunningMove(int i, int j) {
if (j - i > 2)
return 2;
else if (j - i < -2)
return -2;
else
return j - i;
}
public void resetFollow() {
c.followId = 0;
c.followId2 = 0;
c.mageFollow = false;
c.outStream.createFrame(174);
c.outStream.writeWord(0);
c.outStream.writeByte(0);
c.outStream.writeWord(1);
}
public void walkTo(int i, int j) {
c.newWalkCmdSteps = 0;
if (++c.newWalkCmdSteps > 50)
c.newWalkCmdSteps = 0;
int k = c.getX() + i;
k -= c.mapRegionX * 8;
c.getNewWalkCmdX()[0] = c.getNewWalkCmdY()[0] = 0;
int l = c.getY() + j;
l -= c.mapRegionY * 8;
for (int n = 0; n < c.newWalkCmdSteps; n++) {
c.getNewWalkCmdX()[n] += k;
c.getNewWalkCmdY()[n] += l;
}
}
public void walkTo2(int i, int j) {
if (c.freezeDelay > 0)
return;
c.newWalkCmdSteps = 0;
if (++c.newWalkCmdSteps > 50)
c.newWalkCmdSteps = 0;
int k = c.getX() + i;
k -= c.mapRegionX * 8;
c.getNewWalkCmdX()[0] = c.getNewWalkCmdY()[0] = 0;
int l = c.getY() + j;
l -= c.mapRegionY * 8;
for (int n = 0; n < c.newWalkCmdSteps; n++) {
c.getNewWalkCmdX()[n] += k;
c.getNewWalkCmdY()[n] += l;
}
}
public void stopDiagonal(int otherX, int otherY) {
if (c.freezeDelay > 0)
return;
c.newWalkCmdSteps = 1;
int xMove = otherX - c.getX();
int yMove = 0;
if (xMove == 0)
yMove = otherY - c.getY();
/*
* if (!clipHor) { yMove = 0; } else if (!clipVer) { xMove = 0; }
*/
int k = c.getX() + xMove;
k -= c.mapRegionX * 8;
c.getNewWalkCmdX()[0] = c.getNewWalkCmdY()[0] = 0;
int l = c.getY() + yMove;
l -= c.mapRegionY * 8;
for (int n = 0; n < c.newWalkCmdSteps; n++) {
c.getNewWalkCmdX()[n] += k;
c.getNewWalkCmdY()[n] += l;
}
}
public void walkToCheck(int i, int j) {
if (c.freezeDelay > 0)
return;
c.newWalkCmdSteps = 0;
if (++c.newWalkCmdSteps > 50)
c.newWalkCmdSteps = 0;
int k = c.getX() + i;
k -= c.mapRegionX * 8;
c.getNewWalkCmdX()[0] = c.getNewWalkCmdY()[0] = 0;
int l = c.getY() + j;
l -= c.mapRegionY * 8;
for (int n = 0; n < c.newWalkCmdSteps; n++) {
c.getNewWalkCmdX()[n] += k;
c.getNewWalkCmdY()[n] += l;
}
}
public int getMove(int place1, int place2) {
if (System.currentTimeMillis() - c.lastSpear < 4000)
return 0;
if ((place1 - place2) == 0) {
return 0;
} else if ((place1 - place2) < 0) {
return 1;
} else if ((place1 - place2) > 0) {
return -1;
}
return 0;
}