Advertisement
Guest User

Untitled

a guest
May 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. /**
  2. * @filename Barbarian.js
  3. * @author kolton
  4. * @desc Barbarian attack sequence
  5. */
  6.  
  7. var ClassAttack = {
  8. doAttack: function (unit, preattack) {
  9. if (Config.MercWatch && Town.needMerc()) {
  10. Town.visitTown();
  11. }
  12.  
  13. if (preattack && Config.AttackSkill[0] > 0 && Attack.checkResist(unit, Attack.getSkillElement(Config.AttackSkill[0])) && (!me.getState(121) || !Skill.isTimed(Config.AttackSkill[0]))) {
  14. if (Math.round(getDistance(me, unit)) > Skill.getRange(Config.AttackSkill[0]) || checkCollision(me, unit, 0x4)) {
  15. if (!Attack.getIntoPosition(unit, Skill.getRange(Config.AttackSkill[0]), 0x4)) {
  16. return false;
  17. }
  18. }
  19.  
  20. Skill.cast(Config.AttackSkill[0], Skill.getHand(Config.AttackSkill[0]), unit);
  21.  
  22. return true;
  23. }
  24.  
  25. var index,
  26. attackSkill = -1;
  27.  
  28. index = ((unit.spectype & 0x7) || unit.type === 0) ? 1 : 3;
  29.  
  30. if (Attack.getCustomAttack(unit)) {
  31. attackSkill = Attack.getCustomAttack(unit)[0];
  32. } else {
  33. attackSkill = Config.AttackSkill[index];
  34. }
  35.  
  36. if (!Attack.checkResist(unit, attackSkill)) {
  37. attackSkill = -1;
  38.  
  39. if (Config.AttackSkill[index + 1] > -1 && Attack.checkResist(unit, Config.AttackSkill[index + 1])) {
  40. attackSkill = Config.AttackSkill[index + 1];
  41. }
  42. }
  43.  
  44. // Low mana skill
  45. if (Skill.getManaCost(attackSkill) > me.mp && Config.LowManaSkill[0] > -1 && Attack.checkResist(unit, Config.LowManaSkill[0])) {
  46. attackSkill = Config.LowManaSkill[0];
  47. }
  48.  
  49. switch (this.doCast(unit, attackSkill)) {
  50. case 0: // Fail
  51. break;
  52. case 1: // Success
  53. return true;
  54. case 2: // Telestomp with barbs is pointless
  55. break;
  56. }
  57.  
  58. // Couldn't attack
  59. return false;
  60. },
  61.  
  62. afterAttack: function (pickit) {
  63. var needRepair;
  64.  
  65. Misc.unShift();
  66. Precast.doPrecast(false);
  67.  
  68. needRepair = Town.needRepair();
  69.  
  70. if (needRepair && needRepair.length > 0) { // Repair check
  71. Town.visitTown();
  72. }
  73.  
  74. if (pickit) {
  75. this.findItem(me.area === 83 ? 60 : 60);
  76. }
  77. },
  78.  
  79. doCast: function (unit, attackSkill) {
  80. var walk;
  81.  
  82. if (attackSkill < 0) {
  83. return 2;
  84. }
  85.  
  86. switch (attackSkill) {
  87. case 151:
  88. if (Math.ceil(getDistance(me, unit)) > Skill.getRange(attackSkill) || checkCollision(me, unit, 0x1)) {
  89. if (!Attack.getIntoPosition(unit, Skill.getRange(attackSkill), 0x1, 2)) {
  90. return 0;
  91. }
  92. }
  93.  
  94. if (!unit.dead) {
  95. this.whirlwind(unit);
  96. }
  97.  
  98. return 1;
  99. default:
  100. if (Skill.getRange(attackSkill) < 4 && !Attack.validSpot(unit.x, unit.y)) {
  101. return 0;
  102. }
  103.  
  104. if (Math.round(getDistance(me, unit)) > Skill.getRange(attackSkill) || checkCollision(me, unit, 0x4)) {
  105. walk = Skill.getRange(attackSkill) < 4 && getDistance(me, unit) < 10 && !checkCollision(me, unit, 0x1);
  106.  
  107. if (!Attack.getIntoPosition(unit, Skill.getRange(attackSkill), 0x4, walk)) {
  108. return 0;
  109. }
  110. }
  111.  
  112. if (!unit.dead) {
  113. Skill.cast(attackSkill, Skill.getHand(attackSkill), unit);
  114. }
  115.  
  116. return 1;
  117. }
  118. },
  119.  
  120. whirlwind: function (unit) {
  121. if (!Attack.checkMonster(unit)) {
  122. return true;
  123. }
  124.  
  125. var i, coords, angle,
  126. angles = [180, 175, -175, 170, -170, 165, -165, 150, -150, 135, -135, 45, -45, 90, -90];
  127.  
  128. if (unit.spectype & 0x7) {
  129. angles.unshift(120);
  130. }
  131.  
  132. //me.runwalk = 0;
  133. angle = Math.round(Math.atan2(me.y - unit.y, me.x - unit.x) * 180 / Math.PI);
  134.  
  135. for (i = 0; i < angles.length; i += 1) { // get a better spot
  136. coords = [Math.round((Math.cos((angle + angles[i]) * Math.PI / 180)) * 4 + unit.x), Math.round((Math.sin((angle + angles[i]) * Math.PI / 180)) * 4 + unit.y)];
  137.  
  138. if (!CollMap.checkColl(me, {x: coords[0], y: coords[1]}, 0x1, 1)) {
  139. return Skill.cast(151, Skill.getHand(151), coords[0], coords[1]);
  140. }
  141. }
  142.  
  143. if (!Attack.validSpot(unit.x, unit.y)) {
  144. return false;
  145. }
  146.  
  147. return Skill.cast(151, Skill.getHand(151), me.x, me.y);
  148. },
  149.  
  150. checkCloseMonsters: function (range) {
  151. var monster;
  152.  
  153. monster = getUnit(1);
  154.  
  155. if (monster) {
  156. do {
  157. if (getDistance(me, monster) <= range && Attack.checkMonster(monster) && !checkCollision(me, monster, 0x4) &&
  158. (Attack.checkResist(monster, Attack.getSkillElement(Config.AttackSkill[(monster.spectype & 0x7) ? 1 : 3])) ||
  159. (Config.AttackSkill[3] > -1 && Attack.checkResist(monster, Attack.getSkillElement(Config.AttackSkill[3]))))) {
  160. return true;
  161. }
  162. } while (monster.getNext());
  163. }
  164.  
  165. return false;
  166. },
  167.  
  168. findItem: function (range) {
  169. if (!Config.FindItem || !me.getSkill(142, 1)) {
  170. return false;
  171. }
  172.  
  173. var i, j, tick, corpse, orgX, orgY, retry,
  174. corpseList = [];
  175.  
  176. orgX = me.x;
  177. orgY = me.y;
  178.  
  179. MainLoop:
  180. for (i = 0; i < 3; i += 1) {
  181. corpse = getUnit(1);
  182.  
  183. if (corpse) {
  184. do {
  185. if ((corpse.mode === 0 || corpse.mode === 12) && getDistance(corpse, orgX, orgY) <= range && this.checkCorpse(corpse)) {
  186. corpseList.push(copyUnit(corpse));
  187. }
  188. } while (corpse.getNext());
  189. }
  190.  
  191. while (corpseList.length > 0) {
  192. if (this.checkCloseMonsters(5)) {
  193. if (Config.FindItemSwitch) {
  194. Precast.weaponSwitch(Math.abs(Config.FindItemSwitch - 1));
  195. }
  196.  
  197. Attack.clear(10, false, false, false, false);
  198.  
  199. retry = true;
  200.  
  201. break MainLoop;
  202. }
  203.  
  204. corpseList.sort(Sort.units);
  205.  
  206. corpse = corpseList.shift();
  207.  
  208. if (this.checkCorpse(corpse)) {
  209. if (getDistance(me, corpse) > 0.5 || checkCollision(me, corpse, 0x1)) {
  210. Pather.moveToUnit(corpse);
  211. }
  212.  
  213. if (Config.FindItemSwitch) {
  214. Precast.weaponSwitch(Config.FindItemSwitch);
  215. }
  216.  
  217. CorpseLoop:
  218. for (j = 0; j < 3; j += 1) {
  219. Skill.cast(142, 3, corpse);
  220.  
  221. tick = getTickCount();
  222.  
  223. while (getTickCount() - tick < 1000) {
  224. if (corpse.getState(118)) {
  225. Pickit.fastPick();
  226.  
  227. break CorpseLoop;
  228. }
  229.  
  230. delay(10);
  231. }
  232. }
  233. }
  234. }
  235. }
  236.  
  237. if (retry) {
  238. return this.findItem(me.area === 83 ? 60 : 60);
  239. }
  240.  
  241. if (Config.FindItemSwitch) {
  242. Precast.weaponSwitch(Math.abs(Config.FindItemSwitch - 1));
  243. }
  244.  
  245. Pickit.pickItems();
  246.  
  247. return true;
  248. },
  249.  
  250. checkCorpse: function (unit) {
  251. if (unit.mode !== 0 && unit.mode !== 12) {
  252. return false;
  253. }
  254.  
  255. if ([345, 346, 347].indexOf(unit.classid) === -1 && unit.spectype === 0) {
  256. return false;
  257. }
  258.  
  259. if (unit.classid <= 575 && !getBaseStat("monstats2", unit.classid, "corpseSel")) { // monstats2 doesn't contain guest monsters info. sigh..
  260. return false;
  261. }
  262.  
  263. if (getDistance(me, unit) <= 25 &&
  264. !unit.getState(1) && // freeze
  265. !unit.getState(96) && // revive
  266. !unit.getState(99) && // redeemed
  267. !unit.getState(104) && // nodraw
  268. !unit.getState(107) && // shatter
  269. !unit.getState(118) // noselect
  270. ) {
  271. return true;
  272. }
  273.  
  274. return false;
  275. }
  276. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement