Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • More Useful "canCast" Method For Spells


    DavidHall

    Recommended Posts

    Threw this together because the built in method doesn't check for staffs. May be useful to you all. Let me know if I'm doing anything stupid here 😜

    public static boolean canCast(Spell spell, MethodContext context)
    {
    	if (spell == null)
    	{
    		return false;
    	}
    
    	if (context.getSkills().getRealLevel(Skill.MAGIC) < spell.getLevel())
    	{
    		return false;
    	}
    
    	Inventory inventory = context.getInventory();
    	Equipment equipment = context.getEquipment();
    
    	for (Rune rune : spell.getCost())
    	{
    		int amount = rune.getAmount();
    		String fullRuneName = rune.getName();
    		String runeType = fullRuneName.substring(0, fullRuneName.indexOf(RUNE_SUFFIX)).toLowerCase();
    		Item runesInInv = inventory.get(fullRuneName);
    
    		//if not enough runes and no staff of that type
    		if ((runesInInv == null || runesInInv.getAmount() < amount) &&
    				!equipment.slotContains(EquipmentSlot.WEAPON.getRealSlot(),
    						item -> item != null && item.getName().toLowerCase().contains(runeType)))
    		{
    			return false;
    		}
    	}
    
    	return true;
    }

     

    Link to comment
    Share on other sites

    I think you forgot about the staves that offer multiple runes like mud staves 😛

    Perhaps it's a good idea to create an enum that contains all staves with an array of supported Rune objects? :)

    Link to comment
    Share on other sites

    1 hour ago, Articron said:

    I think you forgot about the staves that offer multiple runes like mud staves 😛

    Perhaps it's a good idea to create an enum that contains all staves with an array of supported Rune objects? :)

    Was about to point this out myself. But good job on the contribution fam.

    Link to comment
    Share on other sites

    Oh shit, it sounds like I'm super skeptical about your snippet >.> 

    Hey dude, I didn't mean it in an offensive way haha, I'm glad you're contributing to the snippet section <3
    I hope you didn't take my last comment in a passive-agressive way, because that was NOT the intention 😛 

     

     

    Link to comment
    Share on other sites

    6 hours ago, Articron said:

    I think you forgot about the staves that offer multiple runes like mud staves 😛

    Perhaps it's a good idea to create an enum that contains all staves with an array of supported Rune objects? :)

    maybe you can implement spells interface on the staff enum.

    Link to comment
    Share on other sites

    4 minutes ago, Miami 369 said:

    maybe you can implement spells interface on the staff enum.

    I don't think that makes much sense considering staves aren't spells 😛 . You'd have to contract Spells#getLevel etc which isn't related to staves.

    Link to comment
    Share on other sites

    13 minutes ago, Articron said:

    I don't think that makes much sense considering staves aren't spells 😛 . You'd have to contract Spells#getLevel etc which isn't related to staves.

    I understand you but its just a simple interface. if I made the staff enum I would implement the interface. Just cause it already has the method you need to create.

    getName(); //return name of the staff or override toString();

    getRune(); //returns arrays of runes needed

    getLevel(); //return lvl needed to wield staff

     

    but that's just me

    Link to comment
    Share on other sites

    7 hours ago, Articron said:

    I think you forgot about the staves that offer multiple runes like mud staves 😛

    Perhaps it's a good idea to create an enum that contains all staves with an array of supported Rune objects? :)

    Lol whoops you're right. I don't play RuneScape much legit and forgot about those. Thanks for pointing it out!

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.