Jump to content

Does castSpellOnEntity() or castSpell() block next call to same method until spell finishes?


yfoo

Recommended Posts

In the process of writing a stun alching script I noticed that after calling castSpellOnEntity(HIGH_ALCH) then calling hoverSpell(STUN). The next call of castSpell(STUN) will not process until after the previous call of castSpellOnEntity(HIGH_ALCH). 

To better summarize: cast high alch -> hover cursor over stun -> pause until after high alch completes -> cast stun.

However by replacing hoverSpell() with a call to Mouse.move() with random coordinates within the bounds of the stun spell, stun will be casted mid animation of high alch resulting in the desired outcome. 

My conclusion is that internally castSpell() or castSpellOnEntity() will delay the next castSpell() or castSpellOnEntity(). Can anyone else confim this?

On another note, how do you check what interface tab the player is currently at (i.e: magic tab, inventory tab, quest tab, etc.)

relevant code that handles stun alching:

public int executeNodeAction() throws InterruptedException{
        Magic m = hostScriptReference.getMagic();
        PriorityNode nextNode = this.pq.peek();
        hostScriptReference.log("Executing: " + nextNode.p.name());
        switch(nextNode.p){
            case ALCH:
                if(m.canCast(Spells.NormalSpells.HIGH_LEVEL_ALCHEMY)){
                    m.castSpell(Spells.NormalSpells.HIGH_LEVEL_ALCHEMY);
                    MethodProvider.sleep(ConstantsAndStatics.randomNormalDist(ConstantsAndStatics.BETWEEN_ALCH_MEAN_MS, ConstantsAndStatics.BETWEEN_ALCH_STDDEV_MS));
                    if(m.isSpellSelected()){
                        hostScriptReference.getInventory().interact("Cast","Magic longbow");
                    }
                    MethodProvider.sleep(ConstantsAndStatics.randomNormalDist(ConstantsAndStatics.RS_GAME_TICK_MS, 80));
                    swapKeysStunAlch(); 
                    if(hoverOverStun()){ //originally was m.hoverSpell(Spells.NormalSpells.STUN)
                        //return (int) ConstantsAndStatics.randomNormalDist(50, 5);
                        return 0; //force onLoop to not sleep to better test
                    }
                }
                hostScriptReference.log("cannot cast alch");
                return 10;


            case STUN:

                if(m.canCast(Spells.NormalSpells.STUN)){
                    if(npc == null){
                        hostScriptReference.log("no NPC creating instance");
                        npc = hostScriptReference.getNpcs().closest("Monk of Zamorak");
                    }
                    stop = System.currentTimeMillis();
                    m.castSpellOnEntity(Spells.NormalSpells.STUN, npc);

                    swapKeysStunAlch();
                    if(m.hoverSpell(Spells.NormalSpells.HIGH_LEVEL_ALCHEMY)){
                        //return (int) ConstantsAndStatics.randomNormalDist(50, 5);
                        return 0; //force onLoop to not sleep to better test
                    }
                }
                hostScriptReference.log("cannot cast stun");
                return 10;
            case ALCH_ERROR: //for later implementations of emulating human mistakes
                return 0;
            case STUN_ERROR:
                return 0;
        }
        return 1000;
    }

    private boolean hoverOverStun(){
        int randX = ThreadLocalRandom.current().nextInt(STUN_UPPER_LEFT_BOUND.x, STUN_LOWER_RIGHT_BOUND.x);
        int randY = ThreadLocalRandom.current().nextInt(STUN_UPPER_LEFT_BOUND.y, STUN_LOWER_RIGHT_BOUND.y);
        hostScriptReference.log("hovering stun at: (" + randX + ", " + randY + ")");
        return !hostScriptReference.getMouse().move(randX, randY);
    }

The onLoop() method:

@Override
public int onLoop() throws InterruptedException {
	return pqw.executeNodeAction();
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...