Jump to content

MagicTracker


Joseph

Recommended Posts

Currently supports:

  • Most staffs
  • Standard spell book
  • Ancient spell book
  • Lunar spell book

When i have a chance i want to implement the new magic class and stuff osbot has. On my todo list

 

MagicManager class

package dependencies.trackers;

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

import org.osbot.rs07.api.ui.EquipmentSlot;
import org.osbot.rs07.api.ui.Spell;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

/**
 * @author Josedpay
 */
@SuppressWarnings("deprecation")
public class MagicTracker extends MethodProvider{

	public MagicTracker(Script s)	{
		this.exchangeContext(s.bot);
	}
	
	public static enum Rune	{
		STEAM, MIST, MUD, LAVA, SMOKE, DUST,
		EARTH, FIRE, WATER, AIR, ASTRAL, BLOOD, 
		BODY, CHAOS, COSMIC, DEATH, LAW, MIND, NATURE, SOUL;
		
		@Override
		public String toString() {
			return super.name().toLowerCase() +" rune";
		}		
	}
	
	public static enum Staff	{
		AIR_STAFF(new String[] {"staff of air", "air battlestaff", "mystic air staff"}, Rune.AIR),
		EARTH_STAFF(new String[] {"staff of earth", "earth battlestaff", "mystic earth staff"}, Rune.EARTH),
		WATER_STAFF(new String[] {"staff of water", "water battlestaff", "mystic water staff"}, Rune.WATER),
		FIRE_STAFF(new String[] {"staff of fire", "fire battlestaff", "mystic fire staff"}, Rune.FIRE),
		LAVA_STAFF(new String[] {"lava battlestaff", "mystic lava staff"}, Rune.LAVA, Rune.EARTH, Rune.FIRE),
		MUD_STAFF(new String[] {"mud battlestaff", "mystic mud staff"}, Rune.MUD, Rune.WATER, Rune.EARTH),
		STEAM_STAFF(new String[] {"steam battlestaff", "mystic steam staff"}, Rune.STEAM, Rune.WATER, Rune.FIRE),
		SMOKE_STAFF(new String[] {"smoke battlestaff", "mystic smoke staff"}, Rune.SMOKE, Rune.AIR, Rune.FIRE),
		GUTHIX_STAFF(null), 
		SARADOMIN_STAFF(null), 
		ZAMORAK_STAFF(null),
		AHRIMS_STAFF(null),
		ANCIENT_STAFF(null), 
		LUNAR_STAFF(null),
		IBAN1S_STAFF(null),
		SLAYER1S_STAFF(null),
		TRIDENT_OF_THE_SEAS(null),
		STAFF_OF_DEAD(null),
		BEGINNER_WAND(null),
		APPRENTICE_WAND(null),
		TEACHER_WAND(null),
		MASTER_WAND(null),
		Y3RD_AGE_WAND(null);	
		
		String[] names;
		Rune[] runes;
		
		Staff(String[] names, Rune...runes)	{
			String name = new StringBuilder(super.name().toLowerCase().replace("_", " ").replace("1", "'").replace("Y", "")).toString();
			this.names = (names != null) ? names: new String[] {name};
			this.runes = runes;
		}		
		
		public String[] names()	{
			return this.names;
		}
		
		public Rune[] runes() {
			return this.runes;
		}		
		
	}
	
	public static class RuneSupply	{
		private Rune rune;
		private int amount;
		
		public RuneSupply(int amount, Rune rune)	{
			this.rune = rune;
			this.amount = amount;
		}
				
		public Rune rune()	{
			return this.rune;
		}
		
		public int amount()	{
			return this.amount;
		}
	}
	
	public static class ItemSupply	{
		private String name;
		private int amount;
		
		public ItemSupply(int amount, String name)	{
			this.name = name;
			this.amount = amount;
		}
		
		@Override
		public String toString()	{
			return this.name.toLowerCase();
		}
		
		public int amount(){
			return this.amount;
		}
	}	
	
	public static interface SpellBook	{
		public boolean useStaff();
		public Staff staff();
		public boolean useItem();
		public RuneSupply[] runeSupply();
		public ItemSupply itemSupply();
		public String variableName();
	}

	public static enum Standard implements SpellBook	{
		WIND_STRIKE(new RuneSupply(1, Rune.AIR), new RuneSupply(1, Rune.MIND)),
		WATER_STRIKE(new RuneSupply(1, Rune.AIR), new RuneSupply(1, Rune.MIND), new RuneSupply(1, Rune.WATER)),
		EARTH_STRIKE(new RuneSupply(1, Rune.AIR), new RuneSupply(1, Rune.MIND), new RuneSupply(2, Rune.EARTH)),
		FIRE_STRIKE(new RuneSupply(1, Rune.AIR), new RuneSupply(1, Rune.MIND), new RuneSupply(3, Rune.FIRE)),
		
		WIND_BOLT(new RuneSupply(2, Rune.AIR), new RuneSupply(1, Rune.CHAOS)),
		WATER_BOLT(new RuneSupply(2, Rune.AIR), new RuneSupply(1, Rune.CHAOS), new RuneSupply(2, Rune.WATER)),
		EARTH_BOLT(new RuneSupply(2, Rune.AIR), new RuneSupply(1, Rune.CHAOS), new RuneSupply(3, Rune.EARTH)),
		FIRE_BOLT(new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.CHAOS), new RuneSupply(4, Rune.FIRE)),

		WIND_BLAST(new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.DEATH)),
		WATER_BLAST(new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.DEATH), new RuneSupply(3, Rune.WATER)),
		EARTH_BLAST(new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.DEATH), new RuneSupply(4, Rune.EARTH)),
		FIRE_BLAST(new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.DEATH), new RuneSupply(5, Rune.FIRE)),

		WIND_WAVE(new RuneSupply(5, Rune.AIR), new RuneSupply(1, Rune.BLOOD)),
		WATER_WAVE(new RuneSupply(5, Rune.AIR), new RuneSupply(1, Rune.BLOOD), new RuneSupply(7, Rune.WATER)),
		EARTH_WAVE(new RuneSupply(5, Rune.AIR), new RuneSupply(1, Rune.BLOOD), new RuneSupply(7, Rune.EARTH)),
		FIRE_WAVE(new RuneSupply(5, Rune.AIR), new RuneSupply(1, Rune.BLOOD), new RuneSupply(7, Rune.FIRE)),

		CONFUSE(new RuneSupply(3, Rune.WATER), new RuneSupply(2, Rune.EARTH), new RuneSupply(1, Rune.BODY)),
		WEAKEN(new RuneSupply(3, Rune.WATER), new RuneSupply(2, Rune.EARTH), new RuneSupply(1, Rune.BODY)), 
		CURSE(new RuneSupply(2, Rune.WATER), new RuneSupply(3, Rune.EARTH), new RuneSupply(2, Rune.BODY)), 
		BIND(new RuneSupply(3, Rune.WATER), new RuneSupply(3, Rune.EARTH), new RuneSupply(2, Rune.NATURE)), 
		SNARE(new RuneSupply(4, Rune.EARTH), new RuneSupply(4, Rune.WATER), new RuneSupply(3, Rune.NATURE)),
		VULNERABILITY(new RuneSupply(5, Rune.EARTH), new RuneSupply(5, Rune.WATER), new RuneSupply(1, Rune.SOUL)),
		ENFEEBLE(new RuneSupply(8, Rune.EARTH), new RuneSupply(8, Rune.WATER), new RuneSupply(1, Rune.SOUL)),
		ENTANGLE(new RuneSupply(5, Rune.EARTH), new RuneSupply(5, Rune.WATER), new RuneSupply(4, Rune.NATURE)),
		STUN(new RuneSupply(12, Rune.EARTH), new RuneSupply(12, Rune.WATER), new RuneSupply(1, Rune.SOUL)),
		CHARGE(new RuneSupply(3, Rune.FIRE), new RuneSupply(3, Rune.BLOOD), new RuneSupply(3, Rune.AIR)),
		
		BONES_TO_BANANAS(new RuneSupply(2, Rune.EARTH), new RuneSupply(2, Rune.WATER), new RuneSupply(1, Rune.NATURE)),
		BONES_TO_PEACHES(new RuneSupply(2, Rune.NATURE), new RuneSupply(4, Rune.WATER), new RuneSupply(4, Rune.EARTH)),
		
		VARROCK_TELEPORT(new RuneSupply(1, Rune.FIRE), new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.LAW)),
		LUMBRIDGE_TELEPORT(new RuneSupply(1, Rune.EARTH), new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.LAW)),
		FALADOR_TELEPORT(new RuneSupply(1, Rune.WATER), new RuneSupply(3, Rune.AIR), new RuneSupply(1, Rune.LAW)),
		HOUSE_TELEPORT(new RuneSupply(1, Rune.LAW), new RuneSupply(1, Rune.AIR), new RuneSupply(1, Rune.EARTH)),
		CAMELOT_TELEPORT(new RuneSupply(5, Rune.AIR), new RuneSupply(1, Rune.LAW)), 
		ARDOUGNE_TELEPORT(new RuneSupply(2, Rune.WATER), new RuneSupply(2, Rune.LAW)),
		WATERTOWER_TELEPORT(new RuneSupply(2, Rune.EARTH), new RuneSupply(2, Rune.LAW)),
		TROLLHEIM_TELEPORT(new RuneSupply(2, Rune.FIRE), new RuneSupply(2, Rune.LAW)),
		
		TELEOTHER_LUMBRIDGE(new RuneSupply(1, Rune.SOUL), new RuneSupply(1, Rune.LAW), new RuneSupply(1, Rune.EARTH)),
		TELEOTHER_FALADOR(new RuneSupply(1, Rune.SOUL), new RuneSupply(1, Rune.WATER), new RuneSupply(1, Rune.LAW)),
		TELEOTHER_CAMELOT(new RuneSupply(2, Rune.SOUL),new RuneSupply(1, Rune.LAW)),
		TELE_BLOCK(new RuneSupply(1, Rune.LAW), new RuneSupply(1, Rune.CHAOS), new RuneSupply(1, Rune.DEATH)),
			
		TELEKINETIC_GRAB(new RuneSupply(1, Rune.AIR), new RuneSupply(1, Rune.LAW)),
		
		CRUMBLE_UNDEAD(new RuneSupply(2, Rune.EARTH), new RuneSupply(2, Rune.AIR), new RuneSupply(1, Rune.CHAOS)),
		
		LOW_LEVEL_ALCHEMY(new RuneSupply(3, Rune.FIRE), new RuneSupply(1, Rune.NATURE)),
		HIGH_LEVEL_ALCHEMY(new RuneSupply(5, Rune.FIRE), new RuneSupply(1, Rune.NATURE)),

		LVL_1_ENCHANT(new RuneSupply(1, Rune.WATER), new RuneSupply(1, Rune.COSMIC)),
		LVL_2_ENCHANT(new RuneSupply(2, Rune.AIR), new RuneSupply(1, Rune.COSMIC)),
		LVL_3_ENCHANT(new RuneSupply(5, Rune.FIRE), new RuneSupply(1, Rune.COSMIC)),
		LVL_4_ENCHANT(new RuneSupply(10, Rune.EARTH), new RuneSupply(1, Rune.COSMIC)),
		LVL_5_ENCHANT(new RuneSupply(15, Rune.WATER), new RuneSupply(15, Rune.EARTH), new RuneSupply(1, Rune.COSMIC)),
		LVL_6_ENCHANT(new RuneSupply(20, Rune.EARTH), new RuneSupply(20, Rune.FIRE), new RuneSupply(1, Rune.COSMIC)),

		IBAN_BLAST(Staff.IBAN1S_STAFF, new RuneSupply(5, Rune.FIRE), new RuneSupply(1, Rune.DEATH)),
		MAGIC_DART(Staff.SLAYER1S_STAFF, new RuneSupply(1, Rune.DEATH), new RuneSupply(4, Rune.MIND)),
		SARADOMIN_STRIKE(Staff.SARADOMIN_STAFF, new RuneSupply(2, Rune.BLOOD), new RuneSupply(4, Rune.FIRE), new RuneSupply(4, Rune.AIR)),
		CLAWS_OF_GUTHIX(Staff.GUTHIX_STAFF, new RuneSupply(2, Rune.BLOOD), new RuneSupply(1, Rune.FIRE), new RuneSupply(4, Rune.AIR)),
		FLAMES_OF_ZAMORAK(Staff.ZAMORAK_STAFF, new RuneSupply(2, Rune.BLOOD), new RuneSupply(4, Rune.FIRE), new RuneSupply(1, Rune.AIR)),
		;
		//add in spells with item, for example: teleport to ape toll		
		
		private Staff staff;
		private RuneSupply[] supplies;
		private ItemSupply item;
		
		Standard(RuneSupply...supplies)	{
			this.staff = null;
			this.item = null;
			this.supplies = supplies;
		}
		
		Standard(Staff staff, RuneSupply...supplies)	{
			this.staff = staff;
			this.item = null;
			this.supplies = supplies;
		}
		
		private Standard(ItemSupply item, RuneSupply...supplies)	{
			this.staff = null;
			this.item = item;
			this.supplies = supplies;
		}
		
		@Override
		public boolean useStaff() {
			return this.staff != null;
		}

		@Override
		public Staff staff() {
			return this.staff;
		}

		public boolean useItem() {
			return this.item != null;
		}

		@Override
		public RuneSupply[] runeSupply() {
			return this.supplies;
		}

		@Override
		public ItemSupply itemSupply() {
			return this.item;
		}	
		
		@Override
		public String toString()	{
			return super.name().replace("_", " ").toLowerCase();
		}

		@Override
		public String variableName() {
			return super.name();
		}
	}
	
	public boolean isWearingStaff(Staff staff)	{
		if (staff == null)	return false;
		else{
			for (String name: staff.names)
				if (name != null && equipment.isWearingItem(EquipmentSlot.WEAPON, name))
					return true;
		}
		return false;
	}
	
	private boolean contains(RuneSupply supply)	{
		return inventory.getAmount(supply.rune.toString()) >= supply.amount;
	}
	
	public boolean contains(RuneSupply...supplies)	{
		for (RuneSupply supply: supplies)
			if (!contains(supply))
				return false;
		return true;				
	}
	
	public boolean contains(Staff staff, SpellBook spell)	{
		return contains(getSupply(staff, spell));
	}
	
	public RuneSupply[] getSupply(Staff staff, SpellBook spell)	{
		if (staff == null || !this.isWearingStaff(staff)) 
			return spell.runeSupply();
		else{
			List<Rune> runeList = new ArrayList<Rune>();
			List<RuneSupply> supplyList = new ArrayList<RuneSupply>();

			for (Rune rune: staff.runes())	{
				runeList.add(rune);
			}
			
			for (RuneSupply supply: spell.runeSupply())	{
				if (!runeList.contains(supply.rune()))	{
					supplyList.add(supply);
				}
			}
			
			return supplyList.toArray(new RuneSupply[supplyList.size()]);
		}
	}

	public RuneSupply[] getSupply(SpellBook spell)	{
		return spell.useStaff() ? getSupply(spell.staff(), spell): getSupply(null, spell);
	}
	
	public int getLowest(Integer...amountArray)	{
		int lowest = amountArray[0];
		for (int amount: amountArray)	{
			if (amount < lowest)
				lowest = amount;
		}
		return lowest;
	}
	
	private int getCastAmount(RuneSupply...supplies)	{
		List<Integer> amount = new ArrayList<Integer>();
		
		if (!this.contains(supplies))	return -1;
		else{
			for (RuneSupply supply: supplies)	{
				int currentAmount = (int) inventory.getAmount(supply.rune().toString());
				amount.add(currentAmount / supply.amount());
			}
			
			Integer[] amountArray = amount.toArray(new Integer[amount.size()]);
			return this.getLowest(amountArray);
		}
	}
	
	public int getCastAmount(SpellBook spell)	{			
		if (spell.useStaff())
			return getCastAmount(spell.staff(), spell);
		else{
			RuneSupply[] supplies = getSupply(spell);
			return getCastAmount(supplies);
		}
	}
	
	public int getCastAmount(Staff staff, SpellBook spell)	{
		if (staff == null || !spell.useStaff())	
			return getCastAmount(spell);
		else{
			if (!this.isWearingStaff(staff))
				return -2;
			else{
				RuneSupply[] supplies = this.getSupply(staff, spell);
				return getCastAmount(supplies);
			}
		}
	}
	
	public Spell getSpell(SpellBook spell)	{
		return Spell.valueOf(spell.variableName());
	}	
} 

 

Change log:

  • 10/30:
  • Renamed it,
  • extends MethodProvider, so i dont have to create a script instance,
  • re-orded rune supply constructor, made it easier to read.
  •  
  • 8/15 (check second page for more details):
  • rename spell variables,
  • rename staff variable,
  • add in new staffs,
  • add in two new methods,
  •  
  • 8/13:
  • rename MagicSupply into RuneSupply
  • change RuneSupply constuctor, into (int, Rune)
  • removed staff type class,
  • shorten down staff enum,
  • revamped up my methods,
  • removed acient and lunar until i actually add them in.
  •  
  • 6/15:
  • Did some renaming of classes and enums
  • Remove the element enum <-- redundant
  • Add in a new ItemSupply class which isnt fully supported. Example: Teleport to ape toll, you need bananas.
  •  
  • 5/15:
  • initial release
Edited by josedpay
  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

 

Currently supports:

  • Most staffs
  • Standard spell book
  • Ancient spell book
  • Lunar spell book

 

MagicManager class

package dependencies.magic.manager;

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

import org.osbot.rs07.api.ui.EquipmentSlot;
import org.osbot.rs07.script.Script;

public class MagicManager {

	private Script script;
	
	public MagicManager(Script script)	{
		this.script = script;
	}
	
	public static enum Rune	{
		STEAM, MIST, MUD, LAVA, SMOKE, DUST,
		EARTH, FIRE, WATER, AIR, ASTRAL, BLOOD, 
		BODY, CHAOS, COSMIC, DEATH, LAW, MIND, NATURE, SOUL;
		
		@Override
		public String toString() {
			return super.name().toLowerCase() +" rune";
		}
		
	}
	
	public interface StaffType	{
		public Rune[] runes();
	}
	
	public static enum Staff implements StaffType	{
		STAFF_OF_AIR(Rune.AIR),
		STAFF_OF_EARTH(Rune.EARTH),
		STAFF_OR_WATER(Rune.WATER),
		STAFF_OF_FIRE(Rune.FIRE),
		
		AIR_BATTLESTAFF(Rune.AIR),
		EARTH_BATTLESTAFF(Rune.EARTH),
		WATER_BATTLESTAFF(Rune.WATER),
		FIRE_BATTLESTAFF(Rune.FIRE),
		LAVA_BATTLESTAFF(Rune.LAVA, Rune.EARTH, Rune.FIRE),
		MUD_BATTLESTAFF(Rune.MUD, Rune.WATER, Rune.EARTH),
		STEAM_BATTLESTAFF(Rune.STEAM, Rune.WATER, Rune.FIRE),
		SMOKE_BATTLESTAFF(Rune.SMOKE, Rune.AIR, Rune.FIRE),
		
		MYSTIC_AIR_STAFF(Rune.AIR),
		MYSTIC_WATER_STAFF(Rune.WATER),
		MYSTIC_EARTH_STAFF(Rune.EARTH),
		MYSTIC_FIRE_STAFF(Rune.FIRE),
		MYSTIC_LAVA_STAFF(Rune.LAVA, Rune.EARTH, Rune.FIRE),
		MYSTIC_MUD_STAFF(Rune.MUD, Rune.WATER, Rune.EARTH),
		MYSTIC_STEAM_STAFF(Rune.STEAM, Rune.WATER, Rune.FIRE),
		MYSTIC_SMOKE_BATTLESTAFF(Rune.SMOKE, Rune.AIR, Rune.FIRE),
		
		GUTHIX_SATFF, 
		SARADOMIN_STAFF, 
		ZAMORAK_STAFF,
		
		AHRIMS_STAFF,
		ANCIENT_STAFF, 
		LUNAR_STAFF,
		IBAN1S_STAFF,
		SLAYER1S_STAFF,
		TRIDENT_OF_THE_SEAS,
		STAFF_OF_DEAD;

		private Rune[] runes;
			
		Staff(Rune...runes){
			this.runes = runes;
		}
		
		@Override
		public Rune[] runes() {
			return runes != null ? runes: null;
		}
		
		@Override
		public String toString()	{
			String newName = super.name().replace("1", " ");
			return newName.replace("_", " ");
		}
	}
	
	public static class MagicSupply	{
		
		private Rune rune;
		private int amount;
		
		public MagicSupply(Rune rune, int amount)	{
			this.rune = rune;
			this.amount = amount;
		}
				
		public Rune rune()	{
			return this.rune;
		}
		
		public int amount()	{
			return this.amount;
		}
	}

	public static class ItemSupply	{
		
		private String name;
		private int amount;
		
		public ItemSupply(String name, int amount)	{
			this.name = name;
			this.amount = amount;
		}
		
		@Override
		public String toString()	{
			return this.name.toLowerCase();
		}
		
		public int amount(){
			return this.amount;
		}
	}
	
	public static interface SpellBook	{
		public boolean useStaff();
		public Staff staff();
		public boolean useItem();
		public ItemSupply itemSupply();
		public MagicSupply[] magicSupply();
	}

	public static enum Standard	implements SpellBook	{
		WIND_STRIKE(new MagicSupply(Rune.AIR, 1), new MagicSupply(Rune.MIND, 1)),
		WATER_STRIKE(new MagicSupply(Rune.AIR, 1), new MagicSupply(Rune.MIND, 1), new MagicSupply(Rune.WATER, 1)),
		EARTH_STRIKE(new MagicSupply(Rune.AIR, 1), new MagicSupply(Rune.MIND, 1), new MagicSupply(Rune.EARTH, 2)),
		FIRE_STRIKE(new MagicSupply(Rune.AIR, 1), new MagicSupply(Rune.MIND, 1), new MagicSupply(Rune.FIRE, 3)),
			
		WIND_BOLT(new MagicSupply(Rune.AIR, 2), new MagicSupply(Rune.CHAOS, 1)),
		WATER_BOLT(new MagicSupply(Rune.AIR, 2), new MagicSupply(Rune.CHAOS, 1), new MagicSupply(Rune.WATER, 2)),
		EARTH_BOLT(new MagicSupply(Rune.AIR, 2), new MagicSupply(Rune.CHAOS, 1), new MagicSupply(Rune.EARTH, 3)),
		FIRE_BOLT(new MagicSupply(Rune.AIR, 3), new MagicSupply(Rune.CHAOS, 1), new MagicSupply(Rune.FIRE, 4)),

		AIR_BLAST(new MagicSupply(Rune.AIR, 3), new MagicSupply(Rune.DEATH, 1)),
		WATER_BLAST(new MagicSupply(Rune.AIR, 3), new MagicSupply(Rune.DEATH, 1), new MagicSupply(Rune.WATER, 3)),
		EARTH_BLAST(new MagicSupply(Rune.AIR, 3), new MagicSupply(Rune.DEATH, 1), new MagicSupply(Rune.EARTH, 4)),
		FIRE_BLAST(new MagicSupply(Rune.AIR, 3), new MagicSupply(Rune.DEATH, 1), new MagicSupply(Rune.FIRE, 5)),

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

		IBAN_BLAST(Staff.IBAN1S_STAFF, new MagicSupply(Rune.FIRE, 5), new MagicSupply(Rune.DEATH, 1)),
		MAGIC_DART(Staff.SLAYER1S_STAFF, new MagicSupply(Rune.DEATH, 1), new MagicSupply(Rune.MIND, 4)),
		SARADOMIN_STRIKE(Staff.SARADOMIN_STAFF, new MagicSupply(Rune.BLOOD, 2), new MagicSupply(Rune.FIRE, 4), new MagicSupply(Rune.AIR, 4)),
		CLAW_OF_GUTHIX(Staff.GUTHIX_SATFF, new MagicSupply(Rune.BLOOD, 2), new MagicSupply(Rune.FIRE, 1), new MagicSupply(Rune.AIR, 4)),
		FLAMES_OF_ZAMORAK(Staff.ZAMORAK_STAFF, new MagicSupply(Rune.BLOOD, 2), new MagicSupply(Rune.FIRE, 4), new MagicSupply(Rune.AIR, 1)),

		
		//add in spells with item, for example: teleport to ape toll		
		;
		
		private Staff staff;
		private ItemSupply item;
		private MagicSupply[] supplies;
		
		Standard(MagicSupply...supplies)	{
			this.staff = null;
			this.item = null;
			this.supplies = supplies;
		}
		
		Standard(Staff staff, MagicSupply...supplies)	{
			this.staff = staff;
			this.item = null;
			this.supplies = supplies;
		}
		
		@Deprecated
		Standard(ItemSupply item, MagicSupply...supplies)	{
			this.staff = null;
			this.item = item;
			this.supplies = supplies;
		}
		
		@Override
		public boolean useStaff() {
			return this.staff != null;
		}

		@Override
		public Staff staff() {
			return useStaff() ? this.staff: null;
		}

		@Override
		public boolean useItem() {
			return this.item != null;
		}

		@Override
		public ItemSupply itemSupply() {
			return this.item != null ? this.item: null;
		}
		
		@Override
		public MagicSupply[] magicSupply() {
			return this.supplies;
		}
		
		@Override
		public String toString()	{
			return super.name().replace("_", " ").toLowerCase();
		}
	}

	public static enum Ancient implements SpellBook	{
		;

		private Staff staff;
		private ItemSupply item;
		private MagicSupply[] supplies;

		@Override
		public boolean useStaff() {
			return this.staff != null;
		}

		@Override
		public Staff staff() {
			return useStaff() ? this.staff: null;
		}

		@Override
		public boolean useItem() {
			return this.item != null;
		}

		@Override
		public ItemSupply itemSupply() {
			return this.item != null ? this.item: null;
		}
		
		@Override
		public MagicSupply[] magicSupply() {
			return this.supplies;
		}
		
		@Override
		public String toString()	{
			return super.name().replace("_", " ").toLowerCase();
		}
	}
	
	public static enum Lunar implements SpellBook	{
		;

		private Staff staff;
		private ItemSupply item;
		private MagicSupply[] supplies;

		@Override
		public boolean useStaff() {
			return this.staff != null;
		}

		@Override
		public Staff staff() {
			return useStaff() ? this.staff: null;
		}

		@Override
		public boolean useItem() {
			return this.item != null;
		}

		@Override
		public ItemSupply itemSupply() {
			return this.item != null ? this.item: null;
		}
		
		@Override
		public MagicSupply[] magicSupply() {
			return this.supplies;
		}
		
		@Override
		public String toString()	{
			return super.name().replace("_", " ").toLowerCase();
		}		
	}

	public boolean isWearingStaff(StaffType staff)	{
		return script.equipment.isWearingItem(EquipmentSlot.WEAPON, staff.toString());
	}
	
	public boolean contains(MagicSupply supply)	{
		return script.inventory.contains(supply.rune().toString())
				&& script.inventory.getAmount(supply.rune().toString()) >= supply.amount();
	}
	
	public boolean contains(MagicSupply...supplies)	{
		for (MagicSupply supply: supplies)
			if (!this.contains(supply))
				return false;
		return true;
	}

	public MagicSupply[] getSupply(SpellBook spell)	{
		return spell.useStaff() ? this.getSupply(spell.staff(), spell): spell.magicSupply();
	}
	
	public MagicSupply[] getSupply(StaffType staff, SpellBook spell)	{
		if (!this.isWearingStaff(staff)) 
			return null;
		else{
			List<Rune> runeList = new ArrayList<Rune>();
			List<MagicSupply> supplyList = new ArrayList<MagicSupply>();

			for (Rune rune: staff.runes())	{
				runeList.add(rune);
			}
			
			for (MagicSupply supply: spell.magicSupply())	{
				if (!runeList.contains(supply.rune()))	{
					supplyList.add(supply);
				}
			}
			
			return supplyList.toArray(new MagicSupply[supplyList.size()]);
		}
	}

	public int getLowest(Integer...amountArray)	{
		int lowest = amountArray[0];
		for (int amount: amountArray)	{
			if (amount < lowest)
				lowest = amount;
		}
		return lowest;
	}
	
	public int getCastAmount(SpellBook spell)	{
		List<Integer> amount = new ArrayList<Integer>();

		if (spell.useStaff())
			return this.getCastAmount(spell.staff(), spell);
		else{

			MagicSupply[] supplies = this.getSupply(spell);
			
			if (!this.contains(supplies))
				return -1;
			else{
				for (MagicSupply supply: supplies)	{
					int currentAmount = (int) script.inventory.getAmount(supply.rune().toString());
					amount.add(currentAmount / supply.amount());
				}
				
				Integer[] amountArray = amount.toArray(new Integer[amount.size()]);
				return this.getLowest(amountArray);
			}		
		}
	}
	
	public int getCastAmount(StaffType staff, SpellBook spell)	{
		List<Integer> amount = new ArrayList<Integer>();
		
		if (!this.isWearingStaff(staff))
			return -2;
		else{
			MagicSupply[] supplies = this.getSupply(staff, spell);
			
			if (!this.contains(supplies))
				return -1;
			else{
				for (MagicSupply supply: supplies)	{
					int currentAmount = (int) script.inventory.getAmount(supply.rune().toString());
					amount.add(currentAmount / supply.amount());
				}
				
				Integer[] amountArray = amount.toArray(new Integer[amount.size()]);
				return this.getLowest(amountArray);
			}
		}
	}


}

 

i was able to fix the problem i was having with this snippet. If someone would be glad to lend me an account that supports ancient or lunar i could easily add that in.

 

Change log:

  • Did some renaming of classes and enums
  • Remove the element enum <-- redundant
  • Add in a new ItemSupply class which isnt fully supported. Example: Teleport to ape toll, you need bananas.

 

 

very nice,

Do you need the data of lunar and ancient spellbook? 

Just hit me up on skype ;)

 

You might want to add.

if a certain spellbook is selected or not (standard,ancient,lunars)

 

 

Khaleesi,

  • Like 1
Link to comment
Share on other sites

very nice,

Do you need the data of lunar and ancient spellbook? 

Just hit me up on skype ;)

 

You might want to add.

if a certain spellbook is selected or not (standard,ancient,lunars)

 

 

Khaleesi,

That's on the todo list, I'll hit you up soon, I have other things a bit more important, but I will comeback and update it soon

Link to comment
Share on other sites

  • 1 month later...

Thanks, saves me some time with spell rune requirements :)

You've missed wands btw. They basically act the same as staves.

Also, the StaffType interface seems quite redundant

I'll add in wands, but staff type interface may seem redundant but I added it in, so let say you wanted to create your own staff enum and allow user to choose the staff they want on your GUI. Rather then having my long enum of staff, you simply implement the interface, and now your still able to use the magic manager methods. Just like I use to do it on my construction script.

I going to update this snippet soon

Edited by josedpay
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...