Help with Summits gate pls

// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
// summon troops
var stage = 1;
var tacktick = 'hold';
var summonTypes = ['griffin-rider'];
function summon() {
    var types = summonTypes[hero.built.legth % summonTypes.length];
    if (hero.gold >= hero.costOf(types)) {
        hero.summon(types);
    }
}

/* -summon
   -command
   -findlowhelt
   -attack
   -strat
   -move
   -collect
   -command troop
   
*/

function findLowHelt() {
    var lowestHealth = 99999;
    var lowestFriend = null;
    var friends = hero.findFriends();
    for (var f = 0; f < friends.length; f++) {
        var friend = friends[f];
        if (friend.health < lowestHealth && friend.health < friend.maxHealth) {
            lowestHealth = friend.health;
            lowestFriend = friend;
        }
    }
    return lowestFriend;
}

function commandPal(pal, warlock) {
    var friends = hero.findFriends();
    var low = findLowHelt();
    for (var i = 0; i < friends.length; i ++) {
        var friend = friends[i];
        if (low) {
            if (pal.canCast("heal", low)) {
                hero.command(pal, "cast", "heal", low);
            }
        } else if (pal.health < 100) {
            hero.command(pal, "shield");
        } else if (stage < 4) {
            hero.command(paladin, "move", {'x': 94, 'y': 34});
        } else if (stage == 5) {
            hero.command(paladin, "move", {'x': 284, 'y': 33});
        } else {
            var enemy = pal.findNearestEnemy();
            if (warlock) {
                enemy = warlock;
            }
            if (enemy) {
                hero.command(pal, "attack", enemy);
            }
        }
        
    }
} 

function commandSol(sol, warlock) {
    var enemy = sol.findNearestEnemy();
    if (warlock) {
        enemy = warlock;
    } if (stage == 3) {
        hero.command(soldier, "move", {'x': 84, 'y': 34});
    } else if (enemy) {
        hero.command(sol, "attack", enemy);
    }
    
}

function commandTroops() {
    var friends = hero.findFriends();
    var warlock = hero.findNearest(hero.findByType("warlock"));
    for (var i = 0; i < friends.length; i ++) {
        var friend = friends[i];
        if (tacktick == 'hold') {
            hero.command(friend, "defend", {'x': 1, 'y': 40});
        } else if (friend.type == "paladin") {
            commandPal(friend, warlock);
        } else {
            commandSol(friend, warlock);
        }
    }
}

function move(pos) {
    if (hero.isReady("jump")) {
        hero.jumpTo(pos);
    }
    else {
        hero.move(pos);
    }
}

function attack(target) {
    if (target) {
        if (hero.distanceTo(target) < 10) {
            move(target.pos);
        } else if (hero.isReady("bash")) {
            hero.bash(target);
        } else if (hero.canCast("chain-lightning", target)) {
            hero.cast("chain-lightning", target);
        } else {
            hero.attack(target);
        }
         
    }
}

function pickUp() {
    var item = hero.findNearestItem();
    if (item) {
        move(item.pos);
    }
}

commandTroops();
hero.moveXY(31, 56);
while(true) {
    var catal = hero.findNearest(hero.findByType("catapult"));
    var warlok = hero.findNearest(hero.findByType("warlock"));
    var enemy = hero.findNearestEnemy();
    var item = hero.findNearestItem();
    var time = hero.time;
    if (catal) {
        stage = 1;
        attack(catal);
    } else if (time < 20) {
        tacktick = 'defend';
        stage = 2;
        move({"x": 50, "y": 33});
    } else if (stage < 4) {
        if (enemy) {
            stage = 3;
            attack(enemy);
        }
        else {
            move({"x": 172, "y": 46});
        }
        if (hero.pos.x > 170) {
            stage = 4;
        }
    } else if (stage < 5) {
        if (hero.pos.x < 240) {
            move({"x": 274, "y": 35});
            tacktick = 'defend';
        } else if (item && hero.distanceTo(item) < 10) {
            pickUp();
            tacktick = "attack";
        } else if (warlok) {
            enemy = warlok;
            summon();
            attack(enemy);
        } else if (enemy && enemy.type != 'gates') {
            attack(enemy);
        } else if (item && hero.distanceTo(item) < 45) {
            pickUp();
            tacktick = 'defend';
            summon();
        } else {
            attack(enemy);
        } if (hero.pos.x > 290) {
            stage = 5;
        } 
        tacktick = attack;
    } else {
        summon();
        attack(enemy);
    } commandTroops();
    
}
1 Like

not related but tacktick is spelled tactic