• API
• FAQ
• Tools
• Archive
daily pastebin goal
10%
SHARE
TWEET

# Untitled

bhok Apr 3rd, 2017 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # Hushbaum has been ambushed by ogres!
2. # She is busy healing her soldiers, you should command them to fight!
3. # The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!
4.
5. # Soldiers spread out in a circle and defend.
6. def commandSoldier(soldier, soldierIndex, numSoldiers):
7.     angle = Math.PI * 2 * soldierIndex / numSoldiers
8.     defendPos = {"x": 41, "y": 40}
9.     defendPos.x += 10 * Math.cos(angle)
10.     defendPos.y += 10 * Math.sin(angle)
11.     hero.command(soldier, "defend", defendPos);
12.
13. # Find the strongest target (most health)
14. # This function returns something! When you call the function, you will get some value back.
15. def findStrongestTarget():
16.     mostHealth = 0
17.     bestTarget = None
18.     enemies = hero.findEnemies()
19.     # Figure out which enemy has the most health, and set bestTarget to be that enemy.
20.     for enemy in enemies:
21.         if enemy.health > mostHealth:
22.             mostHealth = enemy.health
23.             bestTarget = enemy
24.     # Only focus archers' fire if there is a big ogre.
25.     if bestTarget and bestTarget.health > 15:
26.         return bestTarget
27.     else:
28.         return None
29.
30.
31. # If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
32. def commandArcher(archer):
33.     nearest = archer.findNearestEnemy()
34.     if archerTarget:
35.         hero.command(archer, "attack", archerTarget)
36.     elif nearest:
37.         hero.command(archer, "attack", nearest)
38.
39. archerTarget = None
40.
41. while True:
42.     # If archerTarget is defeated or doesn't exist, find a new one.
43.     if not archerTarget or archerTarget.health <= 0:
44.         # Set archerTarget to be the target that is returned by findStrongestTarget()
45.         archerTarget = findStrongestTarget()
46.
47.     friends = hero.findFriends()
48.     soldiers = hero.findByType("soldier")
49.     # Create a variable containing your archers.
50.     archers = hero.findByType("archer")
51.     for i in range(len(soldiers)):
52.         soldier = soldiers[i]
53.         commandSoldier(soldier, i, len(soldiers));
54.     # use commandArcher() to command your archers
55.     for a in range(len(archers)):
56.         archer = archers[a]
57.         commandArcher(archer);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top