Hi there,
First off thanks for the great level. So great, I got seriously stuck on it. I feel like I’m doing everything right but still missing out on smth. My griffin-riders won’t attack anyone else after attacking one enemy, even after he died they keep having him as their “target”.
Thanks in adavnce to everyone trying to help me.
Here’s my code:
function chooseStrategy() {
var enemies = hero.findEnemies();
var fangrider = hero.findNearest(hero.findByType("fangrider"));
// If you can summon a griffin-rider, return "griffin-rider"
if (hero.gold >= hero.costOf("griffin-rider")) {
return "griffin-rider";
} // If there is a fangrider on your side of the mines, return "attackFangrider"
else if (fangrider && fangrider.pos.x < 38) {
return "attackFangrider";
} else {
// Otherwise, return "collect-coins"
return "collect-coins";
}
}
function commandAttack() {
hero.say("the func commandAttack starts");
// Command your griffin riders to attack ogres.
hero.summon("griffin-rider");
var friends = hero.findFriends();
for (var g = 0; g < friends.length; g++) {
var griffin = friends[g];
var enemy = griffin.findNearestEnemy();
if (enemy) {
hero.say(enemy);
hero.command(griffin, "attack", enemy);
} else {
hero.say("we'll wait.");
}
}
}
function pickUpCoin() {
var coin = hero.findNearestItem();
if (coin) {
hero.moveXY(coin.pos.x, coin.pos.y);
}
}
function heroAttack() {
// Your hero should attack fang riders that cross the minefield
hero.say("attack!!!!");
var enemy = hero.findNearestEnemy();
if (enemy && enemy.type == "fangrider") {
if (hero.isReady("bash")) {
hero.bash(enemy);
} else if (hero.isReady("cleave")) {
hero.cleave(enemy);
} else {
hero.attack(enemy);
}
}
}
while (true) {
var strategy = chooseStrategy();
// Call a function, depending on what the current strategy is.
if (strategy == "griffin-rider") {
commandAttack();
} else if (strategy == "attackFangrider") {
heroAttack();
} else if (strategy == "collect-coins") {
pickUpCoin();
}
}