Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Grim determination : because brute force won't work

As of now, i am stuck on this particularly hard level. The few thing i am currently struggling with are:

  1. How to counter the growth spell cast by the warlocks to the skeleton
  2. How to mitigate the sliding effect of paladins when hit with the warlocks spectral arrow (they end up sliding into the mines)

Here’s my code.

// Your goal is to protect Reynaldo

// Find the paladin with the lowest health.
function lowestHealthPaladin() {
    var lowestHealth = 99999;
    var lowestFriend = null;
    var friends = hero.findFriends();
    for(var f=0; f < friends.length; f++) {
        var friend = friends[f];
        if(friend.type != "paladin") { continue; }
        if(friend.health < lowestHealth && friend.health < friend.maxHealth) {
            lowestHealth = friend.health;
            lowestFriend = friend;
        }
    }
    return lowestFriend;
}

function commandPaladin(friend) {
    // Heal the paladin with the lowest health using lowestHealthPaladin()
    // You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
    // Paladins can also shield: command(paladin, "shield")
    // And dont forget, they can attack, too!
    var enemy = friend.findNearestEnemy();
    var least = lowestHealthPaladin();
    var enemyMissiles = hero.findEnemyMissiles();
    var nearest = friend.findNearest(enemyMissiles);
    var castable = friend.canCast("heal", least);
    if (least) {
        if (castable && least.health) {
        hero.command(friend, "cast", "heal", least);
        }
    }
    if (nearest) {
        var distance1 = friend.distanceTo(nearest);
        if (distance1 < 10) {
            hero.command(friend, "shield");
        }
    }
    if (enemy) {
        var distance2 = friend.distanceTo(enemy);
        if (distance2 < 8) {
            hero.command(friend, "attack", enemy);
        }
    }
    if (friend.pos.x < 66) {
         hero.command(friend, "move", {x : friend.pos.x + 1, y: friend.pos.y});
    }
     if (friend.pos.x > 69) {
         hero.command(friend, "move", {x : friend.pos.x - 1, y: friend.pos.y});
    }
  
}

function commandPeasant(friend){
    var item = friend.findNearestItem();
    var castable = hero.canCast("shrink", friend);
    if (castable) {
        hero.cast("shrink", friend);
    }
    if (item) {
        hero.command(friend, "move", item.pos);
    }
}

function commandGriffin(friend){
    var enemy = hero.findNearestEnemy();
     if (enemy) {
        hero.command(friend, "attack", enemy);
    }
}

function commandFriends() {
    // Command your friends.
    var friends = hero.findFriends();
    for(var i=0; i < friends.length; i++) {
        var friend = friends[i];
        if(friend.type == "peasant") {
            commandPeasant(friend);
        } else if(friend.type == "griffin-rider") {
            commandGriffin(friend);
        } else if(friend.type == "paladin") {
            commandPaladin(friend);
        }
    }
}

while(true) {
    commandFriends();
    // Summon griffin riders!
    var friends = hero.findFriends();
    var friend = hero.findNearest(friends);
    if (hero.gold > hero.costOf("griffin-rider")) {
        hero.summon("griffin-rider");
  
    }
}

Can you please tell me which part i can optimize? I’m currently using the mage class, so any spell casting tips would be useful. Thanks in advance

Aim for the warlocks first

Or use the castgoldstorm spell like I did

if i aim for the warlocks another one will just spawn in one or two seconds, and what does gold storm do again?

Gold storm creates a massive storm of gold (clue’s in the name!). It makes one about once every 10 ish seconds I think. And creates loads of gold. I recommend it. Make sure you don’t try and follow the gold towards the ogres though.

Ok, i beat the level, i still have problems getting the bonus tho… i want to ask something too. Can you somehow prevent or mitigate the growth spell the warlocks casted on the skeletons?

Not unless you kill them :grin:
I wouldn’t recommend targeting them though.

I know, since

  1. they explode into a mess of fiery death and leave all of my troops half dead when they die
  2. the game spawn another one 2-3 seconds after the other dies