I am at the start of ‘Summit’s Gate’ and wanted to check how to find out the ending points of the fire-balls thrown from the first wall’s defense.
Even if the thrown balls themselves are apparently inaccessible objects, I found that I can access the throwing machines by ‘hero.findByType(“catapult”)’ and then can use the property ‘target’ to get the ending points of a currently thrown fire-ball.
To verify this, I use my pet::
catapults = hero.findByType("catapult")
if len(catapults) > 0:
c = catapults[0]
if c.target:
pet.say(c.target.pos.x)
However, there is a strange effect now:
I’m using ‘Amara’ with the ‘RazorBlade’ item and at least here, the code above influences the behaviour of the hero.
For the following examples, I have tried to reduce the code as much as possible (only to revive to the critical point, neglecting paladins) but it should reproducibly work:
def AttackEnemy(enemy):
if not enemy or enemy.health <= 0:
return
dist = hero.distanceTo(enemy)
#if hero.isReady("attack") and dist <= hero.attackRange:
# hero.attack(enemy)
if hero.isReady("throw") and dist <= hero.throwRange:
hero.throw(enemy)
while True:
enemies = hero.findEnemies()
soldiers = hero.findByType("soldier")
archers = hero.findByType("archer")
catapults = hero.findByType("catapult")
if len(catapults) > 0:
c = catapults[0]
if c.target:
pet.say(c.target.pos.x)
for soldier in soldiers:
hero.command(soldier, "attack", soldier.findNearest(enemies))
for archer in archers:
hero.command(archer, "attack", archer.findNearest(enemies))
AttackEnemy(hero.findNearestEnemy())
Here, the champion suddenly moves at some point, even if there should be no reason to move at all:
When I comment out the debug code at top, the champion does not move (as expected):
while True:
enemies = hero.findEnemies()
soldiers = hero.findByType("soldier")
archers = hero.findByType("archer")
# catapults = hero.findByType("catapult")
# if len(catapults) > 0:
# c = catapults[0]
# if c.target:
# pet.say(c.target.pos.x)
for soldier in soldiers:
hero.command(soldier, "attack", soldier.findNearest(enemies))
for archer in archers:
hero.command(archer, "attack", archer.findNearest(enemies))
AttackEnemy(hero.findNearestEnemy())
Also, when I leave the debug code but don’t use ‘throw’, the behaviour seems ok:
def AttackEnemy(enemy):
if not enemy or enemy.health <= 0 or enemy.type == "catapult":
return
dist = hero.distanceTo(enemy)
if hero.isReady("attack") and dist <= hero.attackRange:
hero.attack(enemy)
#if hero.isReady("throw") and dist <= hero.throwRange:
# hero.throw(enemy)
This is quite strange and probably a bug. Or is there a different reason I’m too blind to see?