Hello. I’m trying to get all the bonuses for The One Wizard Challenge, but I can only defeat 17 ogres with the code below:
while(true) {
var enemy = hero.findNearestEnemy();
if (enemy) {
if (hero.canCast("chain-lightning")) {
hero.cast("chain-lightning", enemy);
}
else if (hero.canCast("lightning-bolt")) {
hero.cast("lightning-bolt", enemy);
}
else {
hero.attack(enemy);
}
}
if (hero.health < 50 && hero.canCast("regen")) {
hero.cast("regen", hero);
}
}
I read somewhere about using certain spells depending on enemy type, so I modified the code I wrote above as can be seen below:
while(true) {
var enemy = hero.findNearestEnemy();
if (enemy) {
if (enemy.type == "scout" || enemy.type == "munchkin" && hero.canCast("chain-lightning")) {
hero.cast("chain-lightning", enemy);
}
else if (enemy.type == "catapult" || enemy.type == "ogre" && hero.canCast("lightning-bolt")) {
hero.cast("lightning-bolt", enemy);
}
else {
hero.attack(enemy);
}
}
if (hero.health < 50 && hero.canCast("regen")) {
hero.cast("regen", hero);
}
}
I’m not getting any errors with either of the codes. But I still can’t get all the bonuses (defeat 44 ogres). Does anyone have any idea what’s wrong with either of these codes? Thanks.