Advertisement
NameUnknown

silent chaos

Jul 18th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *   @filename   Diablo.js
  3. *   @author     kolton
  4. *   @desc       clear Chaos Sanctuary and kill Diablo
  5. */
  6.  
  7. function Diablo() {
  8.     // Sort function
  9.     this.sort = function (a, b) {
  10.         if (Config.BossPriority) {
  11.             if ((a.spectype & 0x5) && (b.spectype & 0x5)) {
  12.                 return getDistance(me, a) - getDistance(me, b);
  13.             }
  14.  
  15.             if (a.spectype & 0x5) {
  16.                 return -1;
  17.             }
  18.  
  19.             if (b.spectype & 0x5) {
  20.                 return 1;
  21.             }
  22.         }
  23.  
  24.         // Entrance to Star / De Seis
  25.         if (me.y > 5325 || me.y < 5260) {
  26.             if (a.y > b.y) {
  27.                 return -1;
  28.             }
  29.  
  30.             return 1;
  31.         }
  32.  
  33.         // Vizier
  34.         if (me.x < 7765) {
  35.             if (a.x > b.x) {
  36.                 return -1;
  37.             }
  38.  
  39.             return 1;
  40.         }
  41.  
  42.         // Infector
  43.         if (me.x > 7825) {
  44.             if (!checkCollision(me, a, 0x1) && a.x < b.x) {
  45.                 return -1;
  46.             }
  47.  
  48.             return 1;
  49.         }
  50.  
  51.         return getDistance(me, a) - getDistance(me, b);
  52.     };
  53.  
  54.     // general functions
  55.     this.getLayout = function (seal, value) {
  56.         var sealPreset = getPresetUnit(108, 2, seal);
  57.  
  58.         if (!seal) {
  59.             throw new Error("");
  60.         }
  61.  
  62.         if (sealPreset.roomy * 5 + sealPreset.y === value || sealPreset.roomx * 5 + sealPreset.x === value) {
  63.             return 1;
  64.         }
  65.  
  66.         return 2;
  67.     };
  68.  
  69.     this.initLayout = function () {
  70.         this.vizLayout = this.getLayout(396, 5275);
  71.         this.seisLayout = this.getLayout(394, 7773);
  72.         this.infLayout = this.getLayout(392, 7893);
  73.     };
  74.  
  75.     this.openSeal = function (classid) {
  76.         var i, seal, warn;
  77.  
  78.         switch (classid) {
  79.         case 396:
  80.         case 394:
  81.         case 392:
  82.             warn = true;
  83.  
  84.             break;
  85.         default:
  86.             warn = false;
  87.  
  88.             break;
  89.         }
  90.  
  91.         for (i = 0; i < 5; i += 1) {
  92.             Pather.moveToPreset(108, 2, classid, classid === 394 ? 5 : 2, classid === 394 ? 5 : 0);
  93.  
  94.             seal = getUnit(2, classid);
  95.  
  96.             if (!seal) {
  97.                 return false;
  98.             }
  99.  
  100.             if (seal.mode) { // for pubbies
  101.                 if (warn) {
  102.                     say(Config.Diablo.SealWarning);
  103.                 }
  104.  
  105.                 return true;
  106.             }
  107.  
  108.             warn = false;
  109.  
  110.             if (classid === 394) {
  111.                 Misc.click(0, 0, seal);
  112.             } else {
  113.                 seal.interact();
  114.             }
  115.  
  116.             delay(classid === 394 ? 1000 : 500);
  117.  
  118.             if (!seal.mode) {
  119.                 if (classid === 394 && Attack.validSpot(seal.x + 15, seal.y)) { // de seis optimization
  120.                     Pather.moveTo(seal.x + 15, seal.y);
  121.                 } else {
  122.                     Pather.moveTo(seal.x - 5, seal.y - 5);
  123.                 }
  124.  
  125.                 delay(500);
  126.             } else {
  127.                 return true;
  128.             }
  129.         }
  130.  
  131.         return false;
  132.     };
  133.  
  134.     this.chaosPreattack = function (name, amount) {
  135.         var i, n, target, positions;
  136.  
  137.         switch (me.classid) {
  138.         case 0:
  139.             break;
  140.         case 1:
  141.             break;
  142.         case 2:
  143.             break;
  144.         case 3:
  145.             target = getUnit(1, name);
  146.  
  147.             if (!target) {
  148.                 return;
  149.             }
  150.  
  151.             positions = [[6, 11], [0, 8], [8, -1], [-9, 2], [0, -11], [8, -8]];
  152.  
  153.             for (i = 0; i < positions.length; i += 1) {
  154.                 if (Attack.validSpot(target.x + positions[i][0], target.y + positions[i][1])) { // check if we can move there
  155.                     Pather.moveTo(target.x + positions[i][0], target.y + positions[i][1]);
  156.                     Skill.setSkill(Config.AttackSkill[2], 0);
  157.  
  158.                     for (n = 0; n < amount; n += 1) {
  159.                         Skill.cast(Config.AttackSkill[1], 1);
  160.                     }
  161.  
  162.                     break;
  163.                 }
  164.             }
  165.  
  166.             break;
  167.         case 4:
  168.             break;
  169.         case 5:
  170.             break;
  171.         case 6:
  172.             break;
  173.         }
  174.     };
  175.  
  176.     this.getBoss = function (name) {
  177.         var i, boss,
  178.             glow = getUnit(2, 131);
  179.  
  180.         for (i = 0; i < 16; i += 1) {
  181.             boss = getUnit(1, name);
  182.  
  183.             if (boss) {
  184.                 this.chaosPreattack(name, 8);
  185.  
  186.                 return Attack.clear(40, 0, name, this.sort);
  187.             }
  188.  
  189.             delay(250);
  190.         }
  191.  
  192.         return !!glow;
  193.     };
  194.  
  195.     this.vizierSeal = function () {
  196.         print("" + this.vizLayout);
  197.         this.followPath(this.vizLayout === 1 ? this.starToVizA : this.starToVizB);
  198.  
  199.         if (!this.openSeal(395) || !this.openSeal(396)) {
  200.             throw new Error("");
  201.         }
  202.  
  203.         if (this.vizLayout === 1) {
  204.             Pather.moveTo(7691, 5292);
  205.         } else {
  206.             Pather.moveTo(7695, 5316);
  207.         }
  208.  
  209.         if (!this.getBoss(getLocaleString(2851))) {
  210.             throw new Error("");
  211.         }
  212.  
  213.         return true;
  214.     };
  215.  
  216.     this.seisSeal = function () {
  217.         print("" + this.seisLayout);
  218.         this.followPath(this.seisLayout === 1 ? this.starToSeisA : this.starToSeisB);
  219.  
  220.         if (!this.openSeal(394)) {
  221.             throw new Error("");
  222.         }
  223.  
  224.         if (this.seisLayout === 1) {
  225.             Pather.moveTo(7771, 5196);
  226.         } else {
  227.             Pather.moveTo(7798, 5186);
  228.         }
  229.  
  230.         if (!this.getBoss(getLocaleString(2852))) {
  231.             throw new Error("");
  232.         }
  233.  
  234.         return true;
  235.     };
  236.  
  237.     this.infectorSeal = function () {
  238.         print("Inf layout " + this.infLayout);
  239.         this.followPath(this.infLayout === 1 ? this.starToInfA : this.starToInfB);
  240.  
  241.         if (!this.openSeal(392)) {
  242.             throw new Error("");
  243.         }
  244.  
  245.         if (this.infLayout === 1) {
  246.             delay(1);
  247.         } else {
  248.             Pather.moveTo(7928, 5295); // temp
  249.         }
  250.  
  251.         if (!this.getBoss(getLocaleString(2853))) {
  252.             throw new Error("");
  253.         }
  254.  
  255.         if (!this.openSeal(393)) {
  256.             throw new Error("");
  257.         }
  258.  
  259.         return true;
  260.     };
  261.  
  262.     this.diabloPrep = function () {
  263.         var trapCheck,
  264.             tick = getTickCount();
  265.  
  266.         while (getTickCount() - tick < 30000) {
  267.             if (getTickCount() - tick >= 8000) {
  268.                 switch (me.classid) {
  269.                 case 1: // Sorceress
  270.                     if ([56, 59, 64].indexOf(Config.AttackSkill[1]) > -1) {
  271.                         if (me.getState(121)) {
  272.                             delay(500);
  273.                         } else {
  274.                             Skill.cast(Config.AttackSkill[1], 0, 7793, 5293);
  275.                         }
  276.  
  277.                         break;
  278.                     }
  279.  
  280.                     delay(500);
  281.  
  282.                     break;
  283.                 case 3: // Paladin
  284.                     Skill.setSkill(Config.AttackSkill[2]);
  285.                     Skill.cast(Config.AttackSkill[1], 1);
  286.  
  287.                     break;
  288.                 case 5: // Druid
  289.                     if (Config.AttackSkill[1] === 245) {
  290.                         Skill.cast(Config.AttackSkill[1], 0, 7793, 5293);
  291.  
  292.                         break;
  293.                     }
  294.  
  295.                     delay(500);
  296.  
  297.                     break;
  298.                 case 6: // Assassin
  299.                     if (Config.UseTraps) {
  300.                         trapCheck = ClassAttack.checkTraps({x: 7793, y: 5293});
  301.  
  302.                         if (trapCheck) {
  303.                             ClassAttack.placeTraps({x: 7793, y: 5293, classid: 243}, trapCheck);
  304.  
  305.                             break;
  306.                         }
  307.                     }
  308.  
  309.                     delay(500);
  310.  
  311.                     break;
  312.                 default:
  313.                     delay(500);
  314.  
  315.                     break;
  316.                 }
  317.             } else {
  318.                 delay(500);
  319.             }
  320.  
  321.             if (getUnit(1, 243)) {
  322.                 return true;
  323.             }
  324.         }
  325.  
  326.         throw new Error("");
  327.     };
  328.  
  329.     this.followPath = function (path) {
  330.         var i;
  331.  
  332.         for (i = 0; i < path.length; i += 2) {
  333.             if (this.cleared.length) {
  334.                 this.clearStrays();
  335.             }
  336.  
  337.             Pather.moveTo(path[i], path[i + 1], 3, getDistance(me, path[i], path[i + 1]) > 50);
  338.             Attack.clear(30, 0, false, this.sort);
  339.  
  340.             // Push cleared positions so they can be checked for strays
  341.             this.cleared.push([path[i], path[i + 1]]);
  342.  
  343.             // After 5 nodes go back 2 nodes to check for monsters
  344.             if (i === 10 && path.length > 16) {
  345.                 path = path.slice(6);
  346.                 i = 0;
  347.             }
  348.         }
  349.     };
  350.  
  351.     this.clearStrays = function () {
  352.         /*if (!Config.PublicMode) {
  353.             return false;
  354.         }*/
  355.  
  356.         var i,
  357.             oldPos = {x: me.x, y: me.y},
  358.             monster = getUnit(1);
  359.  
  360.         if (monster) {
  361.             do {
  362.                 if (Attack.checkMonster(monster)) {
  363.                     for (i = 0; i < this.cleared.length; i += 1) {
  364.                         if (getDistance(monster, this.cleared[i][0], this.cleared[i][1]) < 30 && Attack.validSpot(monster.x, monster.y)) {
  365.                             me.overhead("");
  366.                             Pather.moveToUnit(monster);
  367.                             Attack.clear(15, 0, false, this.sort);
  368.  
  369.                             break;
  370.                         }
  371.                     }
  372.                 }
  373.             } while (monster.getNext());
  374.         }
  375.  
  376.         if (getDistance(me, oldPos.x, oldPos.y) > 5) {
  377.             Pather.moveTo(oldPos.x, oldPos.y);
  378.         }
  379.  
  380.         return true;
  381.     };
  382.  
  383.     this.defendPlayers = function () {
  384.         var player,
  385.             oldPos = {x: me.x, y: me.y},
  386.             monster = getUnit(1);
  387.  
  388.         if (monster) {
  389.             do {
  390.                 if (Attack.checkMonster(monster)) {
  391.                     player = getUnit(0);
  392.  
  393.                     if (player) {
  394.                         do {
  395.                             if (player.name !== me.name && getDistance(monster, player) < 30) {
  396.                                 me.overhead("");
  397.                                 Pather.moveToUnit(monster);
  398.                                 Attack.clear(15, 0, false, this.sort);
  399.                             }
  400.                         } while (player.getNext());
  401.                     }
  402.                 }
  403.             } while (monster.getNext());
  404.         }
  405.  
  406.         if (getDistance(me, oldPos.x, oldPos.y) > 5) {
  407.             Pather.moveTo(oldPos.x, oldPos.y);
  408.         }
  409.  
  410.         return true;
  411.     };
  412.  
  413.     this.cleared = [];
  414.  
  415.     // path coordinates
  416.     this.entranceToStar = [7794, 5517, 7791, 5491, 7768, 5459, 7775, 5424, 7817, 5458, 7777, 5408, 7769, 5379, 7777, 5357, 7809, 5359, 7805, 5330, 7780, 5317, 7791, 5293];
  417.     this.starToVizA = [7759, 5295, 7734, 5295, 7716, 5295, 7718, 5276, 7697, 5292, 7678, 5293, 7665, 5276, 7662, 5314];
  418.     this.starToVizB = [7759, 5295, 7734, 5295, 7716, 5295, 7701, 5315, 7666, 5313, 7653, 5284];
  419.     this.starToSeisA = [7781, 5259, 7805, 5258, 7802, 5237, 7776, 5228, 7775, 5205, 7804, 5193, 7814, 5169, 7788, 5153];
  420.     this.starToSeisB = [7781, 5259, 7805, 5258, 7802, 5237, 7776, 5228, 7811, 5218, 7807, 5194, 7779, 5193, 7774, 5160, 7803, 5154];
  421.     this.starToInfA = [7809, 5268, 7834, 5306, 7852, 5280, 7852, 5310, 7869, 5294, 7895, 5295, 7919, 5290];
  422.     this.starToInfB = [7809, 5268, 7834, 5306, 7852, 5280, 7852, 5310, 7869, 5294, 7895, 5274, 7927, 5275, 7932, 5297, 7923, 5313];
  423.     Pather._teleport = Pather.teleport;
  424.  
  425.     // start
  426.     Town.doChores();
  427.     Pather.useWaypoint(Config.RandomPrecast ? "" : 107);
  428.     Precast.doPrecast(true);
  429.  
  430.     if (me.area !== 107) {
  431.         Pather.useWaypoint(107);
  432.     }
  433.  
  434.     if (!Pather.moveTo(7790, 5544)) {
  435.         throw new Error("");
  436.     }
  437.  
  438.     this.initLayout();
  439.  
  440.     if (Config.Diablo.Entrance) {
  441.         Attack.clear(30, 0, false, this.sort);
  442.         Pather.moveTo(7790, 5544);
  443.  
  444.         if (Config.PublicMode) {
  445.             Pather.makePortal();
  446.             say(Config.Diablo.EntranceTP);
  447.             Pather.teleport = !Config.Diablo.WalkClear && Pather._teleport;
  448.         }
  449.  
  450.         Pather.moveTo(7790, 5544);
  451.         Precast.doPrecast(true);
  452.         Attack.clear(30, 0, false, this.sort);
  453.         this.followPath(this.entranceToStar);
  454.     } else {
  455.         Pather.moveTo(7774, 5305);
  456.         Attack.clear(15, 0, false, this.sort);
  457.     }
  458.  
  459.     Pather.moveTo(7791, 5293);
  460.  
  461.     if (Config.PublicMode) {
  462.         Pather.makePortal();
  463.         say(Config.Diablo.StarTP);
  464.         Pather.teleport = !Config.Diablo.WalkClear && Pather._teleport;
  465.     }
  466.  
  467.     Attack.clear(30, 0, false, this.sort);
  468.     this.vizierSeal();
  469.     this.seisSeal();
  470.     Precast.doPrecast(true);
  471.     this.infectorSeal();
  472.  
  473.     switch (me.classid) {
  474.     case 1:
  475.         Pather.moveTo(7792, 5294);
  476.  
  477.         break;
  478.     default:
  479.         Pather.moveTo(7788, 5292);
  480.  
  481.         break;
  482.     }
  483.  
  484.  
  485.     if (Config.PublicMode) {
  486.         say(Config.Diablo.DiabloMsg);
  487.     }
  488.  
  489.     this.diabloPrep();
  490.     Attack.kill(243); // Diablo
  491.     Pickit.pickItems();
  492.  
  493.     Pather.teleport = Pather._teleport;
  494.  
  495.     return true;
  496. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement