Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- import java.util.ArrayList;
- import org.powerbot.concurrent.Task;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.Tabs;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Mouse;
- import org.powerbot.game.api.methods.interactive.NPCs;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.node.Menu;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.methods.tab.Skills;
- import org.powerbot.game.api.methods.widget.Camera;
- import org.powerbot.game.api.util.Filter;
- import org.powerbot.game.api.util.Random;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.game.api.util.Timer;
- import org.powerbot.game.api.wrappers.Area;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.interactive.NPC;
- import org.powerbot.game.api.wrappers.node.Item;
- import org.powerbot.game.api.wrappers.widget.WidgetChild;
- import org.powerbot.game.bot.event.MessageEvent;
- import org.powerbot.game.bot.event.listener.MessageListener;
- import org.powerbot.game.bot.event.listener.PaintListener;
- @Manifest(name = "Barbarian Village Fly Fisher", authors = { "Battleguard" }, description= "Fly Fishes at Barbarian Village Only.")
- public class FlyFisher extends ActiveScript implements PaintListener, MessageListener, MouseListener, MouseMotionListener {
- private final Timer RUN_TIME = new Timer(0);
- private boolean hop = false;
- private int startXp;
- private int startLvl;
- private int fishCaught = 0;
- public Dropper r;
- public FishDraw fishDraw;
- @Override
- protected void setup() {
- startXp = Skills.getExperience(Skills.FISHING) - 1;
- startLvl = Skills.getLevel(Skills.FISHING);
- setupRectangles();
- r = new Dropper();
- Fisher m = new Fisher();
- Cam c = new Cam();
- StopCheck s = new StopCheck();
- fishDraw = new FishDraw();
- provide(new Strategy(r, r));
- provide(new Strategy(m, m));
- provide(new Strategy(c, c));
- provide(new Strategy(s, s));
- provide(new Strategy(fishDraw, fishDraw));
- }
- public class PlaceCannon extends Strategy implements Task{
- @Override
- public void run() {
- final Tile base = Players.getLocal().getLocation();
- }
- public Area getCannonSpot(final Tile base) {
- for(int i = 1; i < 5; i++) {
- final Rectangle spots = new Rectangle(base.getX() - i, base.getY() - i, i * 2 + 1, i * 2 + 1);
- for(int y = spots.y; y < spots.y + spots.height; y++) {
- p1: for(int x = spots.x; y < spots.x + spots.width; x++) {
- final Area cannon = new Area(new Tile(base.getX() - 1, base.getY() - 1, 0), new Tile(base.getX() + 1, base.getY() + 1, 0));
- final Tile[] tiles = cannon.getTileArray();
- for (Tile tile : tiles) {
- if(SceneEntities.getAt(tile) != null) continue p1;
- }
- return cannon;
- }
- }
- }
- return null;
- }
- @Override
- public boolean validate() {
- return false;
- }
- }
- public class Dropper extends Strategy implements Task{
- @Override
- public void run() {
- dropdown();
- }
- @Override
- public boolean validate(){
- if(Tabs.getCurrent() != Tabs.INVENTORY) openInventoryTab();
- return Inventory.getCount() == 28;
- }
- void dropdown() {
- final WidgetChild inv = Widgets.get(679, 0);
- for(int x = 0; x < 4; x++) {
- for(int y = x; y < 28; y+=4) {
- final WidgetChild spot = inv.getChild(y);
- if(spot != null && spot.getChildId() != 314) {
- clickFish(spot);
- }
- }
- }
- }
- public void clickFish(final WidgetChild fish) {
- if(!fish.getBoundingRectangle().contains(Mouse.getLocation())) {
- Move(fish.getCentralPoint().x, fish.getAbsoluteY() + 5, hop);
- }
- Mouse.click(false);
- Move(Mouse.getX(), getDropActionYLocation(), hop);
- Mouse.click(true);
- }
- public void Move(final int x, final int y, final boolean Hop) {
- if(Hop) Mouse.hop(x, y, 3, 3);
- else Mouse.move(x, y, 3, 3);
- }
- public int getDropActionYLocation() {
- final String []actions = Menu.getItems();
- for(int i = 0; i < actions.length; i++) {
- if(actions[i].contains("Drop ")) {
- return Menu.getLocation().y + 21 + 16 * i + Random.nextInt(3, 6);
- }
- }
- return Menu.getLocation().y + 40;
- }
- public void openInventoryTab() {
- final WidgetChild inv = Widgets.get(548, 93);
- Time.sleep(2000);
- if(inv != null) Widgets.get(548, 93).click(true);
- Time.sleep(500);
- }
- }
- public final class StopCheck extends Strategy implements Task{
- @Override
- public void run() {
- stop();
- }
- @Override
- public boolean validate(){
- return Inventory.getCount(314) == 0;
- }
- }
- public final class Fisher extends Strategy implements Task{
- public final Filter<NPC> FishSpots = new Filter<NPC>() {
- public boolean accept(NPC npc) {
- return npc.getId() == 328 || npc.getId() == 9645;
- }
- };
- @Override
- public void run() {
- final NPC BestSpot = NPCs.getNearest(FishSpots);
- if(BestSpot.isOnScreen()) {
- BestSpot.interact("Lure");
- } else {
- Walking.walk(BestSpot.getLocation());
- }
- Time.sleep(2000);
- }
- @Override
- public boolean validate(){
- return Players.getLocal().getAnimation() == -1;
- }
- }
- public final class Cam extends Strategy implements Task{
- private Timer cameraTimer = new Timer(2 * 60 * 1000);
- @Override
- public void run() {
- Camera.setPitch(Random.nextInt(70, 100));
- Camera.setAngle(Random.nextInt(0, 180));
- cameraTimer = new Timer(Random.nextInt(180, 240) * 1000);
- }
- @Override
- public boolean validate(){
- return !cameraTimer.isRunning();
- }
- }
- public final class FishDraw extends Strategy implements Task {
- public boolean draw = false;
- public ArrayList<Integer> spots = new ArrayList<Integer>();
- private static final int salmonID = 331;
- public final Filter<Item> salmonFilter = new Filter<Item>() {
- public boolean accept(Item inv) {
- return inv.getId() == salmonID;
- }
- };
- @Override
- public void run() {
- draw = false;
- ArrayList<Integer> currentSalmon = new ArrayList<Integer>();
- for(int i = 0; i < 28; i++) {
- if(Inventory.getItemAt(i).getId() == salmonID) {
- if(spots.contains(i)) spots.remove(spots.indexOf(i));
- else currentSalmon.add(i);
- }
- }
- for(int i = 0; i < spots.size() && !currentSalmon.isEmpty(); i++) {
- final Point dragPoint = Widgets.get(679, 0).getChild(spots.get(i)).getCentralPoint();
- final Point clickPoint = Inventory.getItemAt(currentSalmon.remove(0)).getWidgetChild().getCentralPoint();
- r.Move(clickPoint.x, clickPoint.y, false);
- Mouse.drag(dragPoint);
- }
- spots.clear();
- }
- @Override
- public boolean validate(){
- return draw && !spots.isEmpty();
- }
- }
- private NumberFormat k = new DecimalFormat("###,###,###");
- @Override
- public void onRepaint(Graphics g) {
- final int CUR_XP = Skills.getExperience(Skills.FISHING);
- final int CUR_XP_GAIN = CUR_XP - startXp;
- final double XP_PER_HOUR = (((double) CUR_XP_GAIN / (double) RUN_TIME.getElapsed()) * 3600000d);
- final int CUR_LVL = Skills.getLevel(Skills.FISHING);
- final double Percentage = (double)((double)(CUR_XP - Skills.XP_TABLE[CUR_LVL]) / (double)(Skills.XP_TABLE[CUR_LVL + 1] - Skills.XP_TABLE[CUR_LVL]));
- final long TTL = (long) ((RUN_TIME.getElapsed() * (Skills.XP_TABLE[CUR_LVL+1] - CUR_XP)) / CUR_XP_GAIN);
- final Color OPAQUE_BLACK = new Color(0, 0, 0, 160);
- final Color OPAQUE_BLACK2 = new Color(0, 0, 0, 180);
- final Color GREEN = new Color(85, 110, 36, 180);
- int yComp = 277, xComp = 20;
- g.setColor(OPAQUE_BLACK);
- g.fill3DRect(0, yComp+=18, 290, 45, true);
- g.setFont(new Font("Gayatri", 0, 12));
- final String l1 = "Run Time: " + RUN_TIME.toElapsedString() + " || Fish Caught: " + k.format(fishCaught);
- shadowText(g, l1, xComp, yComp+=18);
- g.setColor(Color.BLACK);
- g.draw3DRect(xComp-5, yComp+5, 270, 17, true);
- g.setColor(OPAQUE_BLACK2);
- g.fill3DRect(xComp-5, yComp+5, 270, 17, true);
- g.setColor(GREEN);
- g.fillRect(xComp-4, yComp+6, (int) (268 * Percentage), 15);
- final String l2 = "Fishing (" + CUR_LVL + ")" + (CUR_LVL == startLvl ? "" : "+" + (CUR_LVL - startLvl))
- + " " + formatter(CUR_XP_GAIN) + " - " + formatter((int)XP_PER_HOUR) + "/H - TTL: " + Time.format(TTL);
- shadowText(g, l2, xComp, yComp+=18);
- drawMouse(g);
- drawButton(g);
- drawInventory(g);
- }
- public void drawInventory(Graphics g) {
- g.setColor(Color.BLUE);
- for(int i = 0; i < fishDraw.spots.size(); i++) {
- g.drawRect(invSpots[fishDraw.spots.get(i)].x, invSpots[fishDraw.spots.get(i)].y, invSpots[fishDraw.spots.get(i)].width, invSpots[fishDraw.spots.get(i)].height);
- }
- }
- public void drawMouse(Graphics g) {
- g.setColor(Mouse.isPressed() ? Color.RED : Color.GREEN);
- final Point m = Mouse.getLocation();
- g.drawLine(m.x -5, m.y + 5, m.x + 5, m.y - 5);
- g.drawLine(m.x -5, m.y - 5, m.x + 5, m.y + 5);
- }
- private final Rectangle REC = new Rectangle(372, 345, 125, 15);
- public void drawButton(Graphics g) {
- g.setColor(Color.BLACK);
- g.drawRect(REC.x-1, REC.y-1, REC.width+1, REC.height+1);
- g.setColor(hop ? new Color(85, 110, 36, 180): new Color(153, 0, 36, 180));
- g.fillRect(REC.x, REC.y, REC.width, REC.height);
- g.setColor(Color.WHITE);
- shadowText(g, "Fast Drop: " + (hop ? "Enabled" : "Disabled"), REC.x + 3, REC.y + 13);
- }
- public void shadowText(Graphics g, final String line, final int x, final int y) {
- g.setColor(Color.BLACK);
- g.drawString(line, x+1, y+1);
- g.setColor(Color.WHITE);
- g.drawString(line, x, y);
- }
- public String formatter(final int num) {
- return num / 1000 + "." + (num % 1000) / 100 + "K";
- }
- @Override
- public void messageReceived(MessageEvent e) {
- if(e.getMessage().contains("You catch a ")) fishCaught++;
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- if(REC.contains(e.getPoint())) hop ^= true;
- }
- @Override
- public void mousePressed(MouseEvent e) {}
- @Override
- public void mouseReleased(MouseEvent e) {
- fishDraw.draw = true;
- }
- @Override
- public void mouseEntered(MouseEvent e) {}
- @Override
- public void mouseExited(MouseEvent e) {}
- private Rectangle [] invSpots = new Rectangle[28];
- void setupRectangles() {
- WidgetChild inv = Widgets.get(679, 0);
- for(int i = 0; i < 28; i++) {
- invSpots[i] = inv.getChild(i).getBoundingRectangle();
- }
- }
- @Override
- public void mouseDragged(MouseEvent e) {
- final Point p = e.getPoint();
- if(Inventory.getWidget(false).contains(p)) {
- for(int i = 0; i < 28; i++) {
- if(invSpots[i].contains(p)) {
- for(int j = 0; j < fishDraw.spots.size(); j++) {
- if(fishDraw.spots.get(j) == i) return;
- }
- fishDraw.spots.add(i);
- }
- }
- }
- }
- @Override
- public void mouseMoved(MouseEvent e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement