Advertisement
dzik

NotNormalDiablo.js

Oct 28th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *   @filename   NotNormalDiablo.js
  3. *   @author     dzik (base on kolton's fast diablo)
  4. *   @desc       clear way from waypoint to diablo skipping normal mobs.
  5. */
  6.  
  7. var temp2 = Pather.moveTo;
  8. Pather.moveTo = function (x, y, retry, clearPath, pop) {
  9.     if (me.dead) { // Abort if dead
  10.         return false;
  11.     }
  12.  
  13.     var i, path, adjustedNode, cleared,
  14.         node = {x: x, y: y},
  15.         fail = 0;
  16.  
  17.     for (i = 0; i < Pather.cancelFlags.length; i += 1) {
  18.         if (getUIFlag(Pather.cancelFlags[i])) {
  19.             me.cancel();
  20.         }
  21.     }
  22.  
  23.     if (getDistance(me, x, y) < 2) {
  24.         return true;
  25.     }
  26.  
  27.     if (x === undefined || y === undefined) {
  28.         throw new Error("moveTo: Function must be called with at least 2 arguments.");
  29.     }
  30.  
  31.     if (typeof x !== "number" || typeof y !== "number") {
  32.         throw new Error("moveTo: Coords must be numbers");
  33.     }
  34.  
  35.     if (retry === undefined) {
  36.         retry = 3;
  37.     }
  38.  
  39.     if (clearPath === undefined) {
  40.         clearPath = false;
  41.     }
  42.  
  43.     if (pop === undefined) {
  44.         pop = false;
  45.     }
  46.  
  47.     Pather.useTeleport = Pather.teleport && !me.getState(139) && !me.getState(140) && !me.inTown &&
  48.                         ((me.classid === 1 && me.getSkill(54, 1)) || me.getStat(97, 54));
  49.  
  50.     // Teleport without calling getPath if the spot is close enough
  51.     if (Pather.useTeleport && getDistance(me, x, y) <= Pather.teleDistance) {
  52.         //Misc.townCheck();
  53.  
  54.         return Pather.teleportTo(x, y);
  55.     }
  56.  
  57.     // Walk without calling getPath if the spot is close enough
  58.     if (!Pather.useTeleport && (getDistance(me, x, y) <= 5 || (getDistance(me, x, y) <= 25 && !CollMap.checkColl(me, {x: x, y: y}, 0x1)))) {
  59.         return Pather.walkTo(x, y);
  60.     }
  61.  
  62.     path = getPath(me.area, x, y, me.x, me.y, 0, 20);
  63.  
  64.     if (!path) {
  65.         throw new Error("moveTo: Failed to generate path.");
  66.     }
  67.  
  68.     path.reverse();
  69.  
  70.     if (pop) {
  71.         path.pop();
  72.     }
  73.  
  74.     PathDebug.drawPath(path);
  75.  
  76.     if (Pather.useTeleport && Config.TeleSwitch) {
  77.         Misc.teleSwitch();
  78.     }
  79.  
  80.     while (path.length > 0) {
  81.         if (me.dead) { // Abort if dead
  82.             return false;
  83.         }
  84.  
  85.         for (i = 0; i < Pather.cancelFlags.length; i += 1) {
  86.             if (getUIFlag(Pather.cancelFlags[i])) {
  87.                 me.cancel();
  88.             }
  89.         }
  90.  
  91.         node = path.shift();
  92.  
  93.         /* Right now getPath's first node is our own position so it's not necessary to take it into account
  94.             This will be removed if getPath changes
  95.         */
  96.         if (getDistance(me, node) > 2) {
  97.             // Make life in Maggot Lair easier
  98.             if ([62, 63, 64].indexOf(me.area) > -1) {
  99.                 adjustedNode = Pather.getNearestWalkable(node.x, node.y, 15, 3, 0x1 | 0x4 | 0x800 | 0x1000);
  100.  
  101.                 if (adjustedNode) {
  102.                     node.x = adjustedNode[0];
  103.                     node.y = adjustedNode[1];
  104.                 }
  105.             }
  106.  
  107.             if (Pather.useTeleport ? Pather.teleportTo(node.x, node.y) : Pather.walkTo(node.x, node.y, (fail > 0 || me.inTown) ? 2 : 4)) {
  108.                 if (!me.inTown) {
  109.                     if (Pather.recursion) {
  110.                         Pather.recursion = false;
  111.  
  112.                         NodeAction.go({clearPath: clearPath});
  113.  
  114.                         if (getDistance(me, node.x, node.y) > 5) {
  115.                             Pather.moveTo(node.x, node.y);
  116.                         }
  117.  
  118.                         Pather.recursion = true;
  119.                     }
  120.  
  121.                     Misc.townCheck();
  122.                 }
  123.             } else {
  124.                 if (fail > 0 && !Pather.useTeleport && !me.inTown) {
  125.                     // Don't go berserk on longer paths
  126.                     if (!cleared) {
  127.                         Attack.clear(5);
  128.  
  129.                         cleared = true;
  130.                     }
  131.  
  132.                     if (fail > 1 && me.getSkill(143, 1)) {
  133.                         Skill.cast(143, 0, node.x, node.y);
  134.                     }
  135.                 }
  136.  
  137.                 // Reduce node distance in new path
  138.                 path = getPath(me.area, x, y, me.x, me.y, 0, 20);
  139.                 fail += 1;
  140.  
  141.                 if (!path) {
  142.                     throw new Error("moveTo: Failed to generate path.");
  143.                 }
  144.  
  145.                 path.reverse();
  146.                 PathDebug.drawPath(path);
  147.  
  148.                 if (pop) {
  149.                     path.pop();
  150.                 }
  151.  
  152.                 print("move retry " + fail);
  153.                 Attack.clear(5);
  154.  
  155.                 if (fail > 0 && fail >= retry) {
  156.                     break;
  157.                 }
  158.             }
  159.         }
  160.  
  161.         delay(5);
  162.     }
  163.  
  164.     if (Pather.useTeleport && Config.TeleSwitch) {
  165.         Precast.weaponSwitch(Misc.oldSwitch);
  166.     }
  167.  
  168.     PathDebug.removeHooks();
  169.  
  170.     return getDistance(me, node.x, node.y) < 5;
  171. };
  172.  
  173. NodeAction.killMonsters = function (arg) {
  174.     var monList;
  175.  
  176.     if (Config.Countess.KillGhosts && [21, 22, 23, 24, 25].indexOf(me.area) > -1) {
  177.         monList = Attack.getMob(38, 0, 30);
  178.  
  179.         if (monList) {
  180.             Attack.clearList(monList);
  181.         }
  182.     }
  183.  
  184.     if ((typeof Config.ClearPath === "number" || typeof Config.ClearPath === "object") && arg.clearPath === false) {
  185.         switch (typeof Config.ClearPath) {
  186.         case "number":
  187.             Attack.clear(40, 0xF);
  188.  
  189.             break;
  190.         case "object":
  191.             if (!Config.ClearPath.hasOwnProperty("Areas") || Config.ClearPath.Areas.length === 0 || Config.ClearPath.Areas.indexOf(me.area) > -1) {
  192.                 Attack.clear(Config.ClearPath.Range, Config.ClearPath.Spectype);
  193.             }
  194.  
  195.             break;
  196.         }
  197.     }
  198.  
  199.     if (arg.clearPath !== false) {
  200.         Attack.clear(15, typeof arg.clearPath === "number" ? arg.clearPath : 0);
  201.     }
  202. };
  203.  
  204. var temp = Attack.clear;
  205.  
  206. Attack.clear = function (range, spectype, bossId, sortfunc, pickit) {
  207.     while (!me.gameReady) {
  208.         delay(40);
  209.     }
  210.  
  211.     if (Config.MFLeader && !!bossId) {
  212.         Pather.makePortal();
  213.         say("clear " + bossId);
  214.     }
  215.  
  216.     if (range === undefined) {
  217.         range = 25;
  218.     }
  219.  
  220.     if (spectype === undefined) {
  221.         spectype = 0xF;
  222.     }
  223.  
  224.     if (bossId === undefined) {
  225.         bossId = false;
  226.     }
  227.  
  228.     if (sortfunc === undefined) {
  229.         sortfunc = false;
  230.     }
  231.  
  232.     if (pickit === undefined) {
  233.         pickit = true;
  234.     }
  235.  
  236.     if (typeof (range) !== "number") {
  237.         throw new Error("Attack.clear: range must be a number.");
  238.     }
  239.  
  240.     var i, boss, orgx, orgy, target, result, monsterList, start,
  241.         gidAttack = [],
  242.         attackCount = 0;
  243.  
  244.     if (Config.AttackSkill[1] < 0 || Config.AttackSkill[3] < 0) {
  245.         return false;
  246.     }
  247.  
  248.     if (!sortfunc) {
  249.         sortfunc = Attack.sortMonsters;
  250.     }
  251.  
  252.     if (bossId) {
  253.         for (i = 0; !boss && i < 5; i += 1) {
  254.             boss = bossId > 999 ? getUnit(1, -1, -1, bossId) : getUnit(1, bossId);
  255.  
  256.             delay(200);
  257.         }
  258.  
  259.         if (!boss) {
  260.             throw new Error("Attack.clear: " + bossId + " not found");
  261.         }
  262.  
  263.         orgx = boss.x;
  264.         orgy = boss.y;
  265.     } else {
  266.         orgx = me.x;
  267.         orgy = me.y;
  268.     }
  269.  
  270.     monsterList = [];
  271.     target = getUnit(1);
  272.  
  273.     if (target) {
  274.         do {
  275.             if ((target.spectype & 0xF) && Attack.checkMonster(target) && Attack.skipCheck(target)) {
  276.                 // Speed optimization - don't go through monster list until there's at least one within clear range
  277.                 if (!start && getDistance(target, orgx, orgy) <= range &&
  278.                         (me.getSkill(54, 1) || !Scripts.Follower || !checkCollision(me, target, 0x1))) {
  279.                     start = true;
  280.                 }
  281.  
  282.                 monsterList.push(copyUnit(target));
  283.             }
  284.         } while (target.getNext());
  285.     }
  286.  
  287.     while (start && monsterList.length > 0 && attackCount < 300) {
  288.         if (boss) {
  289.             orgx = boss.x;
  290.             orgy = boss.y;
  291.         }
  292.  
  293.         if (me.dead) {
  294.             return false;
  295.         }
  296.  
  297.         //monsterList.sort(Sort.units);
  298.         monsterList.sort(sortfunc);
  299.  
  300.         target = copyUnit(monsterList[0]);
  301.  
  302.         if ((target.spectype & 0xF) && target.x !== undefined && (getDistance(target, orgx, orgy) <= range || (Attack.getScarinessLevel(target) > 7 && getDistance(me, target) <= range)) && Attack.checkMonster(target)) {
  303.             if (Config.Dodge && me.hp * 100 / me.hpmax <= Config.DodgeHP) {
  304.                 Attack.deploy(target, Config.DodgeRange, 5, 9);
  305.             }
  306.  
  307.             Misc.townCheck(true);
  308.             me.overhead("attacking " + target.name + " spectype " + target.spectype + " id " + target.classid);
  309.  
  310.             result = ClassAttack.doAttack(target, attackCount % 15 === 0);
  311.  
  312.             if (result) {
  313.                 for (i = 0; i < gidAttack.length; i += 1) {
  314.                     if (gidAttack[i].gid === target.gid) {
  315.                         break;
  316.                     }
  317.                 }
  318.  
  319.                 if (i === gidAttack.length) {
  320.                     gidAttack.push({gid: target.gid, attacks: 0, name: target.name});
  321.                 }
  322.  
  323.                 gidAttack[i].attacks += 1;
  324.                 attackCount += 1;
  325.  
  326.                 // Desync/bad position handler
  327.                 switch (Config.AttackSkill[(target.spectype & 0x7) ? 1 : 3]) {
  328.                 case 112:
  329.                     //print(gidAttack[i].name + " " + gidAttack[i].attacks);
  330.  
  331.                     // Tele in random direction with Blessed Hammer
  332.                     if (gidAttack[i].attacks > 0 && gidAttack[i].attacks % ((target.spectype & 0x7) ? 4 : 2) === 0) {
  333.                         //print("random move m8");
  334.                         Pather.moveTo(me.x + rand(-1, 1) * 5, me.y + rand(-1, 1) * 5);
  335.                     }
  336.  
  337.                     break;
  338.                 default:
  339.                     // Flash with melee skills
  340.                     if (gidAttack[i].attacks > 0 && gidAttack[i].attacks % ((target.spectype & 0x7) ? 15 : 5) === 0 && Skill.getRange(Config.AttackSkill[(target.spectype & 0x7) ? 1 : 3]) < 4) {
  341.                         Packet.flash(me.gid);
  342.                     }
  343.  
  344.                     break;
  345.                 }
  346.  
  347.                 // Skip non-unique monsters after 15 attacks, except in Throne of Destruction
  348.                 if (me.area !== 131 && !(target.spectype & 0x7) && gidAttack[i].attacks > 15) {
  349.                     print("˙c1Skipping " + target.name + " " + target.gid + " " + gidAttack[i].attacks);
  350.                     monsterList.shift();
  351.                 }
  352.  
  353.                 if (target.mode === 0 || target.mode === 12 || Config.FastPick === 2) {
  354.                     Pickit.fastPick();
  355.                 }
  356.             } else {
  357.                 monsterList.shift();
  358.             }
  359.         } else {
  360.             monsterList.shift();
  361.         }
  362.     }
  363.  
  364.     ClassAttack.afterAttack(pickit);
  365.     Attack.openChests(range, orgx, orgy);
  366.  
  367.     if (attackCount > 0 && pickit) {
  368.         Pickit.pickItems();
  369.     }
  370.  
  371.     return true;
  372. };
  373.  
  374. function NotNormalDiablo() {
  375.     this.getLayout = function (seal, value) {
  376.         var sealPreset = getPresetUnit(108, 2, seal);
  377.  
  378.         if (!seal) {
  379.             Pather.moveTo = temp2;
  380.             Attack.clear = temp;
  381.             throw new Error("Seal preset not found");
  382.         }
  383.  
  384.         if (sealPreset.roomy * 5 + sealPreset.y === value || sealPreset.roomx * 5 + sealPreset.x === value) {
  385.             return 1;
  386.         }
  387.  
  388.         return 2;
  389.     };
  390.  
  391.     this.initLayout = function () {
  392.         this.vizLayout = this.getLayout(396, 5275);
  393.         this.seisLayout = this.getLayout(394, 7773);
  394.         this.infLayout = this.getLayout(392, 7893);
  395.     };
  396.  
  397.     this.getBoss = function (name) {
  398.         var i, boss,
  399.             glow = getUnit(2, 131);
  400.  
  401.         for (i = 0; i < 24; i += 1) {
  402.             boss = getUnit(1, name);
  403.  
  404.             if (boss) {
  405.                 this.chaosPreattack(name, 8);
  406.  
  407.                 try {
  408.                     Attack.kill(name);
  409.                 } catch (e) {
  410.                     Attack.clear(10, 0, name);
  411.                 }
  412.  
  413.                 Pickit.pickItems();
  414.  
  415.                 return true;
  416.             }
  417.  
  418.             delay(250);
  419.         }
  420.  
  421.         return !!glow;
  422.     };
  423.  
  424.     this.chaosPreattack = function (name, amount) {
  425.         var i, n, target, positions;
  426.  
  427.         switch (me.classid) {
  428.         case 0:
  429.             break;
  430.         case 1:
  431.             break;
  432.         case 2:
  433.             break;
  434.         case 3:
  435.             target = getUnit(1, name);
  436.  
  437.             if (!target) {
  438.                 return;
  439.             }
  440.  
  441.             positions = [[6, 11], [0, 8], [8, -1], [-9, 2], [0, -11], [8, -8]];
  442.  
  443.             for (i = 0; i < positions.length; i += 1) {
  444.                 if (Attack.validSpot(target.x + positions[i][0], target.y + positions[i][1])) { // check if we can move there
  445.                     Pather.moveTo(target.x + positions[i][0], target.y + positions[i][1], 3, true);
  446.                     Skill.setSkill(Config.AttackSkill[2], 0);
  447.  
  448.                     for (n = 0; n < amount; n += 1) {
  449.                         Skill.cast(Config.AttackSkill[1], 1);
  450.                     }
  451.  
  452.                     break;
  453.                 }
  454.             }
  455.  
  456.             break;
  457.         case 4:
  458.             break;
  459.         case 5:
  460.             break;
  461.         case 6:
  462.             break;
  463.         }
  464.     };
  465.  
  466.     this.diabloPrep = function () {
  467.         var trapCheck,
  468.             tick = getTickCount();
  469.  
  470.         while (getTickCount() - tick < 17500) {
  471.             if (getTickCount() - tick >= 8000) {
  472.                 switch (me.classid) {
  473.                 case 1: // Sorceress
  474.                     if ([56, 59, 64].indexOf(Config.AttackSkill[1]) > -1) {
  475.                         if (me.getState(121)) {
  476.                             delay(500);
  477.                         } else {
  478.                             Skill.cast(Config.AttackSkill[1], 0, 7793, 5293);
  479.                         }
  480.  
  481.                         break;
  482.                     }
  483.  
  484.                     delay(500);
  485.  
  486.                     break;
  487.                 case 3: // Paladin
  488.                     Skill.setSkill(Config.AttackSkill[2]);
  489.                     Skill.cast(Config.AttackSkill[1], 1);
  490.  
  491.                     break;
  492.                 case 5: // Druid
  493.                     if (Config.AttackSkill[1] === 245) {
  494.                         Skill.cast(Config.AttackSkill[1], 0, 7793, 5293);
  495.  
  496.                         break;
  497.                     }
  498.  
  499.                     delay(500);
  500.  
  501.                     break;
  502.                 case 6: // Assassin
  503.                     if (Config.UseTraps) {
  504.                         trapCheck = ClassAttack.checkTraps({x: 7793, y: 5293});
  505.  
  506.                         if (trapCheck) {
  507.                             ClassAttack.placeTraps({x: 7793, y: 5293, classid: 243}, trapCheck);
  508.  
  509.                             break;
  510.                         }
  511.                     }
  512.  
  513.                     delay(500);
  514.  
  515.                     break;
  516.                 default:
  517.                     delay(500);
  518.                 }
  519.             } else {
  520.                 delay(500);
  521.             }
  522.  
  523.             if (getUnit(1, 243)) {
  524.                 return true;
  525.             }
  526.         }
  527.        
  528.         Pather.moveTo = temp2;
  529.         Attack.clear = temp;
  530.         throw new Error("Diablo not found");
  531.     };
  532.  
  533.     this.openSeal = function (classid) {
  534.         var i, j, seal;
  535.  
  536.         for (i = 0; i < 5; i += 1) {
  537.             Pather.moveToPreset(108, 2, classid, classid === 394 ? 5 : 2, classid === 394 ? 5 : 0, true);
  538.  
  539.             if (i > 1) {
  540.                 Attack.clear(10);
  541.             }
  542.  
  543.             for (j = 0; j < 3; j += 1) {
  544.                 seal = getUnit(2, classid);
  545.  
  546.                 if (seal) {
  547.                     break;
  548.                 }
  549.  
  550.                 delay(100);
  551.             }
  552.  
  553.             if (!seal) {
  554.                 Pather.moveTo = temp2;
  555.                 Attack.clear = temp;
  556.                 throw new Error("Seal not found (id " + classid + ")");
  557.             }
  558.  
  559.             if (seal.mode) {
  560.                 return true;
  561.             }
  562.  
  563.             sendPacket(1, 0x13, 4, 0x2, 4, seal.gid);
  564.             delay(classid === 394 ? 1000 : 500);
  565.  
  566.             if (!seal.mode) {
  567.                 if (classid === 394 && Attack.validSpot(seal.x + 15, seal.y)) { // de seis optimization
  568.                     Pather.moveTo(seal.x + 15, seal.y, 3, true);
  569.                 } else {
  570.                     Pather.moveTo(seal.x - 5, seal.y - 5, 3, true);
  571.                 }
  572.  
  573.                 delay(500);
  574.             } else {
  575.                 return true;
  576.             }
  577.         }
  578.         Pather.moveTo = temp2;
  579.         Attack.clear = temp;
  580.         throw new Error("Failed to open seal (id " + classid + ")");
  581.     };
  582.  
  583.     Town.doChores();
  584.     Pather.useWaypoint(106);
  585.     Pather.moveToExit(107, true, false);
  586.    
  587.     Precast.doPrecast(true);
  588.    
  589.     if (!Pather.moveToPreset(me.area, 2, 376, true)) {
  590.         throw new Error("Failed to move to Hephasto");
  591.     }
  592.     Attack.kill(getLocaleString(1067)); // Hephasto The Armorer
  593.     Pickit.pickItems();
  594.    
  595.     Precast.doPrecast(true);
  596.     this.initLayout();
  597.     this.openSeal(395);
  598.     this.openSeal(396);
  599.  
  600.     if (this.vizLayout === 1) {
  601.         Pather.moveTo(7691, 5292, 3, true);
  602.     } else {
  603.         Pather.moveTo(7695, 5316, 3, true);
  604.     }
  605.  
  606.     if (!this.getBoss(getLocaleString(2851))) {
  607.         Pather.moveTo = temp2;
  608.         Attack.clear = temp;
  609.         throw new Error("Failed to kill Vizier");
  610.     }
  611.  
  612.     this.openSeal(394);
  613.  
  614.     if (this.seisLayout === 1) {
  615.         Pather.moveTo(7771, 5196, 3, true);
  616.     } else {
  617.         Pather.moveTo(7798, 5186, 3, true);
  618.     }
  619.  
  620.     if (!this.getBoss(getLocaleString(2852))) {
  621.         Pather.moveTo = temp2;
  622.         Attack.clear = temp;
  623.         throw new Error("Failed to kill de Seis");
  624.     }
  625.  
  626.     this.openSeal(392);
  627.     this.openSeal(393);
  628.  
  629.     if (this.infLayout === 1) {
  630.         delay(1);
  631.     } else {
  632.         Pather.moveTo(7928, 5295, 3, true); // temp
  633.     }
  634.  
  635.     if (!this.getBoss(getLocaleString(2853))) {
  636.         Pather.moveTo = temp2;
  637.         Attack.clear = temp;
  638.         throw new Error("Failed to kill Infector");
  639.     }
  640.  
  641.     Pather.moveTo(7788, 5292, 3, true);
  642.     Pather.moveTo = temp2;
  643.     Attack.clear = temp;
  644.     this.diabloPrep();
  645.     Attack.kill(243); // Diablo
  646.     Pickit.pickItems();
  647.  
  648.     return true;
  649. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement