Advertisement
joedezzy1

MerchanterMain

Mar 12th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.53 KB | None | 0 0
  1. package scripts.autoMerchanter;
  2.  
  3. import java.awt.BasicStroke;
  4. import java.awt.Color;
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.awt.Graphics2D;
  8.  
  9. import org.tribot.api.General;
  10. import org.tribot.api.Timing;
  11. import org.tribot.api.types.generic.Condition;
  12. import org.tribot.api.util.ABCUtil;
  13. import org.tribot.api2007.GameTab;
  14. import org.tribot.api2007.Interfaces;
  15. import org.tribot.api2007.PathFinding;
  16. import org.tribot.api2007.Player;
  17. import org.tribot.api2007.Skills;
  18. import org.tribot.api2007.GameTab.TABS;
  19. import org.tribot.script.Script;
  20. import org.tribot.script.ScriptManifest;
  21. import org.tribot.script.interfaces.MessageListening07;
  22. import org.tribot.script.interfaces.Painting;
  23.  
  24. @ScriptManifest(authors = { "JoeDezzy" }, category = "Merchanting", name = "Merchanter")
  25. public class Main extends Script implements Painting, MessageListening07 {
  26.      
  27.     public static boolean running = true;
  28.    
  29.     public boolean GUI_COMPLETE = false;
  30.    
  31.     public String tradedBy;
  32.    
  33.     private ABCUtil abc = new ABCUtil();
  34.     private Check attributes = new Check();
  35.     private Trader trader = new Trader(attributes);
  36.     private Typer typer = new Typer(attributes);
  37.    
  38.     private STATE state;
  39.    
  40.     enum STATE {
  41.         ADVERTISING,
  42.         INITIALIZING_TRADE,
  43.         HANDLING_TRADE1,
  44.         HANDLING_TRADE2,
  45.         RETURNING_TO_POS,
  46.         WAIT
  47.     }
  48.    
  49.     public Main(){}
  50.  
  51.     @Override
  52.     public void clanMessageReceived(String arg0, String arg1) { }
  53.     @Override
  54.     public void duelRequestReceived(String arg0, String arg1) { }
  55.     @Override
  56.     public void personalMessageReceived(String arg0, String arg1) { }
  57.     @Override
  58.     public void playerMessageReceived(String arg0, String arg1) { }
  59.     @Override
  60.     public void serverMessageReceived(String arg0) { }
  61.     @Override
  62.     public void tradeRequestReceived(String arg0) { tradedBy = arg0; }
  63.    
  64.     private STATE getState() {  
  65.         if (!attributes.inOriginalPosition()) {
  66.             return STATE.RETURNING_TO_POS;
  67.         }    
  68.         else if(tradedBy != null && !attributes.inTrade()) {
  69.             return STATE.INITIALIZING_TRADE;                        
  70.         }                
  71.         else if (Interfaces.isInterfaceValid(335)) {
  72.             return STATE.HANDLING_TRADE1;
  73.         }                
  74.         else if (Interfaces.isInterfaceValid(334) && Interfaces.get(334, 40) != null) {
  75.             return STATE.HANDLING_TRADE2;
  76.         }                
  77.         else if (!attributes.inTrade()){
  78.             return STATE.ADVERTISING;
  79.         }
  80.         return STATE.WAIT;
  81.     }
  82.    
  83.     @Override
  84.     public void run() {        
  85.         setLoginBotState(false);                    
  86.         openGui();
  87.         onStart();
  88.        
  89.         while(running){
  90.             state = getState();
  91.             openInv();
  92.            
  93.             switch (state) {
  94.         case ADVERTISING:
  95.             antiban();
  96.                     typer.advertise();
  97.             break;
  98.         case HANDLING_TRADE1:
  99.             tradedBy = null;
  100.                     trader.handleFirstTrade();
  101.             break;
  102.         case HANDLING_TRADE2:
  103.                     trader.handleSecondTrade();
  104.             break;
  105.         case INITIALIZING_TRADE:
  106.             trader.startTrade();
  107.             break;
  108.         case RETURNING_TO_POS:
  109.             toOriginalPosition();
  110.             break;
  111.         case WAIT:
  112.             break;
  113.         default:
  114.         break;              
  115.            }
  116.        sleep(400, 900);
  117.        }
  118.    }
  119.  
  120.     private void onStart() {
  121.     attributes.startTime = System.currentTimeMillis();
  122.     attributes.originalTile = Player.getRSPlayer().getPosition();
  123.         General.useAntiBanCompliance(true);        
  124.         println("Welcome to JDezzy's Flawless Merchanter "
  125.                      + "\nYou are flipping item: " + attributes.itemName
  126.                      + "\nFor a price of: " + attributes.buyingPrice
  127.                      + "\n \t to " + attributes.sellingPrice);                              
  128.     }
  129.    
  130.     private void openInv() {
  131.     if (!GameTab.getOpen().equals(TABS.INVENTORY)) {
  132.             GameTab.open(TABS.INVENTORY);                      
  133.         }
  134.     }
  135.    
  136.     private void toOriginalPosition() {        
  137.      if (PathFinding.aStarWalk(attributes.originalTile)) {               
  138.          Timing.waitCondition(new Condition(){
  139.         @Override
  140.          public boolean active() {
  141.              return Player.getPosition().equals(attributes.originalTile);
  142.          }               
  143.          }, General.random(2400, 3400));               
  144.          }         
  145.      }
  146.        
  147.     public void antiban() {
  148.         checkXp();
  149.         ranRightClick();
  150.         checkEquipment();
  151.         checkFl();
  152.         checkMusic();
  153.         rotateCam();
  154.         ranMouseMoves();
  155.         examineObj();
  156.         pickUpMouse();
  157.         leaveGame();      
  158.     }
  159.  
  160.     public final void rotateCam() {
  161.         if (abc.TIME_TRACKER.ROTATE_CAMERA.next() <= Timing.currentTimeMillis()){
  162.             abc.performRotateCamera();
  163.         }
  164.     }
  165.  
  166.     public void checkXp() {
  167.         if (abc.TIME_TRACKER.CHECK_XP.next() <= Timing.currentTimeMillis()){
  168.             abc.performXPCheck(Skills.SKILLS.RUNECRAFTING);
  169.         }
  170.     }
  171.  
  172.     public final void pickUpMouse() {
  173.         if (abc.TIME_TRACKER.PICKUP_MOUSE.next() <= Timing.currentTimeMillis()){
  174.             abc.performPickupMouse();
  175.         }
  176.     }
  177.  
  178.     public void leaveGame() {
  179.         if (abc.TIME_TRACKER.LEAVE_GAME.next() <= Timing.currentTimeMillis()){
  180.             abc.performLeaveGame();
  181.             sleep(14000,30000);
  182.         }
  183.     }
  184.  
  185.     public void examineObj() {
  186.         if (abc.TIME_TRACKER.EXAMINE_OBJECT.next() <= Timing.currentTimeMillis()){
  187.             abc.performExamineObject();
  188.         }
  189.     }
  190.  
  191.     public void ranRightClick() {
  192.         if (abc.TIME_TRACKER.RANDOM_RIGHT_CLICK.next() <= Timing.currentTimeMillis()){
  193.             abc.performRandomRightClick();
  194.         }
  195.     }
  196.  
  197.     public void ranMouseMoves() {
  198.         if (abc.TIME_TRACKER.RANDOM_MOUSE_MOVEMENT.next() <= Timing.currentTimeMillis()){
  199.             abc.performRandomMouseMovement();
  200.         }
  201.     }
  202.  
  203.     public void checkEquipment() {
  204.         if (abc.TIME_TRACKER.CHECK_EQUIPMENT.next() <= Timing.currentTimeMillis()){
  205.             abc.performEquipmentCheck();
  206.         }
  207.     }
  208.  
  209.     public final void checkFl() {
  210.         if (abc.TIME_TRACKER.CHECK_FRIENDS.next() <= Timing.currentTimeMillis()){
  211.             abc.performFriendsCheck();
  212.         }
  213.     }
  214.  
  215.     public final void checkMusic() {
  216.         if (abc.TIME_TRACKER.CHECK_MUSIC.next() <= Timing.currentTimeMillis()){
  217.             abc.performMusicCheck();
  218.         }
  219.     }
  220.  
  221.     private void openGui() {          
  222.         new merchGUI();
  223.         while(!GUI_COMPLETE){
  224.             sleep(300);
  225.         }
  226.     }
  227.        
  228.     private final Color color1 = new Color(0, 0, 0);
  229.     private final Color color2 = new Color(204, 204, 204);
  230.     private final Color color3 = new Color(255, 255, 255);
  231.     private final BasicStroke stroke1 = new BasicStroke(1);  
  232.     private final Font font1 = new Font("Arial", 0, 12);
  233.     private final Font font2 = new Font("BatangChe", 1, 23);
  234.        
  235.     @Override
  236.     public void onPaint(Graphics g1) {                      
  237.         attributes.profit = (attributes.sellingPrice - attributes.buyingPrice) * attributes.itemsSold;              
  238.         Graphics2D g = (Graphics2D)g1;
  239.         long timeRan = System.currentTimeMillis() - attributes.startTime;
  240.        
  241.         g.setColor(color1);
  242.         g.fillRect(260, 333, 279, 124);
  243.         g.setColor(color2);
  244.         g.setStroke(stroke1);
  245.         g.drawRect(260, 333, 279, 124);
  246.         g.setFont(font1);
  247.         g.setColor(color3);
  248.         g.drawString("Item: " + attributes.itemName, 267, 354);
  249.         g.drawString("Buying Price: " + attributes.buyingPrice, 267, 368);
  250.         g.drawString("Selling Price: " + attributes.sellingPrice, 267, 384);
  251.         g.drawString("Currently: " + attributes.currently, 267, 398);
  252.         g.drawString("Profit: " + attributes.profit, 268, 412);
  253.         g.drawString("Exchanges: " + attributes.exchanges, 268, 427);          
  254.         g.drawString("Time running: " + Timing.msToString(timeRan), 269, 445);
  255.         g.setFont(font2);
  256.         g.setColor(color1);
  257.         g.drawString("Status: " + attributes.status, 13, 368);
  258.     }
  259.    
  260.     public void sendValues(String buyMessage, String sellMessage, String itemName,
  261.             int buyPrice, int sellPrice, int sellingSwitch) {
  262.         //*
  263.         /* Gets all values sent from gui
  264.          * and sets them in the Check class for future reference
  265.          */
  266.         attributes.buyingMessage = buyMessage;
  267.         attributes.sellingMessage = sellMessage;
  268.         attributes.itemName = itemName;
  269.         attributes.buyingPrice = buyPrice;
  270.         attributes.sellingPrice = sellPrice;
  271.         attributes.startSellingSwitch = sellingSwitch; 
  272.     }      
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement