All pastes #1530019 Raw Edit

AlKharid Smelter

public text v1 · immutable
#1530019 ·published 2009-08-14 23:25 UTC
rendered paste body
/*
Credits goes to Apples from KBot.
Redistribution is not permitted without consent from author.
Enjoy the script and post any issues you get while running the script.
*/

package com.scripts;

import com.kbot2.handlers.eventSystem.eventListeners.PaintListener;
import com.kbot2.handlers.eventSystem.eventListeners.ServerMessageListener;
import com.kbot2.scriptable.Script;
import com.kbot2.scriptable.methods.data.Skills;
import com.kbot2.scriptable.methods.data.GameScreen;
import com.kbot2.scriptable.methods.wrappers.Interface;
import com.kbot2.scriptable.methods.wrappers.Tile;
import com.kbot2.scriptable.methods.wrappers.Obj;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AlKharidSmelter extends Script implements PaintListener, ServerMessageListener {

	String[] strings = { "AlKharid Smelter", "Apples", "Smithing", "Loading...", "Bronze", "Blurite", "Iron", "Silver", "Steel", "Gold", "Mithril", "Adamantite", "Runite", "Smith", "AlKharid", "Start inside AlKharid bank and choose the bar\nyour smelting.", "Copper", "Tin", "Coal" };
	String[][] Strings;
	boolean[] booleans = { true, false, false, false, false };
	int[] ints = { -1, 0, -1, -1, 0, 35647, 0, 11666 };
	int[][] Ints;
	long[] longs = { 0L, 0L };

	Tile[] TO_BANK = new Tile[]{ new Tile(3274, 3186), new Tile(3276, 3185), new Tile(3279, 3185), new Tile(3279, 3183), new Tile(3279, 3180), new Tile(3279, 3175), new Tile(3277, 3173), new Tile(3276, 3171), new Tile(3273, 3167), new Tile(3269, 3167) };
	Tile[] TO_SMELT = walking.reversePath(TO_BANK);

	public boolean active() {
		return booleans[0];
	}

	public String getName() {
		return strings[0];
	}

	public String getAuthor() {
		return strings[1];
	}

	public String getCatergory() {
		return strings[2];
	}

	public double getVersion() {
		return 2.001;
	}

	public String getDescription() {
		return strings[15];
	}

	public String[] getTags() {
		return new String[] { strings[1], strings[13], strings[14] };
	}

	public boolean onStart() {
		final JFrame j = new JFrame("AlKharid Smelt Options");
		j.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.BOTH;
		c.anchor = GridBagConstraints.ABOVE_BASELINE_LEADING;
		c.gridx = 1;
		c.gridy = 1;
		c.gridheight = 1;
		c.gridwidth = 1;
		final JComboBox barType = new JComboBox(new String[]{ strings[4], strings[5], strings[6], strings[7], strings[8], strings[9], strings[10], strings[11], strings[12] });
		Strings = new String[][]{ { strings[16], strings[17] }, { strings[5] }, { strings[6] }, { strings[7] }, { strings[6], strings[18] }, { strings[9] }, { strings[10], strings[18] }, { strings[11], strings[18] }, { strings[12], strings[18] } };
		Ints = new int[][]{ { 436, 438, 14, 14, 10, 10, 2349, 16, 35, 99 }, { -99, -1, 99, -1, 999, -1, -1, 20, 86, 99 }, { 440, -1, 99, -1, 999, -1, 2351, 24, 137, 99 }, { 442, -1, 99, -1, 999, -1, 2355, 28, 188, 99 }, { 440, 453, 10, 18, 5, 10, 2353, 32, 239, 10 }, { 444, -1, 99, -1, 999, -1, 2357, 36, 290, 99 }, { 447, 453, 5, 20, 10, 10, 2359, 40, 342, 5 }, { 449, 453, 5, 24, 10, 10, 2361, 44, 395, 5 }, { 451, 453, 5, 24, 10, 10, 2363, 48, 448, 5 } };
		j.add(barType, c);
		c.gridy = 2;
		JButton startButton = new JButton("Start Smelting");
		startButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				for(int i = 0; i < 2; i++)
					longs[i] = System.currentTimeMillis();
				ints[0] = 0;
				ints[2] = skills.getExperience(Skills.SKILL_SMITHING);
				ints[3] = skills.getLevel(Skills.SKILL_SMITHING);
				ints[4] = barType.getSelectedIndex();
				j.setAlwaysOnTop(false);
				j.setVisible(false);
			}
		});
		j.add(startButton, c);
		j.pack();
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
		Point p = new Point((int) d.getWidth()/2 - 200, (int) d.getHeight()/2 - 200);
		j.setResizable(false);
		j.setLocation(p);
		j.setVisible(true);
		j.setAlwaysOnTop(true);
		return true;
	}

	public void onStop() {
		gameScreen.takeScreenshot("AlKharidSmelter", true);
	}

	public void isCollectionOpen() {
		Interface geInterface = interfaces.getInterface(109, 13);
		while(geInterface != null && geInterface.isValid()) {
			geInterface.doClick();
			sleep(415, 732);
		}
	}

	public boolean isInArea(int x1, int x2, int y1, int y2) {
		return ((getMyPlayer().getLocation().getY() >= y1) && (getMyPlayer().getLocation().getY() <= y2) && (getMyPlayer().getLocation().getX() <= x1) && (getMyPlayer().getLocation().getX() >= x2));
	}

	public int antiBan() {
		if (System.currentTimeMillis() - longs[1] > 10000) {
			longs[1] = System.currentTimeMillis();
			switch(random(0, 37)) {
				default:
				case 0:
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 7:
				case 8:
				case 9:
				case 10:
				case 11:
				case 12:
				case 13:
				case 14:
					if (!booleans[4] && isLoggedIn()) {
						gameScreen.openTab(GameScreen.TAB_STATS);
						sleep(500,700);
						mouse.moveMouse(random(665, 710), random(261, 284));
						sleep(2200, 2800);
						gameScreen.openTab(GameScreen.TAB_INVENTORY);
						booleans[4] = true;
					}
					break;
				case 15:
				case 16:
				case 17:
				case 18:
				case 19:
				case 20:
				case 21:
				case 22:
				case 23:
				case 24:
				case 25:
					camera.setAngle(camera.getAngle() + random(-90, 90));
					break;
				case 26:
				case 27:
				case 28:
				case 29:
				case 30:
				case 31:
					mouse.moveMouse(random(41, 644), random(115, 452));
					break;
				case 32:
				case 33:
				case 34:
				case 35:
				case 36:
				case 37:
					break;
			}
		}
		return random(221, 513);
	}
	
	public int bank() {
		if (bank.isOpen() && inventory.getCount() < 4) {
			if (Ints[ints[4]][1] != -1)
				if (bank.contains(Ints[ints[4]][1]))
					//if (random(1, 25)== 5 && Ints[ints[4]][5] != -1)
					//	bank.withdrawItem(436, 10);
					//else
						bank.withdrawItem(Ints[ints[4]][1], Ints[ints[4]][3]);
				else {
					log("No " + Strings[ints[4]][1]);
					while (isLoggedIn()) {
						setMouseSpeed((random(226135, 233456) / 1000000));
						bank.close();
						gameScreen.logout();
						sleep(511, 711);
						booleans[0] = false;
					}
				}
			if (Ints[ints[4]][0] != -1)
				if (bank.contains(Ints[ints[4]][0]))
					//if (random(1, 25)== 5 && Ints[ints[4]][4] != -1)
					//	bank.withdrawItem(436, 10);
					//else
						bank.withdrawItem(Ints[ints[4]][0], Ints[ints[4]][2]);
				else {
					log("No " + Strings[ints[4]][0]);
					while (isLoggedIn()) {
						setMouseSpeed((random(226135, 233456) / 1000000));
						bank.close();
						gameScreen.logout();
						sleep(513, 721);
						booleans[0] = false;
					}
				}
			ints[0] = 2;
			booleans[4] = false;
			booleans[1] = false;
			return random(722, 813);
		} else if (bank.isOpen() && inventory.getCount() > 3) {
			if (!inventory.contains(Ints[ints[4]][6]) && inventory.contains(Ints[ints[4]][0]) && inventory.contains(Ints[ints[4]][1])) {
				ints[0] = 2;
				return random(722, 817);
			}
			strings[3] = "Depositing";
			if (random(1, 10) == 4) {
				mouse.moveMouse(random(568, 593), random(220, 240));
				sleep(111, 223);
				mouse.clickMouse(false);
				menu.atMenu("Deposit-All");
			} else {
				mouse.moveMouse(random(383, 411), random(300, 315));
				sleep(111, 223);
				mouse.clickMouse(true);
			}
			return(random(717, 922));
		} else if (isInArea(3272, 3269, 3161, 3173) && inventory.getCount() > -1) {
			if (!inventory.contains(Ints[ints[4]][6]) && (inventory.contains(Ints[ints[4]][0]) || Ints[ints[4]][0] == -1) && (inventory.contains(Ints[ints[4]][1]) || Ints[ints[4]][1] == -1)) {
				ints[0] = 2;
				return random(722, 813);
			}
			strings[3] = "Banking";
			Obj b = objects.getClosestObject(5, ints[5]);
			if (b != null) {
				b.doAction("quickly");
				isCollectionOpen();
			}
			return random(553, 803);
		}
		return random(546, 807);
	}

	public int Walk() {
		if (isInArea(3272, 3269, 3161, 3173))
			if ((inventory.contains(Ints[ints[4]][0]) || Ints[ints[4]][0] == -1) && (inventory.contains(Ints[ints[4]][1]) || Ints[ints[4]][1] == -1))
				//walking.WalkPath(3274, 3186);
				walking.walkPath(walking.randomizePath(TO_SMELT, 1, 1));
			else
				ints[0] = 1;
		else if (isInArea(3279, 3272, 3184, 3188))
			if ((inventory.contains(Ints[ints[4]][0]) || Ints[ints[4]][0] == -1) && (inventory.contains(Ints[ints[4]][1]) || Ints[ints[4]][1] == -1))
				ints[0] = 3;
			else
				//walking.WalkPath(3269, 3167);
				walking.walkPath(walking.randomizePath(TO_BANK, 2, 2));
		return random(611, 909);
	}

	public int Smelt() {
		if ((skills.getLevel(Skills.SKILL_SMITHING) - ints[3]) > ints[6]) {
			ints[6]++;
			gameScreen.openTab(GameScreen.TAB_STATS);
			sleep(507, 713);
			mouse.moveMouse(random(665, 710), random(261, 284));
			sleep(118, 213);
			mouse.clickMouse(true);
			sleep(3626, 5461);
			mouse.moveMouse(random(440, 460), random(40, 60));
			sleep(118, 213);
			mouse.clickMouse(true);
			sleep(118, 213);
			gameScreen.openTab(GameScreen.TAB_INVENTORY);
			booleans[1] = false;
			return random(535, 711);
		}
		if ((booleans[2]) || (!inventory.contains(Ints[ints[4]][0]) && Ints[ints[4]][0] != -1) || (!inventory.contains(Ints[ints[4]][1]) && Ints[ints[4]][1] != -1)) {
			ints[0] = 4;
			booleans[1] = false;
			booleans[2] = false;
			return random(632, 914);
		}
		if ((random(0, 2) == 1) && booleans[1])
			return antiBan();
		while (!booleans[1]) {
			Obj f = objects.getClosestObject(5, ints[7]);
			Point p = f.getScreenPos();
			mouse.clickMouse(p, 5, 5, true);
			sleep(937, 1153);
			Interface smelter = interfaces.getInterface(311, Ints[ints[4]][7]);
			while (smelter != null && !booleans[1]) {
				mouse.moveMouse(Ints[ints[4]][8] + random(1, 35), random(400, 425));
				mouse.clickMouse(false);
				sleep(213, 387);
				if (Ints[ints[4]][9] == 5 || Ints[ints[4]][9] == 10)
					if (Ints[ints[4]][9] == 5)
						if (random(1, 20)== 5)
							smelter.doAction("Smelt 10");
						else
							smelter.doAction("Smelt 5");
					else
						if (random(1, 20) == 5) {
							smelter.doAction("Smelt 5");
							return random(50, 100);
						} else
							smelter.doAction("Smelt 10");
				else {
					sleep(77, 99);
					if (random(1, 20) == 3)
						keyboard.sendKeys("099", true);
					else if (random(1, 20) == 3)
						keyboard.sendKeys("88", true);
					else
						keyboard.sendKeys("99", true);
				}
				sleep(2897, 3213);
			}
		}
		return random(223, 533);
	}

	public int loop() {
		setMouseSpeed((random(1903544, 2231631) / 1000000));
		if (ints[0] > -1 && !getMyPlayer().isMoving()) {
			if (isInArea(3264, 3258, 3160, 3174) || isInArea(3282, 3281, 3158, 3178))
				walking.walkToMM(new Tile(3271, 3167));
			else if (isInArea(3270, 3263, 3178, 3187))
				walking.walkToMM(new Tile(3275, 3186));
			switch (ints[0]) {
				case 0:
					if (isInArea(3272, 3269, 3161, 3173))
						ints[0] = 1;
					else if (isInArea(3279, 3272, 3184, 3188))
						ints[0] = 3;
					else {
						log("Did not Recongize start area - Shutting Down");
						while (isLoggedIn()) {
							setMouseSpeed((random(226135, 233456) / 1000000));
							gameScreen.logout();
							booleans[0] = false;
						}
					}
					camera.setAltitude(true);
					return random(123, 297);

				case 1:
					strings[3] = "Banking";
					return bank();

				case 2:
					strings[3] = "Walking to Furnace";
					return Walk();

				case 3:
					strings[3] = "Smelting";
					return Smelt();

				case 4:
					strings[3] = "Walking to Bank";
					return Walk();
			}
		}
		return random(112, 331);
	}

	public void onServerMessage(String s) {
		if (s.contains("retrieve")) {
			ints[1]++;
			booleans[1] = true;
		} else if (s.contains("any more") || s.contains("to make") || s.contains("to smelt"))
			booleans[2] = true;
	}

	public void onRepaint(Graphics g) {
		if (ints[0] > -1) {
			long runTime = System.currentTimeMillis() - longs[0];
			int secs = ((int) ((runTime / 1000) % 60));
			int mins = ((int) (((runTime / 1000) / 60) % 60));
			int hours = ((int) ((((runTime / 1000) / 60) / 60) % 60));
			int x = 5;
			int y = 191;
			g.setColor(new Color(0, 0, 100, 100));
			g.fill3DRect(x, y, 185, 100, true);
			x += 5;
			y += 15;
			g.setColor(Color.WHITE);
			g.setFont(new Font("Comic Sans", Font.ITALIC, 15));
			g.drawString(getName() + " v" + getVersion(), x, y);
			y += 18;
			g.setFont(new Font("Comic Sans", Font.PLAIN, 12));
			g.drawString("Status: " + strings[3], x, y);
			y += 12;
			g.drawString("Run time: " + (hours < 10 ? "0" : "") + hours + ":" + (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "") + secs, x, y);
			y += 12;
			g.drawString(strings[ints[4] + 4] + " Bars Smelted: " + ints[1], x, y);
			y += 12;
			g.drawString("Experience gained: " + (skills.getExperience(Skills.SKILL_SMITHING) - ints[2]), x, y);
			y += 12;
			g.drawString("Next level: " + (skills.getExperienceToNextLevel(Skills.SKILL_SMITHING)), x, y);
			y += 12;
			g.drawString("Levels gained: " + (skills.getLevel(Skills.SKILL_SMITHING) - ints[3]), x, y);
		}
	}
}