hello,
I'am currently trying to create a more enhanced cow killer,
I've divided the cow field into 3 different area's:
East,
South,
West
so say if im in "East", and there is no attackable cow the bot runs to "South" I've created this method:
public void walkToArea(String area, Player p) throws InterruptedException {
/* 2 other areas to EAST*/
methods.safeWalkTo(PathSouthToEast);
if(area == "East" && whatAreaPlayer(p) == "South") {
methods.safeWalkTo(PathSouthToEast);
}
if(area == "East" && whatAreaPlayer(p) == "West") {
methods.safeWalkTo(PathWestToEast);
}
/*end EAST*/
/* 2 other areas to West*/
if(area == "West" && whatAreaPlayer(p) == "South") {
methods.safeWalkTo(PathSouthToWest);
}
if(area == "West" && whatAreaPlayer(p) == "East") {
methods.safeWalkTo(PathEastToWest);
}
/* 2 other areas to West*/
if(area == "South" && whatAreaPlayer(p) == "West") {
methods.safeWalkTo(PathWestToSouth);
}
if(area == "South" && whatAreaPlayer(p) == "East") {
methods.safeWalkTo(PathWestToSouth);
}
}
whatAreaPlayer:
public String whatAreaPlayer(Player p) {
if (cowFieldSouth.contains(p))
return "South";
if (cowFieldEast.contains(p))
return "East";
if (cowFieldWest.contains(p))
return "West";
return "cant find";
}
safeWalkTo (thanks to Renegeade)
public void safeWalkTo(Position[] p) throws InterruptedException {
this.getLocalWalker().walkPath(p);
Position lastPos = p[p.length - 1];
while (true) {
double lastDistance = distanceSquared(this.myPosition(), lastPos);
if (lastDistance < 4.5d) {
break;
}
Methods.sleep(3000);
if (Math.abs(distanceSquared(this.myPosition(), lastPos)
- lastDistance) < 1.1d) {
ArrayList<Position> shortenedPath = new ArrayList<Position>();
boolean startAdding = false;
for (Position pos : p) {
if (distanceSquared(this.myPosition(), pos) < 100d) {
startAdding = true;
}
if (startAdding) {
shortenedPath.add(pos);
}
}
this.getLocalWalker().walkPath(shortenedPath);
}
}
}
private double distanceSquared(Position p1, Position p2) {
return Math.pow(p1.getX() - p2.getX(), 2d)
+ Math.pow(p1.getY() - p2.getY(), 2d);
}
but now it just wont move...
thanks in advance,
Jelleplomp