Advertisement
Guest User

Darks POH Curser v 0.6

a guest
Jul 25th, 2013
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.07 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.io.IOException;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.util.Arrays;
  11.  
  12. import javax.imageio.ImageIO;
  13. import javax.swing.JOptionPane;
  14.  
  15. import org.Magic;
  16. import org.RSArea;
  17. import org.SPELL;
  18. import org.tribot.api2007.NPCChat;
  19. import org.tribot.api.General;
  20. import org.tribot.api.Skills.SKILLS;
  21. import org.tribot.api.Timing;
  22. import org.tribot.api.input.Keyboard;
  23. import org.tribot.api2007.Camera;
  24. import org.tribot.api2007.Game;
  25. import org.tribot.api2007.GameTab;
  26. import org.tribot.api2007.GameTab.TABS;
  27. import org.tribot.api2007.Inventory;
  28. import org.tribot.api2007.Login;
  29. import org.tribot.api2007.Objects;
  30. import org.tribot.api2007.PathFinding;
  31. import org.tribot.api2007.Player;
  32. import org.tribot.api2007.Players;
  33. import org.tribot.api2007.Projection;
  34. import org.tribot.api2007.Skills;
  35. import org.tribot.api2007.Walking;
  36. import org.tribot.api2007.types.RSObject;
  37. import org.tribot.api2007.types.RSPlayer;
  38. import org.tribot.api2007.types.RSTile;
  39. import org.tribot.script.Script;
  40. import org.tribot.script.interfaces.Painting;
  41. import org.tribot.script.interfaces.RandomEvents;
  42.  
  43. public class Darks_POH_Curser extends Script implements Painting {
  44.   enum STATE{STARTING,OPENING_DOOR,CREATING_COMBAT_RING_AREA,WALKING_TO_RING,GETTING_IN_RING,CURSING_PLAYER,OUTSIDE_HOUSE,LOGGING_OUT, FAILSAFE;}
  45.   private Image paint = getImage("http://puu.sh/3L453.png");
  46.   private boolean started = false;
  47.   private RSArea combatRingArea;
  48.   private RSArea currentDoorArea;
  49.   private RSObject currentDoor;
  50. private RSTile maxTile;
  51. private RSTile minTile;
  52. private String status;
  53. private String debug = "DEBUG HERE";
  54. private RSObject[] combatRing;
  55. private RSObject combatRingRope;
  56. private STATE currentState;
  57. private String state;
  58. private String playerName ="";
  59. private long time;
  60. public long startTime = 0;
  61. public long millis = 0;
  62. public long hours = 0;
  63. public long minutes = 0;
  64. public long seconds = 0;
  65. public long last = 0;
  66. public int expGained = 0;
  67. public int expPerHour = 0;
  68. private final int startXp = Skills.getXP("MAGIC");
  69. public int expToLevel;
  70. public int curseTNL;
  71. public int curseCount;
  72. public int startLevel;
  73. public int currentLevel;
  74. public int levelsGained;
  75. //public final int startHealth = Player.getRSPlayer().getHealth();
  76. public long sTNL;
  77. public long mTNL;
  78. public long hTNL;
  79. private boolean isDoorOpen = false;
  80. private boolean isYourHouse = true;
  81. private int countPerHour;
  82. public static final int COMBAT_RING_ROPE =13137;
  83. public static final int POH_TAB = 8013;
  84. public static final int PORTAL = 15478;
  85. public static final int INHOME_PORTAL = 13405;
  86.     @Override
  87.     public void run() {
  88.         status = " START";
  89.        
  90.         while(true){
  91.             currentState = getState();
  92.             switch(currentState){
  93.             case CURSING_PLAYER:cursePlayer();
  94.                 break;
  95.             case GETTING_IN_RING:getInRing();
  96.                 break;
  97.             case OUTSIDE_HOUSE:getBackIntoHouse();
  98.                 break;
  99.             case STARTING:
  100.                 break;
  101.             case WALKING_TO_RING: walkToRing();
  102.                 break;
  103.             case OPENING_DOOR:
  104.                 break;
  105.             case CREATING_COMBAT_RING_AREA:
  106.                 break;
  107.             case LOGGING_OUT:Login.logout();
  108.                 break;
  109.             case FAILSAFE: failSafe();
  110.                 break;
  111.             default:
  112.                 break;
  113.              
  114.             }
  115.         }
  116.        
  117.     }
  118.     public boolean openDoor(){
  119.         debug = " GETTING DOOR...";
  120.         if(getDoor() == null){
  121.             isDoorOpen = true;
  122.         }
  123.         if(!isDoorOpen&&currentDoor == null){
  124.             currentDoor =getDoor();
  125.             currentDoorArea = RSArea.createRSArea(currentDoor.getPosition(),1);
  126.         }
  127.         else{
  128.      if(!isDoorOpen){
  129.         isDoorOpen = currentDoor.click();
  130.      }
  131.         debug = " DEBUG: "+isDoorOpen;
  132.         sleep(750);
  133.        
  134.         return isDoorOpen;
  135.         }
  136.         /**if(Walking.blindWalkTo(currentDoorArea.getMaxTile())){
  137.             currentDoor.click();
  138.              while(Game.getDestination().distanceTo(Player.getPosition())!=0){
  139.                  Walking.blindWalkTo(currentDoorArea.getMaxTile());
  140.                  currentDoor.click();
  141.                  return;
  142.              }
  143.         }*/
  144.         return isDoorOpen;
  145.     }
  146.     private RSObject getDoor() {
  147.         debug = " GETTING DOOR OBJECT...";
  148.         // First part checks to see if door is open.
  149.         if(isDoorOpen||currentDoor != null){return currentDoor;}
  150.     if(!isDoorOpen){
  151.         debug = " DOOR ISNT OPEN!";
  152.         for(RSObject o:Objects.findNearest(15,13100)){
  153.             debug = " Found Something";
  154.             if(o != null){
  155.                 debug = " It's not Null "+(combatRingArea.getDistanceFrom(o.getPosition())<15);
  156.             if(combatRingArea.getDistanceFrom(o.getPosition())<8){
  157.                 debug = " It's on screen and less than 8 tiles away from ring.";
  158.               if(Player.getPosition().distanceTo(o.getPosition())<=4){
  159.                   debug = " It's less than 5 tiles away from me.";
  160.                   currentDoorArea = RSArea.createRSArea(o.getPosition(),1);
  161.                   debug = " Distance To Area: "+currentDoorArea.getDistanceFrom(Player.getPosition());
  162.                   debug = "MAX TILE?: ";//+currentDoorArea.getMaxTile().toString();
  163.                 return o;
  164.                  
  165.             }
  166.             }
  167.         }
  168.      }
  169.     }
  170.     return currentDoor;
  171.     }
  172.     private boolean failSafe(){
  173.         if(useTeleTab()&&!isYourHouse){
  174.             sleep(2500);
  175.             return getNearestObject(INHOME_PORTAL,5).click("Enter");
  176.         }
  177.         return false;
  178.     }
  179.     private boolean useTeleTab() {
  180.         if(Inventory.getCount(POH_TAB)>0){
  181.             if(Inventory.find(POH_TAB)[0].click())
  182.             sleepWhileAnimating(3000,4500);
  183.             return true;
  184.         }
  185.         else if(Inventory.getCount(POH_TAB)==0){
  186.             Login.logout();
  187.             stopScript();
  188.         }
  189.         return false;
  190.     }
  191.     private boolean hasRunes(){
  192.         return Inventory.getCount(559)>0;
  193.     }
  194.     private void cursePlayer() {
  195.    
  196.       for(RSPlayer p : Players.getAll()){
  197.           if(p == null){break;}
  198.          if(p.getName() != Player.getRSPlayer().getName()){
  199.             if(GameTab.getOpen() != TABS.MAGIC){
  200.                 GameTab.open(TABS.MAGIC);
  201.             }
  202.            while(hasRunes()&& p.isOnScreen() &&combatRingArea.isInArea(p.getPosition())&&combatRingArea.isInArea(Player.getPosition())){
  203.                if(Magic.cast(SPELL.CURSE)){
  204.                    curseCount++;
  205.                    Camera.turnToTile(p.getPosition());
  206.                    p.click();
  207.                }
  208.            }
  209.          }
  210.       }
  211.     }
  212.     private void getBackIntoHouse(){
  213.       if(isYourHouse){
  214.           if(Objects.findNearest(20,PORTAL).length >0){
  215.             if(Objects.findNearest(20,PORTAL)[0].click("Enter")){
  216.                 if(NPCChat.selectOption("Go to your house",true)){
  217.                     sleep(3500);
  218.                 }
  219.             }
  220.           }
  221.       }
  222.           else{
  223.               if(Objects.findNearest(20,PORTAL).length >0){
  224.                     if(Objects.findNearest(20,PORTAL)[0].click("Enter")){
  225.                         if(NPCChat.selectOption("Go to a friend's house",true)){
  226.                             sleep(650);
  227.                             Keyboard.typeString(playerName);
  228.                              sleep(250);
  229.                              Keyboard.pressEnter();
  230.                              sleep(3500);
  231.                         }
  232.                     }
  233.           }
  234.           }
  235.      
  236.     }
  237.     private void getInRing() {
  238.         if(combatRingRope == null){combatRingRope = getNearestObject(COMBAT_RING_ROPE,15);}
  239.         if(combatRingRope.hover()){
  240.             combatRingRope.click();
  241.           sleepWhileAnimating(450,750);
  242.           return;}
  243.         return;
  244.        
  245.     }
  246.     private STATE getState() {
  247.         if(!started){
  248.             onStart();
  249.             return STATE.STARTING;
  250.         }
  251.         if(!hasRunes()){
  252.             return STATE.LOGGING_OUT;
  253.         }
  254.         if(isInsideHouse()&&combatRingArea == null&&determineCombatRingArea()){
  255.             return STATE.CREATING_COMBAT_RING_AREA;
  256.         }
  257.         if(isInsideHouse()&&!isDoorOpen&&openDoor()){
  258.             return STATE.OPENING_DOOR;
  259.         }
  260.         if(isInsideHouse()&&!combatRingArea.isInArea(Player.getPosition())){
  261.             if(combatRingArea.getDistanceFrom(Player.getPosition())>3){
  262.                 return STATE.WALKING_TO_RING;
  263.             }
  264.             return STATE.GETTING_IN_RING;
  265.         }
  266.         if(isInsideHouse()&&combatRingArea != null&&combatRingArea.isInArea(Player.getPosition())){
  267.             return STATE.CURSING_PLAYER;
  268.         }
  269.         if(getNearestObject(PORTAL,20) !=null){
  270.             return STATE.OUTSIDE_HOUSE;
  271.         }
  272.         if(!isInsideHouse()&&Objects.findNearest(20,PORTAL).length==0 ){
  273.             return STATE.FAILSAFE;
  274.         }
  275.         return null;
  276.     }
  277.     private void walkToRing(){
  278.     if(isDoorOpen){
  279.         if(combatRingRope == null){combatRingRope = getNearestObject(COMBAT_RING_ROPE,50);}
  280.         Walking.walkTo(combatRingRope.getPosition());
  281.     while(Player.isMoving()){
  282.         if(Game.getDestination() != null )
  283.         Camera.turnToTile(getNearestObject("Combat ring",50).getPosition());
  284.      }
  285.     }
  286.     else{
  287.         if(combatRingArea.getDistanceFrom(Player.getPosition())>8){
  288.             openDoor();
  289.         }
  290.     }
  291.     }
  292.     private boolean isInsideHouse() {      
  293.         return Objects.find(25,INHOME_PORTAL) != null &&Objects.find(25,INHOME_PORTAL).length>0;
  294.     }
  295.     private void onStart() {
  296.         //currentState = STATE.STARTING;
  297.         startTime = System.currentTimeMillis();
  298.         startLevel = Skills.getActualLevel("MAGIC");
  299.         playerName +=JOptionPane.showInputDialog("Enter Player's name if it's not your house",Player.getRSPlayer().getName());
  300.         if(!Player.getRSPlayer().getName().equalsIgnoreCase(playerName)||playerName.equals("")){
  301.             isYourHouse = false;
  302.             General.println("This is your house@");
  303.         }
  304.         started = true;
  305.     }
  306.     @Override
  307.     public void onPaint(Graphics g) {
  308.         //MATH
  309.         millis = System.currentTimeMillis() - startTime;
  310.         hours = millis / (1000 * 60 * 60);
  311.         millis -= hours * (1000 * 60 * 60);
  312.         minutes = millis / (1000 * 60);
  313.         millis -= minutes * (1000 * 60);
  314.         seconds = millis / 1000;
  315.         int CurrentExp = Skills.getXP("Magic");
  316.         curseCount = (CurrentExp-startXp)/29;
  317.         countPerHour = (int) ((curseCount) * 3600000D / (System
  318.                 .currentTimeMillis() - startTime));
  319.         expPerHour = (int) ((expGained) * 3600000D / (System
  320.                 .currentTimeMillis() - startTime));
  321.         expGained = Skills.getXP("MAGIC") - startXp;
  322.         curseTNL = Skills.getXPToLevel("MAGIC", currentLevel + 1) / 29;
  323.         currentLevel = Skills.getCurrentLevel("MAGIC");
  324.         levelsGained = currentLevel - startLevel;
  325.         expToLevel = Skills.getXPToNextLevel("MAGIC");
  326.         //DEBUG
  327.         if(currentDoorArea !=null){
  328.             currentDoorArea.paintRSArea(g);
  329.         }
  330.         if(combatRingArea != null){
  331.         combatRingArea.paintRSArea(g);
  332.         g.drawString(debug,250, 300);
  333.         }
  334.        
  335.         g.drawString(debug,250, 300);
  336.        
  337.         if(minTile !=null && maxTile != null){
  338.             g.setColor(Color.RED);
  339.             drawTile(minTile,(Graphics2D)g,false);
  340.             drawTile(maxTile,(Graphics2D)g,false);
  341.            
  342.         }
  343.         g.setColor(Color.BLUE);
  344.         drawTile(Player.getPosition(),(Graphics2D)g,false);
  345.         g.setColor(Color.ORANGE);
  346.     if(Game.getDestination() != null){
  347.         drawTile(Game.getDestination(),(Graphics2D)g,false);}
  348.         g.setColor(Color.GREEN);
  349.         g.drawString("STATUS: "+status,210,410);
  350.     // ACTUAL Paint
  351.         g.drawImage(paint, 0,300,null);
  352.     // Status
  353.         g.setColor(Color.WHITE);
  354.         if(currentState != null){
  355.         state = currentState.toString();
  356.         g.drawString(state,195,375);}
  357.         // Time
  358.          g.drawString(hours+":"+minutes+":"+seconds,245,395);
  359.          g.drawString(formatTime(millis/curseTNL),210,413);
  360.         //Level
  361.          g.drawString(currentLevel+" ( "+levelsGained+" )",220,432);
  362.         //XP
  363.         g.drawString(""+expGained,260,450);
  364.         g.drawString(""+expPerHour,225,470);
  365.        
  366.        
  367.     }
  368.     private boolean determineCombatRingArea() {
  369.     if(getNearestObject("Combat ring",50)!=null){
  370.         status = " Determining Combat Ring Area...";
  371.         int[] xCoords;
  372.         int[] yCoords;
  373.         combatRing =Objects.find(50,"Combat ring");
  374.         xCoords = new int[combatRing.length];
  375.         yCoords = new int[combatRing.length];
  376.         for(int x = 0; x<=combatRing.length-1;x++){
  377.             RSTile pos = combatRing[x].getPosition();
  378.             xCoords[x]= pos.getX();
  379.             yCoords[x] = pos.getY();
  380.         }
  381.         status = " Sorting Coordinates";
  382.         Arrays.sort(xCoords);
  383.         Arrays.sort(yCoords);
  384.         minTile = new RSTile(xCoords[8],yCoords[8]);
  385.         maxTile = new RSTile(xCoords[xCoords.length-8],yCoords[yCoords.length-8]);
  386.         status = "Min Tile : "+minTile.toString()+" MaxTile : "+maxTile.toString();
  387.         status = " Creating Area..";
  388.         combatRingArea = new RSArea(minTile,maxTile);
  389.         status = " Created Area!";
  390.         return true;
  391.     }
  392.     else{
  393.         status = "Could Not Find Combat Ring!";
  394.     }
  395.     return false;
  396.     }  
  397.     public void createDoorArea(){
  398.         if(currentDoor != null){
  399.             int x = currentDoor.getPosition().getX();
  400.             int y = currentDoor.getPosition().getY();
  401.             currentDoorArea = new RSArea(x-1,y+1,x+1,y-1);
  402.         }
  403.     }
  404.     private void drawTile(RSTile tile, Graphics2D g, boolean fill) {
  405.         if(tile.isOnScreen()) {
  406.                 if(fill) {
  407.                         g.fillPolygon(Projection.getTileBoundsPoly(tile, 0));
  408.                 } else {
  409.                         g.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
  410.                 }
  411.         }
  412.     }
  413.     /**@author Druid
  414.      * @return Sleeps while your Animation isn't 1*/
  415.     private void sleepWhileAnimating(int min,int max) {
  416.         long t = System.currentTimeMillis();
  417.         while (Timing.timeFromMark(t) < 3000 && Player.getAnimation() != -1) {
  418.             General.println("Sleeping....");
  419.             sleep(min,max);
  420.         }
  421.     }
  422.     private Image getImage(String url){
  423.         try {
  424.             return ImageIO.read(new URL(url));
  425.         } catch (MalformedURLException e) {
  426.         } catch (IOException e) {
  427.         }
  428.         return null;
  429.     }
  430.     private RSObject getNearestObject(String id,int dist){
  431.         for(RSObject o: Objects.find(dist,id)){
  432.             if(o != null){return o;}
  433.         }
  434.         return null;
  435.     }
  436.     private RSObject getNearestObject(int id,int dist){
  437.         for(RSObject o: Objects.find(dist,id)){
  438.             if(o != null){return o;}
  439.         }
  440.         return null;
  441.     }
  442.     private String formatTime(long time){
  443.         return (time / (1000 * 60 * 60)+":"+(time/ (1000 * 60))+":"+(time / 1000));
  444.     }
  445. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement