kolton / d2bot-with-kolbot

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

Kolbot buys items multiple times + fix suggestion #1119

Open expl0 opened 5 years ago

expl0 commented 5 years ago

I have noticed that my characters often buy certain items (scrolls, keys, ...) multiple times even though shift + buy should take care of that. The result is having more than 12 keys or having to sell the extra scroll. I guess that's why the function Town.clearScrolls() exists.

I have tested the following fix and it seems to work perfectly (file: d2bs.kolbot.libs.common.Prototypes):

Unit.prototype.buy = function (shiftBuy, gamble) {
    if (Config.PacketShopping) {
        return Packet.buyItem(this, shiftBuy, gamble);
    }

    if (this.type !== 4) { // Check if it's an item we want to buy
        throw new Error("Unit.buy: Must be used on items.");
    }

    if (!getUIFlag(0xC) || (this.getParent() && this.getParent().gid !== getInteractedNPC().gid)) { // Check if it's an item belonging to a NPC
        throw new Error("Unit.buy: Must be used in shops.");
    }

    if (me.getStat(14) + me.getStat(15) < this.getItemCost(0)) { // Can we afford the item?
        return false;
    }

    var i = 0, result;

    do {
        result = this.shop(shiftBuy ? 6 : 2);

        delay(500);

        i += 1;
    } while (i < 3 && !result);

    return result;
};
noah- commented 5 years ago

this makes sense, should be using shift buy

hutber commented 4 years ago

I also have this problem and am testing the above fix!

CowVoid commented 3 years ago

Hi expl0. do I need to use packet shopping to use this?