Skip to content

Commit

Permalink
Fixes and improvements (#1158)
Browse files Browse the repository at this point in the history
Attack.js
-Add retry for doAttack fails

D2BotMule.dbj
-Add min game time to stay in game before getting next character
-Wait for area initialization instead of arbitrary delay
-Pick and stash large items first to maximize space use
-Add Gheed's charm handling

OOG.js
-Skip checks if no further characters are found when checking for more characters
-Add default arg for loginCharacter to start from top of the char list
  • Loading branch information
imbalanced authored and noah- committed Jan 30, 2019
1 parent ee24ca5 commit 408fdff
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 18 deletions.
44 changes: 39 additions & 5 deletions d2bs/kolbot/D2BotMule.dbj
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var StarterConfig = {
MinGameTime: 30, // Minimum game length in seconds.

SwitchKeyDelay: 0, // Seconds to wait before switching a used/banned key or after realm down
RealmDownDelay: 3, // Minutes to wait after getting Realm Down message
UnableToConnectDelay: 5, // Minutes to wait after Unable To Connect message
Expand Down Expand Up @@ -60,12 +62,13 @@ var MuleData = {
// stash picked items
function stashItems() {
var i,
items = me.getItems();
items = me.findItems(-1, 0, 3);

// stash large items first by sorting items by size in descending order
items.sort(function(a, b) {return (b.sizex * b.sizey - a.sizex * a.sizey);});

for (i = 0; i < items.length; i += 1) {
if (items[i].mode === 0 && items[i].location === 3) {
Storage.Stash.MoveTo(items[i]);
}
Storage.Stash.MoveTo(items[i]);
}

return true;
Expand Down Expand Up @@ -129,6 +132,19 @@ function pickItems() {
break;
}

// pick large items first by sorting items by size in descending order and move gheed's charm to the end of the list
list.sort(function(a, b) {
if (a.classid === 605 && a.quality === 7 && !Pickit.canPick(a)) {
return 1;
}

if (b.classid === 605 && b.quality === 7 && !Pickit.canPick(b)) {
return -1;
}

return (b.sizex * b.sizey - a.sizex * a.sizey);
});

while (list.length > 0) {
item = list.shift();
canFit = Storage.Inventory.CanFit(item);
Expand All @@ -147,6 +163,12 @@ function pickItems() {
rval = "next";
}

// Gheed's Fortune handling
if (item.classid === 605 && item.quality === 7 && !Pickit.canPick(item)) {
D2Bot.printToConsole("Mule already has Gheed's.", 7);
rval = "next";
}

if (!canFit) {
stashItems();

Expand Down Expand Up @@ -454,7 +476,11 @@ function main() {

D2Bot.updateStatus("In " + (muleMode === 2 ? "anni" : muleMode === 1 ? "torch" : "") + " mule game.");
D2Bot.printToConsole("In " + (muleMode === 2 ? "anni" : muleMode === 1 ? "torch" : "") + " mule game.", 7);
delay(500);
tick = getTickCount();

while (!me.area && getTickCount() - tick < 2000) {
delay(200);
}

Town.goToTown(1);
Town.move("stash");
Expand Down Expand Up @@ -516,6 +542,14 @@ function main() {
MuleData.write(obj);
nextChar();
D2Bot.printToConsole("Mule full, getting next character.", 7);

if (StarterConfig.MinGameTime && getTickCount() - tick < StarterConfig.MinGameTime * 1000) {
while (getTickCount() - tick < StarterConfig.MinGameTime * 1000) {
me.overhead("Stalling for " + Math.round(((tick + (StarterConfig.MinGameTime * 1000)) - getTickCount()) / 1000) + " Seconds");
delay(1000);
}
}

quit();

// TODO: see whether a for loop is better
Expand Down
21 changes: 15 additions & 6 deletions d2bs/kolbot/libs/OOG.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,8 @@ MainLoop:

me.blockMouse = false;
}
} else { // no further check necessary
break;
}
}

Expand Down Expand Up @@ -981,6 +983,8 @@ MainLoop:

me.blockMouse = false;
}
} else { // no further check necessary
break;
}
}

Expand Down Expand Up @@ -1012,12 +1016,16 @@ MainLoop:
return position;
},

loginCharacter: function (info) {
loginCharacter: function (info, startFromTop = true) {
me.blockMouse = true;

var control, text,
count = 0;

if (startFromTop) { // start from beginning of the char list
sendKey(0x24);
}

MainLoop:
while (getLocation() !== 1) { // cycle until in lobby
switch (getLocation()) {
Expand All @@ -1034,8 +1042,9 @@ MainLoop:
if (text[1].toLowerCase() === info.charName.toLowerCase()) {
control.click();
this.click(6, 627, 572, 128, 35);
me.blockMouse = false;

break MainLoop;
return true;
}
}
} while (control.getNext());
Expand All @@ -1051,6 +1060,8 @@ MainLoop:
sendKey(0x28);
sendKey(0x28);
}
} else { // no further check necessary
break MainLoop;
}

break;
Expand All @@ -1060,9 +1071,7 @@ MainLoop:
break;
case 14: // disconnected?
case 30: // player not found?
me.blockMouse = false;

return false;
break MainLoop;
default:
break;
}
Expand All @@ -1072,7 +1081,7 @@ MainLoop:

me.blockMouse = false;

return true;
return false;
},

makeCharacter: function (info) {
Expand Down
44 changes: 37 additions & 7 deletions d2bs/kolbot/libs/common/Attack.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ var Attack = {
}

var i, target, gid,
retry = 0,
errorInfo = "",
attackCount = 0;

Expand Down Expand Up @@ -188,9 +189,15 @@ var Attack = {
}

if (!ClassAttack.doAttack(target, attackCount % 15 === 0)) {
errorInfo = " (doAttack failed)";
if (retry++ > 3) {
errorInfo = " (doAttack failed)";

break;
break;
}

Packet.flash(me.gid);
} else {
retry = 0;
}

attackCount += 1;
Expand Down Expand Up @@ -219,6 +226,7 @@ var Attack = {

hurt: function (classId, percent) {
var i, target,
retry = 0,
attackCount = 0;

for (i = 0; i < 5; i += 1) {
Expand All @@ -233,7 +241,13 @@ var Attack = {

while (attackCount < 300 && Attack.checkMonster(target) && Attack.skipCheck(target)) {
if (!ClassAttack.doAttack(target, attackCount % 15 === 0)) {
break;
if (retry++ > 3) {
break;
}

Packet.flash(me.gid);
} else {
retry = 0;
}

if (!copyUnit(target).x) {
Expand Down Expand Up @@ -317,6 +331,7 @@ var Attack = {
}

var i, boss, orgx, orgy, target, result, monsterList, start, coord,
retry = 0,
gidAttack = [],
attackCount = 0;

Expand Down Expand Up @@ -389,6 +404,8 @@ var Attack = {
result = ClassAttack.doAttack(target, attackCount % 15 === 0);

if (result) {
retry = 0;

for (i = 0; i < gidAttack.length; i += 1) {
if (gidAttack[i].gid === target.gid) {
break;
Expand Down Expand Up @@ -434,7 +451,12 @@ var Attack = {
Pickit.fastPick();
}
} else {
monsterList.shift();
if (retry++ > 3) {
monsterList.shift();
retry = 0;
}

Packet.flash(me.gid);
}
} else {
monsterList.shift();
Expand Down Expand Up @@ -502,6 +524,7 @@ var Attack = {
// Clear an already formed array of monstas
clearList: function (mainArg, sortFunc, refresh) {
var i, target, result, monsterList, coord,
retry = 0,
gidAttack = [],
attackCount = 0;

Expand Down Expand Up @@ -548,6 +571,8 @@ var Attack = {
result = ClassAttack.doAttack(target, attackCount % 15 === 0);

if (result) {
retry = 0;

for (i = 0; i < gidAttack.length; i += 1) {
if (gidAttack[i].gid === target.gid) {
break;
Expand Down Expand Up @@ -591,7 +616,12 @@ var Attack = {
Pickit.fastPick();
}
} else {
monsterList.shift();
if (retry++ > 3) {
monsterList.shift();
retry = 0;
}

Packet.flash(me.gid);
}
} else {
monsterList.shift();
Expand Down Expand Up @@ -777,7 +807,7 @@ var Attack = {
}

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

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

Expand Down Expand Up @@ -1497,4 +1527,4 @@ AuraLoop: // Skip monsters with auras

return false;
}
};
};

0 comments on commit 408fdff

Please sign in to comment.