Advertisement
kolton

Untitled

Jan 6th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. buildDodgeList: function () {
  2. var monster = getUnit(1),
  3. list = [];
  4.  
  5. if (monster) {
  6. do {
  7. if (this.checkMonster(monster)) {
  8. list.push(copyUnit(monster));
  9. }
  10. } while (monster.getNext());
  11. }
  12.  
  13. return list;
  14. },
  15.  
  16. dodge: function (unit, distance, list) {
  17. var i, j, coordx, coordy, monster, count,
  18. maxcount = 99,
  19. coords = [],
  20. goodCoords = [],
  21. angles = [45, 90, 135, 180, 225, 270, 305, 360];
  22.  
  23. // step 1 - build possible dodge positions based on angles
  24.  
  25. for (i = 0; i < angles.length; i = i + 1) {
  26. coordx = Math.round((Math.cos(angles[i] * Math.PI / 180)) * distance + unit.x);
  27. coordy = Math.round((Math.sin(angles[i] * Math.PI / 180)) * distance + unit.y);
  28.  
  29. if (this.validSpot(coordx, coordy)) {
  30. coords.push([coordx, coordy]);
  31. }
  32. }
  33.  
  34. if (coords.length === 0) { // no valid positions - don't move
  35. me.overhead("Can't dodge :(");
  36. return true;
  37. }
  38.  
  39. coords.sort(this.sortRooms);
  40.  
  41. for (i = 0; i < coords.length; i += 1) {
  42. count = 0;
  43.  
  44. for (j = 0; j < list.length; j += 1) {
  45. if (list[j].hp > 0 && getDistance(list[j].x, list[j].y, coords[i][0], coords[i][1]) < 10) {
  46. count += 1;
  47. }
  48. }
  49.  
  50. if (count < maxcount) {
  51. goodCoords = [coords[i][0], coords[i][1]];
  52. maxcount = count;
  53.  
  54. if (count === 0) {
  55. break;
  56. }
  57. }
  58. }
  59.  
  60. if (goodCoords.length > 0) { // just in case goodCoords is empty (shouldn't happen)
  61. if (getDistance(me, goodCoords[0], goodCoords[1]) < 5) { // close enough
  62. return true;
  63. }
  64.  
  65. me.overhead("Dodge!");
  66. Pather.moveTo(goodCoords[0], goodCoords[1], 1);
  67. }
  68.  
  69. return true;
  70. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement