Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

[SOLVED] Trouble with Reaping Fire


#1

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();
    }
}  

#2

Please give additional information about your issue. Could you send a screenshot of the error it gives?


#3

Sure. Now i ran it again and the griffin rider doesn’t do anything until the hero runs his function. By that time the ogres had advanced to the mines. I don’t understand why my hero waits so long to command.


#4

In the commandAttack function you have to check if you have enought gold before summoning it


#5

I checked it in the chooseStrategy() function. Looks like I should have summoned the griffin-rider in the chooseStrategy(). I passed the level with only this change in my code.

Thanks!