def inAttackRange(enemy):
distance = hero.findNearestEnemy()
# Almost all swords have attack range of 3.
if distance <= 3:
return True
else:
return False
# Attack ogres only when they're within reach.
while True:
# Find the nearest enemy and store it in a variable.
enemy = hero.findNearestEnemy()
# Call inAttackRange(enemy), with the enemy as the argument
# and save the result in the variable canAttack.
if enemy:
hero.canAttack = inAttackRange()
# If the result stored in canAttack is True, then attack!
hero.isReady("cleave")
hero.cleave(enemy)
pass
distance = hero.findNearestEnemy()
# Almost all swords have attack range of 3.
if distance <= 3:
return True
else:
return False
# Attack ogres only when they're within reach.
while True:
# Find the nearest enemy and store it in a variable.
enemy = hero.findNearestEnemy()
# Call inAttackRange(enemy), with the enemy as the argument
inAttackRange(enemy)
# and save the result in the variable canAttack.
if enemy:
hero.canAttack = inAttackRange()
# If the result stored in canAttack is True, then attack!
hero.isReady("cleave")
hero.cleave(enemy)
pass