I have recently found that some players like Themasterluke and Bjalla give me an error, which I can’t seem to be able to fix, even if I comment all my code.
This is my code
def summonArmy(target):
if hero.canCast("earthskin", hero):
hero.cast("earthskin", hero)
if hero.canCast("summon-burl", target):
hero.cast("summon-burl")
if hero.canCast("summon-undead", target):
hero.cast("summon-undead")
def summonSoldiers():
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
def commandArmy(target):
soldiers = hero.findByType("soldier")
for soldier in soldiers:
if soldier and soldier.team == "ogres":
if target:
hero.command(soldier, "attack", target)
def findBestCorpse(corpses):
bestCorpse = None
bestValue = 0
corpsesIndex = 0
# Loop over the items array.
# Find the item with the highest valueOverDistance()
while corpsesIndex < len(corpses):
corpse = corpses[corpsesIndex]
corpseValue = corpse.maxHealth / hero.distanceTo(corpse)
if corpseValue > bestValue:
bestCorpse = corpse
bestValue = corpseValue
corpsesIndex += 1
return bestCorpse
def findLunch():
enemies = hero.findEnemies()
enemyIndex = 0
lunch = None
closestLunch = 9999
while enemyIndex < len(enemies):
potentialLunch = enemies[enemyIndex]
if potentialLunch:
distance = hero.distanceTo(potentialLunch)
if potentialLunch.health <= 200 and distance < closestLunch:
lunch = potentialLunch
closestLunch = distance
enemyIndex += 1
return lunch
def findEnemyHero():
enemies = hero.findEnemies()
enemyIndex = 0
enemyHero = None
maxHealth = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemy.maxHealth > maxHealth and enemy.type != "decoy":
enemyHero = enemy
maxHealth = enemy.maxHealth
enemyIndex += 1
return enemyHero
def getAway(enemyHero):
aboveAndRightPoint = {"x": hero.pos.x - 5, "y": hero.pos.y - 5}
aboveAndLeftPoint = {"x": hero.pos.x + 5, "y": hero.pos.y - 5}
belowAndRightPoint = {"x": hero.pos.x - 5, "y": hero.pos.y + 5}
belowAndLeftPoint = {"x": hero.pos.x + 5, "y": hero.pos.y + 5}
if enemyHero and hero.distanceTo(enemyHero) < 20:
isLeft = hero.pos.x > enemyHero.pos.x
# Above: enemy.pos.y is greater than hero.pos.y
isAbove = hero.pos.y < enemyHero.pos.y
# Right: enemy.pos.x is greater than hero.pos.x
isRight = enemyHero.pos.x > hero.pos.x
# Below: enemy.pos.y is less than hero.pos.y
isBelow = enemyHero.pos.y < hero.pos.y
# If enemy isAbove and isLeft:
if isLeft and isAbove and hero.isPathClear(hero.pos, aboveAndLeftPoint):
hero.move(aboveAndLeftPoint)
# If enemy isAbove and isRight:
if isAbove and isRight and hero.isPathClear(hero.pos, aboveAndRightPoint):
hero.move(aboveAndRightPoint)
# If enemy isBelow and isLeft:
if isBelow and isLeft and hero.isPathClear(hero.pos, belowAndLeftPoint):
hero.move(belowAndLeftPoint)
# If enemy isBelow and isRight:
if isBelow and isRight and hero.isPathClear(hero.pos, belowAndRightPoint):
hero.move(belowAndRightPoint)
def findSacrifice():
friends = hero.findFriends()
friendIndex = 0
sacrifice = None
while friendIndex < len(friends):
potentialSacrifice = friends[friendIndex]
if potentialSacrifice:
distance = hero.distanceTo(potentialSacrifice)
if potentialSacrifice.type == "soldier" and distance < 20:
sacrifice = potentialSacrifice
elif potentialSacrifice.type == "skeleton":
sacrifice = potentialSacrifice
elif potentialSacrifice.health < 100:
sacrifice = potentialSacrifice
elif potentialSacrifice.type == "burl":
sacrifice = potentialSacrifice
friendIndex += 1
return sacrifice
def findRecipient():
burls = hero.findByType("burl")
burlIndex = 0
bestBurl = None
bestHealth = 0
while burlIndex < len(burls):
burl = burls[burlIndex]
if burl and burl.health > bestHealth:
bestHeatlh = burl.health
bestBurl = burl
burlIndex += 1
return bestBurl
def enemyHeroTarget(friends, enemyHero):
enemyHeroTarget = None
for i in friends:
friend = friends[i]
if enemyHero.target == friend:
enemyHeroTarget == friend
return enemyHeroTarget
def summonAndCommandArmy(target):
summonArmy(target)
summonSoldiers()
commandArmy(target)
def maybeSacrifice(soldier):
if soldier and enemyHero:
if hero.isReady("sacrifice") and enemyHero.health > hero.health:
hero.cast("sacrifice", soldier)
def eatLunch(lunch):
if lunch:
if lunch.distanceTo(enemyHero) > 10 and hero.isReady("devour"):
while lunch.health > 0:
hero.move(lunch.pos)
hero.devour(lunch)
def spellBook(enemyHero, distance, spell):
if enemyHero:
if enemyHero.hasEffect("hide"):
hero.say("Where are you?")
if hero.canCast(spell, enemyHero):
if hero.distanceTo(enemyHero) < distance:
hero.cast(spell, enemyHero)
def unholyMagic(bestCorpse, soldier):
maybeSacrifice(soldier)
raiseDead(bestCorpse)
def castSpells(enemyHero):
#cast fear
spellBook(enemyHero, 25, "fear")
# cast poisoncloud
spellBook(enemyHero, 30, "poison-cloud")
# cast chain-lightning
spellBook(enemyHero, 50, "chain-lightning")
def raiseDead(bestCorpse):
if bestCorpse and hero.canCast("raise-dead", bestCorpse):
hero.move(bestCorpse.pos)
hero.cast("raise-dead")
def attackEnemyHero(target):
if target:
distance = hero.distanceTo(target)
if distance < 50 and not target.hasEffect("hide"):
if hero.health > 3000:
hero.attack(target)
def warriorTactics(target, soldier, lunch, bestCorpse):
unholyMagic(bestCorpse, soldier)
summonAndCommandArmy(target)
eatLunch(lunch)
castSpells(target)
attackEnemyHero(target)
def shapeShift():
while True:
enemyHero = findEnemyHero()
if pet.isReady("shape-shift") and enemyHero:
if pet.distanceTo(enemyHero) > 5:
pet.moveXY(enemyHero.pos.x - 2, enemyHero.pos.y)
else:
pet.shapeShift()
hero.moveXY(hero.pos.x + 5, hero.pos.y)
pet.on("spawn", shapeShift)
while True:
skeleton = pet.findNearestByType("skeleton")
friends = hero.findFriends()
enemies = hero.findEnemies()
enemy = hero.findNearestEnemy()
corpses = hero.findCorpses()
bestCorpse = findBestCorpse(corpses)
enemyHero = findEnemyHero()
soldier = findSacrifice()
lunch = findLunch()
burl = findRecipient()
warriorTactics(enemyHero, soldier, lunch, bestCorpse)
getAway(enemy)
getAway(enemyHero)
I have tried systematically commenting out every single line of code, and I can’t find the source of the problem. It seems odd that the only time I get these errors I’m fighting against players with very low health, and always Tharin or Anya. It’s also always the same error.
As I said, I tried to find the error, but couldn’t find it. If any one can see it, apologies to the players who I’m accusing, but it looks suspiciously similar to the hero.defeat() method. Any help would be much appreciated,
Brenin Llwyd.