DavidHall 1 Share Posted May 27, 2018 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 More sharing options...
Hashtag 8688 Share Posted May 27, 2018 Thanks for contributing! Link to comment Share on other sites More sharing options...
Articron 738 Share Posted May 27, 2018 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 More sharing options...
Pseudo 179 Share Posted May 27, 2018 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 More sharing options...
Articron 738 Share Posted May 27, 2018 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 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 More sharing options...
Miami 369 7 Share Posted May 27, 2018 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 More sharing options...
Articron 738 Share Posted May 27, 2018 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 More sharing options...
Miami 369 7 Share Posted May 27, 2018 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 More sharing options...
DavidHall 1 Author Share Posted May 27, 2018 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.