Jump to content

Magic Rune Management


Joseph

Recommended Posts

I have to give some credit to , he had the idea at first, the link to his thread.

 

 

Supports:

  • Support the usage of staffs. For example: So if your using an air staff, and it's checking to see if you have the required runes, and amount of rune. It will neglect the air runes.

 

This Snippet contain almost all spells. The spells that aren't supported are:

  • The one that require a different staff that arent in the enum "Staffs". Example: Magic Dart
  • The ones that require an item in your inventory. Example: Charge orb, Teleport to ape Atoll
  • The Lumbridge home teleport. 
  • And any other spell outside of the normal spell book.

 

if i get much love, ill add in more methods such as: interact with spell, interact wtih spell on invetory item, or interact with spell on entity. Or even support the spells that are supported atm.

 

Change Log:


3/18

  • Changed the package name to magic.management
  • Changed the following: Spells to spell, Elements to element, Runes to rune, and Spells to MagicSpell

 

Snippet:

RuneSupply class

package magic.management;

public class RuneSupply	{
	
	private int amount;
	private Rune rune;
	private Element element;
	
	public RuneSupply(Rune rune, int amount)	{
		this.rune = rune;
		this.amount = amount;
		element = rune.getElement();
	}
	
	public Rune getRune()	{
		return rune;
	}
	
	public int getAmount()	{
		return amount;
	}
	
	public Element getElement()	{
		return element;
	}
	
	public enum Element	{
		AIR, WATER, EARTH, FIRE;
		
		private Element element;
		
		public Element getElement()	{
			return element;
		}

	}
	
	public enum Staff {
		AIR(1381, Element.AIR),
		WATER(1383, Element.WATER),
		EARTH(1385, Element.EARTH),
		FIRE(1387, Element.FIRE),
		Lava_BATTLE(3053, Element.FIRE, Element.EARTH),
		MUD(6562, Element.EARTH, Element.WATER);
		
		private int id;
		private Element[] elements;
		
		Staff(int id, Element... elements)	{
			this.id = id;
			this.elements = elements;
		}
		
		public int getId()	{
			return id;
		}
		
		public Element[] getElements()	{
			return elements;
		}
	}
	
	public enum Rune	{
		FIRE(554, Element.FIRE),
		WATER(555, Element.WATER),
		AIR(556, Element.AIR),
		EARTH(557, Element.EARTH),
		MIND(558),	
		BODY(559),
		DEATH(560),
		NATURE(561),
		CHAOS(562),
		LAW(563),
		COSMIC(564),
		BLOOD(565),
		SOUL(566);
		
		private int id;
		private Element element;
		
		Rune(int id)	{
			this.id = id;
		}
		
		Rune(int id, Element element)	{
			this(id);
			this.element = element;
		}
		
		public int getId()	{
			return id;
		}
		
		public Element getElement()	{
			return element;
		}
	}
	

} 

MagicSpell enum

package magic.management;

import java.util.ArrayList;
import java.util.List;

import magic.management.RuneSupply.Rune;

public enum MagicSpell {
	WIND_STRIKE(new RuneSupply(Rune.AIR, 1), new RuneSupply(Rune.MIND, 1)),
	WATER_STRIKE(new RuneSupply(Rune.AIR, 1), new RuneSupply(Rune.MIND, 1), new RuneSupply(Rune.WATER, 1)),
	EARTH_STRIKE(new RuneSupply(Rune.AIR, 1), new RuneSupply(Rune.MIND, 1), new RuneSupply(Rune.EARTH, 2)),
	FIRE_STRIKE(new RuneSupply(Rune.AIR, 1), new RuneSupply(Rune.MIND, 1), new RuneSupply(Rune.FIRE, 3)),
	
	WIND_BOLT(new RuneSupply(Rune.AIR, 2), new RuneSupply(Rune.CHAOS, 1)),
	WATER_BOLT(new RuneSupply(Rune.AIR, 2), new RuneSupply(Rune.CHAOS, 1), new RuneSupply(Rune.WATER, 2)),
	EARTH_BOLT(new RuneSupply(Rune.AIR, 2), new RuneSupply(Rune.CHAOS, 1), new RuneSupply(Rune.EARTH, 3)),
	FIRE_BOLT(new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.CHAOS, 1), new RuneSupply(Rune.FIRE, 4)),
	
	AIR_BLAST(new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.DEATH, 1)),
	WATER_BLAST(new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.DEATH, 1), new RuneSupply(Rune.WATER, 3)),
	EARTH_BLAST(new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.DEATH, 1), new RuneSupply(Rune.EARTH, 4)),
	FIRE_BLAST(new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.DEATH, 1), new RuneSupply(Rune.FIRE, 5)),

	AIR_WAVE(new RuneSupply(Rune.AIR, 5), new RuneSupply(Rune.BLOOD, 1)),
	WATER_WAVE(new RuneSupply(Rune.AIR, 5), new RuneSupply(Rune.BLOOD, 1), new RuneSupply(Rune.WATER, 7)),
	EARTH_WAVE(new RuneSupply(Rune.AIR, 5), new RuneSupply(Rune.BLOOD, 1), new RuneSupply(Rune.EARTH, 7)),
	FIRE_WAVE(new RuneSupply(Rune.AIR, 5), new RuneSupply(Rune.BLOOD, 1), new RuneSupply(Rune.FIRE, 7)),
	
	CONFUSE(new RuneSupply(Rune.WATER, 3), new RuneSupply(Rune.EARTH, 2), new RuneSupply(Rune.BODY, 1)),
	WEAKEN(new RuneSupply(Rune.WATER, 3), new RuneSupply(Rune.EARTH, 2), new RuneSupply(Rune.BODY, 1)), 
	CURSE(new RuneSupply(Rune.WATER, 2), new RuneSupply(Rune.EARTH, 3), new RuneSupply(Rune.BODY, 2)), 
	BIND(new RuneSupply(Rune.WATER, 3), new RuneSupply(Rune.EARTH, 3), new RuneSupply(Rune.NATURE, 2)), 
	SNARE(new RuneSupply(Rune.EARTH, 4), new RuneSupply(Rune.WATER, 4), new RuneSupply(Rune.NATURE, 3)),
	VULNERANILITY(new RuneSupply(Rune.EARTH, 5), new RuneSupply(Rune.WATER, 5), new RuneSupply(Rune.SOUL, 1)),
	ENFEEBLE(new RuneSupply(Rune.EARTH, 8), new RuneSupply(Rune.WATER, 8), new RuneSupply(Rune.SOUL, 1)),
	ENTANGLE(new RuneSupply(Rune.EARTH, 5), new RuneSupply(Rune.WATER, 5), new RuneSupply(Rune.NATURE, 4)),
	STUN(new RuneSupply(Rune.EARTH, 12), new RuneSupply(Rune.WATER, 12), new RuneSupply(Rune.SOUL, 1)),
	CHARGE(new RuneSupply(Rune.FIRE, 3), new RuneSupply(Rune.BLOOD, 3), new RuneSupply(Rune.AIR, 3)),
	
	BONES_TO_BANANAS(new RuneSupply(Rune.EARTH, 2), new RuneSupply(Rune.WATER, 2), new RuneSupply(Rune.NATURE, 1)),
	BONES_TO_PEACHES(new RuneSupply(Rune.NATURE, 2), new RuneSupply(Rune.WATER, 4), new RuneSupply(Rune.EARTH, 4)),
	
	VARROCK_TELEPORT(new RuneSupply(Rune.FIRE, 1), new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.LAW, 1)),
	LUMBRIDGE_TELEPORT(new RuneSupply(Rune.EARTH, 1), new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.LAW, 1)),
	FALADOR_TELEPORT(new RuneSupply(Rune.WATER, 1), new RuneSupply(Rune.AIR, 3), new RuneSupply(Rune.LAW, 1)),
	TELEPORT_TO_HOUSE(new RuneSupply(Rune.LAW, 1), new RuneSupply(Rune.AIR, 1), new RuneSupply(Rune.EARTH, 1)),
	CAMELOT_TELEPORT(new RuneSupply(Rune.AIR, 5), new RuneSupply(Rune.LAW, 1)), 
	ARDOUGNE_TELEPORT(new RuneSupply(Rune.WATER, 2), new RuneSupply(Rune.LAW, 2)),
	WATERTOWER_TELEPORT(new RuneSupply(Rune.EARTH, 2), new RuneSupply(Rune.LAW, 2)),
	TROLLHEIM_TELEPORT(new RuneSupply(Rune.FIRE, 2), new RuneSupply(Rune.LAW, 2)),
	
	TELEOTHER_LUMBRIDGE(new RuneSupply(Rune.SOUL, 1), new RuneSupply(Rune.LAW, 1), new RuneSupply(Rune.EARTH, 1)),
	TELEOTHER_FALADOR(new RuneSupply(Rune.SOUL, 1), new RuneSupply(Rune.WATER, 1), new RuneSupply(Rune.LAW, 1)),
	TELEOTHER_CAMELOT(new RuneSupply(Rune.SOUL, 2),new RuneSupply(Rune.LAW, 1)),
	TELE_BLOCK(new RuneSupply(Rune.LAW, 1), new RuneSupply(Rune.CHAOS, 1), new RuneSupply(Rune.DEATH, 1)),
		
	TELEKINETIC_GRAB(new RuneSupply(Rune.AIR, 1), new RuneSupply(Rune.LAW, 1)),
	
	CRUMBLE_UNDEAD(new RuneSupply(Rune.EARTH, 2), new RuneSupply(Rune.AIR, 2), new RuneSupply(Rune.CHAOS, 1)),
	
	LOW_ALCHEMY(new RuneSupply(Rune.FIRE, 3), new RuneSupply(Rune.NATURE, 1)),
	HIGH_ALCHEMY(new RuneSupply(Rune.FIRE, 5), new RuneSupply(Rune.NATURE, 1)),
	
	ENCHANT_SAPPHIRE(new RuneSupply(Rune.WATER, 1), new RuneSupply(Rune.COSMIC, 1)),
	ENCHANT_EMERALD(new RuneSupply(Rune.AIR, 2), new RuneSupply(Rune.COSMIC, 1)),
	ENCHANT_RUBY(new RuneSupply(Rune.FIRE, 5), new RuneSupply(Rune.COSMIC, 1)),
	ENCHANT_DIAMOND(new RuneSupply(Rune.EARTH, 10), new RuneSupply(Rune.COSMIC, 1)),
	ENCHANT_DRAGONSTONE(new RuneSupply(Rune.WATER, 15), new RuneSupply(Rune.EARTH, 15), new RuneSupply(Rune.COSMIC, 1)),
	ENCHANT_ONYX(new RuneSupply(Rune.EARTH, 20), new RuneSupply(Rune.FIRE, 20), new RuneSupply(Rune.COSMIC, 1));

	
	private RuneSupply[] runeSupplies;
	
	MagicSpell(RuneSupply...runeSupplies){
		this.runeSupplies = runeSupplies;
	}
	
	public RuneSupply[] getSupplies()	{
		return runeSupplies;
	}
	
	public List<Rune> getRunes(RuneSupply...runeSupplies)	{
		List<Rune> list = new ArrayList<Rune>();
		for(RuneSupply rs: runeSupplies)	{
			if (rs!=null && rs.getAmount() >0)
				list.add(rs.getRune());
		}
		return list;
	}
	
	public List<Integer> getAmount(RuneSupply...runeSupplies)	{
		List<Integer> list = new ArrayList<Integer>();
		for(RuneSupply rs: runeSupplies)	{
			if (rs!=null && rs.getAmount() >0)
				list.add(rs.getAmount());
		}
		return list;
	}
} 

RuneManger class

package magic.management;

import magic.management.RuneSupply.Element;
import magic.management.RuneSupply.Staff;

import org.osbot.script.Script;
import org.osbot.script.rs2.ui.Inventory;

public class RuneManager {
	
	private Script script;
	private Inventory getInv;
	
	public RuneManager(Script script) {
		this.script = script;	
		this.getInv = script.client.getInventory();
	}

	public boolean isWearingStaff(Staff staff)	{
		return script.equipmentTab.isWieldingWeapon(staff.getId());
	}
	
	public boolean containsSuppliesFor(MagicSpell spell)	{
		for (RuneSupply runes: spell.getSupplies())	{
			if (runes!=null)
				if (!getInv.contains(runes.getRune().getId()) || getInv.getAmount(runes.getRune().getId())< runes.getAmount())	{
					return false;
				}
		}
		return true;		
	}

	public boolean containsSuppliesFor(MagicSpell spell, Staff staff)	{
		if (!this.isWearingStaff(staff))	return false;
		else
			for (Element elements: staff.getElements())	{
				for (RuneSupply runes: spell.getSupplies())	{				
					if (elements!=null && runes!=null)	{
						if (runes.getElement() != elements)	{
							if (!getInv.contains(runes.getRune().getId()) || getInv.getAmount(runes.getRune().getId()) < runes.getAmount())
								return false;
						}
					}
				}
			}
		return true;
	}
	
	public boolean equiptStaff(Staff staff) throws InterruptedException	{
		if (getInv.contains(staff.getId()))
			return getInv.interactWithId(staff.getId(), "Weild", true);
		return false;
	}
	
}

 

How to initialize it:

First create a new RuneManager variable. The on the onStart() you make the new variable equal the RuneManager Constructor.

	private RuneManager manager;

	@Override
	public void onStart() {
		manager = new RuneManager(this);
	}
	 

How to use it:

		if (manager.containsSuppliesFor(MagicSpell.WIND_BOLT, Staff.AIR)) {
                    /stuff
                }

Edited by josedpay
  • Like 2
Link to comment
Share on other sites

Well done. Just thought I'd throw in that enum names should be singular - Staff and not Staffs, Element and not Elements etc. also package names should be lower case.

O shit I didn't know I left the packages I thought I took them off. I'm remove it in a little. Also I'll fix the name too

 

edit: i change the package name to "magic.management", hopefully its fine now. Change the following Spells to spell, Elements to element, Runes to rune, and Spells to MagicSpell. 

Edited by josedpay
  • Like 1
Link to comment
Share on other sites

 oh i forgot to mention it support staffs biggrin.png. So if your using an air staff, and it's checking to see if you have the required runes, and amount of rune. It will neglect the air runes.

 

 

 

Going to replace my messy lines with these wink.png cheers!

 

Edit: holy s** just noticed howmany spell it supports now, dayum

Edited by Botrepreneur
  • Like 1
Link to comment
Share on other sites

Here are some minor ideas:

 

Int minimumXSuppliesToHaveInInventory;

Boolean containsminimumXSuppliesFor; (this would avoid walking away from the bank with only let's say 5 casts to a combat spot only to return banking after those 5 casts)

Int amountofcaststowithdrawwhenbelowminimum;

 

Logic for banking (when bank is open).

if (usemagic
&& !manager.containsminimumXSuppliesFor(MagicSpell.usedSpell,
usedStaff)) {
int idspecificrunetowithdraw = ?; // what if there are multiple types to withdraw? Array?
int amountofpecificrunetowithdrawfor1spell = ?

int withdrawamount = idspecificrunetowithdraw * amountofpecificrunetowithdrawfor1spell * amountofcaststowithdrawwhenbelowminimum;
bank.withdrawX(specificrunetowithdraw,
withdrawamount);
}
Edited by Botrepreneur
  • Like 1
Link to comment
Share on other sites

 

Here are some minor ideas:

 

Int minimumXSuppliesToHaveInInventory;

Boolean containsminimumXSuppliesFor; (this would avoid walking away from the bank with only let's say 5 casts to a combat spot only to return banking after those 5 casts)

Int amountofcaststowithdrawwhenbelowminimum;

 

Logic for banking (when bank is open).

if (usemagic
&& !manager.containsminimumXSuppliesFor(MagicSpell.usedSpell,
usedStaff)) {
int idspecificrunetowithdraw = ?; // what if there are multiple types to withdraw? Array?
int amountofpecificrunetowithdrawfor1spell = ?

int withdrawamount = idspecificrunetowithdraw * amountofpecificrunetowithdrawfor1spell * amountofcaststowithdrawwhenbelowminimum;
bank.withdrawX(specificrunetowithdraw,
withdrawamount);
}
Int getSupplyAmount(RuneSupply[])
Return the amount runes for a Spell cast are left in your inventory.

im still thinking of how im could do this.

Edited by josedpay
  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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