Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  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. hero.commandSoldier = function(soldier, soldierIndex, numSoldiers) {
  7. var angle = Math.PI * 2 * soldierIndex / numSoldiers;
  8. var 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.  
  14. // Find the strongest target (most health)
  15. // This function returns something! When you call the function, you will get some value back.
  16. hero.findStrongestTarget = function() {
  17. var mostHealth = 0;
  18. var bestTarget = null;
  19. var enemies = hero.findEnemies();
  20. // Figure out which enemy has the most health, and set bestTarget to be that enemy.
  21. for(var i=0 ; i < enemies.length ; i++){
  22. if (enemies[i].health > mostHealth){
  23. mostHealth = enemies[i].health;
  24. bestTarget = enemies[i];
  25. }
  26. }
  27. // Only focus archers' fire if there is a big ogre.
  28. if (bestTarget && bestTarget.health > 15) {
  29. return bestTarget;
  30. } else {
  31. return null;
  32. }
  33. };
  34.  
  35.  
  36. // If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
  37. hero.commandArcher = function(archer) {
  38. var nearest = archer.findNearestEnemy();
  39. if(archerTarget) {
  40. hero.command(archer, "attack", archerTarget);
  41. } else if(nearest) {
  42. hero.command(archer, "attack", nearest);
  43. }
  44. };
  45.  
  46. var archerTarget = null;
  47. while(true) {
  48. // If archerTarget is dead or doesn't exist, find a new one.
  49. if(!archerTarget || archerTarget.health <= 0) {
  50. // Set archerTarget to be the target that is returned by findStrongestTarget()
  51. archerTarget = hero.findStrongestTarget();
  52. }
  53. var friends = hero.findFriends();
  54. var soldiers = hero.findByType("soldier");
  55. // Create a variable containing your archers.
  56. var archers = hero.findByType("archer");
  57. for(var i=0; i < soldiers.length; i++) {
  58. var soldier = soldiers[i];
  59. hero.commandSoldier(soldier, i, soldiers.length);
  60. }
  61. // use commandArcher() to command your archers
  62. for(var i=0; i < archers.length; i++) {
  63. var archer = archers[i];
  64. hero.commandArcher(archer);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement