[Solved] Kelvintaph Burgler (Paladin Movement)

# What eldritch artifacts are these? Don't let them blast you!
# The ice gate will open when both ogres are defeated.
def commandPaladins():
    paladins = hero.findByType("paladin")
    cheiftan = hero.findNearest("Oniko")
    yaks = hero.findByType("ice-yak")
    for yak in yaks:
        for paladin in paladins:
            hero.command(paladin, "move", {'x': 54, 'y': 50})
            if hero.pos.x == 50 and hero.pos.y == 24:
                hero.command(paladin, "move", yak.pos)
def move():
    missiles = hero.findEnemyMissiles()
    witches = hero.findByType("witch")
    chieftans = hero.findByType("chieftain")
    for missile in missiles:
        distance = hero.distanceTo(missile)
        if distance < 10:
            goalPoint  = Vector(68, 14)
            # Vector from goal to hero
            goal = Vector.subtract(goalPoint, hero.pos)
            goal = Vector.normalize(goal)
            goal = Vector.multiply(goal, 10)
            # Vector from hero to missile
            missileVector = Vector.subtract(hero.pos, missile.pos)
            missileVector = Vector.normalize(missileVector)
            missileVector = Vector.multiply(missileVector, 10)
            # Where to go to dodge the missile
            goal = Vector.add(goal, missileVector)
            moveToPos = Vector.add(hero.pos, goal)
            hero.move(moveToPos)
            for witch in witches:
                for cheiftan in chieftans:
                    if witch:
                        hero.cast("chain-lightning", witch)
                    elif chieftan:
                        hero.cast("chain-lightning", chieftan)
while True:
    commandPaladins()
    move()

For the vectors i did copy the one where you have to walk around the yaks, but instead it’s the missiles from the robots :smiley:
With this code my paladin moves back and forth after moving to (54, 50). I know it’s because it only moves to the yak if it’s on (54, 50), but I’m not sure how I can fix that. How can I fix this?

1 Like

Your hero’s moving pretty well :slight_smile: You still need to defeat both ogres…

            hero.command(paladin, "move", {'x': 54, 'y': 50})
            if hero.pos.x == 50 and hero.pos.y == 24:
                hero.command(paladin, "move", yak.pos) // only the last command will be executed if true
           // the structure to command the minions is always if, elif..., else    

In this case if you want to command the paladin to move to the end:

def commandPaladins():
    paladin = hero.findByType("paladin")[0]
    if paladin.pos.x < 52:
        hero.command(paladin, "move", {'x': 55, 'y': 39})
    else:
        hero.command(paladin, "move", {'x': 78, 'y': 39})

PS.

 # cheiftan = hero.findNearest("Oniko") No !
chieftain = hero.findByType("chieftain ")[0]

3 Likes
# The ice gate will open when both ogres are defeated.
def commandPaladins():
    paladins = hero.findByType("paladin")
    yaks = hero.findByType("ice-yak")
    witches = hero.findByType("witch")
    if witches:
        for yak in yaks:
            for witch in witches:
                for paladin in paladin:
                    hero.command(paladin, "move", {'x': 54, 'y': 50})
                    if witch.health == 0:
                        hero.command(paladin, "move", yak.pos)
def move():
    missiles = hero.findEnemyMissiles()
    witches = hero.findByType("witch")
    chieftans = hero.findByType("chieftain")
    for missile in missiles:
        distance = hero.distanceTo(missile)
        if distance < 10:
            goalPoint  = Vector(68, 14)
            # Vector from goal to hero
            goal = Vector.subtract(goalPoint, hero.pos)
            goal = Vector.normalize(goal)
            goal = Vector.multiply(goal, 10)
            # Vector from hero to missile
            missileVector = Vector.subtract(hero.pos, missile.pos)
            missileVector = Vector.normalize(missileVector)
            missileVector = Vector.multiply(missileVector, 10)
            # Where to go to dodge the missile
            goal = Vector.add(goal, missileVector)
            moveToPos = Vector.add(hero.pos, goal)
            hero.move(moveToPos)
            for witch in witches:
                for cheiftan in chieftans:
                    if witch:
                        hero.cast("chain-lightning", witch)
                    elif chieftan:
                        hero.cast("chain-lightning", chieftan)
while True:
    commandPaladins()
    move()

I changed my code a little bit, but I’m getting an error image
I’m not too sure what this means. It’s always helpful to understand error messages :smiley: Can someone explain this?

Never mind. I completed the level by using the hero.time command for when it hits a certain time, command the paladin to go to the yak, and then when the chieftain is dead, have the paladin go to the x. Thanks for the help!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.