I gave up on the warrior, as the other warrior just ties me and he has a bigger army. I have been trying it with the archer. No matter what I do, I can never win. And half the time a yak walks in front of my arrows and then kills me, but even when that doesn’t happen I still lose. Here is my code, is runs fine but isn’t good enough. Anyone have some suggestions?
loop:
enemies = self.findEnemies()
enemyIndex = 0
# Make an array of all enemies.
while enemyIndex < len(enemies):
currentTarget = enemies[enemyIndex]
enemyIndex += 1
distance = self.distanceTo(currentTarget)
# If it's a sand-yak, move to next enemy in the array.
if currentTarget.type is "sand-yak":
pass
# If it's out of range, move to the next enemy in the array.
elif distance > 37:
pass
# Else, we target it.
elif currentTarget.health > 0:
# If it's too close, move back.
if distance < 18:
self.moveXY(self.pos.x - 15, self.pos.y)
# Else, we attack it.
else:
self.attack(currentTarget)
Its hard, but beatable. Remember that the toughest enemy will be the clone, which is identical to your hero except that it is only programmed to attack the nearest target with whatever your primary weapon is. So I suggest not equipping powerful weapons or armor, since that only makes the clone stronger. Instead rely on secondary weapons and effects, like spells if your playing a mage, or throwing knives/bombs as an archer. You don’t even need to equip a primary weapon, in which case the clone won’t even attack.
Also don’t forget that you have allies, try to keep them alive if you can. I also suggest that you prioritize ranged targets above melee ones, especially shamans, you want to kill those quick.
Another alternative is to go with a powerful weapon on the archer, but light on armor, and take the clone out first. It’s starting health will be equal to yours, so if you start low you can often kill him while he’s still targeting your allies.
It’ll cause your hero to say his type in a text bubble. Since the clone has that same type, you will then know what the clone’s type is.
But now that I think if it, I made a list of them a while back, so here it is:
Anya - captain
Tharin - knight
Hushbaum - librarian
Amara - ninja
Omarn - potion-master
Hattori - samurai
Senick - trapper
Naria - forest-archer
Whichever hero you are playing, find its type on this list. The clone will be using that same type. You can then target the clone.
I’m not sure what you are trying to accomplish with the code you posted. If you want to move to the closest item with a distance < 10, you dont need a for loop for that. The following would work just fine.
Small hint (you can use it somewhere else as well, just think creative):
If you ever looked in the level-editor, there is always a blanko-hero that is named Hero Placeholder. If there is a second one, it is (usually) named Hero Placeholder 1 (beware the space!). You can then filter by ID.
myHero = [e for e in self.getFriends() if e.id == 'Hero Placeholder'][0]
enemyHero = [e for e in self.getEnemies() if e.id == 'Hero Placeholder 1'][0]
This is the quick and (really) dirty way to get the hero-object(s). Notice that [e for e in LIST if CONDITION] is a list-assembly function, therefor the result is also a list. I then access the first index ([0]), blindly relying there is one entry. Usually you want to check this first! (Use len(LIST) to get the length).
A more in-depth manual can be found here. This piece of candy offered by the python developers is something you soon will not miss in any program you write.
I’m trying Naria w/o a primary weapon and it won’t even run. I’m wondering if lack of a primary weapon is causing a problem for the clone Naria? Here’s a really simple version of my code that won’t even run.
loop:
enemy = self.findNearest(self.findEnemies())
if enemy:
if self.isReady("throw"):
self.throw(enemy)
@nick I think there’s a bug with clone-ranger code? (accidental pun, haha) The code in the preceding will not work with Naria or Sennick but essentially the same code (merely replacing throw with bash) will work fine for Tharin.
We’ve just made it easier so that it should be more doable just by being smart about targeting archers, not needing nerfing your own weapon to do.
@eiler13 I found the bug with the razor disc that was trying to use the attack instead of the throw when it hit something, so it should be good to go now; thanks for the bug report!
I (Anya) didn’t need to lose her weapon, but she did need to run away a little so her clone would loose enough health so she could win (kite around her archers kind of thing). I never tried the no primary weapon thing, cool idea, I guess that is what I get for assuming her clone new about all the attack forms. (a big if/elif isReady ) it was also touch and go depending on when/if the first shaman/(bigger)ogres came out. Sounds like it is time to go play it again.
Thanks for the code! I changed it up a bit and it worked for me!
you have got to be kidding me? I beat it like this??? It was so funny!
this was my code:
Mod edit: Please do not post solutions. Thanks.
just don’t forget to indent it your self if you use it!
P.S I you haven’t tried it out yet (which I recommend you do even if you finished it already) it’s funny because since there is no weapon in the weapon spot, the CPU clone of you will not move, shield, or even bash! (cause thats what i used as an attack) LOL
I would kinda like to see levels where if its to hard you can just change your armor it would to use elements out off the code and get a little clever with your equips