Seems like this should work, and I’m not sure what else to try. What am I missing?
while (true) {
let item = hero.findNearestItem();
if (item) {
hero.move(item.pos);
}
if (hero.gold >= hero.costOf("soldier")) {
hero.summon("soldier");
}
let friends = hero.findFriends();
for (let friend of friends) {
if (friend.type == "soldier") {
let enemy = friend.findNearestEnemy();
if (enemy) {
hero.command(friend, "attack", enemy);
if (friend.health < 100) {
hero.command(friend, "move", {x: 20,y: 46});
}
} else {
hero.command(friend, "move", {x: 78,y: 46});
}
}
}
}