Advertisement
lengend

Untitled

Sep 9th, 2012
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *   @filename   Misc.js
  3. *   @author     kolton
  4. *   @desc       misc library containing Skill, Misc and Sort classes
  5. */
  6.  
  7. // Raw Game Timer
  8. function gameTimer(tick) {
  9.     if (!tick) {
  10.         return "";
  11.     }
  12.  
  13.     var min, sec;
  14.  
  15.     min = Math.floor((getTickCount() - tick) / 60000).toString();
  16.  
  17.     if (min <= 9) {
  18.         min = "0" + min;
  19.     }
  20.  
  21.     sec = (Math.floor((getTickCount() - tick) / 1000) % 60).toString();
  22.  
  23.     if (sec <= 9) {
  24.         sec = "0" + sec;
  25.     }
  26.  
  27.     return min + "m " + sec + "s";
  28. }
  29.  
  30. var gameTime = getTickCount();
  31.  
  32. // Raw Seconds Timer
  33. function secondsTimer(tick) {
  34.     if (!tick) {
  35.         return "";
  36.     }
  37.  
  38.     var sec;
  39.  
  40.     sec = (Math.floor((getTickCount() - tick) / 1000)).toString();
  41.  
  42.     if (sec <= 9) {
  43.         sec = "0" + sec;
  44.     }
  45.  
  46.     return sec;
  47. }
  48.  
  49. var gameSeconds = getTickCount();
  50.  
  51. var Skill = {
  52.     // Cast a skill on self, Unit or coords
  53.     cast: function (skillId, hand, x, y) {
  54.         if (me.inTown && !this.townSkill(skillId)) {
  55.             return false;
  56.         }
  57.  
  58.         if (!me.getSkill(skillId, 1)) {
  59.             return false;
  60.         }
  61.  
  62.         if (typeof skillId === "undefined") {
  63.             throw new Error("Skill.cast: Must supply a skill ID");
  64.         }
  65.  
  66.         var i, n, clickType, shift;
  67.  
  68.         if (typeof hand === "undefined") {
  69.             hand = 0;
  70.         }
  71.  
  72.         if (typeof x === "undefined") {
  73.             x = me.x;
  74.         }
  75.  
  76.         if (typeof y === "undefined") {
  77.             y = me.y;
  78.         }
  79.  
  80.         switch (hand) {
  81.         case 0:
  82.             clickType = 3;
  83.             shift = 0;
  84.             break;
  85.         case 1:
  86.             clickType = 0;
  87.             shift = 1;
  88.             break;
  89.         case 2: // For melee skills that don't need shift
  90.             clickType = 0;
  91.             shift = 0;
  92.             break;
  93.         }
  94.  
  95.         if (!this.setSkill(skillId, hand)) {
  96.             return false;
  97.         }
  98.  
  99. MainLoop:
  100.         for (n = 0; n < 3; n += 1) {
  101.             if (typeof x === "object") {
  102.                 clickMap(clickType, shift, x);
  103.             } else {
  104.                 clickMap(clickType, shift, x, y);
  105.             }
  106.  
  107.             delay(30);
  108.  
  109.             if (typeof x === "object") {
  110.                 clickMap(clickType + 2, shift, x);
  111.             } else {
  112.                 clickMap(clickType + 2, shift, x, y);
  113.             }
  114.  
  115.             for (i = 0; i < 4; i += 1) {
  116.                 if (me.attacking) {
  117.                     break MainLoop;
  118.                 }
  119.  
  120.                 delay(40);
  121.             }
  122.         }
  123.  
  124.         while (me.attacking) {
  125.             delay(10);
  126.         }
  127.  
  128.         if (this.isTimed(skillId)) { // account for lag, state 121 doesn't kick in immediately
  129.             for (i = 0; i < 10; i += 1) {
  130.                 if (me.getState(121)) {
  131.                     break;
  132.                 }
  133.  
  134.                 delay(10);
  135.             }
  136.         }
  137.  
  138.         return true;
  139.     },
  140.  
  141.     // Put a skill on desired slot
  142.     setSkill: function (skillId, hand) {
  143.         if (!me.getSkill(skillId, 1)) {
  144.             return false;
  145.         }
  146.  
  147.         if (typeof hand === "undefined") {
  148.             hand = 0;
  149.         }
  150.  
  151.         // Check if the skill is already set
  152.         if (me.getSkill(hand === 0 ? 2 : 3) === skillId) {
  153.             return true;
  154.         }
  155.  
  156.         if (me.setSkill(skillId, hand)) {
  157.             return true;
  158.         }
  159.  
  160.         return false;
  161.     },
  162.  
  163.     // Timed skills
  164.     isTimed: function (skillId) {
  165.         return [15, 25, 27, 51, 56, 59, 62, 64, 121, 225, 223, 228, 229, 234, 244, 247, 249, 250, 256, 268, 275, 277, 279].indexOf(skillId) > -1;
  166.     },
  167.  
  168.     // Skills that cn be cast in town
  169.     townSkill: function (skillId) {
  170.         return [32, 40, 43, 50, 52, 58, 60, 68, 75, 85, 94, 117, 221, 222, 226, 227, 235, 236, 237, 246, 247, 258, 267, 268, 277, 278, 279].indexOf(skillId) > -1;
  171.     }
  172. };
  173.  
  174. var Misc = {
  175.     // Click something
  176.     click: function (button, shift, x, y) {
  177.         if (arguments.length < 2) {
  178.             throw new Error("Misc.click: Needs at least 2 arguments.");
  179.         }
  180.  
  181.         switch (arguments.length) {
  182.         case 2:
  183.             clickMap(button, shift, me.x, me.y);
  184.             delay(20);
  185.             clickMap(button + 2, shift, me.x, me.y);
  186.             break;
  187.         case 3:
  188.             if (typeof (x) !== "object") {
  189.                 throw new Error("Misc.click: Third arg must be a Unit.");
  190.             }
  191.  
  192.             clickMap(button, shift, x);
  193.             delay(20);
  194.             clickMap(button + 2, shift, x);
  195.             break;
  196.         case 4:
  197.             clickMap(button, shift, x, y);
  198.             delay(20);
  199.             clickMap(button + 2, shift, x, y);
  200.             break;
  201.         }
  202.  
  203.         return true;
  204.     },
  205.  
  206.     // Check if a player is in your party
  207.     inMyParty: function (name) {
  208.         var player, myPartyId;
  209.  
  210.         try {
  211.             player = getParty();
  212.  
  213.             if (!player) {
  214.                 return false;
  215.             }
  216.  
  217.             myPartyId = player.partyid;
  218.             player = getParty(name); // May throw an error
  219.  
  220.             if (player && player.partyid !== 65535 && player.partyid === myPartyId) {
  221.                 return true;
  222.             }
  223.         } catch (e) {
  224.             player = getParty();
  225.  
  226.             if (player) {
  227.                 myPartyId = player.partyid;
  228.  
  229.                 while (player.getNext()) {
  230.                     if (player.partyid !== 65535 && player.partyid === myPartyId) {
  231.                         return true;
  232.                     }
  233.                 }
  234.             }
  235.         }
  236.  
  237.         return false;
  238.     },
  239.  
  240.     // Open a chest Unit
  241.     openChest: function (unit) {
  242.         if (!unit || unit.mode || unit.x === 12526 || unit.x === 12565) { // Skip invalid, opened and Countess chests
  243.             return false;
  244.         }
  245.  
  246.         if (me.classid !== 6 && unit.islocked && !me.findItem("key", 0, 3)) { // locked chest, no keys
  247.             return false;
  248.         }
  249.  
  250.         var i, tick;
  251.  
  252.         for (i = 0; i < 3; i += 1) {
  253.             if (getDistance(me, unit) < 4 || Pather.moveToUnit(unit, 2, 0)) {
  254.                 unit.interact();
  255.             }
  256.  
  257.             tick = getTickCount();
  258.  
  259.             while (getTickCount() - tick < 1000) {
  260.                 if (unit.mode) {
  261.                     return true;
  262.                 }
  263.  
  264.                 delay(10);
  265.             }
  266.         }
  267.  
  268.         return false;
  269.     },
  270.  
  271.     // Open all chests that have preset units in an area
  272.     openChestsInArea: function (area) {
  273.         if (!area) {
  274.             area = me.area;
  275.         }
  276.  
  277.         var chest,
  278.             presetUnits = getPresetUnits(area),
  279.             chestIds = [5, 6, 87, 92, 104, 105, 106, 107, 143, 140, 141, 144, 146, 147, 148, 176, 177, 181, 183, 198, 240, 241, 242, 243, 329, 330, 331, 332, 333, 334, 335,
  280.                         336, 354, 355, 356, 371, 387, 389, 390, 391, 397, 405, 406, 407, 413, 420, 424, 425, 430, 431, 432, 433, 454, 455, 501, 502, 504, 505, 580, 581];
  281.  
  282.         if (!presetUnits) {
  283.             return false;
  284.         }
  285.  
  286.         while (presetUnits.length > 0) {
  287.             presetUnits.sort(Sort.presetUnits);
  288.  
  289.             if (chestIds.indexOf(presetUnits[0].id) > -1) {
  290.                 Pather.moveToUnit(presetUnits[0], 2, 0);
  291.  
  292.                 chest = getUnit(2);
  293.  
  294.                 if (chest) {
  295.                     do {
  296.                         if (chestIds.indexOf(chest.classid) > -1 && getDistance(me, chest) < 5 && this.openChest(chest)) {
  297.                             Pickit.pickItems();
  298.                         }
  299.                     } while (chest.getNext());
  300.                 }
  301.             }
  302.  
  303.             presetUnits.shift();
  304.         }
  305.  
  306.         return true;
  307.     },
  308.  
  309.     // Use a shrine Unit
  310.     getShrine: function (unit) {
  311.         var i, tick;
  312.  
  313.         for (i = 0; i < 3; i += 1) {
  314.             if (getDistance(me, unit) < 4 || Pather.moveToUnit(unit, 2, 0)) {
  315.                 unit.interact();
  316.             }
  317.  
  318.             tick = getTickCount();
  319.  
  320.             while (getTickCount() - tick < 1000) {
  321.                 if (unit.mode) {
  322.                     return true;
  323.                 }
  324.  
  325.                 delay(10);
  326.             }
  327.         }
  328.  
  329.         return false;
  330.     },
  331.  
  332.     // Check all shrines in area and get the first one of specified type
  333.     getShrinesInArea: function (area, type) {
  334.         var i, coords, shrine,
  335.             shrineLocs = [],
  336.             shrineIds = [2, 81, 83],
  337.             unit = getPresetUnits(area);
  338.  
  339.         if (unit) {
  340.             for (i = 0; i < unit.length; i += 1) {
  341.                 if (shrineIds.indexOf(unit[i].id) > -1) {
  342.                     shrineLocs.push([unit[i].roomx * 5 + unit[i].x, unit[i].roomy * 5 + unit[i].y]);
  343.                 }
  344.             }
  345.         }
  346.  
  347.         while (shrineLocs.length > 0) {
  348.             shrineLocs.sort(Sort.points);
  349.  
  350.             coords = shrineLocs.shift();
  351.  
  352.             Pather.moveTo(coords[0], coords[1], 2, false, true);
  353.  
  354.             shrine = getUnit(2, "shrine");
  355.  
  356.             if (shrine) {
  357.                 do {
  358.                     if (shrine.objtype === type) {
  359.                         this.getShrine(shrine);
  360.  
  361.                         return true;
  362.                     }
  363.                 } while (shrine.getNext());
  364.             }
  365.         }
  366.  
  367.         return false;
  368.     },
  369.  
  370.     // Log kept item stats in the manager.
  371.     logItem: function (action, unit, keptLine) {
  372.         var i, val, code, desc,
  373.             stringColor = "",
  374.             color = -1,
  375.             name = unit.fname.split("\n").reverse().join(" ").replace(/ÿc[0-9!"+<;.*]|^ /, "");
  376.  
  377.        desc = unit.description.split("\n");
  378.  
  379.        // Lines are normally in reverse. Add color tags if needed and reverse order.
  380.        for (i = 0; i < desc.length; i += 1) {
  381.            if (desc[i].match(/^ÿ/)) {
  382.                stringColor = desc[i].substring(0, 3);
  383.            } else {
  384.                desc[i] = stringColor + desc[i];
  385.            }
  386.        }
  387.  
  388.        desc = desc.reverse().join("\n");
  389.        color = unit.getColor();
  390.        desc += ("\nÿc0Item Level: " + unit.ilvl);
  391.  
  392.        if (action === "Kept") {
  393.            val = DataFile.getStats().lastArea;
  394.  
  395.            if (val) {
  396.                desc += ("\nÿc0Area: " + val);
  397.            }
  398.        }
  399.  
  400.        // experimental
  401.        /*switch (unit.quality) {
  402.        case 5:
  403.            // needs item by item handling :/
  404.            break;
  405.        case 7:
  406.            for (i = 0; i < 401; i += 1) {
  407.                if (unit.fname.split("\n").reverse()[0].indexOf(getLocaleString(getBaseStat(17, i, 2))) > -1) {
  408.                    code = getBaseStat(17, i, "invfile");
  409.  
  410.                    break;
  411.                }
  412.            }
  413.  
  414.            break;
  415.        }*/
  416.  
  417.        if (!code) {
  418.            code = getBaseStat(0, unit.classid, 'normcode') || unit.code;
  419.            code = code.replace(" ", "");
  420.  
  421.            if ([10, 12, 58, 82, 83, 84].indexOf(unit.itemType) > -1) {
  422.                code += (unit.gfx + 1);
  423.            }
  424.        }
  425.  
  426.        if (keptLine) {
  427.            desc += ("\nÿc0Line: " + keptLine);
  428.        }
  429.  
  430.        D2Bot.printToItemLog(action + " " + name, desc, code, unit.quality, color);
  431.    },
  432.  
  433.    // Change into werewolf or werebear
  434.    shapeShift: function (mode) { // 0 = werewolf, 1 = werebear
  435.        if (arguments.length === 0 || mode < 0 || mode > 2) {
  436.            throw new Error("Misc.shapeShift: Invalid parameter");
  437.        }
  438.  
  439.        var i, tick,
  440.            state = mode === 0 ? 139 : 140,
  441.            skill = mode === 0 ? 223 : 228;
  442.  
  443.        for (i = 0; i < 3; i += 1) {
  444.            Skill.cast(skill, 0);
  445.  
  446.            tick = getTickCount();
  447.  
  448.            while (getTickCount() - tick < 2000) {
  449.                if (me.getState(state)) {
  450.                    return true;
  451.                }
  452.  
  453.                delay(10);
  454.            }
  455.        }
  456.  
  457.        return false;
  458.    },
  459.  
  460.    // Change back to human shape
  461.    unShift: function () {
  462.        var i, tick;
  463.  
  464.        if (me.getState(139) || me.getState(140)) {
  465.            for (i = 0; i < 3; i += 1) {
  466.                Skill.cast(me.getState(139) ? 223 : 228);
  467.  
  468.                tick = getTickCount();
  469.  
  470.                while (getTickCount() - tick < 2000) {
  471.                    if (!me.getState(139) && !me.getState(140)) {
  472.                        return true;
  473.                    }
  474.  
  475.                    delay(10);
  476.                }
  477.            }
  478.        } else {
  479.            return true;
  480.        }
  481.  
  482.        return false;
  483.    },
  484.  
  485.    // Teleport with slot II
  486.    teleSwitch: function () {
  487.        this.oldSwitch = me.weaponswitch;
  488.  
  489.        Precast.weaponSwitch();
  490.  
  491.        return true;
  492.    },
  493.  
  494.    // Go to town when low on hp/mp or when out of potions. can be upgraded to check for curses etc.
  495.    townCheck: function () {
  496.        var potion, check,
  497.            needhp = true,
  498.            needmp = true;
  499.  
  500.        if (Config.TownCheck && !me.inTown) {
  501.            if (Config.BeltColumn.indexOf("hp") > -1) {
  502.                potion = me.getItem(-1, 2); // belt item
  503.  
  504.                if (potion) {
  505.                    do {
  506.                        if (potion.code.indexOf("hp") > -1) {
  507.                            needhp = false;
  508.  
  509.                            break;
  510.                        }
  511.                    } while (potion.getNext());
  512.                }
  513.  
  514.                if (needhp) {
  515.                    print("We need healing potions");
  516.  
  517.                    check = true;
  518.                }
  519.            }
  520.  
  521.            if (Config.BeltColumn.indexOf("mp") > -1) {
  522.                potion = me.getItem(-1, 2); // belt item
  523.  
  524.                if (potion) {
  525.                    do {
  526.                        if (potion.code.indexOf("mp") > -1) {
  527.                            needmp = false;
  528.  
  529.                            break;
  530.                        }
  531.                    } while (potion.getNext());
  532.                }
  533.  
  534.                if (needmp) {
  535.                    print("We need mana potions");
  536.  
  537.                    check = true;
  538.                }
  539.            }
  540.  
  541.            if (Config.OpenChests && Town.needKeys()) {
  542.                check = true;
  543.            }
  544.        }
  545.  
  546.        if (check) {
  547.            scriptBroadcast("townCheck");
  548.        }
  549.  
  550.        return true;
  551.    },
  552.  
  553.    // Log someone's gear
  554.    spy: function (name) {
  555.        if (!isIncluded("oog.js")) {
  556.            include("oog.js");
  557.        }
  558.  
  559.        if (!isIncluded("common/prototypes.js")) {
  560.            include("common/prototypes.js");
  561.        }
  562.  
  563.        var i, items,
  564.            unit = getUnit(0, name);
  565.  
  566.        if (!unit) {
  567.            print("player not found");
  568.  
  569.            return false;
  570.        }
  571.  
  572.        items = unit.getItems();
  573.  
  574.        for (i = 0; i < items.length; i += 1) {
  575.            this.logItem(name, items[i]);
  576.        }
  577.  
  578.        return true;
  579.    },
  580.  
  581.    // hopefully multi-thread and multi-profile friendly txt func
  582.    fileAction: function (path, mode, msg) {
  583.        var i, file,
  584.            contents = "";
  585.  
  586. MainLoop:
  587.        for (i = 0; i < 30; i += 1) {
  588.            try {
  589.                file = File.open(path, mode);
  590.  
  591.                switch (mode) {
  592.                case 0: // read
  593.                    contents = file.readLine();
  594.  
  595.                    break MainLoop;
  596.                case 1: // write
  597.                case 2: // append
  598.                    file.write(msg);
  599.  
  600.                    break MainLoop;
  601.                }
  602.            } catch (e) {
  603.  
  604.            } finally {
  605.                file.close();
  606.            }
  607.  
  608.            delay(100);
  609.        }
  610.  
  611.        return mode === 0 ? contents : true;
  612.    },
  613.  
  614.    // Report script errors to logs/ScriptErrorLog.txt
  615.    errorReport: function (msg) {
  616.        var h, m, s, date;
  617.  
  618.        date = new Date();
  619.        h = date.getHours();
  620.        m = date.getMinutes();
  621.        s = date.getSeconds();
  622.  
  623.        showConsole();
  624.        print(msg);
  625.        this.fileAction("logs/ScriptErrorLog.txt", 2, "[" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + "] <" + me.profile + "> " + msg.replace(/ÿc[0-9!"+<;.*]/gi, "") + "\n");
  626.     }
  627. };
  628.  
  629. var Sort = {
  630.     // Sort units by comparing distance between the player
  631.     units: function (a, b) {
  632.         return getDistance(me, a) - getDistance(me, b);
  633.     },
  634.  
  635.     // Sort preset units by comparing distance between the player (using preset x/y calculations)
  636.     presetUnits: function (a, b) {
  637.         return getDistance(me, a.roomx * 5 + a.x, a.roomy * 5 + a.y) - getDistance(me, b.roomx * 5 + b.x, b.roomy * 5 + b.y);
  638.     },
  639.  
  640.     // Sort arrays of x,y coords by comparing distance between the player
  641.     points: function (a, b) {
  642.         return getDistance(me, a[0], a[1]) - getDistance(me, b[0], b[1]);
  643.     }
  644. };
  645.  
  646. var Experience = {
  647.     totalExp: [0, 0, 500, 1500, 3750, 7875, 14175, 22680, 32886, 44396, 57715, 72144, 90180, 112725, 140906, 176132, 220165, 275207, 344008, 430010, 537513, 671891, 839864, 1049830, 1312287, 1640359, 2050449, 2563061, 3203826, 3902260, 4663553, 5493363, 6397855, 7383752, 8458379, 9629723, 10906488, 12298162, 13815086, 15468534, 17270791, 19235252, 21376515, 23710491, 26254525, 29027522, 32050088, 35344686, 38935798, 42850109, 47116709, 51767302, 56836449, 62361819, 68384473, 74949165, 82104680, 89904191, 98405658, 107672256, 117772849, 128782495, 140783010, 153863570, 168121381, 183662396, 200602101, 219066380, 239192444, 261129853, 285041630, 311105466, 339515048, 370481492, 404234916, 441026148, 481128591, 524840254, 572485967, 624419793, 681027665, 742730244, 809986056, 883294891, 963201521, 1050299747, 1145236814, 1248718217, 1361512946, 1484459201, 1618470619, 1764543065, 1923762030, 2097310703, 2286478756, 2492671933, 2717422497, 2962400612, 3229426756, 3520485254, 0, 0],
  648.     nextExp: [0, 500, 1000, 2250, 4125, 6300, 8505, 10206, 11510, 13319, 14429, 18036, 22545, 28181, 35226, 44033, 55042, 68801, 86002, 107503, 134378, 167973, 209966, 262457, 328072, 410090, 512612, 640765, 698434, 761293, 829810, 904492, 985897, 1074627, 1171344, 1276765, 1391674, 1516924, 1653448, 1802257, 1964461, 2141263, 2333976, 2544034, 2772997, 3022566, 3294598, 3591112, 3914311, 4266600, 4650593, 5069147, 5525370, 6022654, 6564692, 7155515, 7799511, 8501467, 9266598, 10100593, 11009646, 12000515, 13080560, 14257811, 15541015, 16939705, 18464279, 20126064, 21937409, 23911777, 26063836, 28409582, 30966444, 33753424, 36791232, 40102443, 43711663, 47645713, 51933826, 56607872, 61702579, 67255812, 73308835, 79906630, 87098226, 94937067, 103481403, 112794729, 122946255, 134011418, 146072446, 159218965, 173548673, 189168053, 206193177, 224750564, 244978115, 267026144, 291058498, 0, 0],
  649.  
  650.     // Percent progress into the current level. Format: xx.xx%
  651.     progress: function () {
  652.         return me.getStat(12) === 99 ? 0 : (((me.getStat(13) - this.totalExp[me.getStat(12)]) / this.nextExp[me.getStat(12)]) * 100).toFixed(2);
  653.     },
  654.  
  655.     // Total experience gained in current run
  656.     gain: function () {
  657.         return (me.getStat(13) - DataFile.getStats().experience);
  658.     },
  659.  
  660.     // Percent experience gained in current run
  661.     gainPercent: function () {
  662.         return me.getStat(12) === 99 ? 0 : (this.gain() * 100 / this.nextExp[me.getStat(12)]).toFixed(6);
  663.     },
  664.  
  665.     // Runs until next level
  666.     runsToLevel: function () {
  667.         return Math.round(((100 - this.progress()) / 100) * this.nextExp[me.getStat(12)] / this.gain());
  668.     },
  669.  
  670.     // Total runs needed for next level (not counting current progress)
  671.     totalRunsToLevel: function () {
  672.         return Math.round(this.nextExp[me.getStat(12)] / this.gain());
  673.     },
  674.  
  675.     //Time left till next level
  676.     hoursLeft: function () {
  677.         return (((this.runsToLevel() * secondsTimer(gameSeconds)) / 3600).toFixed(2));
  678.     },
  679.  
  680.     //Time left till next level.
  681.     timeToLevel: function () {
  682.     var totalTime = this.runsToLevel() * secondsTimer(gameSeconds);
  683.     var tDays = Math.floor(totalTime / 86400),
  684.         tHours = Math.floor((totalTime % 86400) / 3600),
  685.         tMinutes = Math.floor(((totalTime % 86400) % 3600) / 60),
  686.         tSeconds = ((totalTime % 86400) % 3600) % 60;
  687.  
  688.     //return tDays + "d " + tHours + "h " + tMinutes + "m " + tSeconds + "s";
  689.     //return tDays + "d " + tHours + "h " + tMinutes + "m";
  690.     return tDays + " days " + tHours + " hours " + tMinutes + " minutes";
  691.     },
  692.  
  693.     // Log to manager
  694.     log: function () {
  695.         var string,
  696.             gain = this.gain(),
  697.             progress = this.progress(),
  698.             runsToLevel = this.runsToLevel(),
  699.             totalRunsToLevel = this.totalRunsToLevel(),
  700.             hoursLeft = this.hoursLeft(),
  701.             timeToLevel = this.timeToLevel();
  702.  
  703.         //string = "Game: " + me.gamename + ", XP Gain: " + gain + ", Level: " + me.getStat(12) + " (" + progress + "%), Next: " + runsToLevel + "/" + totalRunsToLevel;
  704.         //string = "[Game: " + me.gamename + "//" + me.gamepassword + "] [Game Time: " + gameTimer(gameTime) + "] [Level: " + me.getStat(12) + " (" + progress + "%)] [XP Gained: " + gain + "] [Games to Level eta: " + runsToLevel + "] [Time to Level eta: " + hoursLeft + "]";
  705.         string = "[Game: " + me.gamename + "//" + me.gamepassword + "] [Game Time: " + gameTimer(gameTime) + "] [Level: " + me.getStat(12) + " (" + progress + "%)] [XP Gained: " + gain + "] [Games to Level eta: " + runsToLevel + "] [Time to Level eta: " + timeToLevel + "]";
  706.  
  707.         if (gain) {
  708.             D2Bot.printToConsole(string + ";4");
  709.  
  710.             if (me.getStat(12) > DataFile.getStats().level) {
  711.                 D2Bot.printToConsole("Congrats! You gained a level. Current level:" + me.getStat(12) + ";5");
  712.             }
  713.         }
  714.     }
  715. };
  716.  
  717. var Packet = {
  718.     buyItem: function (item, shiftBuy) {
  719.         var i, tick, container,
  720.             itemCount = me.itemcount,
  721.             npc = getInteractedNPC();
  722.  
  723.         if (!npc) {
  724.             throw new Error("buyItem: No NPC menu open.");
  725.         }
  726.  
  727.         if (me.getStat(14) + me.getStat(15) < item.getItemCost(0)) { // Can we afford the item?
  728.             return false;
  729.         }
  730.  
  731.         for (i = 0; i < 3; i += 1) {
  732.             sendPacket(1, 0x32, 4, npc.gid, 4, item.gid, 4, shiftBuy ? 0x80000000 : 0, 4, 0);
  733.  
  734.             tick = getTickCount();
  735.  
  736.             while (getTickCount() - tick < 2000) {
  737.                 if (shiftBuy) {
  738.                     switch (item.classid) {
  739.                     case 529: // tp scroll
  740.                         container = me.getItem(518);
  741.  
  742.                         if (container && container.getStat(70) === 20) {
  743.                             return true;
  744.                         }
  745.  
  746.                         break;
  747.                     case 530: // id scroll
  748.                         container = me.getItem(519);
  749.  
  750.                         if (container && container.getStat(70) === 20) {
  751.                             return true;
  752.                         }
  753.  
  754.                         break;
  755.                     case 543: // key
  756.                         container = me.getItem(543);
  757.  
  758.                         if (container && container.getStat(70) === 12) {
  759.                             return true;
  760.                         }
  761.  
  762.                         break;
  763.                     }
  764.                 }
  765.  
  766.                 if (itemCount !== me.itemcount) {
  767.                     return true;
  768.                 }
  769.  
  770.                 delay(10);
  771.             }
  772.         }
  773.  
  774.         return false;
  775.     },
  776.     castSkill: function (hand, wX, wY) {
  777.         hand = (hand === 0) ? 0x0c : 0x05;
  778.         sendPacket(1, hand, 2, wX, 2, wY);
  779.     },
  780.     unitCast: function (hand, who) {
  781.         hand = (hand === 0) ? 0x11 : 0x0a;
  782.         sendPacket(1, hand, 4, who.type, 4, who.gid);
  783.     },
  784.     moveNPC: function (npc, dwX, dwY) {
  785.         sendPacket(1, 0x59, 4, npc.type, 4, npc.gid, 4, dwX, 4, dwY);
  786.     },
  787.     teleWalk: function (wX, wY) {
  788.         sendPacket(1, 0x5f, 2, wX, 2, wY);
  789.         delay(me.ping + 5);
  790.         sendPacket(1, 0x4b, 4, me.type, 4, me.gid);
  791.     },
  792.     flash: function (gid) {
  793.         sendPacket(1, 0x4b, 4, 0, 4, gid);
  794.     },
  795.     changeStat: function (stat, value) {
  796.         if (value > 0) {
  797.             getPacket(1, 0x1d, 1, stat, 1, value);
  798.         }
  799.     }
  800. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement