Advertisement
kolton

Untitled

Nov 22nd, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. /**
  2. * @filename Paladin.js
  3. * @author kolton
  4. * @desc Paladin attack sequence
  5. */
  6.  
  7. var ClassAttack = {
  8. skillRange: [],
  9. skillHand: [],
  10. skillElement: [],
  11.  
  12. init: function () {
  13. var i;
  14.  
  15. for (i = 0; i < Config.LowManaSkill.length; i += 1) {
  16. Config.AttackSkill.push(Config.LowManaSkill[i]);
  17. }
  18.  
  19. for (i = 0; i < Config.AttackSkill.length; i += 1) {
  20. this.skillHand[i] = getBaseStat("skills", Config.AttackSkill[i], "leftskill");
  21. this.skillElement[i] = Attack.getSkillElement(Config.AttackSkill[i]);
  22.  
  23. switch (Config.AttackSkill[i]) {
  24. case 0: // Normal Attack
  25. this.skillRange[i] = Attack.usingBow() ? 20 : 2;
  26. this.skillHand[i] = 2; // shift bypass
  27.  
  28. break;
  29. case 96: // Sacrifice
  30. case 97: // Smite
  31. case 106: // Zeal
  32. case 116: // Conversion
  33. this.skillRange[i] = 2;
  34. this.skillHand[i] = 2; // shift bypass
  35.  
  36. break;
  37. case 112: // Blessed Hammer
  38. this.skillRange[i] = 3;
  39.  
  40. break;
  41. case 101: // Holy Bolt
  42. this.skillRange[i] = 5;
  43.  
  44. break;
  45. case 107: // Charge
  46. this.skillRange[i] = 10;
  47.  
  48. break;
  49. case 121: // Fist of the Heavens
  50. this.skillRange[i] = 20;
  51.  
  52. break;
  53. default: // Every other skill
  54. this.skillRange[i] = 25;
  55.  
  56. break;
  57. }
  58. }
  59. },
  60.  
  61. doAttack: function (unit, preattack) {
  62. if (Config.MercWatch && Town.needMerc()) {
  63. Town.visitTown();
  64. }
  65.  
  66. if (preattack && Config.AttackSkill[0] > 0 && Attack.checkResist(unit, this.skillElement[0]) && (!me.getState(121) || !Skill.isTimed(Config.AttackSkill[0]))) {
  67. if (getDistance(me, unit) > this.skillRange[0] || checkCollision(me, unit, 0x4)) {
  68. if (!Attack.getIntoPosition(unit, this.skillRange[0], 0x4)) {
  69. return 1;
  70. }
  71. }
  72.  
  73. if (!Skill.cast(Config.AttackSkill[0], this.skillHand[0], unit)) {
  74. return 2;
  75. }
  76.  
  77. return 3;
  78. }
  79.  
  80. var index;
  81.  
  82. index = ((unit.spectype & 0x7) || unit.type === 0) ? 1 : 3;
  83.  
  84. if (Attack.checkResist(unit, this.skillElement[index])) {
  85. if (this.skillRange[index] < 4 && checkCollision(me, unit, 0x1) && (getCollision(unit.area, unit.x, unit.y) & 0x1)) {
  86. return 1;
  87. }
  88.  
  89. switch (this.doCast(unit, index)) {
  90. case 0: // total fail
  91. return 1;
  92. case false: // fail to cast
  93. return 2;
  94. }
  95.  
  96. return 3;
  97. }
  98.  
  99. if (Config.AttackSkill[5] > -1 && Attack.checkResist(unit, this.skillElement[5])) {
  100. if (this.skillRange[5] < 4 && checkCollision(me, unit, 0x1) && (getCollision(unit.area, unit.x, unit.y) & 0x1)) {
  101. return 1;
  102. }
  103.  
  104. switch (this.doCast(unit, 5)) {
  105. case 0: // total fail
  106. return 1;
  107. case false: // fail to cast
  108. return 2;
  109. }
  110.  
  111. return 3;
  112. }
  113.  
  114. return 1;
  115. },
  116.  
  117. afterAttack: function () {
  118. Precast.doPrecast(false);
  119.  
  120. if (Config.Redemption instanceof Array && (me.hp * 100 / me.hpmax < Config.Redemption[0] || me.mp * 100 / me.mpmax < Config.Redemption[1]) && Skill.setSkill(124, 0)) {
  121. delay(1500);
  122. }
  123. },
  124.  
  125. doCast: function (unit, index) {
  126. var i,
  127. atkSkill = index,
  128. aura = index + 1,
  129. dodgeList = [];
  130.  
  131. // Low mana skill
  132. if (Config.AttackSkill[atkSkill] > -1 && Config.AttackSkill[Config.AttackSkill.length - 2] > -1 && Skill.getManaCost(Config.AttackSkill[atkSkill]) > me.mp) {
  133. atkSkill = Config.AttackSkill.length - 2;
  134. }
  135.  
  136. // Low mana aura
  137. if (Config.AttackSkill[aura] > -1 && Config.AttackSkill[Config.AttackSkill.length - 1] > -1 && Skill.getManaCost(Config.AttackSkill[aura]) > me.mp) {
  138. aura = Config.AttackSkill.length - 1;
  139. }
  140.  
  141. if (Config.AttackSkill[atkSkill] === 112) {
  142. if (unit.classid === 691) {
  143. dodgeList = Attack.buildDodgeList();
  144.  
  145. if (dodgeList.length) {
  146. dodgeList.sort(Sort.units);
  147. Attack.dodge(unit, 15, dodgeList);
  148. }
  149.  
  150. if (Config.AttackSkill[aura] > -1) {
  151. Skill.setSkill(Config.AttackSkill[aura], 0);
  152. }
  153.  
  154. return Skill.cast(Config.AttackSkill[atkSkill], this.skillHand[atkSkill], unit);
  155. }
  156.  
  157. if (!this.getHammerPosition(unit)) {
  158. print("can't get to " + unit.name);
  159.  
  160. return (unit.spectype & 0x7) ? 2 : 0; // continue attacking a boss monster
  161. }
  162.  
  163. if (getDistance(me, unit) > 5) { // increase pvp aggressiveness
  164. return false;
  165. }
  166.  
  167. if (Config.AttackSkill[aura] > -1) {
  168. Skill.setSkill(Config.AttackSkill[aura], 0);
  169. }
  170.  
  171. for (i = 0; i < 3; i += 1) {
  172. Skill.cast(Config.AttackSkill[atkSkill], this.skillHand[atkSkill], unit);
  173.  
  174. if (!Attack.checkMonster(unit) || getDistance(me, unit) > 5 || unit.type === 0) {
  175. break;
  176. }
  177. }
  178.  
  179. return true;
  180. }
  181.  
  182. if (Config.AttackSkill[atkSkill] === 101) {
  183. if (getDistance(me, unit) > this.skillRange[atkSkill] + 3 || CollMap.checkColl(me, unit, 0x4)) {
  184. if (!Attack.getIntoPosition(unit, this.skillRange[atkSkill], 0x4)) {
  185. return 0;
  186. }
  187. }
  188.  
  189. CollMap.reset();
  190.  
  191. if (getDistance(me, unit) > this.skillRange[atkSkill] || CollMap.checkColl(me, unit, 0x2004)) {
  192. if (!Attack.getIntoPosition(unit, this.skillRange[atkSkill], 0x2004, true)) {
  193. return 0;
  194. }
  195. }
  196. } else if (getDistance(me, unit) > this.skillRange[atkSkill] || checkCollision(me, unit, 0x4)) {
  197. // walk short distances instead of tele for melee attacks. teleport if failed to walk
  198. switch (Config.AttackSkill[atkSkill]) {
  199. case 0:
  200. case 96:
  201. case 106:
  202. case 116:
  203. if (!Attack.getIntoPosition(unit, this.skillRange[atkSkill], 0x4, getDistance(me, unit) < 10 && !checkCollision(me, unit, 0x1))) {
  204. return 0;
  205. }
  206.  
  207. break;
  208. default:
  209. if (!Attack.getIntoPosition(unit, this.skillRange[atkSkill], 0x4)) {
  210. return 0;
  211. }
  212.  
  213. break;
  214. }
  215. }
  216.  
  217. if (Config.AttackSkill[aura] > -1) {
  218. Skill.setSkill(Config.AttackSkill[aura], 0);
  219. }
  220.  
  221. return Skill.cast(Config.AttackSkill[atkSkill], this.skillHand[atkSkill], unit);
  222. },
  223.  
  224. getHammerPosition: function (unit) {
  225. var i, x, y, positions,
  226. baseId = getBaseStat("monstats", unit.classid, "baseid"),
  227. size = getBaseStat("monstats2", baseId, "sizex");
  228.  
  229. // in case base stat returns something outrageous
  230. if (typeof size !== "number" || size < 1 || size > 3) {
  231. size = 3;
  232. }
  233.  
  234. switch (unit.type) {
  235. case 0: // Player
  236. x = unit.x;
  237. y = unit.y;
  238. positions = [[x + 2, y], [x + 2, y + 1]];
  239.  
  240. break;
  241. case 1: // Monster
  242. x = unit.x;
  243. y = unit.y;
  244. positions = [[x + size - 1, y + size - 1], [x + 2, y - 1], [x, y + 3], [x - 2, y - 1]];
  245.  
  246. break;
  247. }
  248.  
  249. for (i = 0; i < positions.length; i += 1) {
  250. if (getDistance(me, positions[i][0], positions[i][1]) < 1) {
  251. return true;
  252. }
  253. }
  254.  
  255. for (i = 0; i < positions.length; i += 1) {
  256. if (Attack.validSpot(positions[i][0], positions[i][1])) {
  257. this.reposition(positions[i][0], positions[i][1]);
  258.  
  259. if (!checkCollision(me, unit, 0x1)) {
  260. return true;
  261. }
  262. }
  263. }
  264.  
  265. return false;
  266. },
  267.  
  268. reposition: function (x, y) {
  269. while (!me.idle) {
  270. delay(40);
  271. }
  272.  
  273. if (getDistance(me, x, y) > 0) {
  274. if (Pather.teleport && !me.inTown && me.getStat(97, 54)) {
  275. //Pather.teleportTo(x, y);
  276. Skill.cast(54, 0, x, y);
  277. } else {
  278. if (Config.Vigor) {
  279. Skill.setSkill(115, 0);
  280. }
  281.  
  282. me.move(x, y);
  283. }
  284. }
  285.  
  286. while (!me.idle) {
  287. delay(40);
  288. }
  289.  
  290. return true;
  291. }
  292. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement