Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import com.rarebot.event.events.MessageEvent;
- import com.rarebot.event.listeners.MessageListener;
- import com.rarebot.event.listeners.PaintListener;
- import com.rarebot.script.Script;
- import com.rarebot.script.ScriptManifest;
- import com.rarebot.script.methods.Bank;
- import com.rarebot.script.util.Filter;
- import com.rarebot.script.wrappers.RSGroundItem;
- import com.rarebot.script.wrappers.RSItem;
- import com.rarebot.script.wrappers.RSNPC;
- import com.rarebot.script.wrappers.RSObject;
- import com.rarebot.script.wrappers.RSTile;
- @ScriptManifest(authors = "Aron", name = "SpiceGetter", version = 1.0, description = "Gets spices from evil dave's hellcats!")
- public class spiceGetter extends Script implements PaintListener, MessageListener{
- private RSNPC cat = null;
- ArrayList<Integer> spices = new ArrayList<Integer>();
- private String status = "Starting..";
- private int emptySpice = 7496;
- private boolean guiDone = false;
- private RSTile mainTile = new RSTile( 3079, 9886 );
- private int[][] combinableSpices = new int[4][3];
- private boolean returning = true;
- private long sendTime;
- private long antibanTime;
- private int[] fullSpices = { 7480, 7484, 7492, 7488 };
- //Credits to Foulwerp
- private RSNPC interactingNPC() {
- return npcs.getNearest(new Filter<RSNPC>() {
- public boolean accept(RSNPC n) {
- if (n.getInteracting() == null) {
- return false;
- }
- String[] acts = n.getActions();
- if (acts == null) {
- return false;
- }
- for (String a : acts) {
- if (a == null || !a.contains("Pick-up")) {
- continue;
- }
- return n.getInteracting().equals(players.getMyPlayer()) && (n.getName().contains("cat") || n.getName().contains("kitten"));
- }
- return false;
- }
- });
- }
- private RSItem inventoryContainsCat() {
- RSItem[] inv = inventory.getCachedItems();
- for (int i = 0; i < inv.length; i++){
- if (inv[i].getName().contains("cat") || inv[i].getName().contains("kitten"))
- return inv[i];
- }
- return null;
- }
- private RSGroundItem getLoot() {
- return groundItems.getNearest(new Filter<RSGroundItem>(){
- public boolean accept(RSGroundItem item) {
- for (int s : spices) {
- if (item.getItem().getID() == s){
- return true;
- }
- }
- return false;
- }});
- }
- private boolean hasLoot() {
- return getLoot() != null;
- }
- @SuppressWarnings("deprecation")
- private int lootStuff() {
- if (getLoot() != null){
- final RSGroundItem loot = getLoot();
- if (loot != null){
- if (!getMyPlayer().isMoving()){
- if(loot.isOnScreen()){
- loot.doAction("Take " + loot.getItem().getName());
- return random(500, 900);
- } else{
- walking.walkTileMM(walking.getClosestTileOnMap(walking.randomizeTile(loot.getLocation(), 1, 1)));
- return random(500, 1500);
- }
- } else if(!loot.isOnScreen()){
- camera.turnToTile(loot.getLocation(), 20);
- }
- }
- }
- return 0;
- }
- private int canCombine() {
- int[][] spiceLoad = new int[4][4];
- for (int i = 0; i < spices.size(); i++){
- if (i <= 3){
- spiceLoad[0][i] = inventory.getCount(spices.get(i));
- } else if(i <= 7){
- spiceLoad[1][i - 4] = inventory.getCount(spices.get(i));
- } else if(i <= 11){
- spiceLoad[2][i - 8] = inventory.getCount(spices.get(i));
- } else if(i <= 15){
- spiceLoad[3][i - 12] = inventory.getCount(spices.get(i));
- }
- }
- for (int i = 0; i < 4; i++){
- if (hasMultiple(spiceLoad[i])) return (i);
- }
- return - 1;
- }
- private boolean hasMultiple(int[] load) {
- int k = 0;
- for (int i = 0; i < 3; i++){
- if (load[i] != 0) k+= load[i];
- }
- return k > 1;
- }
- private int combineSpices(int index) {
- RSItem item1 = inventory.getItem(combinableSpices[index]);
- RSItem item2 = null;
- RSItem[] spiceArray = inventory.getItems(combinableSpices[index]);
- for (int i = 0; i < spiceArray.length; i++){
- if (spiceArray[i].getComponent().getAbsoluteX() != item1.getComponent().getAbsoluteX()){
- item2 = spiceArray[i];
- continue;
- }
- }
- if (item1 == null || item2 == null || item1.getComponent().getAbsoluteX() == item2.getComponent().getAbsoluteX()) return 0;
- while (!inventory.useItem(item2, item1)){
- sleep(200, 500);
- }
- return random(400, 700);
- }
- private int antiban() {
- status = "Antiban";
- if (random(1, 10) > 3){
- camera.moveRandomly(random(500, 1500));
- antibanTime = System.currentTimeMillis() + random(-10000, -5000);
- return random(200, 700);
- }
- switch(random(1, 10)){
- case 1: mouse.moveRandomly(50, 120);
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 2: mouse.moveRandomly(10, 50);
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 3: mouse.moveOffScreen();
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 4: camera.moveRandomly(random(1000, 3000));
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 5: camera.turnToTile(cat.getLocation());
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 6: mouse.moveSlightly();
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 7: mouse.setSpeed(random(7, 9));
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 8: antibanTime = System.currentTimeMillis() + random(5000, 15000);
- case 9: if (groundItems.getAll()[0] != null)
- groundItems.getAll()[0].getItem().doClick(false);
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- case 10: if (getLoot() != null)
- camera.turnToTile(getLoot().getLocation());
- antibanTime = System.currentTimeMillis() + random(-5000, 5000);
- }
- return random(200, 700);
- }
- public boolean onStart(){
- form form = new form();
- form.setVisible(true);
- mouse.setSpeed(8);
- while(!guiDone){
- sleep(1);
- }
- for (int i = 0; i < 4; i++){
- for (int k = 0; k < 3; k++){
- combinableSpices[i][k] = spices.get(i * 4 + k);
- }
- }
- if (inventoryContainsCat() != null || (interactingNPC() != null && (interactingNPC().getName().contains("cat") || interactingNPC().getName().contains("kitten"))))
- return true;
- log("Start with Cat/kitten in inv/on ground.");
- return false;
- }
- public void onFinish(){
- }
- @Override
- public int loop() {
- //Start - stuff
- if (inventoryContainsCat() != null && cat == null) {
- inventoryContainsCat().doAction("Drop");
- return random(3000, 4500);
- }
- if (interactingNPC() != null)
- cat = interactingNPC();
- //"Real" loop
- if (cat == null){
- log("Something wrong with your cat..");
- stopScript();
- }
- if (inventory.getCount(fullSpices) > 26 && !inventory.containsOneOf(emptySpice)){
- if (!getMyPlayer().isMoving()){
- return bank();
- } else if(walking.getDestination() != null && calc.distanceBetween(getMyPlayer().getLocation(), walking.getDestination()) < 4){
- return bank();
- }
- }
- if (!inventory.containsOneOf(fullSpices) && npcs.getNearest(3382) == null)
- if (!getMyPlayer().isMoving()){
- return back();
- } else if(walking.getDestination() != null && calc.distanceBetween(getMyPlayer().getLocation(), walking.getDestination()) < 4){
- return back();
- }
- if (npcs.getNearest(3382) != null && inventory.getCount() < 28){
- if (getMyPlayer().isMoving()){
- return random(200, 500);
- }
- if (calc.distanceBetween(getMyPlayer().getLocation(), mainTile) > 6 && !hasLoot()){
- walking.walkTileMM(new RSTile(mainTile.getX() + random(-1, 1), mainTile.getY() + random(-1, 1)), 1, 1);
- return random(1000, 1500);
- }
- if (interfaces.getComponent(230, 3).isValid()){
- interfaces.getComponent(230, 3).doClick();
- return random(1000, 2000);
- }
- if (System.currentTimeMillis() - antibanTime > 24000)
- return antiban();
- if (!returning){
- if (System.currentTimeMillis() - sendTime < 10000){
- status = "Waiting for your cat to return";
- return (int) (calc.distanceBetween(cat.getLocation(), getMyPlayer().getLocation()) * random(100, 200));
- } else if (returning && !cat.isMoving() && calc.distanceBetween(cat.getLocation(), getMyPlayer().getLocation()) > 2)
- summoning.doAction("Call Follower");
- return random(300, 600);
- }
- if (hasLoot()) {
- status = "Looting";
- return lootStuff();
- }
- if (canCombine() != - 1){
- status = "Combining Spices";
- combineSpices(canCombine());
- }
- if (inventory.containsOneOf(emptySpice)){
- status = "Dropping empty Spices";
- if(!inventory.getItem(emptySpice).doAction("Drop"))
- return random(100, 300);
- return random(800, 1300);
- }
- status = "Go on puss.. Kill that rat!";
- if (menu.isOpen())
- mouse.moveRandomly(50);
- if (!cat.doAction("Interact-with " + cat.getName()))
- return random(100, 300);
- return random(900, 1300);
- }
- return 0;
- }
- @SuppressWarnings("deprecation")
- private int back() {
- status = "Walking back";
- RSObject stairs = objects.getNearest(12266);
- RSObject closedDoor = objects.getNearest(24381);
- RSObject openDoor = objects.getNearest(24379);
- if (openDoor != null && !openDoor.isOnScreen()){
- walking.walkTileMM(walking.randomizeTile(openDoor.getLocation(), 1, 1));
- return random(1400, 2100);
- }
- if (closedDoor != null){
- if (closedDoor.isOnScreen())
- closedDoor.doAction("Open ");
- else
- walking.walkTileMM(walking.randomizeTile(closedDoor.getLocation(), 1, 1));
- return random(1200, 2100);
- }
- if (stairs != null && openDoor != null){
- if (!stairs.isOnScreen()){
- walking.walkTileMM(walking.randomizeTile(stairs.getLocation(), 1, 1));
- return random(1200, 2100);
- }
- stairs.doHover();
- if (menu.contains("Go-down")){
- if(!stairs.doAction("Go-down"))
- return random(100, 300);
- return random(1200, 2100);
- } else if (menu.contains("Open")){
- if(!stairs.doAction("Open"))
- return random(100, 300);
- return random(1200, 2100);
- }
- }
- return 0;
- }
- @SuppressWarnings("deprecation")
- private int bank() {
- status = "Banking";
- RSObject stairs = objects.getNearest(12265);
- RSObject closedDoor = objects.getNearest(24381);
- RSObject openDoor = objects.getNearest(24379);
- if (bank.isOpen()){
- if(!bank.depositAll())
- return random(200, 500);
- return random(1200, 2100);
- }
- if (openDoor != null && objects.getNearest(Bank.BANK_BOOTHS) != null){
- if (objects.getNearest(Bank.BANK_BOOTHS).isOnScreen())
- objects.getNearest(Bank.BANK_BOOTHS).doAction("Use-quickly ");
- else
- walking.walkTileMM(walking.randomizeTile(objects.getNearest(Bank.BANK_BOOTHS).getLocation(), 1, 1));
- return random(1200, 2100);
- }
- if (closedDoor != null){
- if (closedDoor.isOnScreen())
- closedDoor.doAction("Open ");
- else
- walking.walkTileMM(walking.randomizeTile(closedDoor.getLocation(), 1, 1));
- return random(1200, 2100);
- }
- if (stairs != null){
- if (stairs.isOnScreen())
- stairs.doAction("Climb ");
- else
- walking.walkTileMM(walking.randomizeTile(stairs.getLocation(), 1, 1));
- return random(1200, 2100);
- }
- return 0;
- }
- @Override
- public void messageReceived(MessageEvent m) {
- if (m.getSender() == getMyPlayer().getName()){
- if (m.getMessage().contains("Go on puss")){
- returning = false;
- sendTime = System.currentTimeMillis();
- } else if (m.getMessage().contains("Hey well done")){
- returning = true;
- }
- } else if (m.getID() == MessageEvent.MESSAGE_SERVER){
- if (m.getMessage().contains("Your cat cannot get to its prey"))
- returning = true;
- }
- }
- //PAINT
- @Override
- public void onRepaint(Graphics g) {
- g.setColor(new Color(0, 0, 0, 200));
- g.setFont(new Font("Arial", 0, 11));
- g.drawString(status, 110, 470);
- if (canCombine() != -1){
- int index = canCombine();
- RSItem item1 = inventory.getItem(combinableSpices[index]);
- RSItem item2 = null;
- RSItem[] spiceArray = inventory.getItems(combinableSpices[index]);
- for (int i = 0; i < spiceArray.length; i++){
- if (spiceArray[i].getComponent().getAbsoluteX() != item1.getComponent().getAbsoluteX()){
- item2 = spiceArray[i];
- continue;
- }
- }
- if (item1 != null && item2 != null /*&& item1.getComponent().getAbsoluteX() != item2.getComponent().getAbsoluteX()*/){
- g.setColor(new Color(0, 70, 70, 200));
- g.drawRect(item1.getComponent().getAbsoluteX(), item1.getComponent().getAbsoluteY(), item1.getComponent().getWidth(), item1.getComponent().getHeight());
- g.setColor(new Color(0 , 150, 150, 200));
- g.drawRect(item2.getComponent().getAbsoluteX(), item2.getComponent().getAbsoluteY(), item2.getComponent().getWidth(), item2.getComponent().getHeight());
- g.setColor(new Color(0, 0, 0, 200));
- g.drawLine(item1.getComponent().getAbsoluteX(), item1.getComponent().getAbsoluteY(), item2.getComponent().getAbsoluteX(), item2.getComponent().getAbsoluteY());
- }
- }
- if (cat != null){
- drawModel(cat.getModel().getTriangles(), g);
- g.setColor(new Color(0, 0, 0, 150));
- g.fillOval(cat.getModel().getPoint().x, cat.getModel().getPoint().y, 3, 3);
- }
- }
- private void drawModel(Polygon[] model, Graphics g) {
- int i = 0;
- for (Polygon p : model) {
- if (i >= 1) {
- g.setColor(new Color(255, 255, 255, 150));
- g.drawPolygon(p);
- i = -5;
- }
- i++;
- }
- }
- //GUI
- @SuppressWarnings("serial")
- public class form extends JFrame {
- public form() {
- initComponents();
- }
- private void button1ActionPerformed(ActionEvent e) {
- if (checkBox1.isSelected()){
- spices.add(7491);
- spices.add(7490);
- spices.add(7489);
- spices.add(7488);
- } else {
- for (int i = 0; i < 4; i++){
- spices.add(0);
- }
- }
- if (checkBox2.isSelected()){
- spices.add(7495);
- spices.add(7494);
- spices.add(7493);
- spices.add(7492);
- } else {
- for (int i = 0; i < 4; i++){
- spices.add(0);
- }
- }
- if (checkBox3.isSelected()){
- spices.add(7487);
- spices.add(7486);
- spices.add(7485);
- spices.add(7484);
- } else {
- for (int i = 0; i < 4; i++){
- spices.add(0);
- }
- }
- if (checkBox4.isSelected()){
- spices.add(7483);
- spices.add(7482);
- spices.add(7481);
- spices.add(7480);
- } else {
- for (int i = 0; i < 4; i++){
- spices.add(0);
- }
- }
- setVisible(false);
- guiDone = true;
- }
- private void initComponents() {
- checkBox1 = new JCheckBox();
- checkBox2 = new JCheckBox();
- checkBox3 = new JCheckBox();
- checkBox4 = new JCheckBox();
- button1 = new JButton();
- //======== this ========
- setTitle("Spice");
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- checkBox1 ----
- checkBox1.setText("Brown spice");
- contentPane.add(checkBox1);
- checkBox1.setBounds(new Rectangle(new Point(10, 10), checkBox1.getPreferredSize()));
- //---- checkBox2 ----
- checkBox2.setText("Yellow spice");
- contentPane.add(checkBox2);
- checkBox2.setBounds(new Rectangle(new Point(10, 30), checkBox2.getPreferredSize()));
- //---- checkBox3 ----
- checkBox3.setText("Orange spice");
- contentPane.add(checkBox3);
- checkBox3.setBounds(new Rectangle(new Point(10, 50), checkBox3.getPreferredSize()));
- //---- checkBox4 ----
- checkBox4.setText("Red spice");
- contentPane.add(checkBox4);
- checkBox4.setBounds(new Rectangle(new Point(10, 70), checkBox4.getPreferredSize()));
- //---- button1 ----
- button1.setText("Start");
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- button1ActionPerformed(e);
- }
- });
- contentPane.add(button1);
- button1.setBounds(15, 100, 115, button1.getPreferredSize().height);
- { // compute preferred size
- Dimension preferredSize = new Dimension();
- for(int i = 0; i < contentPane.getComponentCount(); i++) {
- Rectangle bounds = contentPane.getComponent(i).getBounds();
- preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
- preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
- }
- Insets insets = contentPane.getInsets();
- preferredSize.width += insets.right;
- preferredSize.height += insets.bottom;
- contentPane.setMinimumSize(preferredSize);
- contentPane.setPreferredSize(preferredSize);
- }
- pack();
- setLocationRelativeTo(getOwner());
- }
- private JCheckBox checkBox1;
- private JCheckBox checkBox2;
- private JCheckBox checkBox3;
- private JCheckBox checkBox4;
- private JButton button1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement