Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. *   @filename   DupeRerollRare.js
  3. *   @author      Walla + Kolbot + maulepan + sithy  
  4. */
  5. function DupeReroll() {
  6.     var helper = Config.DupeReroll.Helper;
  7.     var opener = Config.DupeReroll.Opener;
  8.     var baseid = Config.DupeReroll.Classid;
  9.     var quality = Config.DupeReroll.Quality;
  10.     var craftList = Config.DupeReroll.craftList;
  11.     var runeList = Config.DupeReroll.runeList;
  12.     var i, k, j, l, items, npc, tick, trader, wp, allitems, string, newitem, result, string, cycles, scroll, dupeN = 1;
  13.     var end = false;
  14.     var list = [];
  15.     var usedGems = [];
  16.     var seconds = 0;
  17.     var minutes = 0;
  18.     var blockStatus = false, dropInventory = false, tradeAccepted = false, leave = false;
  19.    
  20.     function doReroll(bquality, bid){
  21.         if(bquality === 6){
  22.             Town.move("stash");
  23.             delay(20);
  24.             Town.openStash();
  25.             while (!end) {
  26.                         allitems = me.findItems(-1, 0); // get all items
  27.                         list = []; //empty list
  28.                        
  29.                                 for (k = 0; k < allitems.length; k += 1) { // search for a rare item
  30.                                                 if (allitems[k].classid === bid && allitems[k].quality === 6) { // find a rare item
  31.                                                         list.push(allitems[k]); // push into the item list
  32.                                                         break; // stop searching
  33.                                                 }
  34.                                         }
  35.                                 for (k = 0; k < allitems.length; k += 1) { // search for a ring
  36.                                                 if (allitems[k].classid === 522 && allitems[k].quality === 7) { // find a ring
  37.                                                         list.push(allitems[k]); // push into the item list
  38.                                                         break; // stop searching
  39.                                                 }
  40.                                         }
  41.                                 for (k = 0; k < allitems.length; k += 1) { // search for a perf skull
  42.                                                 if (allitems[k].classid === 601) { // find a perf skull
  43.                                                         list.push(allitems[k]); // push into the item list
  44.                                                         break; // stop searching
  45.                                                 }
  46.                                         }
  47.                         if(list.length == 3) {
  48.                                                 // If cube isn't open, attempt to open stash (the function returns true if stash is already open)
  49.                                         if ((!getUIFlag(0x1a) && !Town.openStash()) || !emptyCube()) {
  50.                                                 print("could not open stash");
  51.                                         }
  52.          
  53.                                         i = -1;
  54.                                         string = "transmute: "
  55.                                         while (list.length) {
  56.                                                 string += (list[0].name + (list.length > 1 ? " + " : ""));
  57.                                                 Storage.Cube.MoveTo(list[0]);
  58.                                                 list.shift();
  59.                                         }
  60.          
  61.                                         if (!openCube()) {
  62.                                                 print("could not open stash");
  63.                                         }
  64.          
  65.                                         if(!getParty(helper)) {
  66.                                             print("The Trader is not in the game anymore.");
  67.                                         } else {
  68.                                             transmute();
  69.                                             cycles += 1;
  70.                                         }
  71.                                         delay(700 + me.ping);
  72.                                         print("Cubing: " + string);
  73.                                         //D2Bot.printToConsole(string + ";5");
  74.          
  75.                                         newitem = me.findItems(-1, -1, 6);
  76.          
  77.                                         if (newitem) {
  78.                                                 for (j = 0; j < newitem.length; j += 1) {
  79.                                                         result = Pickit.checkItem(newitem[j]);
  80.          
  81.                                                         switch (result.result) {
  82.                                                         case 0:
  83.                                                                 //Misc.logItem("Not kept", newitem[j]);
  84.                                                                 break;
  85.                                                         case 1:
  86.                                                                 Misc.logItem("Cubing kept", newitem[j]);
  87.                                                                 newitem[j].drop();
  88.                                                                 break;
  89.                                                         }
  90.                                                 }
  91.                                         }
  92.          
  93.                                         if (!emptyCube()) {
  94.                                                 break;
  95.                                         }
  96.            
  97.                         }
  98.                         else {
  99.                         end = true;
  100.                         }
  101.                 }
  102.             while (getUIFlag(0x1A) || getUIFlag(0x19)) {
  103.                 me.cancel();
  104.                 delay(300);
  105.             }
  106.             end = false;
  107.         }      
  108.         if(bquality === 4){
  109.             Town.move("stash");
  110.             delay(20);
  111.             Town.openStash();
  112.             while (!end) {
  113.                         allitems = me.findItems(-1, 0); // get all items
  114.                         list = []; //empty list
  115.                         usedGems = [];
  116.                                 for (k = 0; k < allitems.length; k += 1) { // search for a magic item
  117.                                                 if (allitems[k].classid === bid && allitems[k].quality === 4) { // find a magic item item
  118.                                                         list.push(allitems[k]); // push into the item list
  119.                                                         break; // stop searching
  120.                                                 }
  121.                                         }
  122.                                 for (k = 0; k < allitems.length; k += 1) { // search for perf Gem
  123.                                                 if ([561, 566, 571, 576, 581, 586].indexOf(allitems[k].classid) > -1) { // find a perf gem
  124.                                                         list.push(allitems[k]); // push into the item list
  125.                                                         allitems.splice(k, 1);
  126.                                                         break; // stop searching
  127.                                                 }
  128.                                         }
  129.                                 for (k = 0; k < allitems.length; k += 1) { // search for perf Gem
  130.                                                 if ([561, 566, 571, 576, 581, 586].indexOf(allitems[k].classid) > -1) { // find a perf gem
  131.                                                         list.push(allitems[k]); // push into the item list
  132.                                                         allitems.splice(k, 1);
  133.                                                         break; // stop searching
  134.                                                 }
  135.                                         }
  136.                                 for (k = 0; k < allitems.length; k += 1) { // search for perf Gem
  137.                                                 if ([561, 566, 571, 576, 581, 586].indexOf(allitems[k].classid) > -1) { // find a perf gem
  138.                                                         list.push(allitems[k]); // push into the item list
  139.                                                         allitems.splice(k, 1);
  140.                                                         break; // stop searching
  141.                                                 }
  142.                                         }
  143.                         if(list.length == 4) {
  144.                                                 // If cube isn't open, attempt to open stash (the function returns true if stash is already open)
  145.                                         if ((!getUIFlag(0x1a) && !Town.openStash()) || !emptyCube()) {
  146.                                                 print("could not open stash");
  147.                                         }
  148.          
  149.                                         i = -1;
  150.                                         string = "transmute: "
  151.                                         while (list.length) {
  152.                                                 string += (list[0].name + (list.length > 1 ? " + " : ""));
  153.                                                 Storage.Cube.MoveTo(list[0]);
  154.                                                 list.shift();
  155.                                         }
  156.          
  157.                                         if (!openCube()) {
  158.                                                 print("could not open stash");
  159.                                         }
  160.          
  161.                                         if(!getParty(helper)) {
  162.                                             print("The Trader is not in the game anymore.");
  163.                                         } else {
  164.                                             transmute();
  165.                                             cycles += 1;
  166.                                         }
  167.                                         delay(700 + me.ping);
  168.                                         print("Cubing: " + string);
  169.                                         //D2Bot.printToConsole(string + ";5");
  170.          
  171.                                         newitem = me.findItems(-1, -1, 6);
  172.          
  173.                                         if (newitem) {
  174.                                                 for (j = 0; j < newitem.length; j += 1) {
  175.                                                         result = Pickit.checkItem(newitem[j]);
  176.          
  177.                                                         switch (result.result) {
  178.                                                         case 0:
  179.                                                                 //Misc.logItem("Not kept", newitem[j]);
  180.                                                                 break;
  181.                                                         case 1:
  182.                                                                 Misc.logItem("Cubing kept", newitem[j]);
  183.                                                                 newitem[j].drop();
  184.                                                                 break;
  185.                                                         }
  186.                                                 }
  187.                                         }
  188.          
  189.                                         if (!emptyCube()) {
  190.                                                 break;
  191.                                         }
  192.            
  193.                         }
  194.                         else {
  195.                         end = true;
  196.                         }
  197.                 }
  198.             while (getUIFlag(0x1A) || getUIFlag(0x19)) {
  199.                 me.cancel();
  200.                 delay(300);
  201.             }
  202.             end = false;
  203.         }
  204.         if(bquality === 8){
  205.             Town.move("stash");
  206.             delay(20);
  207.             Town.openStash();
  208.             while (!end) {
  209.                         allitems = me.findItems(-1, 0); // get all items
  210.                         list = []; //empty list
  211.                                 for (k = 0; k < allitems.length; k += 1) { // search for a magic item
  212.                                                 if (allitems[k].classid === bid && allitems[k].quality === 4) { // find a magic item item
  213.                                                         list.push(allitems[k]); // push into the item list
  214.                                                         break; // stop searching
  215.                                                 }
  216.                                         }
  217.                                 for (l = 0; l < craftList.length; l +=1){
  218.                                         for (k = 0; k < allitems.length; k += 1) {
  219.                                                 if (allitems[k].classid === craftList[l]) { // find a ingridient
  220.                                                         list.push(allitems[k]); // push into the item list
  221.                                                         allitems.splice(k, 1);  
  222.                                                         break; // stop searching
  223.                                                 }
  224.                                         }
  225.                                 }
  226.                         if(list.length == craftList.length + 1) {
  227.                                                 // If cube isn't open, attempt to open stash (the function returns true if stash is already open)
  228.                                         if ((!getUIFlag(0x1a) && !Town.openStash()) || !emptyCube()) {
  229.                                                 print("could not open stash");
  230.                                         }
  231.          
  232.                                         i = -1;
  233.                                         string = "transmute: "
  234.                                         while (list.length) {
  235.                                                 string += (list[0].name + (list.length > 1 ? " + " : ""));
  236.                                                 Storage.Cube.MoveTo(list[0]);
  237.                                                 list.shift();
  238.                                         }
  239.          
  240.                                         if (!openCube()) {
  241.                                                 print("could not open stash");
  242.                                         }
  243.          
  244.                                         if(!getParty(helper)) {
  245.                                             print("The Trader is not in the game anymore.");
  246.                                         } else {
  247.                                             transmute();
  248.                                             cycles += 1;
  249.                                         }
  250.                                         delay(700 + me.ping);
  251.                                         print("Cubing: " + string);
  252.                                         //D2Bot.printToConsole(string + ";5");
  253.          
  254.                                         newitem = me.findItems(-1, -1, 6);
  255.          
  256.                                         if (newitem) {
  257.                                                 for (j = 0; j < newitem.length; j += 1) {
  258.                                                         result = Pickit.checkItem(newitem[j]);
  259.          
  260.                                                         switch (result.result) {
  261.                                                         case 0:
  262.                                                                 //Misc.logItem("Not kept", newitem[j]);
  263.                                                                 break;
  264.                                                         case 1:
  265.                                                                 Misc.logItem("Cubing kept", newitem[j]);
  266.                                                                 newitem[j].drop();
  267.                                                                 break;
  268.                                                         }
  269.                                                 }
  270.                                         }
  271.          
  272.                                         if (!emptyCube()) {
  273.                                                 break;
  274.                                         }
  275.            
  276.                         }
  277.                         else {
  278.                         end = true;
  279.                         }
  280.                 }
  281.             while (getUIFlag(0x1A) || getUIFlag(0x19)) {
  282.                 me.cancel();
  283.                 delay(300);
  284.             }
  285.             end = false;
  286.         }
  287.         if(bquality === 9){
  288.             Town.move("stash");
  289.             delay(20);
  290.             Town.openStash();
  291.             while (!end) {
  292.                         allitems = me.findItems(-1, 0); // get all items
  293.                         list = []; //empty list
  294.                                 for (k = 0; k < allitems.length; k += 1) { // search for a base item
  295.                                                 if (allitems[k].classid === bid && allitems[k].quality <= 3 && !allitems[k].getFlag(0x4000000)){ // find a base item
  296.                                                         list.push(allitems[k]); // push into the item list
  297.                                                         break; // stop searching
  298.                                                 }
  299.                                         }
  300.                                 for (l = 0; l < runeList.length; l +=1){
  301.                                         for (k = 0; k < allitems.length; k += 1) {
  302.                                                 if (allitems[k].classid === runeList[l]) { // find a ingridient
  303.                                                         list.push(allitems[k]); // push into the item list
  304.                                                         allitems.splice(k, 1);  
  305.                                                         break; // stop searching
  306.                                                 }
  307.                                         }
  308.                                 }
  309.                         if(list.length == runeList.length + 1) {
  310.                                                 // If cube isn't open, attempt to open stash (the function returns true if stash is already open)
  311.                                         if ((!getUIFlag(0x1a) && !Town.openStash())) {
  312.                                                 print("could not open stash");
  313.                                         }
  314.          
  315.                                         i = -1;                                                                    
  316.                                         if(!getParty(helper)) {
  317.                                             print("The Trader is not in the game anymore.");
  318.                                         } else {
  319.                                                 for(k = 1; k <= runeList.length; k +=1){
  320.                                                     socketItem(list[0], list[k]);                                                  
  321.                                                 }
  322.                                         }
  323.                                         delay(700 + me.ping);
  324.                                        
  325.                                         //D2Bot.printToConsole(string + ";5");
  326.                                         result = Pickit.checkItem(list[0]);
  327.                                         switch (result.result) {
  328.                                             case 0:
  329.                                                 //Misc.logItem("Not kept", list[0]);
  330.                                                 break;
  331.                                             case 1:
  332.                                                 Misc.logItem("Runeword kept", list[0]);
  333.                                                 list[0].drop();
  334.                                                 break;
  335.                                             }
  336.                                         cycles += 1;       
  337.                                        
  338.            
  339.                         }
  340.                         else {
  341.                         end = true;
  342.                         }
  343.                 }
  344.             while (getUIFlag(0x1A) || getUIFlag(0x19)) {
  345.                 me.cancel();
  346.                 delay(300);
  347.             }
  348.             end = false;
  349.         }
  350.         if(bquality !== 6 && bquality !== 4 && bquality !== 8 && bquality !== 9){
  351.              throw new Error("Only Magic, Rare, Runeword and Crafted Items are supported in the script.");
  352.              return false; 
  353.         }
  354.     return true;
  355.     }
  356.     function socketItem(base, rune) {
  357.         var s, tick;
  358.  
  359.         if (!rune.toCursor()) {
  360.             return false;
  361.         }
  362.  
  363.         for (s = 0; s < 3; s += 1) {
  364.             clickItem(0, base.x, base.y, base.location);
  365.  
  366.             tick = getTickCount();
  367.  
  368.             while (getTickCount() - tick < 2000) {
  369.                 if (!me.itemoncursor) {
  370.                     delay(300);
  371.  
  372.                     return true;
  373.                 }
  374.  
  375.                 delay(10);
  376.             }
  377.         }
  378.  
  379.         return false;
  380.     }
  381.     function openCube() {
  382.                 var p, tick,
  383.                         cube = me.getItem(549);
  384.  
  385.                 if (!cube) {
  386.                         return false;
  387.                 }
  388.  
  389.                 for (p = 0; p < 3; p += 1) {
  390.                         cube.interact();
  391.  
  392.                         tick = getTickCount();
  393.  
  394.                         while (getTickCount() - tick < 1000) {
  395.                                 if (getUIFlag(0x1A)) {
  396.                                         delay(500);
  397.  
  398.                                         return true;
  399.                                 }
  400.  
  401.                                 delay(10);
  402.                         }
  403.                 }
  404.  
  405.                 return false;
  406.         }
  407.     function emptyCube() {
  408.                 var cube = me.getItem(549),
  409.                         citems = me.findItems(-1, -1, 6);
  410.  
  411.                 if (!cube) {
  412.                         return false;
  413.                 }
  414.  
  415.                 if (!citems) {
  416.                         return true;
  417.                 }
  418.  
  419.                 while (citems.length) {
  420.                         if (Storage.Inventory.CanFit(citems[0])) {
  421.                                 Storage.Inventory.MoveTo(citems[0]);
  422.                         } else {
  423.                                 return false;
  424.                         }
  425.  
  426.                         citems.shift();
  427.                 }
  428.  
  429.                 return true;
  430.         }
  431.  while(true){
  432.    this.PacketReceived = function(bytes) {
  433.       switch(bytes[0]) {
  434.          case 0x78:
  435.             tradeAccepted = true;
  436.             print("Trade Accepted = True");
  437.          break;
  438.       }
  439.    };
  440.  
  441.    this.PacketSent = function(bytes) {
  442.       switch (bytes[0]) {
  443.          case 0x30:
  444.             if (blockStatus) {
  445.                print("[Blocked] 0x30");
  446.                return true;
  447.             }
  448.          break;
  449.       }
  450.      
  451.       return false;
  452.    };
  453.    this.LeaveHandler = function(user, msg) {
  454.       if (user === opener) {
  455.          if (msg === "leave!") {
  456.             leave = true;
  457.          }
  458.       }
  459.    };
  460.    
  461.    addEventListener("gamepacket", this.PacketReceived);
  462.    addEventListener("gamepacketsent", this.PacketSent);
  463.    addEventListener("chatmsg", this.LeaveHandler);
  464.    // Check act
  465.    delay(2000);
  466.    if (me.area !== 40) {
  467.       print("Not in act 2. Changing acts.");
  468.       if (me.area !== 1) {
  469.          Pather.useWaypoint(1);
  470.       }
  471.       Town.move("warriv");
  472.       npc = getUnit(1, "warriv");
  473.       if (!npc || !npc.openMenu()) {
  474.          showConsole();
  475.          throw new Error("Act change failed.");
  476.          return false;
  477.       }
  478.       Misc.useMenu(0x0D36);
  479.       delay(1000 + me.ping * 2);
  480.       while (!me.area) {
  481.          delay(250);
  482.       }
  483.       if (me.area !== 40) {
  484.          showConsole();
  485.          throw new Error("Act change failed.");
  486.          return false;
  487.       }
  488.       print("Act change done.");
  489.    }
  490.    
  491.    // Start blocking 0x30
  492.    blockStatus = true;
  493.    // Wait to begin
  494.    delay(2000);
  495.    Town.move("jerhyn");
  496.    npc = getUnit(1, "jerhyn");
  497.    if (!npc || !npc.openMenu()) {
  498.       showConsole();
  499.       throw new Error("Couldn't access Jerhyn.");
  500.       return false;
  501.    }
  502.    delay(200);
  503.    me.cancel();
  504.    delay(50);
  505.    // Stop blocking 0x30
  506.    blockStatus = false;
  507.    print("pathern-move");
  508.    Pather.moveTo(me.x - 20, me.y);
  509.    print("pathern-move-end");
  510.    Town.move("waypoint");
  511.    delay(1500);
  512.    wp = getUnit(2, "waypoint");
  513.    if (!wp) {
  514.       print("Couldn't reach waypoint.");
  515.    }
  516.    sendPacket(1, 0x49, 4, wp.gid, 1, 0, 1, 0, 1, 0, 1, 0);
  517.    print("send wp packet");
  518.    delay(200);
  519.    
  520.    tick = getTickCount();
  521.    do {
  522.       trader = getUnit(0, helper);
  523.       // If Helper can't be found in 15s, leave.
  524.       if (getTickCount() - tick >= 15000) {
  525.          print("Couldn't find Helper.");
  526.       }
  527.       delay(100);
  528.    } while (!trader);
  529.    while (!getUIFlag(0x17)) {
  530.       trader.interact();
  531.       delay(250);
  532.    }
  533.    while (!(getUIFlag(0x17) && tradeAccepted)) {
  534.         delay(300);
  535.         print("Trade not Accepted");
  536.     }
  537.     tradeAccepted = false;
  538.     // Close trade window
  539.    
  540.     // Tp Stuck?
  541.         allitems = me.findItems(-1, 0, 5);
  542.         for (k = 0; k < allitems.length; k += 1) { // search for a scroll
  543.             if (allitems[k].classid === 529) { // find a scroll of town protal
  544.                 say("tptrick");
  545.                 while((getUIFlag(0x17))){
  546.                     acceptTrade();
  547.                     delay(1000);
  548.                 }
  549.                 delay(2000);
  550.                 say("closetrade");
  551.                 delay(1000);
  552.                 return true;
  553.             }
  554.         }
  555.    
  556.     allitems = me.findItems(-1, 0); // get all items
  557.     for (k = 0; k < allitems.length; k += 1) { // search for a scroll
  558.         if (allitems[k].classid === 529) { // find a scroll of town protal
  559.             scroll = allitems[k]; // push into the item list
  560.             break; // stop searching
  561.         }
  562.     }
  563.     Storage.TradeScreen.MoveTo(scroll);
  564.     acceptTrade();
  565.     getPacket(1, 0x77, 1, 0x0C);
  566.     print("Closed Trade window");
  567.     delay(100);  
  568.     // Move out of town.
  569.     Pather.moveToExit(41, true);
  570.     delay(50);
  571.     // Move back to town.
  572.     Pather.moveToExit(40, true);
  573.     delay(500);
  574.     if(!me.inTown) {
  575.     Pather.moveToExit(40, true);
  576.     delay(500);
  577.     }
  578.     if(!me.inTown) {
  579.     say("closetrade");
  580.     D2Bot.printToConsole("Failed to go back to town.");
  581.     delay(2000);
  582.     return true;
  583.     }
  584.     Town.move("waypoint");
  585.     delay(50);
  586.     Pather.useWaypoint(1);
  587.     delay(200);
  588.     Town.move("stash");
  589.     delay(200);
  590.     cycles += 1;
  591.     doReroll(quality, baseid);
  592.     say("accept");
  593.     delay(1000);
  594.     doReroll(quality, baseid);
  595.     delay(200);
  596.     say("closetrade");
  597.     dupeN += 1;
  598.     seconds = Math.round(((getTickCount() - me.gamestarttime) / 1000));
  599.     minutes = Math.floor(seconds / 60);
  600.     seconds = seconds - minutes * 60;
  601.     seconds = (seconds < 10 ? "0" + seconds : seconds);
  602.     D2Bot.printToConsole("Run duration is " + minutes + ":" + seconds + " minutes and I rolled " + cycles + " times.");
  603.     say("Starting Dupe #" + dupeN)
  604.     say("Credits To Abelcustoms")
  605. }
  606.     return true;
  607. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement