In trying to create a priority kill list to survive longer by eliminating shamans and throwers first I wrote the following code below, but my hero’s behavior seems unchanged. I was going for:
- go to flag and ignore enemies
- kill shamans or throwers
- kill anything else
So I created an array to collect just the shamans and throwers, and access them one by one to eliminate them before regular enemies.
Any ideas where my logic went wrong?
loop {
var flag = this.findFlag();
// regular enemies
var enemy = this.findNearest(this.findEnemies());
// first enemies to kill
var killFirst = this.findByType("thrower" || "shaman");
var index = 0;
// pick one high priority enemy
var personOfInterest = killFirst[index];
// start off looking for flag if there's one
if (flag) {
this.pickUpFlag(flag);
}
else if (personOfInterest) {
if (this.isReady("warcry")) {
this.warcry();
}
else if (this.isReady("electrocute") && this.canElectrocute(enemy) && this.distanceTo(enemy) < 21) {
this.electrocute(enemy);
}
else if (this.isReady("bash") && this.distanceTo(enemy) < 4) {
this.bash(enemy);
}
else{
this.attack(enemy);
}
}
else if (enemy) {
if (this.isReady("warcry")) {
this.warcry();
}
else if (this.isReady("electrocute") && this.canElectrocute(enemy) && this.distanceTo(enemy) < 21) {
this.electrocute(enemy);
}
else if (this.isReady("bash") && this.distanceTo(enemy) < 4) {
this.bash(enemy);
}
else{
this.attack(enemy);
}
}
else{
this.shield();
}
}
Thanks in advance for any advice!