Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 18.03 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Rectangle;
  7. import java.awt.RenderingHints;
  8. import java.util.Arrays;
  9. import java.util.EnumSet;
  10. import java.util.Vector;
  11. import java.util.regex.Pattern;
  12.  
  13. import javax.swing.JOptionPane;
  14.  
  15. import bergCoder.BergUtils;
  16.  
  17. import impsoft.bots.ColorBot;
  18. import impsoft.bots.reflection.NPC;
  19. import impsoft.bots.reflection.NPCIterator;
  20. import impsoft.bots.reflection.Player;
  21. import impsoft.bots.reflection.PlayerIterator;
  22. import impsoft.scripting.ibot.builtin.itemrec.ItemSlot;
  23. import impsoft.scripting.ibot.builtin.ocr.NPCChat;
  24. import impsoft.scripting.ibot.enums.Skill;
  25. import impsoft.scripting.ibot.interfaces.AutoPaint;
  26. import impsoft.scripting.ibot.interfaces.ChatListener;
  27. import impsoft.scripting.ibot.itemrec.ItemNameExact;
  28. import impsoft.scripting.ibot.structs.AryanTile;
  29. import impsoft.scripting.ibot.structs.AryanTileZone;
  30. import impsoft.scripting.types.ColorScript;
  31. import impsoft.utils.general.Timer;
  32. import impsoft.utils.ibot.RandomGenerator;
  33. import impsoft.utils.ruler.RulerClickOptions;
  34. import impsoft.utils.ruler.RulerScriptUtils;
  35. import impsoft.values.constant.Areas;
  36. import impsoft.values.variable.MouseSettings;
  37.  
  38. public class HunterFalconry extends ColorScript implements AutoPaint, ChatListener
  39. {
  40.  
  41.     AryanTileZone falconryZone = new AryanTileZone(new AryanTile(2367, 3591), new AryanTile(2379, 3580));
  42.     public int[] kebbitID;
  43.     public int[] falconID;
  44.     int lvlStartHunter;
  45.     int xpStartHunter, xpNowHunter, xpStartPrayer, xpNowPrayer;
  46.     Timer timeRan = new Timer(0);
  47.     Timer antiBanTimer = null;
  48.     BergUtils berg = new BergUtils(this);
  49.     int dropAt;
  50.  
  51.     boolean lostFalconry = false;
  52.     boolean huntSucess = false;
  53.     boolean huntFail = false;
  54.     boolean falconBack = false;
  55.  
  56.     public static String author = "FlashWeb";
  57.     public static String name = "HunterFalconry FW";
  58.     public static String description = "Hunts Spotted/Dark Kebbit using Falconry in Piscatoris Hunter area";
  59.     public static String version = "3";
  60.  
  61.     public HunterFalconry(ColorBot c)
  62.     {
  63.         super(c);
  64.     }
  65.  
  66.     public enum State
  67.     {
  68.         WALK, HUNT, LOOT, DROP, ANTIBAN, LOST
  69.     }
  70.  
  71.     State botState;
  72.  
  73.     NPC kebbit;
  74.  
  75.     @Override
  76.     public void script() throws InterruptedException, Exception
  77.     {
  78.  
  79.         sleep(100);
  80.  
  81.         boolean noFalcon = false;
  82.  
  83.         if (this.theTabs.Equipment.getWeapon() == null)
  84.         {
  85.             noFalcon = true;
  86.         }
  87.         else if (!this.theTabs.Equipment.getWeapon().equalsIgnoreCase("Falconer's glove"))
  88.         {
  89.             noFalcon = true;
  90.         }
  91.  
  92.         if (noFalcon)
  93.         {
  94.             getGyrFalcon();
  95.         }
  96.  
  97.         RulerScriptUtils.useModels = true;
  98.         antiBanTimer = new Timer(random(90000, 240000));
  99.  
  100.         lvlStartHunter = this.theTabs.Statistics.getStatBottom(Skill.HUNTER);
  101.         xpStartHunter = this.theTabs.Statistics.getStatExperience(Skill.HUNTER);
  102.         xpStartPrayer = this.theTabs.Statistics.getStatExperience(Skill.PRAYER);
  103.  
  104.         dropAt();
  105.  
  106.         if (lvlStartHunter < 43)
  107.         {
  108.             slowExit("You need Level 43 to catch Spotted Kebbit");
  109.         }
  110.         else if (lvlStartHunter < 57)
  111.         {
  112.             log("You can catch Spotted Kebbit");
  113.             kebbitID = new int[] { 5098 };
  114.             falconID = new int[] { 5094 };
  115.         }
  116.         else if (lvlStartHunter >= 57)
  117.         {
  118.             log("You can catch Spotted Kebbit and Dark Kebbit");
  119.             kebbitID = new int[] { 5098, 5099 };
  120.             falconID = new int[] { 5094, 5096 };
  121.         }
  122.  
  123.         while (true)
  124.         {
  125.             getBotState();
  126.  
  127.             switch (this.botState)
  128.             {
  129.             case WALK:
  130.                 walk();
  131.                 break;
  132.             case HUNT:
  133.                 hunt();
  134.                 break;
  135.             case LOOT:
  136.                 loot();
  137.                 break;
  138.             case DROP:
  139.                 drop();
  140.                 break;
  141.             case ANTIBAN:
  142.                 antiBan();
  143.                 break;
  144.             case LOST:
  145.                 getGyrFalcon();
  146.                 break;
  147.             }
  148.         }
  149.     }
  150.  
  151.     private void getBotState() throws InterruptedException
  152.     {
  153.  
  154.         if (this.huntSucess)
  155.         {
  156.             this.botState = State.LOOT;
  157.         }
  158.         else if (this.lostFalconry)
  159.         {
  160.             this.botState = State.LOST;
  161.         }
  162.         else if (antiBanTimer.isUp())
  163.         {
  164.             this.botState = State.ANTIBAN;
  165.         }
  166.         else if (this.theTabs.Inventory.count(new ItemNameExact("Bones")) > dropAt)
  167.         {
  168.             this.botState = State.DROP;
  169.         }
  170.         else
  171.         {
  172.             kebbit = getNearestNpcById(kebbitID);
  173.  
  174.             if (this.kebbit == null)
  175.             {
  176.                 this.botState = State.WALK;
  177.             }
  178.             else
  179.             {
  180.                 this.botState = State.HUNT;
  181.             }
  182.         }
  183.  
  184.         log("[getBotState()] " + this.botState);
  185.     }
  186.  
  187.     private void dropAt()
  188.     {
  189.         dropAt = random(6, 10);
  190.     }
  191.  
  192.     private void slowExit(String msg) throws InterruptedException
  193.     {
  194.         log("FORCE SHUTDOWN");
  195.         this.startAllRandoms();
  196.         log(msg);
  197.         JOptionPane.showMessageDialog(null, msg, "HunterFalconry FW", JOptionPane.ERROR_MESSAGE);
  198.         sleep(1000);
  199.         shutDown();
  200.     }
  201.  
  202.     private void drop() throws InterruptedException
  203.     {
  204.         if (!this.theTabs.Inventory.isSelected())
  205.         {
  206.             this.theTabs.Inventory.click();
  207.         }
  208.  
  209.         int[] clickOrder = { 0, 4, 8, 12, 16, 20, 24, 1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27 };
  210.  
  211.         for (int i = 0; i < clickOrder.length; i++)
  212.         {
  213.             ItemSlot itemSlot = theTabs.Inventory.SLOTS[clickOrder[i]];
  214.  
  215.             if (itemSlot.isItemInSlot())
  216.             {
  217.                 if (itemSlot.getItemName().equals("Bones"))
  218.                 {
  219.                     itemSlot.mouseMoveOn();
  220.                     itemSlot.mouseClickLeftOn();
  221.                     sleep(800, 900);
  222.                 }
  223.             }
  224.         }
  225.  
  226.         xpNowPrayer = this.theTabs.Statistics.getStatExperience(Skill.PRAYER);
  227.  
  228.         for (int i = 0; i < clickOrder.length; i++)
  229.         {
  230.             ItemSlot itemSlot = theTabs.Inventory.SLOTS[clickOrder[i]];
  231.  
  232.             if (itemSlot.isItemInSlot())
  233.             {
  234.                 if (itemSlot.getItemName().contains("kebbit fur"))
  235.                 {
  236.                     itemSlot.mouseMoveOn();
  237.                     itemSlot.mouseClickRightOn();
  238.                     this.theMenuFinder.doMenuContains("Drop");
  239.                     sleep(1000, 1500);
  240.                 }
  241.             }
  242.         }
  243.  
  244.         dropAt();
  245.     }
  246.  
  247.     private void loot() throws InterruptedException
  248.     {
  249.         log("[loot()] looting");
  250.         kebbit = getNearestNpcById(falconID);
  251.  
  252.         if (kebbit != null)
  253.         {
  254.             falconBack = false;
  255.  
  256.             Pattern lootPattern = Pattern.compile(".*Retrieve.*" + kebbit.getName() + ".*", Pattern.CASE_INSENSITIVE);
  257.             RulerScriptUtils.clickWorldObject(this, null, this.kebbit, null, lootPattern, lootPattern, EnumSet.of(RulerClickOptions.GOAL_NORMAL_CLICK,
  258.                     RulerClickOptions.WALK_USING_ANY, RulerClickOptions.PAINT_GAMESCREEN_WALKING, RulerClickOptions.PAINT_PREDICTION_POLYGON));
  259.             sleep(500, 800);
  260.  
  261.             while (!this.falconBack)
  262.             {
  263.                 sleep(50, 100);
  264.                 log("[loot()] waiting for chat update");
  265.             }
  266.  
  267.             this.huntSucess = false;
  268.         }
  269.         else
  270.         {
  271.             kebbit = getNearestNpcById(falconID);
  272.            
  273.             if (kebbit == null)
  274.             {
  275.                 this.huntSucess = false;
  276.             }
  277.         }
  278.  
  279.         xpNowHunter = this.theTabs.Statistics.getStatExperience(Skill.HUNTER);
  280.     }
  281.  
  282.     public NPC getNearestNpcById(int[] id)
  283.     {
  284.         log("[getNearestNpcById()] " + Arrays.toString(id));
  285.  
  286.         NPC closest = null;
  287.  
  288.         double closeDistance = 100;
  289.  
  290.         AryanTile here = getLocation();
  291.  
  292.         for (NPCIterator po = getNPCIterator(); po.hasNext();)
  293.         {
  294.             NPC npc = po.next();
  295.  
  296.             Integer ID = npc.getType();
  297.  
  298.             for (int i : id)
  299.             {
  300.                 if (ID == i)
  301.                 {
  302.                     double distance = npc.getLocation().distanceToPrecise(here);
  303.                     if (distance < closeDistance)
  304.                     {
  305.                         closest = npc;
  306.                         closeDistance = distance;
  307.                     }
  308.                 }
  309.             }
  310.         }
  311.         return closest;
  312.     }
  313.  
  314.     private void hunt() throws InterruptedException
  315.     {
  316.         checkPlayers();
  317.  
  318.         log("[hunt()] start");
  319.  
  320.         kebbit = this.getNearestNpcById(kebbitID);
  321.  
  322.         Timer moveTimer = new Timer(1000);
  323.  
  324.         while (kebbit.isMoving())
  325.         {
  326.             sleep(50, 75);
  327.  
  328.             if (moveTimer.isUp())
  329.             {
  330.                 log("[hunt()] NPC moving for long time, finding another NPC");
  331.                 return;
  332.             }
  333.         }
  334.  
  335.         log("[hunt()] Clicking");
  336.  
  337.         this.huntFail = false;
  338.         this.huntSucess = false;
  339.  
  340.         Pattern catchSpotted = Pattern.compile(".*Catch.*" + kebbit.getName() + ".*", Pattern.CASE_INSENSITIVE);
  341.         RulerScriptUtils.clickWorldObject(this, null, this.kebbit, null, catchSpotted, catchSpotted, EnumSet.of(RulerClickOptions.GOAL_MENU_CLICK,
  342.                 RulerClickOptions.WALK_USING_ANY, RulerClickOptions.PAINT_GAMESCREEN_WALKING, RulerClickOptions.PAINT_PREDICTION_POLYGON,
  343.                 RulerClickOptions.PEND_FOR_MOVEMENT_TO_STOP));
  344.  
  345.         Timer huntFailTimer = new Timer(2000);
  346.  
  347.         while (this.huntFail == false && this.huntSucess == false)
  348.         {
  349.             log("[hunt()] waiting for ChatListener to update hunt status");
  350.             sleep(50, 100);
  351.  
  352.             if (huntFailTimer.isUp())
  353.             {
  354.                 log("[hunt()] breaking as no hunt status update from ChatListener");
  355.                 break;
  356.             }
  357.         }
  358.  
  359.         log("[hunt()] end");
  360.     }
  361.  
  362.     private void walk() throws InterruptedException
  363.     {
  364.         log("[walk()] start");
  365.         this.theWorldMap.walkTo(this.falconryZone.random());
  366.         log("[walk()] end");
  367.     }
  368.  
  369.     public void antiBan() throws InterruptedException
  370.     {
  371.         switch (random(1, 10))
  372.         {
  373.         case 1:
  374.             log("[antiBan()] Short pause and mouse of screen");
  375.             berg.moveMouseOffscreen();
  376.             sleep(random(10, 30) * 1000);
  377.             break;
  378.         case 2:
  379.             log("[antiBan()] Mouse movement");
  380.             mouseMove(Areas.ENTIRE);
  381.             if (theTopText.isTopTextContaining("level"))
  382.             {
  383.                 mouseClickRight(getCurrentMouseXY());
  384.                 log("We found a player or an NPC. Right clicked");
  385.             }
  386.             break;
  387.         case 3:
  388.             log("[antiBan()] Right clicking");
  389.             mouseClickRight(Areas.GAME);
  390.             sleep(150, 200);
  391.             if (random(1, 5) < 3)
  392.                 theMenuFinder.doMenuContains("ancel");
  393.             break;
  394.         case 4:
  395.             log("[antiBan()] Reverting mouse speed");
  396.             setMouseSpeed(random(100, 106));
  397.             break;
  398.         case 5:
  399.             log("[antiBan()] Speeding mouse movements by 5-10%");
  400.             increaseMouseSpeed(random(5, 11));
  401.             break;
  402.         case 6:
  403.             log("[antiBan()] Decreasing mouse movements by 5-10%");
  404.             decreaseMouseSpeed(random(5, 11));
  405.             break;
  406.         case 7:
  407.             log("[antiBan()] move mouse out of screen");
  408.             berg.moveMouseOffscreen();
  409.             break;
  410.         case 8:
  411.             log("[antiBan()] skill checking");
  412.             if (!this.theTabs.Statistics.isSelected())
  413.             {
  414.                 this.theTabs.Statistics.setSelected();
  415.             }
  416.             this.mouseMove(new Rectangle(617, 408, 42, 15));
  417.             sleep(600, 1500);
  418.             this.theTabs.Inventory.click();
  419.             sleep(100, 200);
  420.             this.mouseMove(Areas.ENTIRE);
  421.         default:
  422.             log("[antiBan()] compass movement");
  423.             theParallelCompass.setYawRandom();
  424.             break;
  425.         }
  426.         antiBanTimer.reset();
  427.         sleep(500, 900);
  428.     }
  429.  
  430.     // Credits Perfecticus
  431.  
  432.     private void increaseMouseSpeed(int percent)
  433.     {
  434.         final int increase = (100 + percent);
  435.  
  436.         getColorBot().currentSpeed = new MouseSettings()
  437.         {
  438.             public double getSpeed(int dist)
  439.             {
  440.                 if (dist > 300)
  441.                 {
  442.                     return RandomGenerator.randomNormalDouble(0.5, 1.5) / ((double) increase / 100);
  443.                 }
  444.                 else if (dist > 150)
  445.                 {
  446.                     return RandomGenerator.randomNormalDouble(1, 2.3) / ((double) increase / 100);
  447.                 }
  448.                 else
  449.                 {
  450.                     return RandomGenerator.randomNormalDouble(3, 5) / ((double) increase / 100);
  451.                 }
  452.             }
  453.         };
  454.     }
  455.  
  456.     // Credits Perfecticus
  457.  
  458.     private void decreaseMouseSpeed(int percent)
  459.     {
  460.         final int increase = (100 - percent);
  461.  
  462.         getColorBot().currentSpeed = new MouseSettings()
  463.         {
  464.             public double getSpeed(int dist)
  465.             {
  466.                 if (dist > 300)
  467.                 {
  468.                     return RandomGenerator.randomNormalDouble(0.5, 1.5) / ((double) increase / 100);
  469.                 }
  470.                 else if (dist > 150)
  471.                 {
  472.                     return RandomGenerator.randomNormalDouble(1, 2.3) / ((double) increase / 100);
  473.                 }
  474.                 else
  475.                 {
  476.                     return RandomGenerator.randomNormalDouble(3, 5) / ((double) increase / 100);
  477.                 }
  478.             }
  479.         };
  480.     }
  481.  
  482.     private void setMouseSpeed(final int percent)
  483.     {
  484.  
  485.         getColorBot().currentSpeed = new MouseSettings()
  486.         {
  487.             public double getSpeed(int dist)
  488.             {
  489.                 if (dist > 300)
  490.                 {
  491.                     return RandomGenerator.randomNormalDouble(0.5, 1.5) / ((double) percent / 100);
  492.                 }
  493.                 else if (dist > 150)
  494.                 {
  495.                     return RandomGenerator.randomNormalDouble(1, 2.3) / ((double) percent / 100);
  496.                 }
  497.                 else
  498.                 {
  499.                     return RandomGenerator.randomNormalDouble(3, 5) / ((double) percent / 100);
  500.                 }
  501.             }
  502.         };
  503.     }
  504.  
  505.     public void checkPlayers() throws InterruptedException
  506.     {
  507.         Vector<Player> players = new Vector<Player>();
  508.         PlayerIterator playerz = getPlayerIterator();
  509.  
  510.         while (playerz.hasNext())
  511.         {
  512.             if (playerz.next() != null)
  513.                 players.add(playerz.next());
  514.         }
  515.  
  516.         if (players.size() > 1)
  517.         {
  518.             slowExit("HOP TO WORLD WITH NO ONE IN FALCONRY AREA");
  519.         }
  520.     }
  521.  
  522.     private void getGyrFalcon() throws InterruptedException
  523.     {
  524.         NPCChat chat = null;
  525.         NPC Matthias = null;
  526.        
  527.         while(Matthias == null)
  528.         {
  529.             Matthias  = theWorldObjectFinder.findNPC(5092);
  530.         }
  531.        
  532.         while (!theNPCChatFinder.isNPCChatUp())
  533.         {
  534.            
  535.             berg.clickNPCByName(new String[] { "Matthias" }, Matthias.getLocation(), "Falconry");
  536.            
  537.             Timer waitTimer = new Timer(3000);
  538.            
  539.             while (!theNPCChatFinder.isNPCChatUp())
  540.             {
  541.                 log("waiting for npc chat");
  542.                 sleep(100, 200);
  543.                
  544.                 if (waitTimer.isUp())
  545.                 {
  546.                     break;
  547.                 }
  548.             }
  549.         }
  550.  
  551.         if (this.theTabs.Equipment.getWeapon() == null)
  552.         {
  553.  
  554.             if (this.theTabs.Inventory.countStackOf(new ItemNameExact("Coins")) < 500)
  555.             {
  556.                 slowExit("You need 500 GP to get Gyr Falcon");
  557.             }
  558.  
  559.             log("Get Gyr Falcon");
  560.  
  561.             chat = theNPCChatFinder.getNPCChat();
  562.  
  563.             if (chat.contains("Yes"))
  564.             {
  565.                 chat.selectContains("Yes");
  566.                 this.waitTillNPCChatChangesFrom(chat);
  567.                 sleep(1000, 2000);
  568.             }
  569.  
  570.         }
  571.         else if (this.theTabs.Equipment.getWeapon().equalsIgnoreCase("Falconer's glove"))
  572.         {
  573.  
  574.         }
  575.         else
  576.         {
  577.             slowExit("You must get Falconer's glove");
  578.         }
  579.     }
  580.  
  581.     @Override
  582.     public void paint(Graphics g1)
  583.     {
  584.         int xpGained = 0, xpPerHour = 0, xpPrayer = 0;
  585.  
  586.         Graphics2D g = (Graphics2D) g1;
  587.  
  588.         if (this.xpNowHunter > this.xpStartHunter)
  589.         {
  590.             xpGained = this.xpNowHunter - this.xpStartHunter;
  591.             xpPerHour = (int) (xpGained / (timeRan.getTimeElapsed() / 1000D)) * 3600;
  592.         }
  593.  
  594.         if (xpNowPrayer > xpStartPrayer)
  595.         {
  596.             xpPrayer = xpNowPrayer - xpStartPrayer;
  597.         }
  598.  
  599.         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  600.         g.setColor(new Color(0, 102, 0, 200));
  601.         g.fillRoundRect(15, 15, 222, 105, 30, 30);
  602.         g.setColor(new Color(100, 100, 100));
  603.         g.setStroke(new BasicStroke(1));
  604.         g.drawRoundRect(15, 15, 222, 105, 30, 30);
  605.  
  606.         g.setFont(new Font("Comic Sans MS", 1, 13));
  607.         g.setColor(Color.WHITE);
  608.         g.drawString(name + " V" + version, 60, 40);
  609.         g.setFont(new Font("Verdana", 0, 9));
  610.         g.drawString("By: FlashWeb", 140, 50);
  611.         g.drawString("Time Ran: " + timeRan.toStringTimeElapsed(), 40, 60);
  612.         g.drawString("Hunter XP: " + xpGained, 40, 75);
  613.         g.drawString("Hunter XP/H: " + xpPerHour, 40, 90);
  614.         g.drawString("Prayer XP: " + xpPrayer, 40, 105);
  615.  
  616.     }
  617.  
  618.     @Override
  619.     public void chat(String m) throws InterruptedException
  620.     {
  621.         log(m);
  622.  
  623.         if (m.contains("quick for you"))
  624.         {
  625.             lostFalconry = true;
  626.         }
  627.         else if (m.contains("successfully swoops down"))
  628.         {
  629.             huntSucess = true;
  630.         }
  631.         else if (m.contains("misses catching"))
  632.         {
  633.             huntFail = true;
  634.         }
  635.         else if (m.contains("retrieve the falcon"))
  636.         {
  637.             falconBack = true;
  638.         }
  639.     }
  640. }