Skip to content

Commit

Permalink
Fix issue with unintentional area change
Browse files Browse the repository at this point in the history
Set previous only when result is set. Now checks area id only when result is false for better performance.
  • Loading branch information
semajtrip authored and noah- committed Jan 18, 2019
1 parent 6e9890e commit 9bb9968
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions d2bs/kolbot/libs/common/Attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ var Attack = {
say("clearlevel " + getArea().name);
}

var room, result, rooms, myRoom;
var room, result, rooms, myRoom, currentArea, previousArea;

function RoomSort(a, b) {
return getDistance(myRoom[0], myRoom[1], a[0], a[1]) - getDistance(myRoom[0], myRoom[1], b[0], b[1]);
Expand All @@ -756,6 +756,8 @@ var Attack = {

rooms = [];

currentArea = getArea().id;

do {
rooms.push([room.x * 5 + room.xsize / 2, room.y * 5 + room.ysize / 2]);
} while (room.getNext());
Expand All @@ -775,18 +777,23 @@ var Attack = {
}

rooms.sort(RoomSort);
room = rooms.shift();
room = rooms.shift();

result = Pather.getNearestWalkable(room[0], room[1], 18, 3);

if (result) {
Pather.moveTo(result[0], result[1], 3, spectype);
previousArea = result;
//this.countUniques();

if (!this.clear(40, spectype)) {
break;
}
}
// Make sure bot does not get stuck in different area.
else if (currentArea !== getArea().id) {
Pather.moveTo(previousArea[0], previousArea[1], 3, spectype);
}
}

//this.storeStatistics(Pather.getAreaName(me.area));
Expand Down Expand Up @@ -1490,4 +1497,4 @@ AuraLoop: // Skip monsters with auras

return false;
}
};
};

0 comments on commit 9bb9968

Please sign in to comment.