As of now, i am stuck on this particularly hard level. The few thing i am currently struggling with are:
- How to counter the growth spell cast by the warlocks to the skeleton
- 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