Summit's Gate - Javascript Help

// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
function summonUnits() {
    if (hero.gold >= hero.costOf("griffin-rider")) {
        hero.summon("griffin-rider");
    } else {
        var summonable = null;
    }
}
function commandUnits(friends) {
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "paladin") {
            commandPaladin(friend);
        } else if (friend.type == "archer") {
            commandArcher(friend);
        } else if (friend.type == "griffin-rider") {
            commandGriffin(friend);
        } else if (friend.type == "soldier") {
            commandSoldier(friend);
        } else {
            var commandable = null;
        }
    }
}
function commandArcher(archer) {
    var enemy = archer.findNearestEnemy();
    if (enemy) {
        hero.command(archer, "attack", enemy);
    }
    if (archer.health < 10) {
        hero.brew("heal", archer);
    }
}
function commandPaladin(paladin) {
    var enemy = paladin.findNearestEnemy();
    if (paladin.health < 100) {
        if (paladin.canCast("heal")) {
            hero.command(paladin, "cast", "heal", paladin);
        } else {
            hero.command(paladin, "shield");
        }
    } else {
        hero.command(paladin, "attack", enemy);
    }
}
function commandGriffin(griffin) {
    var enemy = griffin.findNearestEnemy();
    if (enemy) {
        hero.command(griffin, "attack", enemy);
    }
    if (griffin.health < 50) {
        hero.brew("heal", griffin);
    }
}
function commandSoldier(soldier) {
    var enemy = soldier.findNearestEnemy();
    if (enemy && enemy.type == "catapult") {
        hero.command(soldier, "attack", enemy);
    } else {
        hero.command(soldier, "move", {
            x: soldier.pos.x + 5,
            y: soldier.pos.y
        });
    }
    var catapults = hero.findByType("catapult");
    for (var i = 0; i < catapults.length; i++) {
        var catapult = catapults[i];
        if (catapult.health <= 0) {
            hero.command(soldier, "attack", enemy);
        }
    }
}
function heroAction() {
    var enemy = hero.findNearestEnemy();
    if (enemy.type == "tower") {
        if (hero.distanceTo("enemy" > 29)) {
            hero.moveXY(enemy.pos.x - 29, hero.pos.y);
        } else if (hero.canCast("disintegrate", enemy)) {
            hero.cast("disintegrate", enemy);
        } else {
            hero.attack(enemy);
        }
    }
}
while (true) {
    var friends = hero.findFriends();
    summonUnits();
    commandUnits(friends);
    heroAction();
}

I breach the outer gate, however the hero does not disintegrate or move toward the beam towers. I have enchanted lenses. What do I do to fix this? (No error) I might need help in future parts of summits gate.
Thanks

Anybody there? Hello!

You hero is doing nothing because of typo:

function heroAction() {
// code
        if (hero.distanceTo("enemy" > 29)) //code

preserving your code and with the simplest for the hero

    var enemy = hero.findNearestEnemy();
    if (enemy) hero.attack(enemy) ;

you can reach the Inner Sanctum


but you lose so many soldiers…
didn’t try but i think you need only paladins and archers, i passed the level with a free hero, without summoning any and without losing any unit.
See Jenny's method - stacking while true loops: Summit Gate? how the level can be divided into several while true loops

Has anybody tested the new brew ability?

3 Likes

I have used the explosion and heal abilities, could you please put that in Javascript?
Should I use the twilight glasses?
This is my new code for heroAction

function heroAction() {
    var enemy = hero.findNearestEnemy();
   if (enemy) {
       hero.attack(enemy);
   }
   if (hero.canCast("poison-cloud",enemy)) {
       hero.cast("poison-cloud", enemy);
   }
   if (hero.health < 500) {
       hero.brew("heal",hero);
   }
}

I breach the outer gate but get killed shortly after. @xython

1 Like

I never played with this hero and till now i have negative feelings about his “new” abilities. Using “brew” Omarn is attacked by his wolf. I think this was supposed to happen only when skeletons are summoned. Not a fan of stacking ifs and your main goal is to stay alive. Your function can be modified to

function heroAction() {
   var enemy = hero.findNearestEnemy();
   if (hero.health < 500) 
       hero.brew("heal",hero);
   else if (enemy) {
      if (hero.canCast("poison-cloud",enemy)) 
         hero.cast("poison-cloud", enemy);
      else
         hero.attack(enemy);
   }
}

but using the above function you will die being too close to towers
so used only attack with Vine Staff ( you can equip also the Lightning Twig ( i’m a big fan of it) but it will be slower. I also modified all minion’s attack functions. They don’t need to attack the enemies when their positions are in the second battlefield.

function heroAction() {
   var enemy = hero.findNearestEnemy();
   if (hero.health < hero.maxHealth && hero.isReady("brew")) // only for testing
       hero.brew("heal",hero); // you really don't need it
   else if (enemy) 
       hero.attack(enemy);
}

function commandSoldier(soldier) {
    var enemy = soldier.findNearestEnemy();
    if (enemy && enemy.pos.x < 100){
   // code
    }
 }

the result is displayed in an ugly quick gif

Can you use the console? Did you see the link from the previous post and do you understand it?

1 Like

I can not use the console and I do not understand the link.

Your hero, twilight glasses, cheap weapon, no brew gimmicks, no casualties, using the method from the link in the post
изображение
OmSGsmall

What do you don’t understand from the link?
Why you cannot use the console?

1 Like

The inspect menu is blocked on my school chromebook, and I don’t get how you stack while true loops.

Can you use this method How to unblock inspect element - Quora?

Chromebooks don’t have function (f) buttons.

see How to (fast and ugly) debug witht he pet
You can stack while true loops this way:

// code
var  doors = hero.findByType("door");
var Gate = doors[2],
    InnerGate = doors[1],
    SanctumGate = doors[0];
// code
while (true){
  // code for catapults and ogres
  if (Gate.health > 0)
    hero.attack(Gate);
  else break;
}
// code
while (true){
  // code
  if (InnerGate .health > 0)
    hero.attack(InnerGate );
  else break;
}
// code....

WHat does the console and debug do?

You can debug your code more successfully, find the Ids, health, positions and their relations with a specific array, find mistakes. Something like this is shown here: HELP Kelvintaph Crusader - #70 by xython (sorry - python )

Hi @xython
Sorry for the late reply, I figured out how to use the while-loops and break to make sections.

// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
function summonUnits() {
    if (hero.gold >= hero.costOf("griffin-rider")) {
        hero.summon("griffin-rider");
    } else {
        var summonable = null;
    }
}
function commandUnits(friends) {
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "paladin") {
            commandPaladin(friend);
        } else if (friend.type == "archer") {
            commandArcher(friend);
        } else if (friend.type == "griffin-rider") {
            commandGriffin(friend);
        } else if (friend.type == "soldier") {
            commandSoldier(friend);
        } else {
            var commandable = null;
        }
    }
}
function commandArcher(archer) {
    var enemy = archer.findNearestEnemy();
    if (enemy && enemy.pos.x < 100) {
        hero.command(archer, "attack", enemy);
    }
    if (archer.health < 10) {
        hero.brew("heal", archer);
    }
}
function commandPaladin(paladin) {
    hero.command(paladin, "shield");
}
function commandGriffin(griffin) {
    var enemy = hero.findNearestEnemy();
    if (enemy && enemy.pos.x < 120) {
        hero.command(griffin, "attack", enemy);
    }
    if (griffin.health < 50) {
        hero.brew("heal", griffin);
    }
}
function commandSoldier(soldier) {
    var enemy = soldier.findNearestEnemy();
    if (enemy && enemy.type == "catapult") {
        hero.command(soldier, "attack", enemy);
    } else {
        hero.command(soldier, "move", {
            x: soldier.pos.x + 5,
            y: soldier.pos.y
        });
    }
    var catapults = hero.findByType("catapult");
    for (var i = 0; i < catapults.length; i++) {
        var catapult = catapults[i];
        if (catapult.health <= 0) {
            hero.command(soldier, "attack", enemy);
        }
    }
}
function heroAction() {
    var enemy = hero.findNearestEnemy();
    if (hero.health < 500) {
        hero.brew("heal", hero);
    } else if (enemy && hero.distanceTo(enemy) < 45) {
        hero.attack(enemy);
    } else {
        var attack = null;
    }
}
while (true) {
    var friends = hero.findFriends();
    var enemy = hero.findNearestEnemy();
    if (enemy.type == "tower") {
        break;
    } else {
        summonUnits();
        commandUnits(friends);
        heroAction();
    }
}
var indexer2 = 0;
while (indexer2<1) {
    var enemy = hero.findNearestEnemy();
    var paladins = hero.findByType("paladin");
    var paladin1 = paladins[0];
    var palaldin2 = paladins[1];
    if (enemy.pos.y >39) {
        hero.moveXY(enemy.pos.x, enemy.pos.y + 5);
        hero.command(paladin1, "move", {x:hero.pos.x,y:hero.pos.y + 5});
        if (paladin1.pos.x < hero.pos.x) {
            hero.brew("heal",hero);
        }
        else {
            indexer2 = 1;
        }
    }
}
while(true) {
    var enemy = hero.findNearestEnemy();
    var paladins = hero.findByType("paladin");
    var paladin1 = paladins[0];
    var palaldin2 = paladins[1];
    hero.attack(enemy);
    if (paladin1.canCast("heal")) {
        hero.command(paladin1, "cast", "heal",hero);
    }
    
}

This is my current code. The hero moves to the beam tower but the paladin takes a long time to move and continues shielding after the hero starts moving.
Thanks

Anybody there? @xython ?

What wand you use and how much health you have? I hope you’re wearing the best glasses.Your first code is a better basis for solving the level

I am using Vine staff, and have 1034 maxHealth. I am using twilight glasses.

Can you write a function that returns all enemies except those with a type “door”?

@xython ,

// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
hero.setFlowerColor("red");
function summonUnits() {
    if (hero.gold >= hero.costOf("griffin-rider")) {
        hero.summon("griffin-rider");
    } else {
        var summonable = null;
    }
}
function commandUnits(friends) {
    for (var i = 0; i < friends.length; i++) {
        var friend = friends[i];
        if (friend.type == "paladin") {
            commandPaladin(friend);
        } else if (friend.type == "archer") {
            commandArcher(friend);
        } else if (friend.type == "griffin-rider") {
            commandGriffin(friend);
        } else if (friend.type == "soldier") {
            commandSoldier(friend);
        } else {
            var commandable = null;
        }
    }
}
function commandArcher(archer) {
    var enemy = archer.findNearestEnemy();
    if (enemy && enemy.pos.x < 100) {
        hero.command(archer, "attack", enemy);
    }
    if (archer.health < 10) {
        hero.brew("heal", archer);
    }
}
function commandPaladin(paladin) {
    hero.command(paladin, "shield");
}
function commandGriffin(griffin) {
    var enemy = hero.findNearestEnemy();
    if (enemy && enemy.pos.x < 120) {
        hero.command(griffin, "attack", enemy);
    }
    if (griffin.health < 50) {
        hero.brew("heal", griffin);
    }
}
function commandSoldier(soldier) {
    var enemy = soldier.findNearestEnemy();
    if (enemy && enemy.type == "catapult") {
        hero.command(soldier, "attack", enemy);
    } else {
        hero.command(soldier, "move", {
            x: soldier.pos.x + 5,
            y: soldier.pos.y
        });
    }
    var catapults = hero.findByType("catapult");
    for (var i = 0; i < catapults.length; i++) {
        var catapult = catapults[i];
        if (catapult.health <= 0) {
            hero.command(soldier, "attack", enemy);
        }
    }
}
function heroAction() {
    var enemy = hero.findNearestEnemy();
    if (hero.health < 500) {
        hero.brew("heal", hero);
    } else if (enemy && hero.distanceTo(enemy) < 45) {
        hero.attack(enemy);
    } else {
        var attack = null;
    }
}
while (true) {
    var friends = hero.findFriends();
    var enemy = hero.findNearestEnemy();
    var enemies = hero.findEnemies();
    if (enemy.type == "tower" && enemies.length ==4) {
        break;
    } else {
        summonUnits();
        commandUnits(friends);
        heroAction();
    }
}
function removeDoors(enemies){
    var enemies1 = [];
    for(var i=0;i<enemies.length; i++){
        var enemy = enemies[i];
        if (enemy.type !="door") {
            enemies1.push(enemy);
        }
    }
    return enemies1;
}
while(true) {
    var paladin = hero.findByType("paladin")[0];
    if (hero.pos.x==57&&hero.pos.y==37&&paladin.pos.x==52&&paladin.pos.y==37) {
        break;
    }
    else {
        hero.moveXY(57, 37);
    hero.command(paladin, "move", {x:hero.pos.x-5,y:hero.pos.y}); 
    }
}

I changed some of the code and made the function. (I posted all of the code because I might get an infinite loop and need this code to proceed)
Thanks

Why does your removeDoors() function just return the initial input?