In this code I’m using my Senick Steelclaw (has a throw method), but I ran into the problem with my normal Hero Sir Tharin Thunderfist using “cleave” as well.
The code seems to be working for me up until I kill the final enemy, an Ogre. Then, he just stands there not picking up coins for the last quarter of the countdown: adding in a !enemy didn’t seem to make any difference.
Since I’m not getting any errors, I’m assuming I have a logic error. Could anyone point out where I went wrong?
// Collect coins. Ignore sand yaks and burls. Fight throwers and ogres.
loop {
var enemy = this.findNearestEnemy();
var item = this.findNearestItem();
if (enemy) {
if (enemy.type == "sand-yak" || enemy.type == "burl") {
var position = item.pos;
var x = position.x;
var y = position.y;
this.moveXY(x, y);
// Don't fight sand yaks or burls! Just keep collecting coins.
}
// But if the enemy is type "thrower" or "ogre", attack them.
else if (enemy.type == "thrower" || enemy.type == "ogre") {
if (this.isReady("throw") && this.distanceTo(enemy) < this.throwRange) {
this.throw(enemy);
}else {
this.attack(enemy);
}
} else if (!enemy) {
// Collect coins.
if (item) {
position = item.pos;
x = position.x;
y = position.y;
this.moveXY(x, y);
}
}
}
}
Thanks for any assist!