kolton / d2bot-with-kolbot

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

Demon Limb enchant #2814

Open Sirk74 opened 4 years ago

Sirk74 commented 4 years ago

So, the title could also have been about "charged skills", but I thought about putting some variety :P

Everything started when I decided my barb should cast enchant from Demon Limb to solve his AR issues. Since I already managed to apply the same solution to Oak and Hoto with both sorc and paladin with decents results, I thought it would have been a walk in the park. How naive of me :-\

I tried to apply the same solution I used before, that is adding Demon Limb enchant to barbarian on precasts, by adding the following lines after warcries precast:

if ((me.getItems(-1, 1).filter(item => item.description.includes("Demon Limb")).first()) && (!me.getState(16) || force)) {
    Attack.weaponSwitch(1);
    me.castChargedSkill(52);
}

Same lines I used for Hoto with changed skill numbers and a weaponswitch before since DemonLimb is on secondary slot, but nothing gets casted. Other warcries in precasts are casted as normal though, and I even see the weaponswitch above, but no Enchant :(

In order to isolate and simplify the problem as much as I could, I thought about writing its own mini-script. After all, Enchant lasts 10 minutes, more than any of my runs, and I don't need to recast or cast on other chars (as it's expensive enough as it is!). So, I dont' need a full integration in precast, it's enough having its own independent script to be cast at the beginning of each game. This would also prevent errors for other barbarians checking the same lines (as it happened to me with Hoto), since I would only have the script on a char with the Limb. So not even needing if lines to check if have state or item: I do have the item (weapon arm, slot2) and I do not have the state, this is as easy as it could get. I saved the following lines as DemonLimb.js on bots folder and put Scripts.DemonLimb = true; as first script on char config.

function DemonLimb () {
    Attack.weaponSwitch(1);
    me.castChargedSkill(52);
}

This time, instead, I got: Error in DemonLimb (prototypes.js line 1146): stats[204].filter is not a function Which is completely obscure to me (I also tried to check prototypes, but I learned I have not yet the skills to go there :P)

I think I am not far behind, but I cannot figure what's missing.

DarkHorseDre commented 4 years ago

I havent read the whole of your text but I would check the setskill is working - if you SET the skill it will be set in the appropriate skill hand (it can only be set in one hand)

once set you then cast from the appropriate hand

if you watch the bot you will see if it correctly weapon switches, sets the skill and then should be easy to cast as enchant doesn't require x.y coords (can be cast if the mouse isnt on the toon, etc)

Sirk74 commented 4 years ago

I had seen the skill.setskill code in some threads, but since I had managed to have hoto work without it I didn't use it. I will try the setskill way, even if it's completely new to me. Thanks

PS: still no clue why with me.castchargedskill it does not work this time :-\

DarkHorseDre commented 4 years ago

you kinda didn't answer this - a key part of evidence gathering:

if you watch the bot you will see if it correctly weapon switches

anyway, what I was trying to do is get you to go back to basics and focus upon the fundamentals: break it down - does it do each small part of the process? does it find the correct object? does it detect state properly? etc

oh well you never find out if you don't look! but I tried to replicate and I got it working (not on weaponswitch but thats easy) - you can either use this or work the problem and solve it (you have everything you need) - this is taken from what is in precast.js and I use the basic set and cast skill.. you can replace that with your function or whatever.

    item = me.getItem(-1, 1);

    if (item) {
        do {
            //if (item.getPrefix(21387)) { // demon limb
            if(((me.getItems(-1, 1).filter(item => item.description.includes("Demon Limb")).first()))) { // demon limb
                print("item: "+ item.name);
                Skill.setSkill(52, 0, item); //0 is right hand, charged skills always right
                Packet.castSkill(0, me.x, me.y); //cannot be skill.cast
            }
            print("loop..");
        } while (item.getNext());
    }

That said this is very slow for some reason... not sure why but you can work it out ;)

Sirk74 commented 4 years ago

Wow! Thanks a lot!

I tried to paste it into my DemonLimb script but at the beginning it didn't work. Then I removed the do-while part and defined var item at the beginning and now it works perfectly.

About the being slow, could it be the fact that it is looping the items? And exactly, what does imply for me having removed that part? (except that it works I have no idea what was the function of the loop, so..).

Basically, this is my DemonLimb script now:

function DemonLimb () {
    var item
    item = me.getItem(-1, 1);

    if((me.getItems(-1, 1).filter(item => item.description.includes("Demon Limb")).first())) {
        Attack.weaponSwitch(1);
        Skill.setSkill(52, 0, item);
        Packet.castSkill(0, me.x, me.y);
    }

}
DarkHorseDre commented 4 years ago

np

we cant compare the two approaches as they are not the same.

getItem(x,1) looks at your items and starts at first (body location I think) - the object.getNext loop cycles through all items of mode 1. this is done in many files in the base code. You do not need it as you are using getItems with filter...

the failure isn't in the geitems line as its the same as before.

what is different is the explicit setskill/castskill (the only way I cast charged skills)

compare the initial code you had and what you have now and you'll get it