DavidHall 1 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; }
Articron 740 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?
Pseudo 179 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.
Articron 740 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 😛
Miami 369 7 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.
Articron 740 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.
Miami 369 7 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
DavidHall 1 Author 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!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.