Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.methods.Bank;
- import org.rsbot.script.util.Timer;
- import org.rsbot.script.wrappers.*;
- import java.awt.*;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.util.ArrayList;
- /**
- * Created by IntelliJ IDEA.
- * User: Tyler Janca
- * Date: Jan 23, 2011
- * Time: 5:34:36 PM
- */
- @ScriptManifest(authors = "Janca", name = "Ash Collector V2", version = 1.666)
- public class AshCollector extends Script implements PaintListener, MouseMotionListener, MouseListener {
- int maxAreaDistance = 30, ashID = 592, fireID = 2732, ashCollected, ashMPrice, flag, invent = 0, failPickup = 0;
- RSPath walkingPath;
- RSTile startingTile;
- RSArea startingArea;
- AshCollectorPaint paint = new AshCollectorPaint();
- ScriptMethods methods = new ScriptMethods();
- Thread p;
- Point mousePoint = new Point(-1, -1);
- boolean scriptStopping = false, didClick = false;
- ArrayList<ColorButton> colorButtons = new ArrayList<ColorButton>();
- ArrayList<MouseEffects> effects = new ArrayList<MouseEffects>();
- RSTile newLocation = null;
- Color colors[];
- long startTime = -1;
- public boolean onStart() {
- if (!game.isLoggedIn()) {
- log.warning("You MUST be fully logged in before starting this script!");
- return false;
- }
- methods.createColorButtons();
- p = new Thread(paint);
- p.start();
- startTime = System.currentTimeMillis();
- startingTile = getMyPlayer().getLocation();
- startingArea = new RSArea(new RSTile(startingTile.getX() - maxAreaDistance, startingTile.getY() - maxAreaDistance),
- new RSTile(startingTile.getX() + maxAreaDistance, startingTile.getY() + maxAreaDistance));
- return true;
- }
- public int loop() {
- try {
- if (bank.isOpen() && inventory.getCount() == 0) {
- if (bank.close()) {
- Timer fs = new Timer(5000);
- while (fs.isRunning() && bank.isOpen()) sleep(120);
- if (bank.isOpen())
- return 120;
- }
- }
- if (failPickup > 5) {
- if (newLocation == null) {
- RSGroundItem items[] = groundItems.getAll();
- int dist = Integer.MIN_VALUE;
- RSTile location = null;
- for (RSGroundItem item : items) {
- RSTile locationTemp = item.getLocation();
- if (calc.distanceTo(locationTemp) > dist && startingArea.contains(locationTemp)) {
- dist = calc.distanceTo(locationTemp);
- location = locationTemp;
- }
- }
- newLocation = (location == null ? methods.nearestBank() : location);
- }
- if (calc.distanceTo(newLocation) > 4) {
- methods.setStatus("Moving to a new location");
- walking.walkTo(newLocation);
- } else {
- newLocation = null;
- failPickup = 0;
- }
- }
- methods.antibanHandler();
- methods.clearInventoryOfUnwantedItems();
- if (inventory.isFull()) {
- if (calc.distanceTo(methods.nearestBank()) >= 4) {
- methods.setStatus("Walking to Bank");
- if (walkingPath == null) {
- walkingPath = walking.getPath(methods.nearestBank());
- } else {
- walkingPath.traverse();
- }
- } else {
- walkingPath = null;
- if (!bank.isOpen()) {
- if (methods.openBank())
- methods.depositAll();
- } else {
- methods.depositAll();
- }
- }
- } else {
- if (!startingArea.contains(getMyPlayer().getLocation())) {
- methods.setStatus("Walking to Start Position");
- if (walkingPath == null) {
- walkingPath = walking.getPath(startingTile);
- } else {
- walkingPath.traverse();
- }
- } else {
- walkingPath = null;
- RSGroundItem temp = methods.getNearestAshPile();
- RSGroundItem ash = (startingArea.contains(temp.getLocation()) && methods.pureAsh(temp.getLocation()) ? temp : null);
- if (ash == null) {
- methods.setStatus("Waiting");
- RSObject temp1 = objects.getNearest(fireID);
- RSObject fire = (startingArea.contains(temp1.getLocation()) ? temp1 : null);
- if (fire == null)
- flag++;
- if (calc.distanceTo(fire) > 1) {
- methods.setStatus("Walking to Fire");
- walking.walkTo(objects.getNearest(fireID).getLocation());
- if (random(0, 20) < 4)
- flag++;
- } else {
- if (random(0, 16) < 10)
- methods.bored();
- }
- return 100;
- }
- if (getMyPlayer().isMoving()) {
- if (ash == null)
- return 200;
- if (calc.distanceTo(walking.getDestination()) <= 3) {
- if (random(0, 20) < 4)
- camera.turnTo(ash.getLocation(), random(0, 25));
- methods.setStatus("Taking Ashes");
- if (random(0, 12) < 8) {
- int inventB4 = inventory.getCount();
- if (ash.doAction("Take")) {
- didClick = true;
- Timer fs = new Timer(3200);
- do sleep(500);
- while (fs.isRunning() && inventB4 == inventory.getCount());
- }
- } else {
- mouse.move(groundItems.getNearest(ashID).getModel().getPoint(), 50, 180);
- }
- return 20;
- }
- } else {
- if (ash == null)
- return 200;
- if (ash.isOnScreen()) {
- methods.setStatus("Taking Ashes");
- int inventB4 = inventory.getCount();
- if (ash.doAction("Take")) {
- didClick = true;
- Timer fs = new Timer(3200);
- do sleep(500);
- while (fs.isRunning() && inventB4 == inventory.getCount());
- }
- } else {
- if (ash == null)
- return 250;
- if (walking.walkTo(ash.getLocation())) {
- methods.setStatus("Walking to Ash");
- Timer fs = new Timer(909);
- while (fs.isRunning()) {
- if (walking.getDestination() != null) {
- if (calc.distanceTo(walking.getDestination()) < 8)
- break;
- } else if (walking.getDestination() == null) {
- break;
- }
- }
- }
- }
- }
- }
- }
- int t = inventory.getCount(ashID);
- if (t > invent) {
- ashCollected += t - invent;
- invent = t;
- if ((failPickup - 2) > 0) failPickup -= 2;
- else if (failPickup > 0) failPickup++;
- } else if (t <= 0) {
- invent = 0;
- } else if (t == invent) {
- if (didClick)
- failPickup++;
- }
- didClick = false;
- } catch (Exception ignore) {}
- return random(520, 950);
- }
- public void onFinish() {
- scriptStopping = true;
- sleep(1200);
- env.saveScreenshot(false);
- sleep(1200);
- }
- public void onRepaint(Graphics g1) {
- Graphics2D g = (Graphics2D) g1;
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- if (game.isLoggedIn())
- paint.paint(g);
- if (scriptStopping) {
- g.setFont(paint.statsBarFont);
- g.setColor(new Color(0, 0, 0, 220));
- g.fillRect(547, 205, 189, 260);
- g.setColor(new Color(0, 0, 0));
- g.drawRect(547, 205, 189, 260);
- int y = 226;
- g.setColor(paint.themeColor);
- drawStringCentered(g, paint.statsBarFont, "Ash Collector :: By Janca", 226);
- drawStringCentered(g, paint.statsBarFont, "Running Time: " + paint.getTimeRunning(), y += 16);
- drawStringCentered(g, paint.statsBarFont, "Ashes Collected: " + ashCollected, y += 16);
- drawStringCentered(g, paint.statsBarFont, "Ashes/Hour: " + (ashCollected > 0
- ? (int) ((ashCollected * 3600000D) / (System.currentTimeMillis() - startTime))
- : "N/A"), y += 16);
- drawStringCentered(g, paint.statsBarFont, "Profit Made: " + (ashCollected * ashMPrice), y += 16);
- drawStringCentered(g, paint.statsBarFont, "Profit/Hour: " + (ashCollected > 0
- ? (int) (((ashCollected * ashMPrice) * 3600000D) / (System.currentTimeMillis() - startTime))
- : "N/A"), y += 16);
- }
- }
- private void drawStringCentered(Graphics2D g, Font font, String string, int y) {
- FontMetrics metrics = g.getFontMetrics(font);
- g.drawString(string, (1285 - metrics.stringWidth(string)) / 2, y);
- }
- public void mouseClicked(MouseEvent e) {
- Rectangle rect = new Rectangle(724, 0, 40, 20);
- if (rect.contains(e.getPoint())) {
- log("You have changed your staring position: " + startingTile.toString());
- startingTile = getMyPlayer().getLocation();
- startingArea = new RSArea(new RSTile(startingTile.getX() - maxAreaDistance, startingTile.getY() - maxAreaDistance),
- new RSTile(startingTile.getX() + maxAreaDistance, startingTile.getY() + maxAreaDistance));
- }
- for (ColorButton colorButton1 : colorButtons) {
- if (colorButton1.onButton(e.getPoint())) {
- for (ColorButton colorButton : colorButtons) {
- if (colorButton.onButton(e.getPoint())) {
- colorButton.setSelected(true);
- paint.themeColor = colorButton.getColor();
- } else {
- colorButton.setSelected(false);
- }
- }
- }
- }
- }
- public void mousePressed(MouseEvent e) {}
- public void mouseReleased(MouseEvent e) {}
- public void mouseEntered(MouseEvent e) {}
- public void mouseExited(MouseEvent e) {}
- public void mouseDragged(MouseEvent e) {}
- int currentIdx = 0;
- Point origPoint = new Point(-1, -1);
- public void mouseMoved(MouseEvent e) {
- if (distanceBetween(origPoint, e.getPoint()) > 5) {
- effects.add(new MouseEffects(e.getX(), e.getY(), currentIdx < colorButtons.size() ? colors[currentIdx++] : colors[(currentIdx = 0)]));
- origPoint = e.getPoint();
- }
- paint.hoverColor = null;
- for (ColorButton colorButton : colorButtons) {
- if (colorButton.onButton(e.getPoint())) {
- if (paint.themeColor != colorButton.getColor())
- paint.hoverColor = colorButton.getColor();
- }
- }
- }
- public int distanceBetween(Point point1, Point point2) {
- return (int) Math.sqrt((point1.getX() - point2.getX()) * (point1.getX() - point2.getX())
- + (point1.getY() - point2.getY()) * (point1.getY() - point2.getY()));
- }
- public class ScriptMethods {
- public void createColorButtons() {
- int x = 0;
- colorButtons.add(new ColorButton(x, 318, new Color(128, 0, 255), true));
- colorButtons.add(new ColorButton(x, 318, new Color(158, 11, 11), false));
- colorButtons.add(new ColorButton(x, 318, new Color(255, 0, 0), false));
- colorButtons.add(new ColorButton(x, 318, new Color(255, 0, 128), false));
- colorButtons.add(new ColorButton(x, 318, new Color(237, 20, 91), false));
- colorButtons.add(new ColorButton(x, 318, new Color(0, 84, 166), false));
- colorButtons.add(new ColorButton(x, 318, new Color(0, 174, 239), false));
- colorButtons.add(new ColorButton(x, 318, new Color(0, 255, 255), false));
- colorButtons.add(new ColorButton(x, 318, new Color(100, 255, 0), false));
- colorButtons.add(new ColorButton(x, 318, new Color(200, 255, 0), false));
- colorButtons.add(new ColorButton(x, 318, new Color(255, 255, 0), false));
- colorButtons.add(new ColorButton(x, 318, new Color(230, 125, 0), false));
- colorButtons.add(new ColorButton(x, 318, new Color(255, 128, 0), false));
- x = 516 - (colorButtons.size() * 21) - 24;
- colors = new Color[colorButtons.size()];
- for (int i = 0; i < colorButtons.size(); i++) {
- colorButtons.get(i).setX(x += 21);
- colors[i] = colorButtons.get(i).getColor();
- }
- }
- public void clearInventoryOfUnwantedItems() {
- RSItem inventItems[] = inventory.getItems();
- for (RSItem item : inventItems) {
- if (item.getID() != ashID && item.getID() != -1 && item != null) {
- mouse.setSpeed(random(8, 14));
- methods.setStatus("Dropping: " + item.getName());
- int inB4 = inventory.getCount();
- if (item.doAction("Drop")) {
- Timer fs = new Timer(2200);
- do sleep(1200);
- while (fs.isRunning() && inB4 == inventory.getCount());
- if (inventory.contains(item.getID()))
- sleep(1200);
- }
- }
- }
- }
- public void antibanHandler() {
- if (random(0, 100) <= 60)
- mouse.setSpeed(random(2, 8));
- if (flag > 7 && random(0, 12) < 8) {
- antiban(random(0, 15));
- flag = 0;
- }
- if (random(0, 30) < 5)
- flag++;
- }
- private void bored() {
- switch (random(0, 10)) {
- case 1:
- case 2:
- case 3:
- setStatus("Being Bored...");
- sleep(120);
- break;
- case 4:
- setStatus("Being Bored...");
- moveCameraRandomly(random(10, 910));
- if (random(0, 12) < 6)
- moveCameraRandomly(random(100, 800));
- if (random(0, 18) < 5)
- moveCameraRandomly(random(10, 800));
- break;
- case 5:
- setStatus("Being Bored...");
- mouse.moveRandomly(120, 800);
- if (random(0, 17) < 9)
- mouse.moveOffScreen();
- if (random(0, 20) < 19)
- mouse.moveRandomly(120, 1200);
- break;
- case 6:
- case 7:
- case 8:
- setStatus("Being Bored...");
- moveCameraRandomly(random(10, 800));
- if (random(0, 12) < 2)
- moveCameraRandomly(random(10, 800));
- if (random(0, 18) < 9)
- moveCameraRandomly(random(500, 1200));
- break;
- case 9:
- setStatus("Being Bored...");
- sleep(120);
- break;
- default:
- setStatus("Being Bored...");
- sleep(120);
- break;
- }
- }
- private void moveCameraRandomly(int timeOut) {
- int lowPosCamAlt = random(75, 100);
- int vertical = random(0, 20) < 15 ? KeyEvent.VK_DOWN : KeyEvent.VK_UP;
- int horizontal = random(0, 20) < 15 ? KeyEvent.VK_LEFT : KeyEvent.VK_RIGHT;
- Timer hold = new Timer(timeOut);
- if (random(0, 20) < 14)
- keyboard.pressKey((char) vertical);
- if (random(0, 20) < 14)
- keyboard.pressKey((char) horizontal);
- while (hold.isRunning()) {
- if (camera.getPitch() < lowPosCamAlt)
- keyboard.releaseKey((char) vertical);
- sleep(10);
- }
- keyboard.releaseKey((char) horizontal);
- keyboard.releaseKey((char) vertical);
- }
- private void antiban(int switchNumber) {
- switch (switchNumber) {
- case 0:
- setStatus("Mouse Moving Off-Screen");
- mouse.moveOffScreen();
- break;
- case 1:
- case 2:
- case 3:
- setStatus("Moving Camera");
- camera.setAngle(random(0, 450));
- break;
- case 4:
- setStatus("Meddling with Camera");
- camera.setPitch(true);
- camera.setCompass(random(0, 12) < 6 ? 'n' : 's');
- mouse.moveSlightly();
- break;
- case 5:
- setStatus("Hovering Nearest Player");
- RSPlayer playersAroundUs[] = players.getAll();
- RSPlayer nearestPlayer = null;
- int nearest = 1000;
- for (RSPlayer player : playersAroundUs) {
- if (!player.equals(getMyPlayer())) {
- if (calc.distanceTo(player) < nearest) {
- nearest = calc.distanceTo(player);
- nearestPlayer = player;
- }
- }
- }
- if (nearestPlayer != null) {
- if (nearestPlayer.isOnScreen()) {
- mouse.click(nearestPlayer.getModel().getPoint(), false);
- sleep(500, 2300);
- }
- }
- mouse.moveSlightly();
- mouse.moveSlightly();
- break;
- case 6:
- setStatus("Adjusting Mouse Speed");
- mouse.setSpeed(random(6, 14));
- break;
- case 7:
- case 8:
- case 9:
- case 10:
- setStatus("Moving Mouse");
- mouse.moveRandomly(120, 510);
- break;
- default:
- setStatus("Pausing Briefly");
- mouse.moveOffScreen();
- sleep(120, 5000);
- }
- if (random(0, 50) < 4)
- antiban(random(0, 15));
- }
- public void setStatus(String message) {
- paint.mouseStatus = message;
- }
- public boolean pureAsh(RSTile tile) {
- RSGroundItem itemsOnTile[] = groundItems.getAllAt(tile);
- for (RSGroundItem item : itemsOnTile)
- if (item.getItem().getID() != ashID)
- return false;
- return true;
- }
- public RSTile f2pBankTiles[] = {
- new RSTile(3186, 3438), // Varrock West
- new RSTile(3253, 3421), //Varrock East
- new RSTile(3161, 3488), //Grand Exchange
- new RSTile(2944, 3369), //Falador West
- new RSTile(3013, 3355), //Falador East
- new RSTile(3094, 3243), //Draynor
- new RSTile(3270, 3167), //Al Kharid
- new RSTile(3093, 3494) //Edgeville
- };
- public RSTile nearestBank() {
- int closestDistance = Integer.MAX_VALUE;
- RSTile closestTile = null;
- for (RSTile tile : f2pBankTiles) {
- int distance = calc.distanceTo(tile);
- if (distance < closestDistance) {
- closestDistance = distance;
- closestTile = tile;
- }
- }
- return closestTile;
- }
- public boolean depositAll() {
- methods.setStatus("Depositing Inventory");
- if (!bank.isOpen())
- return false;
- if (interfaces.getComponent(Bank.INTERFACE_BANK, Bank.INTERFACE_BANK_BUTTON_DEPOSIT_CARRIED_ITEMS).doClick(true)) {
- Timer fs = new Timer(8000);
- while (fs.isRunning() && inventory.getCount() > 0) sleep(120);
- if (inventory.getCount() == 0)
- bank.close();
- sleep(1200);
- return inventory.getCount() == 0;
- }
- return false;
- }
- public boolean openBank() {
- RSNPC banker = npcs.getNearest(Bank.NPC_BANKERS);
- if (banker != null) {
- if (!banker.isOnScreen()) {
- walking.walkTo(banker.getLocation());
- } else {
- camera.turnTo(banker, random(10, 25));
- methods.setStatus("Opening Bank [NPC]");
- if (banker.doAction("Bank Banker")) {
- Timer fs = new Timer(4000);
- while (fs.isRunning() && !bank.isOpen()) sleep(120);
- return bank.isOpen();
- }
- }
- } else {
- RSObject bankBooth = objects.getNearest(Bank.OBJECT_BANKS);
- if (bankBooth != null) {
- if (!bankBooth.isOnScreen()) {
- walking.walkTo(bankBooth.getLocation());
- } else {
- camera.turnTo(bankBooth, random(10, 25));
- methods.setStatus("Opening Bank [OBJECT]");
- if (bankBooth.doAction("Quickly")) {
- Timer fs = new Timer(4000);
- while (fs.isRunning() && !bank.isOpen()) sleep(120);
- return bank.isOpen();
- }
- }
- }
- }
- return false;
- }
- public RSGroundItem getNearestAshPile() {
- RSGroundItem groundItemAU[] = groundItems.getAll();
- int min = Integer.MAX_VALUE;
- RSGroundItem toReturn = null;
- for (RSGroundItem item : groundItemAU) {
- RSTile tile = item.getLocation();
- if (calc.distanceTo(tile) < min && pureAsh(tile)) {
- min = calc.distanceTo(tile);
- toReturn = item;
- }
- }
- return toReturn;
- }
- }
- private class AshCollectorPaint implements Runnable {
- public boolean stop = false;
- String message = "Getting Ash Price", mouseStatus = "...";
- Color toolbarBackground = new Color(0, 0, 0, 220), gloss = new Color(255, 255, 255, 55),
- outLine = new Color(0, 0, 0), themeColor = new Color(128, 0, 255, 255), hoverColor = null,
- white = new Color(255, 255, 255);
- Font statsBarFont = new Font("Tahoma", 1, 11);
- Point origPoint = new Point(-1, -1);
- public void run() {
- while (ashMPrice <= 0) {
- ashMPrice = grandExchange.lookup(ashID).getGuidePrice();
- sleep(1200);
- }
- int timer = 0;
- while (!stop) {
- if (timer < 20) {
- message = "Ashes Collected: " + numberToKM(ashCollected);
- timer++;
- } else if (timer < 40) {
- message = "Profit Made: " + numberToKM(ashCollected * ashMPrice);
- timer++;
- } else if (timer < 60) {
- message = "Ashes/Hour: " + (ashCollected > 0
- ? numberToKM((int) ((ashCollected * 3600000D) / (System.currentTimeMillis() - startTime)))
- : "N/A");
- timer++;
- } else if (timer < 80) {
- message = "Profit/Hour: " + (ashCollected > 0
- ? numberToKM((int) (((ashCollected * ashMPrice) * 3600000D) / (System.currentTimeMillis() - startTime)))
- : "N/A");
- timer++;
- } else {
- timer = 0;
- }
- sleep(120);
- }
- }
- private String numberToKM(int number) {
- String s = String.valueOf(number);
- for (int k = s.length() - 3; k > 0; k -= 3)
- s = s.substring(0, k) + "," + s.substring(k);
- if (s.length() > 8)
- s = s.substring(0, s.length() - 8) + "M";
- else if (s.length() > 4)
- s = s.substring(0, s.length() - 4) + "K";
- return " " + s;
- }
- public String getTimeRunning() {
- long hours = 0, minutes = 0, seconds;
- seconds = (System.currentTimeMillis() - startTime) / 1000;
- if (seconds >= 60) {
- minutes = seconds / 60;
- seconds -= (minutes * 60);
- }
- if (minutes >= 60) {
- hours = minutes / 60;
- minutes -= (hours * 60);
- }
- return (hours < 10 ? "0" + hours : "" + hours) + ":"
- + (minutes < 10 ? "0" + minutes : "" + minutes) + ":"
- + (seconds < 10 ? "0" + seconds : "" + seconds);
- }
- public void paint(Graphics2D g) {
- if (distanceBetween(origPoint, mouse.getLocation()) > 5) {
- effects.add(new MouseEffects((int) mousePoint.getX(), (int) mousePoint.getY(), currentIdx < colorButtons.size() ? colors[currentIdx++] : colors[(currentIdx = 0)]));
- origPoint = mousePoint;
- }
- mousePoint = mouse.getLocation();
- //Paint Ash Tiles Invent and Minimap
- if (!bank.isOpen())
- drawTileOverlay(g, ashID);
- paintInventItems(g);
- //starting tile
- g.setColor(new Color(255, 0, 128, 200));
- g.fillOval((int) calc.tileToMinimap(startingTile).getX() - 3, (int) calc.tileToMinimap(startingTile).getY() - 2, 5, 5);
- //Color Button Toolbar
- if (!bank.isOpen()) {
- paintColorButtons(g);
- }
- //Stats bar
- g.setStroke(new BasicStroke(1));
- g.setColor(toolbarBackground);
- g.fillRect(0, 479, 518, 22); //stats bar
- g.fillRect(724, 0, 40, 20); //ST button
- g.setColor(outLine);
- g.drawRect(0, 479, 518, 22); //stats bar
- g.drawRect(724, 0, 40, 20); //ST button
- g.setFont(statsBarFont);
- g.setColor(hoverColor == null ? themeColor : hoverColor);
- drawStringCentered(g, statsBarFont, "Ash Collector :: By Janca", 493, 1);
- drawStringCentered(g, statsBarFont, "Time Running: " + getTimeRunning(), 493, 2);
- drawStringCentered(g, statsBarFont, message, 493, 3);
- g.setColor(gloss);
- g.fillRect(1, 480, 516, 9); //stats bar
- g.fillRect(725, 1, 38, 9); //ST Button
- FontMetrics metrics = g.getFontMetrics(statsBarFont);
- g.setColor(themeColor);
- g.drawString("ST", 729 + (metrics.stringWidth("ST") / 2), 13);
- //Mouse trails
- paintMouseTrail(g);
- //Mouse status
- paintMouseStatus(g, statsBarFont);
- }
- int sX = 0;
- int cX = 366;
- private void paintColorButtons(Graphics2D g) {
- g.setColor(toolbarBackground);
- g.fillRect(516 - (colorButtons.size() * 21) - 12, 312, (colorButtons.size() * 21) + 12, 26);
- g.setColor(outLine);
- g.drawRect(516 - (colorButtons.size() * 21) - 12, 312, (colorButtons.size() * 21) + 12, 26);
- for (ColorButton colorButton : colorButtons) {
- if (colorButton.isSelected()) {
- sX = colorButton.x;
- }
- colorButton.paint(g);
- }
- if (cX > sX)
- cX -= 3;
- else if (cX < sX)
- cX += 3;
- g.setStroke(new BasicStroke(2));
- g.setColor(white);
- g.drawRect(cX, 318, 15, 15);
- g.setStroke(new BasicStroke(1));
- g.setColor(gloss);
- g.fillRect(516 - (colorButtons.size() * 21) - 11, 313, (colorButtons.size() * 21) + 11, 11);
- }
- private void paintMouseTrail(Graphics2D g) {
- ArrayList<MouseEffects> temp = effects;
- if (temp.size() > 0) {
- for (MouseEffects effect : temp) {
- if (!effect.effectTimeOver()) {
- effect.paint(g);
- }
- }
- }
- int size = 0;
- for (MouseEffects fx : effects) {
- if (fx.effectTimeOver())
- size++;
- }
- if (size == effects.size() && size != 0) {
- effects.clear();
- }
- }
- private void paintMouseStatus(Graphics2D g, Font font) {
- int width;
- FontMetrics metrics = g.getFontMetrics(font);
- g.setFont(font);
- if (mouseStatus.equals("")) {
- width = 0;
- } else {
- width = metrics.stringWidth(mouseStatus) + 10;
- }
- if (mousePoint.x > 0 && mousePoint.y > 0) {
- if (mousePoint.x < 764 - (width / 2) && mousePoint.x - (width / 2) > 0) {
- if (mousePoint.y < 475) {
- g.setColor(toolbarBackground);
- g.fillRect(mousePoint.x - (width / 2), mousePoint.y + 15, width, 16);
- g.setColor(themeColor);
- g.drawString(mouseStatus, (mousePoint.x - (width / 2)) + 5, mousePoint.y + 27);
- g.setColor(gloss);
- g.fillRect(mousePoint.x - (width / 2), mousePoint.y + 15, width, 8);
- g.setColor(outLine);
- g.setStroke(new BasicStroke(1));
- g.drawRect(mousePoint.x - (width / 2), mousePoint.y + 15, width, 16);
- } else {
- g.setColor(toolbarBackground);
- g.fillRect(mousePoint.x - (width / 2), mousePoint.y - 15 - 16, width, 16);
- g.setColor(themeColor);
- g.drawString(mouseStatus, (mousePoint.x - (width / 2)) + 5, mousePoint.y - 3 - 16);
- g.setColor(gloss);
- g.fillRect(mousePoint.x - (width / 2), mousePoint.y - 15 - 16, width, 8);
- g.setColor(outLine);
- g.setStroke(new BasicStroke(1));
- g.drawRect(mousePoint.x - (width / 2), mousePoint.y - 15 - 16, width, 16);
- }
- } else if (mousePoint.x > 764 - (width / 2)) {
- if (mousePoint.y < 475) {
- g.setColor(toolbarBackground);
- g.fillRect(mousePoint.x - width, mousePoint.y + 15, width, 16);
- g.setColor(themeColor);
- g.drawString(mouseStatus, mousePoint.x - (width - 5), mousePoint.y + 27);
- g.setColor(gloss);
- g.fillRect(mousePoint.x - width, mousePoint.y + 15, width, 8);
- g.setColor(outLine);
- g.setStroke(new BasicStroke(1));
- g.drawRect(mousePoint.x - width, mousePoint.y + 15, width, 16);
- } else {
- g.setColor(toolbarBackground);
- g.fillRect(mousePoint.x - width, mousePoint.y - 15 - 16, width, 16);
- g.setColor(themeColor);
- g.drawString(mouseStatus, mousePoint.x - (width - 5), mousePoint.y - 3 - 16);
- g.setColor(gloss);
- g.fillRect(mousePoint.x - width, mousePoint.y - 15 - 16, width, 8);
- g.setColor(outLine);
- g.setStroke(new BasicStroke(1));
- g.drawRect(mousePoint.x - width, mousePoint.y - 15 - 16, width, 16);
- }
- } else {
- if (mousePoint.y < 475) {
- g.setColor(toolbarBackground);
- g.fillRect(mousePoint.x, mousePoint.y + 15, width, 16);
- g.setColor(themeColor);
- g.drawString(mouseStatus, mousePoint.x + 5, mousePoint.y + 27);
- g.setColor(gloss);
- g.fillRect(mousePoint.x, mousePoint.y + 15, width, 8);
- g.setColor(outLine);
- g.setStroke(new BasicStroke(1));
- g.drawRect(mousePoint.x, mousePoint.y + 15, width, 16);
- } else {
- g.setColor(toolbarBackground);
- g.fillRect(mousePoint.x, mousePoint.y - 15 - 16, width, 16);
- g.setColor(themeColor);
- g.drawString(mouseStatus, mousePoint.x + 5, mousePoint.y - 3 - 16);
- g.setColor(gloss);
- g.fillRect(mousePoint.x, mousePoint.y - 15 - 16, width, 8);
- g.setColor(outLine);
- g.setStroke(new BasicStroke(1));
- g.drawRect(mousePoint.x, mousePoint.y - 15 - 16, width, 16);
- }
- }
- }
- g.setColor(outLine);
- g.drawRect(mousePoint.x - 6, mousePoint.y - 6, 12, 12);
- g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x, mousePoint.y + 14);
- g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x, mousePoint.y - 14);
- g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x + 14, mousePoint.y);
- g.drawLine(mousePoint.x, mousePoint.y, mousePoint.x - 14, mousePoint.y);
- }
- private void drawStringCentered(Graphics g, Font font, String line, int y, int pos) {
- FontMetrics metrics = g.getFontMetrics(font);
- g.drawString(line, (((pos == 3 ? 878 : pos == 2 ? 520 : 164) - metrics.stringWidth(line)) / 2), y);
- }
- private boolean pointContainsNegValue(Point point) {
- return point.getX() < 0 || point.getY() < 0;
- }
- private void drawTileOverlay(Graphics2D g, int groundItemID) {
- RSGroundItem bonePiles[] = groundItems.getAll();
- for (RSGroundItem item : bonePiles) {
- if (item.getItem().getID() == groundItemID) {
- if (item.isOnScreen() && calc.tileOnScreen(item.getLocation())) {
- RSTile tile = item.getLocation();
- Point southwest = calc.tileToScreen(tile, 0, 0, 0);
- Point southeast = calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY()), 0, 0, 0);
- Point northwest = calc.tileToScreen(new RSTile(tile.getX(), tile.getY() + 1), 0, 0, 0);
- Point northeast = calc.tileToScreen(new RSTile(tile.getX() + 1, tile.getY() + 1), 0, 0, 0);
- if (startingArea.contains(tile)) {
- int dist = calc.distanceTo(item.getLocation());
- if (dist <= 1)
- g.setColor(new Color(128, 255, 0, 180));
- else if (dist <= 3)
- g.setColor(new Color(200, 252, 0, 180));
- else if (dist <= 6)
- g.setColor(new Color(230, 252, 3, 180));
- else if (dist <= 7)
- g.setColor(new Color(250, 200, 5, 180));
- else if (dist <= 8)
- g.setColor(new Color(250, 85, 2, 180));
- else
- g.setColor(new Color(240, 20, 15, 180));
- } else {
- g.setColor(new Color(255, 0, 0, 100));
- }
- if (!pointContainsNegValue(southeast) && !pointContainsNegValue(southwest)
- && !pointContainsNegValue(northeast) && !pointContainsNegValue(northwest)) {
- if (!getMyPlayer().getLocation().equals(tile)) {
- g.fillPolygon(new int[]{(int) northwest.getX(), (int) northeast.getX(), (int) southeast.getX(),
- (int) southwest.getX()}, new int[]{(int) northwest.getY(), (int) northeast.getY(),
- (int) southeast.getY(), (int) southwest.getY()}, 4);
- }
- g.setColor(new Color(0, 0, 0));
- g.setStroke(new BasicStroke((float) 1.3));
- g.drawPolygon(new int[]{(int) northwest.getX(), (int) northeast.getX(), (int) southeast.getX(),
- (int) southwest.getX()}, new int[]{(int) northwest.getY(), (int) northeast.getY(),
- (int) southeast.getY(), (int) southwest.getY()}, 4);
- }
- }
- }
- }
- }
- private void paintArea(Graphics2D g, RSArea area) {
- RSTile areaTiles[] = area.getTileArray();
- for (RSTile tile : areaTiles) {
- if (calc.tileOnMap(tile)) {
- if (tileContains(tile, ashID))
- g.setColor(new Color(0, 255, 0, 200));
- } else {
- if (tileContains(tile, ashID))
- g.setColor(new Color(230, 230, 0, 200));
- }
- if (tileContains(tile, ashID))
- g.fillOval((int) calc.tileToMinimap(tile).getX() - 3, (int) calc.tileToMinimap(tile).getY() - 2, 5, 5);
- g.setColor(new Color(255, 0, 128, 200));
- g.fillOval((int) calc.tileToMinimap(startingTile).getX() - 3, (int) calc.tileToMinimap(startingTile).getY() - 2, 5, 5);
- }
- }
- public boolean tileContains(RSTile tile, int groundItemID) {
- RSGroundItem items[] = groundItems.getAllAt(tile);
- for (RSGroundItem item : items) {
- if (item.getItem().getID() == groundItemID)
- return true;
- }
- return false;
- }
- private void paintInventItems(Graphics2D g) {
- g.setStroke(new BasicStroke(1));
- RSItem itemsInInvent[] = inventory.getItems();
- for (RSItem item : itemsInInvent) {
- if (item.getID() == ashID && item.getID() > 0) {
- paintInventBox2(g, item, new Color(102, 255, 0, 255));
- } else if (item.getID() != ashID && item.getID() > 0) {
- paintInventBox2(g, item, new Color(255, 0, 0, 255));
- }
- }
- }
- private void paintInventBox(Graphics2D g, RSItem item, Color color) {
- RSComponent invenComp = item.getComponent();
- g.setColor(color);
- g.fillRoundRect(invenComp.getAbsoluteX(), invenComp.getAbsoluteY(), invenComp.getWidth(), invenComp.getHeight(), 8, 8);
- g.setColor(new Color(0, 0, 0));
- g.drawRoundRect(invenComp.getAbsoluteX(), invenComp.getAbsoluteY(), invenComp.getWidth(), invenComp.getHeight(), 8, 8);
- }
- private void paintInventBox2(Graphics2D g, RSItem item, Color color) {
- RSComponent inventComp = item.getComponent();
- int x = inventComp.getAbsoluteX(), y = inventComp.getAbsoluteY(), width = inventComp.getWidth(),
- height = inventComp.getHeight();
- g.setColor(outLine);
- g.drawRect(x, y, width, height);
- g.setColor(toolbarBackground);
- g.fillRect(x + width - 15, y, 15, 15);
- g.setColor(outLine);
- g.drawRect(x + width - 15, y, 15, 15);
- g.setColor(color);
- g.fillRect(x + width - 12, y + 3, 10, 10);
- g.setColor(gloss);
- g.fillRect(x + width - 14, y + 1, 13, 6);
- }
- }
- private class ColorButton {
- private int x, y;
- private Color color;
- private boolean selected = false;
- private ColorButton(int x, int y, Color color, boolean selected) {
- this.x = x;
- this.y = y;
- this.color = color;
- this.selected = selected;
- }
- public void paint(Graphics2D g) {
- g.setColor(color);
- g.fillRect(x, y, 15, 15);
- g.setColor(paint.outLine);
- g.drawRect(x, y, 15, 15);
- /*if (selected) {
- g.setStroke(new BasicStroke(2));
- g.setColor(white);
- g.drawRect(x, y, 15, 15);
- g.setStroke(new BasicStroke(1));
- }*/
- }
- public void setX(int x) {
- this.x = x;
- }
- public boolean onButton(Point point) {
- Rectangle rect = new Rectangle(x, y, 15, 15);
- return rect.contains(point);
- }
- public boolean isSelected() {
- return selected;
- }
- public Color getColor() {
- return color;
- }
- public void setSelected(boolean selected) {
- this.selected = selected;
- }
- }
- private class MouseEffects {
- int x, y, size;
- Color color, black = new Color(0, 0, 0, 255);
- long startTime, lastOChange;
- public MouseEffects(int x, int y, Color color) {
- this.x = x;
- this.y = y;
- this.color = color;
- this.size = 12;
- this.startTime = System.currentTimeMillis();
- }
- int pass = 0;
- public void paint(Graphics2D g) {
- if (System.currentTimeMillis() - lastOChange > 10 && color.getAlpha() > 0) {
- color = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() - 5);
- black = new Color(0, 0, 0, color.getAlpha());
- if (size > 2 && pass >= 6) {
- size -= 2;
- pass = 0;
- }
- lastOChange = System.currentTimeMillis();
- pass++;
- }
- g.setColor(color);
- //g.setStroke(new BasicStroke(1));
- g.fillOval(x - (size / 2), y - (size / 2), size, size);
- g.setColor(black);
- g.setStroke(new BasicStroke((float) 1.5));
- g.drawOval(x - (size / 2), y - (size / 2), size, size);
- }
- public boolean effectTimeOver() {
- return System.currentTimeMillis() - startTime > 2000 || color.getAlpha() == 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment