Skip to content

Commit

Permalink
Fix item pick fail (#1302)
Browse files Browse the repository at this point in the history
Misc.js, Pather.js, Pickit.js
-Fix occasional item pick fail caused after town visit because useTeleport variable wasn't re-evaluated
  • Loading branch information
imbalanced authored and noah- committed Mar 3, 2019
1 parent b0c20ba commit d824eca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions d2bs/kolbot/libs/common/Misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -1015,7 +1015,7 @@ var Misc = {
}

if (!range) {
range = Pather.useTeleport ? 25 : 15;
range = Pather.useTeleport() ? 25 : 15;
}

var i, j, shrine,
Expand Down Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions d2bs/kolbot/libs/common/Pather.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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.");
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -286,7 +289,7 @@ var Pather = {
delay(5);
}

if (this.useTeleport && Config.TeleSwitch) {
if (useTeleport && Config.TeleSwitch) {
Attack.weaponSwitch(Attack.getPrimarySlot());
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
},

/*
Expand Down
4 changes: 2 additions & 2 deletions d2bs/kolbot/libs/common/Pickit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d824eca

Please sign in to comment.