Hello,
After a few days of struggling, I finally managed to finish Sarven Sun, however, my code is acting funny and I’m not sure what I’m doing wrong.
Running this code will succesully finish the levele, including the optional goal. But I have a function for my pet to fetch me potions. However, when the pet does that, my hero stops doing the action he’s doing until he gets the potion.
Can someone kindly take a look at my code and tell me how to run those actions in parallel? Or what am I doing wrong?
Thanks in advance.
(also, most likely my code it’s overly complicated, but, I’m VERY new to programming)
# To disable the fire-traps add the lowest trap.value to the highest value.
# Move to the white X and say the answer to Kitty the cougar.
# Defeat all the ogres if you dare.
# Once all ogres are defeated move to the red X.
# Look out for potions to boost your health.
whiteX = {'x':27, 'y':42}
redX = {'x':151 , 'y': 118}
def deactivateTrap():
traps = hero.findHazards()
trapIndex = 0
minValue = 99999999
maxValue = 0
while trapIndex < len(traps):
trap = traps[trapIndex]
if trap.value < minValue:
minValue = trap.value
if trap.value > maxValue:
maxValue = trap.value
trapIndex += 1
hero.say(minValue + maxValue)
def ligthning(target):
if target:
if hero.canCast("chain-lightning", target):
hero.cast("chain-lightning", target)
def petPotion():
item = hero.findNearestItem()
if item and item.type == "potion" and hero.health <= (hero.maxHealth / 2):
pet.fetch(item)
def fight():
enemies = hero.findEnemies()
weakest = None
enemyIndex = 0
maxiHealth = 999999
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
distance = hero.distanceTo(enemy)
if enemy.health < maxiHealth:
weakest = enemy
maxiHealth = enemy.health
enemyIndex += 1
if enemy:
if len(enemies) > 5:
ligthning(enemy)
else:
hero.attack(enemy)
enemyIndex +=1
hero.moveXY(27, 42)
deactivateTrap()
while True:
hero.move(redX)
fight()
petPotion()