here is my code, can someone please help?
// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
// Прорвись через святилище к вождю огров и убей её.
var enemies, enemy;
var summonTypes = ["archer"];
this.summonTroops = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};
// Найти паладина с самым низким количеством здоровья.
this.lowestHealthPaladin = function() {
var lowestHealth = 99999;
var lowestFriend = null;
var friends = this.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;
};
this.commandPaladin = function(paladin) {
// Полечи паладина с низким количеством здоровья используя lowestHealthPaladin()
// Ты можешь использовать paladin.canCast ("heal") и command(paladin, "cast", "heal", target)
// Паладины также могут использовать щит: command(paladin, "shield")
// And don't forget, they can attack, too!
var healTarget = this.lowestHealthPaladin();
enemy = paladin.findNearest(enemies);
if (healTarget && paladin.canCast("heal")) {
this.command(paladin, "cast", "heal", healTarget);
} else if (enemy) {
this.command(paladin, "attack", enemy);
}
};
this.commandSoldier = function(soldier) {
enemy = soldier.findNearest(enemies);
if (enemy) {
this.command(soldier, "attack", enemy);
} else {
this.command(soldier, "move", {x: soldier.pos.x+10, y: soldier.pos.y});
}
};
this.commandArcher = function(archer) {
enemy = archer.findNearest(enemies);
if (enemy) {
this.command(archer, "attack", enemy);
} else {
this.command(archer, "move", {x: archer.pos.x+5, y: archer.pos.y});
}
};
this.commandGriffin = function(griffin) {
enemy = griffin.findNearest(enemies);
if (enemy) {
this.command(griffin, "attack", enemy);
} else {
this.command(griffin, "move", {x: griffin.pos.x+10, y: griffin.pos.y});
}
};
this.commandFriends = function() {
// Командуй своими союзниками.
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "soldier") {
this.commandSoldier(friend);
} else if(friend.type == "archer") {
this.commandArcher(friend);
} else if(friend.type == "griffin-rider") {
this.commandGriffin(friend);
} else if(friend.type == "paladin") {
this.commandPaladin(friend);
}
}
};
this.heroPlan = function () {
enemy = this.findNearest(enemies);
var catapult = this.findNearest(this.findByType("catapult"));
if (catapult) {
enemy = catapult;
} else {
var nearestX = 101;
for (var i; i < enemies.length; i++) {
if (enemies[i].pos.x < nearestX) {
nearestX == enemies[i].pos.x;
enemy = enemies[i];
}
}
}
/*if (enemy && enemy.type != "tower") {
this.attack(enemy);
} else {
this.moveXY(159, 34);//this.attack(enemy);
}*/
if (enemy) {
this.attack(enemy);
}
};
this.saveFriednsLeft = function () {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if (friend) this.command(friend, "move", {x: 0, y: 40});
}
};
while(true) {
enemies = this.findEnemies();
var catapult = this.findNearest(this.findByType("catapult"));
if (catapult) {
this.saveFriednsLeft();
} else this.commandFriends();
this.summonTroops();
this.heroPlan();
}