Advertisement
gtoilet

barbarian attack file

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