diff --git a/d2bs/kolbot/libs/common/Misc.js b/d2bs/kolbot/libs/common/Misc.js index 826d104d4..1417f9fed 100644 --- a/d2bs/kolbot/libs/common/Misc.js +++ b/d2bs/kolbot/libs/common/Misc.js @@ -999,7 +999,7 @@ var Misc = { unit = unitList.shift(); - if (unit && (Pather.useTeleport || !checkCollision(me, unit, 0x4)) && this.openChest(unit)) { + if (unit && (Pather.useTeleport() || !checkCollision(me, unit, 0x4)) && this.openChest(unit)) { Pickit.pickItems(); } } @@ -1015,7 +1015,7 @@ var Misc = { } if (!range) { - range = Pather.useTeleport ? 25 : 15; + range = Pather.useTeleport() ? 25 : 15; } var i, j, shrine, @@ -1086,7 +1086,7 @@ var Misc = { // Get the shrine if we have no active state or to refresh current state or if the shrine has no state // Don't override shrine state with a lesser priority shrine if (index === -1 || i <= index || this.shrineStates[i] === 0) { - if (shrineList[j].objtype === Config.ScanShrines[i] && (Pather.useTeleport || !checkCollision(me, shrineList[j], 0x4))) { + if (shrineList[j].objtype === Config.ScanShrines[i] && (Pather.useTeleport() || !checkCollision(me, shrineList[j], 0x4))) { this.getShrine(shrineList[j]); // Gem shrine - pick gem diff --git a/d2bs/kolbot/libs/common/Pather.js b/d2bs/kolbot/libs/common/Pather.js index cb6ec0d52..3e5647415 100644 --- a/d2bs/kolbot/libs/common/Pather.js +++ b/d2bs/kolbot/libs/common/Pather.js @@ -117,6 +117,10 @@ var Pather = { wpAreas: [1, 3, 4, 5, 6, 27, 29, 32, 35, 40, 48, 42, 57, 43, 44, 52, 74, 46, 75, 76, 77, 78, 79, 80, 81, 83, 101, 103, 106, 107, 109, 111, 112, 113, 115, 123, 117, 118, 129], recursion: true, + useTeleport: function () { + return this.teleport && !me.getState(139) && !me.getState(140) && !me.inTown && ((me.classid === 1 && me.getSkill(54, 1)) || me.getStat(97, 54)); + }, + /* Pather.moveTo(x, y, retry, clearPath, pop); x - the x coord to move to @@ -130,7 +134,7 @@ var Pather = { return false; } - var i, path, adjustedNode, cleared, + var i, path, adjustedNode, cleared, useTeleport, node = {x: x, y: y}, fail = 0; @@ -164,24 +168,23 @@ var Pather = { pop = false; } - this.useTeleport = this.teleport && !me.getState(139) && !me.getState(140) && !me.inTown && - ((me.classid === 1 && me.getSkill(54, 1)) || me.getStat(97, 54)); + useTeleport = this.useTeleport(); /* Disabling getPath optimizations, they are causing desync -- noah // Teleport without calling getPath if the spot is close enough - if (this.useTeleport && getDistance(me, x, y) <= this.teleDistance) { + if (useTeleport && getDistance(me, x, y) <= this.teleDistance) { //Misc.townCheck(); return this.teleportTo(x, y); } // Walk without calling getPath if the spot is close enough - if (!this.useTeleport && (getDistance(me, x, y) <= 5 || (getDistance(me, x, y) <= 25 && !CollMap.checkColl(me, {x: x, y: y}, 0x1)))) { + if (!useTeleport && (getDistance(me, x, y) <= 5 || (getDistance(me, x, y) <= 25 && !CollMap.checkColl(me, {x: x, y: y}, 0x1)))) { return this.walkTo(x, y); } */ - path = getPath(me.area, x, y, me.x, me.y, this.useTeleport ? 1 : 0, this.useTeleport ? ([62, 63, 64].indexOf(me.area) > -1 ? 30 : this.teleDistance) : this.walkDistance); + path = getPath(me.area, x, y, me.x, me.y, useTeleport ? 1 : 0, useTeleport ? ([62, 63, 64].indexOf(me.area) > -1 ? 30 : this.teleDistance) : this.walkDistance); if (!path) { throw new Error("moveTo: Failed to generate path."); @@ -195,7 +198,7 @@ var Pather = { PathDebug.drawPath(path); - if (this.useTeleport && Config.TeleSwitch && path.length > 5) { + if (useTeleport && Config.TeleSwitch && path.length > 5) { Attack.weaponSwitch(Attack.getPrimarySlot() ^ 1); } @@ -226,7 +229,7 @@ var Pather = { } } - if (this.useTeleport ? this.teleportTo(node.x, node.y) : this.walkTo(node.x, node.y, (fail > 0 || me.inTown) ? 2 : 4)) { + if (useTeleport ? this.teleportTo(node.x, node.y) : this.walkTo(node.x, node.y, (fail > 0 || me.inTown) ? 2 : 4)) { if (!me.inTown) { if (this.recursion) { this.recursion = false; @@ -243,7 +246,7 @@ var Pather = { Misc.townCheck(); } } else { - if (fail > 0 && !this.useTeleport && !me.inTown) { + if (fail > 0 && !useTeleport && !me.inTown) { // Don't go berserk on longer paths if (!cleared) { Attack.clear(5); @@ -257,7 +260,7 @@ var Pather = { } // Reduce node distance in new path - path = getPath(me.area, x, y, me.x, me.y, this.useTeleport ? 1 : 0, this.useTeleport ? rand(25, 35) : rand(10, 15)); + path = getPath(me.area, x, y, me.x, me.y, useTeleport ? 1 : 0, useTeleport ? rand(25, 35) : rand(10, 15)); fail += 1; if (!path) { @@ -286,7 +289,7 @@ var Pather = { delay(5); } - if (this.useTeleport && Config.TeleSwitch) { + if (useTeleport && Config.TeleSwitch) { Attack.weaponSwitch(Attack.getPrimarySlot()); } @@ -496,8 +499,7 @@ ModeLoop: pop - remove last node */ moveToUnit: function (unit, offX, offY, clearPath, pop) { - this.useTeleport = this.teleport && !me.getState(139) && !me.getState(140) && !me.inTown && - ((me.classid === 1 && me.getSkill(54, 1)) || me.getStat(97, 54)); + var useTeleport = this.useTeleport(); if (offX === undefined) { offX = 0; @@ -523,12 +525,12 @@ ModeLoop: return this.moveTo(unit.roomx * 5 + unit.x + offX, unit.roomy * 5 + unit.y + offY, 3, clearPath); } - if (!this.useTeleport) { + if (!useTeleport) { // The unit will most likely be moving so call the first walk with 'pop' parameter this.moveTo(unit.x + offX, unit.y + offY, 0, clearPath, true); } - return this.moveTo(unit.x + offX, unit.y + offY, this.useTeleport && unit.type && unit.type === 1 ? 3 : 0, clearPath, pop); + return this.moveTo(unit.x + offX, unit.y + offY, useTeleport && unit.type && unit.type === 1 ? 3 : 0, clearPath, pop); }, /* diff --git a/d2bs/kolbot/libs/common/Pickit.js b/d2bs/kolbot/libs/common/Pickit.js index acf2b148f..830cdb325 100644 --- a/d2bs/kolbot/libs/common/Pickit.js +++ b/d2bs/kolbot/libs/common/Pickit.js @@ -115,7 +115,7 @@ var Pickit = { // Check if the item unit is still valid and if it's on ground or being dropped if (copyUnit(pickList[0]).x !== undefined && (pickList[0].mode === 3 || pickList[0].mode === 5) && - (Pather.useTeleport || me.inTown || !checkCollision(me, pickList[0], 0x1))) { // Don't pick items behind walls/obstacles when walking + (Pather.useTeleport() || me.inTown || !checkCollision(me, pickList[0], 0x1))) { // Don't pick items behind walls/obstacles when walking // Check if the item should be picked status = this.checkItem(pickList[0]); @@ -267,7 +267,7 @@ MainLoop: Skill.cast(43, 0, item); } else { if (getDistance(me, item) > (Config.FastPick === 2 && i < 1 ? 6 : 4) || checkCollision(me, item, 0x1)) { - if (Pather.useTeleport) { + if (Pather.useTeleport()) { Pather.moveToUnit(item); } else if (!Pather.moveTo(item.x, item.y, 0)) { continue MainLoop;