Advertisement
Guest User

Darks POH Curser V0.9

a guest
Jul 26th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 21.73 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.Polygon;
  9. import java.io.IOException;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12. import java.util.Arrays;
  13.  
  14. import javax.imageio.ImageIO;
  15. import javax.swing.JOptionPane;
  16.  
  17. import org.Magic;
  18. import org.RSArea;
  19. import org.SPELL;
  20. import org.tribot.api2007.NPCChat;
  21. import org.tribot.api.General;
  22. import org.tribot.api.Timing;
  23. import org.tribot.api.input.Keyboard;
  24. import org.tribot.api.input.Mouse;
  25. import org.tribot.api.types.generic.Condition;
  26. import org.tribot.api2007.Camera;
  27. import org.tribot.api2007.Game;
  28. import org.tribot.api2007.GameTab;
  29. import org.tribot.api2007.GameTab.TABS;
  30. import org.tribot.api2007.ChooseOption;
  31. import org.tribot.api2007.Interfaces;
  32. import org.tribot.api2007.Inventory;
  33. import org.tribot.api2007.Login;
  34. import org.tribot.api2007.Objects;
  35. import org.tribot.api2007.Player;
  36. import org.tribot.api2007.Players;
  37. import org.tribot.api2007.Projection;
  38. import org.tribot.api2007.Skills;
  39. import org.tribot.api2007.Walking;
  40. import org.tribot.api2007.types.RSItem;
  41. import org.tribot.api2007.types.RSModel;
  42. import org.tribot.api2007.types.RSObject;
  43. import org.tribot.api2007.types.RSPlayer;
  44. import org.tribot.api2007.types.RSTile;
  45. import org.tribot.script.Script;
  46. import org.tribot.script.ScriptManifest;
  47. import org.tribot.script.interfaces.Ending;
  48. import org.tribot.script.interfaces.Painting;
  49. import org.tribot.script.interfaces.RandomEvents;
  50. @ScriptManifest(authors = { "Dark" }, description = "The Requirements are lvl 19 magic and a POH in the same location as the Host.", category = "Magic", name = "Dark's POH Curser")
  51. public class Darks_POH_Curser extends Script implements Painting, Ending,RandomEvents{
  52.     enum STATE {
  53.         STARTING, OPENING_DOOR, CREATING_COMBAT_RING_AREA, WALKING_TO_RING, GETTING_IN_RING, CURSING_PLAYER, OUTSIDE_HOUSE, LOGGING_OUT, FAILSAFE, ERROR, LOADING_HOUSE;
  54.     }
  55.    
  56.     private Image paint = getImage("http://puu.sh/3MBha.png");
  57.     //http://puu.sh/3L453.png
  58.     private boolean started = false;
  59.     private RSArea combatRingArea;
  60.     private RSArea currentDoorArea;
  61.     private RSObject currentDoor;
  62.     private RSTile maxTile;
  63.     private RSTile minTile;
  64.     private String debug = "DEBUG HERE";
  65.     private RSObject[] combatRing;
  66.     private RSObject combatRingRope;
  67.     private STATE currentState;
  68.     private String state;
  69.     private String playerName = "";
  70.     public long startTime = 0;
  71.     public long millis = 0;
  72.     public long hours = 0;
  73.     public long minutes = 0;
  74.     public long seconds = 0;
  75.     public long last = 0;
  76.     public int expGained = 0;
  77.     public int expPerHour = 0;
  78.     private final int startXp = Skills.getXP("MAGIC");
  79.     public int expToLevel;
  80.     public int curseTNL;
  81.     public int curseCount;
  82.     public int startLevel;
  83.     public int currentLevel;
  84.     public int levelsGained;
  85.     // public final int startHealth = Player.getRSPlayer().getHealth();
  86.     public long sTNL;
  87.     public long mTNL;
  88.     public long hTNL;
  89.     private boolean isDoorOpen = false;
  90.     private boolean isYourHouse = true;
  91.     public static final int COMBAT_RING_ROPE = 13137;
  92.     public static final int POH_TAB = 8013;
  93.     public static final int PORTAL = 15478;
  94.     public static final int[] INHOME_PORTAL = {4525,13405};
  95.     // DEBUG
  96.     RSModel currentModel;
  97.     private int countPerHour;
  98.     private boolean usedTab = false;
  99.     private boolean failsafe = false;
  100.     private long TNL = 0;
  101.     private boolean clicking = false;
  102.     public final String version = " 0.9";
  103.     @Override
  104.     public void run() {
  105.  
  106.         while (true) {
  107.             currentState = getState();
  108.             switch (currentState) {
  109.             case CURSING_PLAYER:
  110.                 cursePlayer();
  111.                 break;
  112.             case GETTING_IN_RING:
  113.                 getInRing();
  114.                 break;
  115.             case OUTSIDE_HOUSE:
  116.                 getBackIntoHouse();
  117.                 break;
  118.             case STARTING:
  119.                 onStart();
  120.                 break;
  121.             case WALKING_TO_RING:
  122.                 walkToRing();
  123.                 break;
  124.             case OPENING_DOOR:
  125.                 while(!isDoorOpen){
  126.                     sleep(186,250);
  127.                 }
  128.                 break;
  129.             case CREATING_COMBAT_RING_AREA:
  130.                 while(combatRingArea == null){
  131.                     sleep(186,250);
  132.                 }
  133.                 break;
  134.             case LOGGING_OUT:
  135.                 Login.logout();
  136.                 this.stopScript();
  137.                 break;
  138.             case FAILSAFE:
  139.                 failSafe();
  140.                 break;
  141.             case LOADING_HOUSE:
  142.                 Timing.waitCondition(new Condition(){
  143.                     @Override
  144.                     public boolean active() {
  145.                        return Interfaces.get(399, 1) == null;
  146.                     }
  147.                 },2500);break;
  148.             default:
  149.                 break;
  150.  
  151.             }
  152.         }
  153.  
  154.     }
  155.  
  156.     public boolean openDoor() {
  157.         debug = " GETTING DOOR...";
  158.         if (getDoor() == null) {
  159.             isDoorOpen = true;
  160.         }
  161.         if (!isDoorOpen && currentDoor == null) {
  162.             currentDoor = getDoor();
  163.             currentModel = currentDoor.getModel();
  164.             currentDoorArea = RSArea.createRSArea(currentDoor.getPosition(), 1);
  165.         } else {
  166.             if (!isDoorOpen) {
  167.                 clickModel(currentModel,"",false);
  168.             }
  169.             debug = " DEBUG:IS Door Open? " + isDoorOpen;
  170.             sleep(750);
  171.  
  172.             return isDoorOpen;
  173.         }
  174.         /**
  175.          * if(Walking.blindWalkTo(currentDoorArea.getMaxTile())){
  176.          * currentDoor.click();
  177.          * while(Game.getDestination().distanceTo(Player.getPosition())!=0){
  178.          * Walking.blindWalkTo(currentDoorArea.getMaxTile());
  179.          * currentDoor.click(); return; } }
  180.          */
  181.         return isDoorOpen;
  182.     }
  183.  
  184.     private RSObject getDoor() {
  185.         debug = " GETTING DOOR OBJECT...";
  186.         // First part checks to see if door is open.
  187.         if (isDoorOpen && currentDoor != null) {
  188.             return currentDoor;
  189.         }
  190.         if (!isDoorOpen) {
  191.             debug = " DOOR ISNT OPEN!";
  192.             for (RSObject o : Objects.findNearest(15, 13100)) {
  193.                 debug = " Found Something";
  194.                 if (o != null) {
  195.                     debug = " It's not Null "
  196.                             + (combatRingArea.getDistanceFrom(o.getPosition()) < 15);
  197.                     if (combatRingArea.getDistanceFrom(o.getPosition()) < 8) {
  198.                         debug = " It's on screen and less than 8 tiles away from ring.";
  199.                         if (Player.getPosition().distanceTo(o.getPosition()) <= 4) {
  200.                             debug = " It's less than 5 tiles away from me.";
  201.                             currentDoorArea = RSArea.createRSArea(
  202.                                     o.getPosition(), 1);
  203.                             debug = " Distance To Area: "
  204.                                     + currentDoorArea.getDistanceFrom(Player
  205.                                             .getPosition());
  206.                             debug = "MAX TILE?: ";// +currentDoorArea.getMaxTile().toString();
  207.                             return o;
  208.  
  209.                         }
  210.                     }
  211.                 }
  212.             }
  213.         }
  214.         return null;
  215.     }
  216.  
  217.     /**
  218.      * This Method will use a tele tab to get back to their house, then if it
  219.      * isn't their house it will leave their house and hand over control back to
  220.      * the script. The script will continue on. Otherwise it will just continue
  221.      * on after it is back in their house.If you have no tele tabs it will log
  222.      * out and end the script.
  223.      */
  224.     private boolean failSafe() {
  225.         failsafe = true;
  226.     if(!usedTab){
  227.         if(useTeleTab()){
  228.             usedTab = true;
  229.         if (!isYourHouse) {
  230.             sleep(1000,1500);
  231.             Timing.waitCondition(new Condition(){
  232.                 @Override
  233.                 public boolean active() {
  234.                    return Interfaces.get(399, 1) == null;
  235.                 }
  236.             },2500);
  237.             sleep(1000,1500);
  238.          if(getNearestObject(INHOME_PORTAL, 25) !=null)
  239.             Timing.waitCondition(new Condition() {
  240.                 @Override
  241.                 public boolean active() {
  242.                     return getNearestObject("Portal", 25).click("Enter");
  243.                 }
  244.             }, 650);
  245.          Timing.waitCondition(new Condition(){@Override
  246.         public boolean active() {
  247.             return Interfaces.get(399, 1) != null;
  248.         }},3500);
  249.          Timing.waitCondition(new Condition(){
  250.                 @Override
  251.                 public boolean active() {
  252.                    return Interfaces.get(399, 1) == null;
  253.                 }
  254.             },2500);
  255.              failsafe = false;
  256.             return true;
  257.         }
  258.     }
  259.     }
  260.         failsafe = false;
  261.         return usedTab;
  262.     }
  263.  
  264.     private boolean useTeleTab() {
  265.         if (Inventory.getCount(POH_TAB) > 0) {
  266.             Timing.waitCondition(new Condition() {
  267.                 @Override
  268.                 public boolean active() {
  269.                     return Inventory.find(POH_TAB)[0].hover();
  270.                 }
  271.             }, 650);
  272.              RSItem i=Inventory.find(POH_TAB)[0];
  273.             int x = (int)i.getArea().getCenterX();
  274.             int y = (int)i.getArea().getCenterY();
  275.             Mouse.click(x, y, 3);
  276.             ChooseOption.select("Break");
  277.             General.println("USED TAB");
  278.             Timing.waitCondition(new Condition(){
  279.                 @Override
  280.                 public boolean active() {
  281.                    return Interfaces.get(399, 1) != null;
  282.                 }
  283.             },2500);
  284.             Timing.waitCondition(new Condition() {
  285.                 @Override
  286.                 // Sleep while That interface is up.
  287.                 public boolean active() {
  288.                     return Interfaces.get(399, 1) == null;
  289.                 }
  290.             }, 4500);
  291.             usedTab = false;
  292.             return true; // Return true after your player is at their house.
  293.         } else if (Inventory.getCount(POH_TAB) == 0) {
  294.             General.println("You were lost or lured away or something happened, and you had no tele tabs so this script logged you out and ended.");
  295.             Login.logout();
  296.             stopScript();
  297.             // If you have no tabs it will stop the script.
  298.             // So really this method can only return true.
  299.         }
  300.         return false;
  301.     }
  302.  
  303.     private boolean hasRunes() {
  304.         return Inventory.getCount(559) > 0;
  305.     }
  306.  
  307.     private void cursePlayer() {
  308.         for (final RSPlayer p : Players.getAll()) {
  309.             if (p == null) {
  310.                 break;
  311.             }
  312.             if (p.getName() != Player.getRSPlayer().getName()) {
  313.                 debug = " Combat cycle : "+p.getCombatCycle()+"\n"+"My cycle "+Player.getRSPlayer().getCombatCycle();
  314.                 while (hasRunes()&& p.isOnScreen()
  315.                         && combatRingArea.isInArea(p.getPosition())
  316.                         && combatRingArea.isInArea(Player.getPosition())) {
  317.                     if (GameTab.getOpen() != TABS.MAGIC) {
  318.                         GameTab.open(TABS.MAGIC);
  319.                     }
  320.                     if (Magic.cast(SPELL.CURSE)) {
  321.                         curseCount++;
  322.                         Camera.turnToTile(p.getPosition());
  323.                         currentModel = null;
  324.                         Timing.waitCondition(new Condition() {
  325.                             @Override
  326.                             public boolean active() {
  327.                                 return p.click();
  328.                             }
  329.                         }, 650);
  330.                         if(Player.getRSPlayer().getInteractingCharacter() == null){
  331.                             break;
  332.                         }
  333.                     }
  334.                 }
  335.             }
  336.         }
  337.     }
  338.  
  339.     private void getBackIntoHouse() {
  340.         long t = System.currentTimeMillis();
  341.         while(Timing.timeFromMark(t)< 300000&& !isInsideHouse()){
  342.         currentDoorArea = null;
  343.         if (isYourHouse) {
  344.             if (Objects.findNearest(20, PORTAL).length > 0) {
  345.                 currentModel = Objects.findNearest(20, PORTAL)[0].getModel();
  346.                 if (clickModel(currentModel, "Enter", true)) {
  347.                     if (NPCChat.selectOption("Go to your house", true)) {
  348.                         currentModel = null;
  349.                         Timing.waitCondition(new Condition() {
  350.                             @Override
  351.                             public boolean active() {
  352.                                 return Interfaces.get(399, 1) == null;
  353.                             }
  354.                         }, 3500);
  355.                     }
  356.                 }
  357.             }
  358.         } else {
  359.             if (Objects.findNearest(20, PORTAL).length > 0) {
  360.                 currentModel = Objects.findNearest(20, PORTAL)[0].getModel();
  361.                 if (clickModel(currentModel, "Enter", true)) {
  362.                     if (NPCChat.selectOption("Go to a friend's house", true)) {
  363.                         typeString(playerName);
  364.                         currentModel = null;
  365.                         Timing.waitCondition(new Condition() {
  366.                             @Override
  367.                             public boolean active() {
  368.                                 return Interfaces.get(399, 1) == null;
  369.                             }
  370.                         }, 3500);
  371.                     }
  372.                 }
  373.             }
  374.         }
  375.         }
  376.         if(Timing.timeFromMark(t)>=300000){
  377.             Login.logout();
  378.             this.stopScript();
  379.         }
  380.     }
  381.  
  382.     private void getInRing() {
  383.         if (combatRingRope == null) {
  384.             combatRingRope = Objects.find(50, COMBAT_RING_ROPE)[General.random(0,Objects.find(50, COMBAT_RING_ROPE).length-1)];
  385.         }
  386.         else{
  387.         currentModel = combatRingRope.getModel();
  388.     if(!clicking){
  389.         clicking = true;
  390.         Timing.waitCondition(new Condition(){
  391.             @Override
  392.             public boolean active() {
  393.                 return clickModel(currentModel, "", false);
  394.             }
  395.         },5000);
  396.         sleep(450,800);
  397.         Timing.waitCondition(new Condition(){
  398.             @Override
  399.             public boolean active() {
  400.             return Player.getAnimation() == 3688;
  401.             }
  402.         }, 1250);
  403.         Timing.waitCondition(new Condition() {
  404.             @Override
  405.             public boolean active() {
  406.                 return Player.getAnimation() == -1;
  407.             }
  408.         }, 5000);}clicking = false;}
  409.         currentDoorArea = null;
  410.         currentDoor = null;
  411.         currentModel = null;
  412.         return;
  413.     }
  414.  
  415.     private STATE getState() {
  416.         if (!started) {
  417.             return STATE.STARTING;
  418.         }
  419.         if(Interfaces.get(399, 1) != null){
  420.             return STATE.LOADING_HOUSE;
  421.         }
  422.         if (!failsafe&&!isInsideHouse() && Objects.findNearest(20, PORTAL).length == 0) {
  423.             combatRingArea = null;
  424.             return STATE.FAILSAFE;
  425.         }
  426.         if (!hasRunes()) {
  427.             return STATE.LOGGING_OUT;
  428.         }
  429.         if (!failsafe&&isInsideHouse() && combatRingArea == null
  430.                 && determineCombatRingArea()) {
  431.             return STATE.CREATING_COMBAT_RING_AREA;
  432.         }
  433.         if (!failsafe&&isInsideHouse() && !isDoorOpen) {
  434.             if (combatRingArea != null
  435.                     && combatRingArea.isInArea(Player.getPosition())) {
  436.                 return STATE.CURSING_PLAYER;
  437.             } else if (openDoor()) {
  438.                 return STATE.OPENING_DOOR;
  439.             }
  440.         }
  441.         if (!failsafe&&isInsideHouse() &&combatRingArea != null&& !combatRingArea.isInArea(Player.getPosition())) {
  442.             if (combatRingArea.getDistanceFrom(Player.getPosition()) > 2) {
  443.                 return STATE.WALKING_TO_RING;
  444.             }
  445.             return STATE.GETTING_IN_RING;
  446.         }
  447.         if (!failsafe&&isInsideHouse() && combatRingArea != null
  448.                 && combatRingArea.isInArea(Player.getPosition())) {
  449.             return STATE.CURSING_PLAYER;
  450.         }
  451.         if (getNearestObject(PORTAL,35) != null) {
  452.             combatRingArea = null;
  453.             return STATE.OUTSIDE_HOUSE;
  454.         }
  455.         return STATE.ERROR;
  456.     }
  457.  
  458.     private void walkToRing() {
  459.         if (isDoorOpen) {
  460.             if (combatRingRope == null) {
  461.                 combatRingRope = Objects.find(50, COMBAT_RING_ROPE)[General.random(0,Objects.find(50, COMBAT_RING_ROPE).length-1)];
  462.             }
  463.             Walking.walkTo(combatRingRope.getPosition());
  464.             while (Player.isMoving()) {
  465.                 Camera.turnToTile(combatRingRope.getPosition());
  466.             }
  467.         } else {
  468.             if (combatRingArea.getDistanceFrom(Player.getPosition()) > 8) {
  469.                 openDoor();
  470.             }
  471.         }
  472.     }
  473.  
  474.     private boolean isInsideHouse() {
  475.         return Objects.find(25, INHOME_PORTAL) != null
  476.                 && Objects.find(25, INHOME_PORTAL).length > 0;
  477.     }
  478.  
  479.     private void onStart() {
  480.         // currentState = STATE.STARTING;
  481.         startTime = System.currentTimeMillis();
  482.         startLevel = Skills.getActualLevel("MAGIC");
  483.         playerName += JOptionPane.showInputDialog(
  484.                 "Enter Player's name if it's not your house. Otherwise hit enter.", Player
  485.                         .getRSPlayer().getName());
  486.         if (!Player.getRSPlayer().getName().equalsIgnoreCase(playerName)) {
  487.             isYourHouse = false;
  488.             General.println("This isn't your house@");
  489.         }
  490.         if(playerName.length() >1){
  491.             /**this.setRandomSolverState(RANDOM_SOLVERS.STRANGEPLANT,false);
  492.             this.setRandomSolverState(RANDOM_SOLVERS.DWARF,false);
  493.             this.setRandomSolverState(RANDOM_SOLVERS.SECURITYGUARD,false);
  494.             this.setRandomSolverState(RANDOM_SOLVERS.RICKTURPENTINE,false);*/
  495.             started = true;
  496.         }
  497.     }
  498.  
  499.     @Override
  500.     public void onPaint(Graphics g) {
  501.         // MATH
  502.         millis = System.currentTimeMillis() - startTime;
  503.         hours = millis / (1000 * 60 * 60);
  504.         millis -= hours * (1000 * 60 * 60);
  505.         minutes = millis / (1000 * 60);
  506.         millis -= minutes * (1000 * 60);
  507.         seconds = millis / 1000;
  508.         int currentExp = Skills.getXP("Magic");
  509.         curseCount = (currentExp - startXp) / 29;
  510.         countPerHour = (int) ((curseCount) * 3600000D / (System
  511.                 .currentTimeMillis() - startTime));
  512.         expPerHour = (int) ((expGained) * 3600000D / (System
  513.                 .currentTimeMillis() - startTime));
  514.         expGained = Skills.getXP("MAGIC") - startXp;
  515.         curseTNL = Skills.getXPToLevel("MAGIC", currentLevel + 1) / 29;
  516.         currentLevel = Skills.getCurrentLevel("MAGIC");
  517.         levelsGained = currentLevel - startLevel;
  518.         expToLevel = Skills.getXPToNextLevel("MAGIC");
  519.         if(expPerHour != 0){
  520.          TNL =(long)(expToLevel*3600000.0D)/expPerHour;}
  521.         // DEBUG
  522.        
  523.         debug = ""+Skills.getXPToNextLevel("Magic");
  524.         if (currentModel != null) {
  525.             paintRSModel(g, currentModel);
  526.         }
  527.         if (currentDoorArea != null) {
  528.             currentDoorArea.paintRSArea(g);
  529.         }
  530.         if (combatRingArea != null) {
  531.             combatRingArea.paintRSArea(g);
  532.             g.drawString(debug, 250, 300);
  533.         }
  534.  
  535.         g.drawString(debug, 250, 300);
  536.  
  537.         if (minTile != null && maxTile != null) {
  538.             g.setColor(Color.RED);
  539.             drawTile(minTile, (Graphics2D) g, false);
  540.             drawTile(maxTile, (Graphics2D) g, false);
  541.  
  542.         }
  543.         g.setColor(Color.BLUE);
  544.         drawTile(Player.getPosition(), (Graphics2D) g, false);
  545.         g.setColor(Color.ORANGE);
  546.         if (Game.getDestination() != null) {
  547.             drawTile(Game.getDestination(), (Graphics2D) g, false);
  548.         }
  549.         // ACTUAL Paint - old y 300
  550.         g.drawImage(paint, 0, 225, null);
  551.         // Status
  552.         g.setColor(Color.WHITE);
  553.         if (currentState != null) {
  554.             state = currentState.toString();
  555.             g.drawString(state, 300, 375);
  556.         }
  557.         g.drawString(version, 490,375);
  558.         // Time
  559.         g.drawString(hours + ":" + minutes + ":" + seconds, 418, 400);
  560.         g.drawString(formatTime(TNL), 381, 415);
  561.         // Level
  562.         g.drawString(currentLevel + " (" + levelsGained + ")", 390, 435);
  563.         // XP
  564.         g.drawString("" + expGained, 430, 452);
  565.         g.drawString("" + expPerHour, 400, 470);
  566.  
  567.     }
  568.  
  569.     private boolean determineCombatRingArea() {
  570.         if (getNearestObject("Combat ring", 50) != null) {
  571.             int[] xCoords;
  572.             int[] yCoords;
  573.             combatRing = Objects.find(50, "Combat ring");
  574.             xCoords = new int[combatRing.length];
  575.             yCoords = new int[combatRing.length];
  576.             for (int x = 0; x <= combatRing.length - 1; x++) {
  577.                     RSTile pos = combatRing[x].getPosition();
  578.                     xCoords[x] = pos.getX();
  579.                     yCoords[x] = pos.getY();
  580.             }
  581.            
  582.             Arrays.sort(xCoords);
  583.             Arrays.sort(yCoords);
  584.             minTile = new RSTile(xCoords[8], yCoords[8]);
  585.             maxTile = new RSTile(xCoords[xCoords.length - 8],
  586.                             yCoords[yCoords.length - 8]);
  587.            
  588.                            
  589.            
  590.             combatRingArea = new RSArea(minTile, maxTile);
  591.            
  592.             return true;
  593.     } else {
  594.            
  595.     }
  596.     return false;
  597.     }
  598.  
  599.     public void createDoorArea() {
  600.         if (currentDoor != null && currentDoorArea == null) {
  601.             int x = currentDoor.getPosition().getX();
  602.             int y = currentDoor.getPosition().getY();
  603.             currentDoorArea = new RSArea(x - 1, y + 1, x + 1, y - 1);
  604.         }
  605.     }
  606.  
  607.     private void drawTile(RSTile tile, Graphics2D g, boolean fill) {
  608.         if (tile.isOnScreen()) {
  609.             if (fill) {
  610.                 g.fillPolygon(Projection.getTileBoundsPoly(tile, 0));
  611.             } else {
  612.                 g.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
  613.             }
  614.         }
  615.     }
  616.  
  617.     private Image getImage(String url) {
  618.         try {
  619.             return ImageIO.read(new URL(url));
  620.         } catch (MalformedURLException e) {
  621.         } catch (IOException e) {
  622.         }
  623.         return null;
  624.     }
  625.  
  626.     private RSObject getNearestObject(String id, int dist) {
  627.         for (RSObject o : Objects.find(dist, id)) {
  628.             if (o != null) {
  629.                 return o;
  630.             }
  631.         }
  632.         return null;
  633.     }
  634.  
  635.     private RSObject getNearestObject(int id, int dist) {
  636.         for (RSObject o : Objects.find(dist, id)) {
  637.             if (o != null) {
  638.                 return o;
  639.             }
  640.         }
  641.         return null;
  642.     }
  643.  
  644.     private Object getNearestObject(int[] inhomePortal, int dist) {
  645.         for(RSObject o : Objects.find(dist, INHOME_PORTAL)){
  646.             if(o != null){
  647.                 return o;
  648.             }
  649.         }
  650.         return null;
  651.     }
  652.  
  653.     public Point getBestPoint(Point[] points) {
  654.         int sumX = 0, sumY = 0;
  655.         int averageX, averageY;
  656.         int count = 0;
  657.  
  658.         for (Point p : points) {
  659.             sumX += p.getX();
  660.             sumY += p.getY();
  661.             count++;
  662.         }
  663.         averageX = sumX / count;
  664.         averageY = sumY / count;
  665.         return averageX > 0 && averageY > 0 ? new Point(averageX, averageY)
  666.                 : null;
  667.     }
  668.  
  669.     public boolean clickModel(RSModel model, String option, boolean rightClick) {
  670.    
  671.        
  672.           while(Player.isMoving()){
  673.               sleep(750,956);
  674.           }
  675.     if(Camera.getCameraAngle() <60&& Camera.getCameraAngle() > 70 ){
  676.         Camera.setCameraAngle(General.random(60,70));}
  677.         Point[] points = model.getAllVisiblePoints();
  678.         int length = points.length;
  679.         if (length != 0) {
  680.             Point p = getBestPoint(points);
  681.             Mouse.move(p);
  682.             {
  683.                 String top = Game.getUptext();
  684.                 if (top.contains(option)) {
  685.                     Mouse.click(p, 0);
  686.                      while(Player.isMoving()){
  687.                          sleep(200,250);
  688.                      }
  689.                     return true;
  690.                 } else if (rightClick) {
  691.                     Mouse.click(3);
  692.                     Timing.waitChooseOption(option,1300);
  693.                     if (!ChooseOption.isOpen())
  694.                         return false;
  695.                     if (ChooseOption.select(option))
  696.                         return true;
  697.                 }
  698.             }
  699.         }
  700.         return false;
  701.     }
  702.     public boolean isInCombat(){
  703.         return Player.getRSPlayer().getInteractingCharacter() != null
  704.                 && Player.getRSPlayer().getInteractingCharacter()
  705.                         .getCombatCycle() > 0;
  706.     }
  707.     public void paintRSModel(Graphics g, RSModel m) {
  708.         g.setColor(Color.GREEN);
  709.         for (Polygon p : m.getTriangles()) {
  710.             g.drawPolygon(p);
  711.         }
  712.     }
  713.  
  714.     private boolean typeString(final String s) {       
  715.         if (s.length() > 0) {
  716.            
  717.             Timing.waitCondition(new Condition() {
  718.                 @Override
  719.                 public boolean active() {
  720.                     return Interfaces.get(548, 94) != null;
  721.                 }
  722.             }, 3000);
  723.             sleep(924,1250);
  724.             Keyboard.typeString(s);
  725.             Timing.waitCondition(new Condition() {
  726.                 @Override
  727.                 public boolean active() {
  728.                     return Interfaces.get(548, 94) != null&&Interfaces.get(548, 94).getText().equals(playerName);
  729.                 }
  730.             }, 3000);
  731.             Keyboard.pressEnter();
  732.             General.println("SENT :"+playerName);
  733.            
  734.             return true;
  735.         }
  736.        
  737.         return false;
  738.     }
  739.  
  740.     private String formatTime(long time) {
  741.         return Timing.msToString(time);
  742.         //return (time / (1000 * 60 * 60) + ":" + (time / (1000 * 60)) + ":" + (time / 1000));
  743.     }
  744.  
  745.     @Override
  746.     public void onEnd() {
  747.         String output = "Script Ended....."+"\n"
  748.                          +"::Script Stats::"
  749.                          +"\n"+"Time Ran : "+formatTime(System.currentTimeMillis() - startTime)+"\n"
  750.                          +"XP Gained : "+expGained+"\n"
  751.                          +"Xp/Hr: "+expPerHour;
  752.         General.println(output);
  753.     }
  754.  
  755.     @Override
  756.     public void onRandom(RANDOM_SOLVERS arg0) {
  757.         if(Game.isUptext("Cast Curse")){
  758.             GameTab.open(TABS.INVENTORY);
  759.         }
  760.        
  761.     }
  762.  
  763.     @Override
  764.     public boolean randomFailed(RANDOM_SOLVERS arg0) {
  765.         return false;
  766.     }
  767.  
  768.     @Override
  769.     public void randomSolved(RANDOM_SOLVERS arg0) {
  770.         // TODO Auto-generated method stub
  771.        
  772.     }
  773.  
  774. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement