Code:
public void followEntity() {
if (c.getFollowEntity() == null || c.getFollowEntity().isDead) {
resetFollow();
return;
}
if (c.freezeTimer > 0 || c.usingMagic) {
return;
}
if (inPitsWait())
c.setFollowEntity(null);
if (c.isDead || c.getHitpoints() < 0)
return;
GameCharacter followEntity = c.getFollowEntity();
int otherX = followEntity.getX();
int otherY = followEntity.getY();
boolean withinDistance = c.goodDistance(otherX, otherY, c.absX, c.absY, 2);
boolean sameSpot = (otherX == c.absX && otherY == c.absY);
if (!c.goodDistance(otherX, otherY, c.absX, c.absY, 25)) {
c.setFollowEntity(null);
return;
}
if (c.goodDistance(otherX, otherY, c.absX, c.absY, 1)) {
if (otherX != c.absX && otherY != c.absY) {
stopDiagonal(otherX, otherY);
return;
}
}
boolean hallyDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 2);
boolean rangeWeaponDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 4);
boolean bowDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 6);
boolean mageDistance = c.goodDistance(otherX, otherY, c.getX(),
c.getY(), 7);
boolean castingMagic = (c.usingMagic || c.mageFollow || c.autocasting || c.spellId > 0)
&& mageDistance;
boolean playerRanging = (c.usingRangeWeapon)
&& rangeWeaponDistance;
boolean playerBowOrCross = (c.usingBow) && bowDistance;
if (!sameSpot) {
if (c.usingSpecial && (playerRanging || playerBowOrCross)) {
c.stopMovement();
c.setFollowEntity(null);
return;
}
if (castingMagic || playerRanging || playerBowOrCross) {
c.stopMovement();
c.setFollowEntity(null);
return;
}
if (c.getCombat().usingHally() && hallyDistance) {
c.stopMovement();
c.setFollowEntity(null);
return;
}
}
boolean faceboolean = c.getFollowEntity().getType() == EntityType.PLAYER ? true : false;
c.setFaceIndex(c.getFollowEntity().index, faceboolean);
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 && Region.canAttack(c, c.getFollowEntity())) {
if (otherY > c.absY && otherX == c.absX) {
playerWalk(otherX, otherY - 1);
} else if (otherY < c.absY && otherX == c.absX) {
playerWalk(otherX, otherY + 1);
} else if (otherX > c.absX && otherY == c.absY) {
playerWalk(otherX - 1, otherY);
} else if (otherX < c.absX && otherY == c.absY) {
playerWalk(otherX + 1, otherY);
} else if (otherX < c.absX && otherY < c.absY) {
playerWalk(otherX + 1, otherY + 1);
} else if (otherX > c.absX && otherY > c.absY) {
playerWalk(otherX - 1, otherY - 1);
} else if (otherX < c.absX && otherY > c.absY) {
playerWalk(otherX + 1, otherY - 1);
} else if (otherX > c.absX && otherY < c.absY) {
playerWalk(otherX + 1, otherY - 1);
}
} else {
if (otherY > c.absY && otherX == c.absX) {
playerWalk(otherX, otherY - 1);
} else if (otherY < c.absY && otherX == c.absX) {
playerWalk(otherX, otherY + 1);
} else if (otherX > c.absX && otherY == c.absY) {
playerWalk(otherX - 1, otherY);
} else if (otherX < c.absX && otherY == c.absY) {
playerWalk(otherX + 1, otherY);
} else if (otherX < c.absX && otherY < c.absY) {
playerWalk(otherX + 1, otherY + 1);
} else if (otherX > c.absX && otherY > c.absY) {
playerWalk(otherX - 1, otherY - 1);
} else if (otherX < c.absX && otherY > c.absY) {
playerWalk(otherX + 1, otherY - 1);
} else if (otherX > c.absX && otherY < c.absY) {
playerWalk(otherX - 1, otherY + 1);
}
}
c.setFaceIndex(followEntity.index, faceboolean);
}