diff --git a/d2bs/kolbot/default.dbj b/d2bs/kolbot/default.dbj index 38607018b..99f6bc937 100644 --- a/d2bs/kolbot/default.dbj +++ b/d2bs/kolbot/default.dbj @@ -92,7 +92,11 @@ function main() { } if (mode === 1638) { // getProfile - GameAction.init(JSON.parse(msg).Tag); + msg = JSON.parse(msg); + + if (msg.Tag) { + GameAction.init(msg.Tag); + } } }; diff --git a/d2bs/kolbot/libs/common/Attacks/Amazon.js b/d2bs/kolbot/libs/common/Attacks/Amazon.js index 5717d76c1..113c2b37c 100644 --- a/d2bs/kolbot/libs/common/Attacks/Amazon.js +++ b/d2bs/kolbot/libs/common/Attacks/Amazon.js @@ -9,8 +9,10 @@ var ClassAttack = { lightFuryTick: 0, doAttack: function (unit, preattack) { - if (Config.MercWatch && Town.needMerc()) { - Town.visitTown(); + var needRepair = Town.needRepair(); + + if ((Config.MercWatch && Town.needMerc()) || needRepair.length > 0) { + Town.visitTown(!!needRepair.length); } if (preattack && Config.AttackSkill[0] > 0 && Attack.checkResist(unit, Config.AttackSkill[0]) && (!me.getState(121) || !Skill.isTimed(Config.AttackSkill[0]))) { @@ -102,7 +104,7 @@ var ClassAttack = { needRepair = Town.needRepair(); if (needRepair && needRepair.length > 0) { // Repair check, mainly to restock arrows - Town.visitTown(); + Town.visitTown(true); } this.lightFuryTick = 0; diff --git a/d2bs/kolbot/libs/common/Attacks/Barbarian.js b/d2bs/kolbot/libs/common/Attacks/Barbarian.js index 5fa908b99..4c338a4a6 100644 --- a/d2bs/kolbot/libs/common/Attacks/Barbarian.js +++ b/d2bs/kolbot/libs/common/Attacks/Barbarian.js @@ -6,8 +6,10 @@ var ClassAttack = { doAttack: function (unit, preattack) { - if (Config.MercWatch && Town.needMerc()) { - Town.visitTown(); + var needRepair = Town.needRepair(); + + if ((Config.MercWatch && Town.needMerc()) || needRepair.length > 0) { + Town.visitTown(!!needRepair.length); } if (preattack && Config.AttackSkill[0] > 0 && Attack.checkResist(unit, Attack.getSkillElement(Config.AttackSkill[0])) && (!me.getState(121) || !Skill.isTimed(Config.AttackSkill[0]))) { @@ -59,7 +61,7 @@ var ClassAttack = { needRepair = Town.needRepair(); if (needRepair && needRepair.length > 0) { // Repair check - Town.visitTown(); + Town.visitTown(true); } if (pickit) { diff --git a/d2bs/kolbot/libs/common/Misc.js b/d2bs/kolbot/libs/common/Misc.js index 38e331f0e..b96ea162d 100644 --- a/d2bs/kolbot/libs/common/Misc.js +++ b/d2bs/kolbot/libs/common/Misc.js @@ -1290,10 +1290,7 @@ var Misc = { var desc, date = new Date(), - h = date.getHours(), - m = date.getMinutes(), - s = date.getSeconds(), - dateString = "[" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + "]"; + dateString = "[" + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0,-5).replace(/-/g, '/').replace('T', ' ') + "]"; switch (action) { case "Sold": @@ -1847,23 +1844,21 @@ MainLoop: // Report script errors to logs/ScriptErrorLog.txt errorReport: function (error, script) { - var i, h, m, s, date, msg, oogmsg, filemsg, source, stack, + var i, date, dateString, msg, oogmsg, filemsg, source, stack, stackLog = ""; date = new Date(); - h = date.getHours(); - m = date.getMinutes(); - s = date.getSeconds(); + dateString = "[" + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0,-5).replace(/-/g, '/').replace('T', ' ') + "]"; if (typeof error === "string") { msg = error; oogmsg = error.replace(/ÿc[0-9!"+<:;.*]/gi, ""); - filemsg = "[" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + "] <" + me.profile + "> " + error.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n"; + filemsg = dateString + " <" + me.profile + "> " + error.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n"; } else { source = error.fileName.substring(error.fileName.lastIndexOf("\\") + 1, error.fileName.length); msg = "ÿc1Error in ÿc0" + script + " ÿc1(" + source + " line ÿc1" + error.lineNumber + "): ÿc1" + error.message; oogmsg = " Error in " + script + " (" + source + " #" + error.lineNumber + ") " + error.message + " (Area: " + me.area + ", Ping:" + me.ping + ", Game: " + me.gamename + ")"; - filemsg = "[" + (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + "] <" + me.profile + "> " + msg.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n"; + filemsg = dateString + " <" + me.profile + "> " + msg.replace(/ÿc[0-9!"+<:;.*]/gi, "") + "\n"; if (error.hasOwnProperty("stack")) { stack = error.stack; diff --git a/d2bs/kolbot/libs/common/Town.js b/d2bs/kolbot/libs/common/Town.js index 424d615aa..dccb489c4 100644 --- a/d2bs/kolbot/libs/common/Town.js +++ b/d2bs/kolbot/libs/common/Town.js @@ -66,7 +66,7 @@ var Town = { ], // Do town chores - doChores: function () { + doChores: function (repair = false) { if (!me.inTown) { this.goToTown(); } @@ -89,7 +89,7 @@ var Town = { this.clearInventory(); Item.autoEquip(); this.buyKeys(); - this.repair(); + this.repair(repair); this.gamble(); this.reviveMerc(); Cubing.doCubing(); @@ -1255,13 +1255,17 @@ CursorLoop: return false; }, - repair: function () { + repair: function (force = false) { var i, quiver, myQuiver, npc, repairAction, bowCheck; this.cubeRepair(); repairAction = this.needRepair(); + if (force && repairAction.indexOf("repair") === -1) { + repairAction.push("repair"); + } + if (!repairAction || !repairAction.length) { return true; } @@ -1367,28 +1371,30 @@ CursorLoop: if (item) { do { if (!item.getFlag(0x400000)) { // Skip ethereal items - switch (item.itemType) { - // Quantity check - case 42: // Throwing knives - case 43: // Throwing axes - case 44: // Javelins - case 87: // Amazon javelins - quantity = item.getStat(70); - - if (typeof quantity === "number" && quantity * 100 / (getBaseStat("items", item.classid, "maxstack") + item.getStat(254)) <= repairPercent) { // Stat 254 = increased stack size - itemList.push(copyUnit(item)); - } + if (!item.getStat(152)) { // Skip indestructible items + switch (item.itemType) { + // Quantity check + case 42: // Throwing knives + case 43: // Throwing axes + case 44: // Javelins + case 87: // Amazon javelins + quantity = item.getStat(70); + + if (typeof quantity === "number" && quantity * 100 / (getBaseStat("items", item.classid, "maxstack") + item.getStat(254)) <= repairPercent) { // Stat 254 = increased stack size + itemList.push(copyUnit(item)); + } - break; - // Durability check - default: - durability = item.getStat(72); + break; + // Durability check + default: + durability = item.getStat(72); - if (typeof durability === "number" && durability * 100 / item.getStat(73) <= repairPercent) { - itemList.push(copyUnit(item)); - } + if (typeof durability === "number" && durability * 100 / item.getStat(73) <= repairPercent) { + itemList.push(copyUnit(item)); + } - break; + break; + } } if (chargedItems) { @@ -2168,7 +2174,7 @@ MainLoop: return true; }, - visitTown: function () { + visitTown: function (repair = false) { if (me.inTown) { this.doChores(); this.move("stash"); @@ -2185,7 +2191,7 @@ MainLoop: return false; } - this.doChores(); + this.doChores(repair); if (me.act !== preAct) { this.goToTown(preAct); diff --git a/d2bs/kolbot/tools/AntiHostile.js b/d2bs/kolbot/tools/AntiHostile.js index a560e5b08..2fe5ebb4a 100644 --- a/d2bs/kolbot/tools/AntiHostile.js +++ b/d2bs/kolbot/tools/AntiHostile.js @@ -27,7 +27,7 @@ include("common/Town.js"); function main() { // Variables and functions - var player, attackCount, prevPos, check, missile, + var player, attackCount, prevPos, check, missile, outside, charClass = ["Amazon", "Sorceress", "Necromancer", "Paladin", "Barbarian", "Druid", "Assassin"], hostiles = []; @@ -194,20 +194,37 @@ function main() { if (hostiles.length > 0 && (Config.HostileAction === 0 || (Config.HostileAction === 1 && me.inTown))) { if (Config.TownOnHostile) { + print("ÿc1Hostility detected, going to town."); this.pause(); - Town.goToTown(); + + if (!me.inTown) { + outside = true; + } + + try { + Town.goToTown(); + } catch (e) { + print(e + " Failed to go to town. Quitting."); + scriptBroadcast("quit"); // quit if failed to go to town + } while (hostiles.length > 0) { delay(500); } - Pather.usePortal(null, me.name); + if (outside) { + outside = false; + Pather.usePortal(null, me.name); + } + this.resume(); } else { scriptBroadcast("quit"); } - return; + delay(500); + + continue; } // Mode 3 - Spam entrance (still experimental) @@ -289,20 +306,37 @@ function main() { // Mode 1 - Quit if hostile player is nearby if (Config.HostileAction === 1) { if (Config.TownOnHostile) { + print("ÿc1Hostile player nearby, going to town."); this.pause(); - Town.goToTown(); + + if (!me.inTown) { + outside = true; + } + + try { + Town.goToTown(); + } catch (e) { + print(e + " Failed to go to town. Quitting."); + scriptBroadcast("quit"); // quit if failed to go to town + } while (hostiles.length > 0) { delay(500); } - Pather.usePortal(null, me.name); + if (outside) { + outside = false; + Pather.usePortal(null, me.name); + } + this.resume(); } else { scriptBroadcast("quit"); } - return; + delay(500); + + continue; } // Kill the hostile player