Advertisement
joedezzy1

Untitled

Jul 31st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.64 KB | None | 0 0
  1. package scripts.abyssCrafterV2;
  2.  
  3. import org.tribot.api.Clicking;
  4. import org.tribot.api.General;
  5. import org.tribot.api.Timing;
  6. import org.tribot.api.interfaces.Positionable;
  7. import org.tribot.api2007.Skills;
  8. import org.tribot.api2007.GameTab.TABS;
  9. import org.tribot.api2007.Skills.SKILLS;
  10. import org.tribot.api.types.generic.Condition;
  11. import org.tribot.api2007.Banking;
  12. import org.tribot.api2007.Camera;
  13. import org.tribot.api2007.Equipment;
  14. import org.tribot.api2007.GameTab;
  15. import org.tribot.api2007.Inventory;
  16. import org.tribot.api2007.NPCs;
  17. import org.tribot.api2007.Objects;
  18. import org.tribot.api2007.PathFinding;
  19. import org.tribot.api2007.Player;
  20. import org.tribot.api2007.Walking;
  21. import org.tribot.api2007.WebWalking;
  22. import org.tribot.api2007.types.RSItem;
  23. import org.tribot.api2007.types.RSNPC;
  24. import org.tribot.api2007.types.RSNPCDefinition;
  25. import org.tribot.api2007.types.RSObject;
  26. import org.tribot.api2007.types.RSObjectDefinition;
  27. import org.tribot.api2007.types.RSTile;
  28.  
  29. public class DezUtils {
  30.  
  31.     public static boolean characterCanDie() {
  32.         return Player.getRSPlayer().getHealth() < getHealthPercentage(.75);
  33.     }
  34.  
  35.     public static int getHealthPercentage(double percentageBelow) {
  36.         return (int) (Skills.getActualLevel(SKILLS.HITPOINTS)
  37.                 - (Skills.getActualLevel(SKILLS.HITPOINTS)
  38.                 * (Skills.getActualLevel(SKILLS.HITPOINTS) * percentageBelow)));
  39.     }
  40.  
  41.     public static boolean interactObject(String object, String option, int dist, Condition c, long timeout) {
  42.         RSObject[] obj = Objects.findNearest(dist, object);
  43.         if (!Player.isMoving() && obj.length > 0){
  44.             RSObjectDefinition def = obj[0].getDefinition();
  45.             if (def != null) {
  46.                 String name = def.getName();
  47.                 if (name != null) {
  48.                     if(obj[0].hover() && Timing.waitUptext(name, General.random(700, 1100))) {
  49.                         if (obj[0] != null && option != null ? obj[0].click(option) : obj[0].click()) {
  50.                             return Timing.waitCondition(c, timeout);
  51.                         }
  52.                         else if (!fixCam(obj[0].getPosition())) {
  53.                             PathFinding.aStarWalk(obj[0].getPosition());
  54.                         }
  55.                     }
  56.                 }
  57.             }      
  58.         }
  59.         return false;
  60.     }
  61.  
  62.     public static boolean interactObject(Positionable tile, String option, Condition c, long timeout) {
  63.         RSObject[] obj = Objects.getAt(tile);
  64.         if (!Player.isMoving() && obj.length > 0){
  65.             RSObjectDefinition def = obj[0].getDefinition();
  66.             if (def != null) {
  67.                 String name = def.getName();
  68.                 if (name != null) {
  69.                     if(obj[0].hover() && Timing.waitUptext(name, General.random(700, 1100))) {
  70.                         if (obj[0] != null && option != null ? obj[0].click(option) : obj[0].click()) {
  71.                             return Timing.waitCondition(c, timeout);
  72.                         }
  73.                         else if (!fixCam(obj[0].getPosition())) {
  74.                             PathFinding.aStarWalk(tile);
  75.                         }
  76.                     }
  77.                 }
  78.             }      
  79.         }
  80.         return false;
  81.     }
  82.    
  83.     public static boolean interactNpc(String interacting, String option, Condition c, long timeout) {
  84.         RSNPC[] npc = NPCs.find(interacting);
  85.         if (!Player.isMoving() && npc.length > 0) {
  86.             RSNPCDefinition def = npc[0].getDefinition();
  87.             if (def != null){
  88.                 String name = def.getName();
  89.                 if (name != null && npc[0] != null ) {
  90.                     if (npc[0].hover() && Timing.waitUptext(name, General.random(700, 1100))) {
  91.                         if (option != null ? npc[0].click(option) : npc[0].click()) {
  92.                             return Timing.waitCondition(c, timeout);
  93.                         }
  94.                     }
  95.                     else if (!fixCam(npc[0].getPosition())) {
  96.                         toNpc(npc[0]);
  97.                     }
  98.                 }
  99.             }      
  100.         }
  101.         return false;
  102.     }
  103.  
  104.     public static boolean fixCam (final RSTile tile) {
  105.         Camera.turnToTile(tile);
  106.         return Timing.waitCondition(new Condition() {
  107.             @Override
  108.             public boolean active() {
  109.                 return tile.isOnScreen();
  110.             }          
  111.         }, General.random(1200, 2400));
  112.     }  
  113.    
  114.     public static boolean withdrawItem(final String name, String deposit, int amt, boolean killBot){
  115.         if (!Banking.isBankScreenOpen()) {
  116.             if (Banking.openBank()) {
  117.                 Timing.waitCondition(new Condition(){
  118.                     @Override
  119.                     public boolean active() {
  120.                         return Banking.isBankScreenOpen();
  121.                     }                  
  122.                 }, General.random(3000, 5000));
  123.             }
  124.         }
  125.         else if (Banking.find(name).length > 0 && Banking.find(name)[0] != null) {
  126.             if (Inventory.isFull()) {
  127.                 if (deposit != null && Banking.deposit(1, deposit)) {
  128.                     General.sleep(1200, 1400);
  129.                 }
  130.             }
  131.             else if (Banking.withdraw(amt, name)) {
  132.                 return Timing.waitCondition(new Condition() {
  133.                         @Override
  134.                         public boolean active() {
  135.                             return Inventory.find(name).length > 0;
  136.                         }                          
  137.                 }, General.random(1200, 1600));
  138.             }
  139.         }
  140.         else {
  141.             killScript();
  142.         }      
  143.         return false;
  144.     }
  145.    
  146.     private static void killScript() {
  147.         Main.running = false;
  148.     }
  149.  
  150.     public static boolean toObject(final RSObject obj) {
  151.         if (obj != null && PathFinding.aStarWalk(obj)) {
  152.             return Timing.waitCondition(new Condition(){
  153.                 @Override
  154.                 public boolean active() {
  155.                     return obj.isOnScreen();
  156.                 }              
  157.             }, General.random(2000, 3500));
  158.         }
  159.         return false;
  160.     }
  161.    
  162.     public static boolean toNpc(final RSNPC npc) {
  163.         if (npc != null && PathFinding.aStarWalk(npc)) {
  164.             return Timing.waitCondition(new Condition(){
  165.                 @Override
  166.                 public boolean active() {
  167.                     return npc.isOnScreen();
  168.                 }              
  169.             }, General.random(2000, 3500));
  170.         }
  171.         return false;
  172.     }
  173.    
  174.     public static void takePath(Positionable[] tile) {
  175.         if (Walking.walkPath(tile, new Condition(){
  176.             @Override
  177.             public boolean active() {
  178.                 return !Player.isMoving() || characterCanDie();
  179.             }          
  180.         }, 2300)) {
  181.             General.sleep(1400, 2400);
  182.         }
  183.     }
  184.    
  185.     public static void takePath(Positionable tile) {
  186.         if (WebWalking.walkTo(tile, new Condition(){
  187.             @Override
  188.             public boolean active() {
  189.                 return !Player.isMoving() || characterCanDie();
  190.             }          
  191.         }, 2300)) {
  192.             General.sleep(1400, 2400);
  193.         }
  194.     }
  195.  
  196.     public static boolean useJewlery(String destination, String... names) {
  197.         RSItem[] item = Equipment.find(names);
  198.         final RSTile origin = Player.getPosition();
  199.         if (item.length > 0 && GameTab.open(TABS.EQUIPMENT)) {
  200.             if (Clicking.click(destination, item[0])) {
  201.                 return Timing.waitCondition(new Condition(){
  202.                     @Override
  203.                     public boolean active() {
  204.                         return !Player.getPosition().equals(origin);
  205.                     }                  
  206.                 }, General.random(7000, 9000));
  207.             }
  208.         }  
  209.         return false;
  210.     }
  211.  
  212.     public static boolean useTeleportTab(String... names) {
  213.         RSItem[] tabs = Inventory.find(names);
  214.         final RSTile origin = Player.getPosition();
  215.         if (tabs.length > 0 && Clicking.click(tabs)) {
  216.             return Timing.waitCondition(new Condition(){
  217.                 @Override
  218.                 public boolean active() {
  219.                     return !Player.getPosition().equals(origin);
  220.                 }          
  221.             }, General.random(7000, 9000));
  222.         }
  223.         return false;
  224.     }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement