kolton / d2bot-with-kolbot

d2bot game manager by D3STROY3R with kolbot libs by kolton for d2bs
345 stars 332 forks source link

How to stop bot when stash is full #2728

Open aloloaalo opened 4 years ago

aloloaalo commented 4 years ago

Hi guys,

I'm using an older version of Kolbot (core15) for my 1.13d client. I play on single player. I've been trying to find out how to stop the bot once the stash is full, but to no avail. My sorc is running Mausoleum + Ancient Tunnel and the stash + inventory become full after ~4 hours. After that, I have to manually stop the bot and move items to Gomule stash (I don't know how to use single player mule. Is there a way to stop the bot after the stash is full? I remember there is a thread somewhere, but it was deleted. Thanks in advance, bros!

DarkHorseDre commented 4 years ago

To do exactly what you want, find this section in your pickit.js (I can't give line numbers as mine has been modded):

// Item can fit - pick it up
    if (canFit) {
        this.pickItem(pickList[0], status.result, status.line);
    }
    }
}
    pickList.shift();
    }

add this afterward:

if(Storage.Stash.UsedSpacePercent() && Storage.Inventory.UsedSpacePercent() === 100) {
    D2Bot.printToConsole("**** stopped Profile - NO SPACE", 8);
    D2Bot.stop(me.profile,true);
}

This should work but not fully tested so let me know.

However, I prefer to not wait until I am completely full as I will miss items (e.g. what if I have 1 slot free but find a good 1x2 slot item?) so I wait until I cant fit a 2x3 item in my inv then stop, using Storage.Inventory.FindSpot()

aloloaalo commented 4 years ago

Thank you very much for the reply, I'll try this and report the result!

aloloaalo commented 4 years ago

To do exactly what you want, find this section in your pickit.js (I can't give line numbers as mine has been modded):

// Item can fit - pick it up
  if (canFit) {
      this.pickItem(pickList[0], status.result, status.line);
  }
  }
}
  pickList.shift();
  }

add this afterward:

if(Storage.Stash.UsedSpacePercent() && Storage.Inventory.UsedSpacePercent() === 100) {
  D2Bot.printToConsole("**** stopped Profile - NO SPACE", 8);
  D2Bot.stop(me.profile,true);
}

This should work but not fully tested so let me know.

However, I prefer to not wait until I am completely full as I will miss items (e.g. what if I have 1 slot free but find a good 1x2 slot item?) so I wait until I cant fit a 2x3 item in my inv then stop, using Storage.Inventory.FindSpot()

This worked beautifully. I set the "UsedSpacePercent" to 80, put some items into the stash and had the bot run Mephisto a few times. After some drops, the bot stopped and printed the line No Space to manager. Beautiful. I increased the UsedSpacePercent to 90 since that seems to be OK and I wont miss a Giant Thresher, for example :P.

As for the "I wait until I cant fit a 2x3 item in my inv then stop, using Storage.Inventory.FindSpot()", can you please clarify more for me, since I don't quite understand this. Where is this Storage.Inventory.FindSpot? Can you give me an example?

DarkHorseDre commented 4 years ago

Cool, np.

bear in mind the percentages relate to spare slots. I assume each 1x1 slot for stash and separately for inventory is a proportion of total (so 40 slots in your char inventory). I guess you could calculate the slots accurately (90% of inv = 36 slots; 4 free) but you cant tell what configuration that space is in (e.g. is it 2x2, 1x4, 2x2 + 1x1 + 1x1? etc.) That's why I do it my way.

This is what I do:

const fakeItem = { //dhd define as the size of item you want. e.g. 2x3 = armour, 2x4 = polearm etc)
    sizex: 2,
    sizey: 3,
}

if ((!Storage.Inventory.FindSpot(fakeItem)) && (needMule && AutoMule.getInfo() && AutoMule.getInfo().hasOwnProperty("muleInfo") && AutoMule.getMuleItems().length > 0)) { //if can't fit a 2x3 item, if not need mule/automule is not true etc.
    D2Bot.printToConsole("**** DHD stopped Profile - NO SPACE", 8);
    D2Bot.stop(me.profile,true);
} 

I use a combination of findspot (can I find a spot to store the fake item (Which is 2x3 in size) + automule settings that I stole from the code (you wont need this if you don't use automule/bnet/multiple bots, so you can keep it as per my first suggestion)

aloloaalo commented 4 years ago

Thank you very much. You saved my day. Now I can sleep peacefully and let the bot do its job 👍

aloloaalo commented 4 years ago

Cool, np.

bear in mind the percentages relate to spare slots. I assume each 1x1 slot for stash and separately for inventory is a proportion of total (so 40 slots in your char inventory). I guess you could calculate the slots accurately (90% of inv = 36 slots; 4 free) but you cant tell what configuration that space is in (e.g. is it 2x2, 1x4, 2x2 + 1x1 + 1x1? etc.) That's why I do it my way.

This is what I do:

const fakeItem = { //dhd define as the size of item you want. e.g. 2x3 = armour, 2x4 = polearm etc)
  sizex: 2,
  sizey: 3,
}

if ((!Storage.Inventory.FindSpot(fakeItem)) && (needMule && AutoMule.getInfo() && AutoMule.getInfo().hasOwnProperty("muleInfo") && AutoMule.getMuleItems().length > 0)) { //if can't fit a 2x3 item, if not need mule/automule is not true etc.
  D2Bot.printToConsole("**** DHD stopped Profile - NO SPACE", 8);
  D2Bot.stop(me.profile,true);
} 

I use a combination of findspot (can I find a spot to store the fake item (Which is 2x3 in size) + automule settings that I stole from the code (you wont need this if you don't use automule/bnet/multiple bots, so you can keep it as per my first suggestion)

I was too hasty to report the result, sir. I noticed strange behavior of the bot (bot stopped too soon). I'll explain here:

Percentages set to 90 (if(Storage.Stash.UsedSpacePercent() && Storage.Inventory.UsedSpacePercent() === 90) {) Stash was empty (48 free slots). Inventory had 4x4 = 16 slots (the remaining slots in the inventory was small charms of luck for MF, Tomes of ID and Town Portal, Keys). Bot did one Mephisto run, picked up some items, did not stash any (which was OK, because those picked up items were not in my .nip pickit file), then quit. Stash was still empty (48 free slots), Inventory had 4 free slots left (Items filled up 12 slots). I assume that the bot decided 4 free slots in inventory was larger than the 90 percent set in the percentage value, so It quit. BUT I thought that the bot counted free slots in stash as well? In my case, shouldn't the bot have waited till the Inventory PLUS Stash filled up about (48+16)*90% = around 57-58 slots before quitting? I'm still scratching my head, sir. Could you give me some explanations to this please? I thought I had this solved but no :O.

aloloaalo commented 4 years ago

I set the percentages to 95, it seems to be working pretty OK now. Stash gets filled first, then inventory. I'll report more findings.

After some runs, the bot works pretty OK at 95 percentages. I can sleep OK again now xD.

DarkHorseDre commented 4 years ago

it's probably due to when it checked and how - looking at where I placed this, it could go inside the if statements above, but I think I tried that and it didn't work. This may require some tweaking ;)

Try changing to this which should show what the bot thinks it has at that time (although I'm not sure if the bot needs to visit stash or holds a copy in memory):

D2Bot.printToConsole("Stopped Profile - NO SPACE. - Stash space available: " + Storage.Stash.UsedSpacePercent() + ". 
 Inv. space: " + Storage.Inventory.UsedSpacePercent() + " area: " + me.area, 8);

let me know where the bot is when it quits - should be in town IIRC (I haven't botted in ages)

DarkHorseDre commented 4 years ago

.. or maybe I need to just use javascript properly?!

if(Storage.Stash.UsedSpacePercent() === 100 && Storage.Inventory.UsedSpacePercent() === 100) {