Level: Library Tactician (JS)


#1

I’ve been stuck on Library Tactician for quite sometime and I can’t seem to figure out why my soldier keeps dying. I’ve had problems similar to this situation before and it’s usually tied to the glasses my hero was using (the one that allows to see through walls). I’ve changed them to the one that gives +60m in range but that didn’t resolve the issue. I’ve noticed some archers are not focus firing on the big ogres and I’m not sure but I think some soldiers are not staying inside the circle.

hero.commandSoldier = function (soldier, soldierIndex, numSoldiers) {
var angle = Math.PI * 2 * soldierIndex / numSoldiers;
var defendPos = {
x: 41, y: 40
};
defendPos.x += 10 * Math.cos(angle);
defendPos.y += 10 * Math.sin(angle);
hero.command(soldier, “defend”, defendPos);
};
hero.findStrongestTarget = function () {
var mostHealth = 0;
var bestTarget = null;
var enemies = hero.findEnemies();

for (var i = 0; i < enemies.length; i++) {
    if (enemies[i].health > mostHealth) {
        mostHealth = enemies[i].health;
        bestTarget = enemies[i];
    }
}
if (bestTarget && bestTarget.health > 15) {
    return bestTarget;
} else {
    return null;
}

};

hero.commandArcher = function (archer) {
var nearest = archer.findNearestEnemy();
if (archerTarget) {
hero.command(archer, “attack”, archerTarget);
} else if (nearest) {
hero.command(archer, “attack”, nearest);
}
};

var archerTarget = null;

while (true) {

if (!archerTarget || archerTarget.health <= 0) {
    archerTarget = hero.findStrongestTarget();
}
var friends = hero.findFriends();
var soldiers = hero.findByType("soldier");
var archers = hero.findByType("archers");
for (var i = 0; i < soldiers.length; i++) {
    var soldier = soldiers[i];
    hero.commandSoldier(soldier, i, soldiers.length);
}
for (i = 0; i < archers.length; i++) {
    var archer = archers[i];
    hero.commandArcher(archer, i, archers.length);
}

}


#2

@gripmaster You have the right idea, something seems off about the archers.

This is one of those “bugs” that is rather difficult so I will just point it out:

you have “archers” but it should be “archer


A way to debug this would be to have the hero command the archers to move to one point. If they never move, chances are that there might be something wrong with the commanding.

hero.say( archer.id + " " + i);

could also help to debug if placed in the code before you call the hero.commandArcher() method.