Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.genchant;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.io.IOException;
- import java.net.URL;
- import javax.imageio.ImageIO;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Mouse;
- import org.tribot.api.util.ABCUtil;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.GameTab;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.Magic;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Skills.SKILLS;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- @ScriptManifest(authors = { "Genka" }, category = "Magic", name = "GEnchant")
- public class main extends Script implements Painting{
- private ABCUtil abc = new ABCUtil();
- public static boolean alive = false;
- private int startXp = Skills.getXP(SKILLS.MAGIC);
- public static String spell = "";
- public static int itemToEnchant = 1639;
- private int cosmicID = 564;
- @Override
- public void run() {
- GUI.handleGui();
- while(!alive){
- sleep(300);
- }
- General.useAntiBanCompliance(true);
- while(alive){
- if(Inventory.getCount(itemToEnchant) == 0 || Inventory.getCount(cosmicID) == 0){
- bank();
- } else {
- if(Banking.isBankScreenOpen()){
- Banking.close();
- } else {
- enchant();
- abc.performTimedActions(SKILLS.MAGIC);
- }
- }
- sleep(10, 50);
- }
- }
- private void enchant(){
- if(!Magic.isSpellSelected()){
- Magic.selectSpell(spell);
- abc.waitNewOrSwitchDelay(System.currentTimeMillis(), true);
- } else {
- RSItem[] item = Inventory.find(itemToEnchant);
- if(item.length > 0 && Magic.getSelectedSpellName().equals(spell) && GameTab.getOpen().equals(TABS.INVENTORY)){
- item[0].click("Cast");
- abc.waitNewOrSwitchDelay(System.currentTimeMillis(), true);
- } else if (item.length > 0 && Magic.getSelectedSpellName().equals(spell) && !GameTab.getOpen().equals(TABS.INVENTORY)){
- fixStuck();
- }
- if(!Magic.getSelectedSpellName().equals(spell)){
- Mouse.click(1);
- }
- }
- }
- private void bank(){
- if(!Banking.isBankScreenOpen()){
- if(Magic.isSpellSelected()){
- Mouse.click(1);
- } else {
- Banking.openBank();
- }
- } else {
- if(Inventory.getCount(cosmicID) == 0){
- if(Inventory.getAll().length == 28){
- Banking.depositAll();
- abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
- } else {
- withDraw(cosmicID, 1000, "Cosmic runes");
- }
- } else if (Inventory.getCount(itemToEnchant) == 0){
- if(Inventory.getAll().length > 1){
- Banking.depositAllExcept(cosmicID);
- abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
- } else {
- withDraw(itemToEnchant, 0, "items to enchant");
- abc.waitNewOrSwitchDelay(System.currentTimeMillis(), false);
- }
- }
- }
- }
- private void fixStuck(){
- long t = System.currentTimeMillis();
- while(!GameTab.getOpen().equals(TABS.INVENTORY) && Timing.timeFromMark(t) < 1500){
- sleep(10,150);
- }
- if (Magic.getSelectedSpellName().equals(spell) && !GameTab.getOpen().equals(TABS.INVENTORY)){
- Mouse.click(1);
- }
- }
- private void withDraw(int itemID, int amount, String itemName){
- if(bankIsLoaded()){
- RSItem[] item = Banking.find(itemID);
- if(item.length > 0){
- Banking.withdraw(amount, itemID);
- } else {
- stopScript("Out of " + itemName);
- }
- }
- }
- private void stopScript(String message){
- println(message);
- Banking.close();
- Login.logout();
- alive = false;
- }
- private boolean bankIsLoaded(){
- if(Banking.isBankScreenOpen()){
- if(Banking.getAll().length > 0){
- return true;
- }
- }
- return false;
- }
- //START: Code generated using Enfilade's Easel
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch(IOException e) {
- return null;
- }
- }
- private final Color color1 = new Color(255, 255, 255);
- private final Font font1 = new Font("Arial", 0, 10);
- private final Image img1 = getImage("http://i.imgur.com/zwBUJ0i.png");
- public void onPaint(Graphics g1) {
- double multiplier = getRunningTime() / 3600000.0D;
- int xpPerHour = (int) ((Skills.getXP(SKILLS.MAGIC) - startXp) / multiplier);
- Graphics2D g = (Graphics2D)g1;
- g.drawImage(img1, 277, 345, null);
- g.setFont(font1);
- g.setColor(color1);
- g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
- g.drawString("Magic level: " + Skills.getActualLevel(SKILLS.MAGIC), 366, 421);
- g.drawString("XP: " + (Skills.getXP(SKILLS.MAGIC) - startXp) + " (" + xpPerHour + ")", 366, 433);
- }
- //END: Code generated using Enfilade's Easel
- }
Add Comment
Please, Sign In to add comment