In Summit’s Gate. I get to the Warlocks which I’m trying to kill with my Griffins.
I do a findFriends to get an array of my Griffins to loop through to attack the Warlocks.
I think what is happening is that one of my griffins is being killed, then resurrected on the warlock side and so when I try and command it to attack the Warlocks an error is thrown (in commandGriffin function)
Does anyone have any ideas about this please?
In the screenshot below Christofide is one of my griffin-riders
Here is my code
#Commented out to stop infinite loop.
# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
# You need 2 archers and 2 soldiers.
def att(enemy):
if enemy.type!='door':
if enemy and hero.distanceTo(enemy)>5 and hero.isReady("jump") and enemy.type!='tower':
hero.jumpTo(enemy.pos)
elif enemy and enemy.health>10 and hero.canCast("chain-lightning", enemy):
hero.cast("chain-lightning", enemy)
if hero.isReady("shield"):
hero.shield()
elif enemy and hero.isReady("cleave") and hero.distanceTo(enemy)<5:
hero.cleave(enemy)
if hero.isReady("shield"):
hero.shield()
elif enemy and hero.isReady("bash") and hero.distanceTo(enemy)<3:
hero.bash(enemy)
if hero.isReady("shield"):
hero.shield()
elif enemy:
hero.attack(enemy)
elif enemy and hero.canCast("chain-lightning", enemy):
hero.cast("chain-lightning", enemy)
if hero.isReady("shield"):
hero.shield()
# This function can be helpful.
def summonAndSend(type, x, y):
while hero.gold>hero.costOf(type):
hero.summon(type)
unit = hero.built[len(hero.built)-1]
hero.command(unit, "move", {"x": x, "y": y})
# Find the paladin with the lowest health.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = None
friends = hero.findByType("paladin", hero.findFriends())
for friend in friends:
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
def commandPaladin():
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
# Paladins can also shield: command(paladin, "shield")
# And don't forget, they can attack, too!
paladins=hero.findByType("paladin", hero.findFriends())
for paladin in paladins:
if paladin.canCast("heal"):
needhealing=lowestHealthPaladin()
if hero.health<hero.maxHealth and hero.distanceTo(paladin)<15:
hero.command(paladin, "cast", "heal", hero)
elif needhealing:
#hero.say('Paladin healing: '+needhealing)
hero.command(paladin, "cast", "heal", needhealing)
enemy=paladin.findNearestEnemy()
if enemy and enemy.type!='door':
#hero.say('Paladin should be attacking: '+enemy)
hero.command(paladin, "attack",enemy)
#hero.command(paladin, "shield")
elif paladin.health<200:
hero.command(paladin, "shield")
pass
def commandSoldier():
soldiers=hero.findByType('soldier',hero.findFriends())
for soldier in soldiers:
enemy = soldier.findNearestEnemy()
if enemy and enemy.type!='door':
hero.command(soldier, "attack", enemy)
def commandGriffin(warlocks):
griffins=hero.findByType("griffin-rider", hero.findFriends())
hero.say('number of griffins '+len(griffins))
hero.say('number of warlock '+len(warlocks))
for griffin in griffins:
if len(warlocks)==0:
enemies=hero.findEnemies()
else:
enemies=warlocks
for enemy in enemies:
if enemy.type=='warlock':
hero.command(griffin, "attack", enemy)
break
else:
enemy=griffin.findNearestEnemy()
if enemy and enemy.type!='door':
hero.command(griffin, "attack", enemy)
break
def commandArcher():
archers=hero.findByType('archer',hero.findFriends())
for archer in archers:
enemy=archer.findNearestEnemy()
if enemy and enemy.type!='door':
hero.command(archer, "attack", enemy)
def commandPeasant(friend):
coins=friend.findItems()
coin=friend.findNearestItem()
hero.command(friend, "move", coin.pos)
def commandFriends(warlocks):
# Command your friends.
commandGriffin(warlocks)
commandArcher()
commandSoldier()
commandPaladin()
def commandFriendsMoveTo(targetLoc):
friends=hero.findFriends()
for friend in friends:
#hero.say('Move: '+friend)
hero.command(friend, "move", targetLoc)
def commandTypeMoveTo(targetLoc,ftype):
friends=hero.findByType(ftype, hero.findFriends())
for friend in friends:
#hero.say('Move: '+friend)
hero.command(friend, "move", targetLoc)
def killByType(enemyType):
enemies=hero.findByType(enemyType, hero.findEnemies())
for enemy in enemies:
while enemy.health>0:
att(enemy)
def getNearestByType(enemyType):
enemies=hero.findByType(enemyType, hero.findEnemies())
nearest=None
nearDist=9999
for enemy in enemies:
dist=hero.distanceTo(enemy)
if dist<nearDist:
nearDist=dist
nearest=enemy
return nearest
def palsHealHero():
#hero.say('about to be healed')
paladins=hero.findByType('paladin', hero.findFriends())
if len(paladins)<2 and hero.gold>hero.costOf('paladin'):
#hero.say('summoning paladin')
hero.summon('paladin')
paladins=hero.findByType('paladin', hero.findFriends())
counter=0
while hero.health<hero.maxHealth and len(paladins)>0 :
hero.say('palshealhero inside while')
paladins=hero.findByType('paladin', hero.findFriends())
for paladin in paladins:
#hero.say('summoning paladin inside for')
healthLev=hero.health
if hero.health<hero.maxHealth and paladin.canCast("heal") and hero.distanceTo(paladin)<15:
#hero.say('being healed'+counter)
hero.command(paladin, "cast", "heal", hero)
counter+=1
elif hero.health<hero.maxHealth and paladin.canCast("heal") and hero.distanceTo(paladin)>=15:
hero.command(paladin, "move", hero.pos)
def everyoneAttackSkeletons():
#except paladins and griffin-riders
allies=hero.findFriends()
for ally in allies:
enemy=ally.findNearestEnemy()
if enemy and ally.type!='griffin-rider' and ally.type!='paladin' and enemy.type=='skeleton':
hero.command(ally, "attack", target)
warlocks=hero.findByType("warlock", hero.findEnemies())
ftype='griffin-rider'
commandFriendsMoveTo({"x":3,"y":40})
killByType("catapult")
killByType("scout")
killByType("munchkin")
hero.say('about to move killed all sect1')
commandFriendsMoveTo({"x":67,"y":40})
hero.say('moved friends')
hero.moveXY(92, 36)
paladins=hero.findByType("paladin", hero.findFriends())
palsHealHero()
summonAndSend('griffin-rider', 67, 40)
commandFriendsMoveTo({"x":50,"y":37})
#going to breakdown nearest door
door=getNearestByType('door')
while door.health>0:
hero.attack(door)
hero.moveXY(60, 33)
killByType("thrower")
killByType("munchkin")
palsHealHero()
summonAndSend('griffin-rider', 50, 40)
commandFriendsMoveTo({"x":50,"y":37})
#Kill towers
hero.moveXY(124, 4)
enemies=hero.findByType("tower")
while enemies[0].health>0:
att(enemies[0])
#get healed
commandFriendsMoveTo({"x":90,"y":37})
hero.moveXY(93,35)
palsHealHero()
summonAndSend('griffin-rider', 90, 40)
#kill other tower
hero.moveXY(122, 64)
enemies=hero.findByType("tower")
while enemies[0].health>0:
att(enemies[0])
commandFriendsMoveTo({"x":127,"y":34})
hero.moveXY(136,35)
palsHealHero()
summonAndSend('griffin-rider', 127, 40)
#going to breakdown nearest door 2
door=getNearestByType('door')
while door.health>0:
hero.attack(door)
#Lure Ogres out
commandFriendsMoveTo({"x":127,"y":34})
hero.moveXY(167, 35)
killByType("ogre")
hero.moveXY(167, 35)
killByType("ogre")
commandFriendsMoveTo({"x":219,"y":15})
palsHealHero()
summonAndSend('griffin-rider', 219, 15)
#Draw out warlocks
while hero.pos.x<273:
hero.move({"x":277,"y":34})
hero.say('where the warlocks are')
warlocks=hero.findByType("warlock", hero.findEnemies())
#run away
while hero.pos.x>230:
hero.move({"x":228,"y":15})
#Hopefully kill warlocks with griffins and everything else with hero and others
commandFriendsMoveTo({"x":246,"y":25})
hero.say("about to send griffs after walocks")
commandGriffin(warlocks)
warlocks=hero.findByType("warlock", hero.findEnemies())
while len(warlocks)>0:
summonAndSend('griffin-rider', hero.pos.x, hero.pos.y)
commandFriends(warlocks)
enemy=hero.findNearestEnemy()
if enemy:
att(enemy)
warlocks=hero.findByType("warlock", hero.findEnemies())
hero.say('clean up skeletons')
skeletons=hero.findByType("skeleton", hero.findEnemies())
while len(skeletons)>0:
commandFriends(warlocks)
enemy=hero.findNearestEnemy()
if enemy:
att(enemy)
skeletons=hero.findByType("skeleton", hero.findEnemies())
commandFriendsMoveTo({"x":267,"y":34})
hero.say('finished skeletons get jewels')
jewels=hero.findItems()
while len(jewels)>0:
jewel=hero.findNearestItem()
hero.move(jewel.pos)
jewels=hero.findItems()
hero.say('got jewels kill boss')
#going to breakdown final door
door=getNearestByType('door')
while door.health>0:
hero.attack(door)