joedezzy1

Untitled

Jul 31st, 2014
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.85 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.input.Mouse;
  6. import org.tribot.api.interfaces.Positionable;
  7. import org.tribot.api.types.generic.Condition;
  8. import org.tribot.api2007.Banking;
  9. import org.tribot.api2007.Constants;
  10. import org.tribot.api2007.Equipment;
  11. import org.tribot.api2007.Game;
  12. import org.tribot.api2007.GameTab;
  13. import org.tribot.api2007.Interfaces;
  14. import org.tribot.api2007.Inventory;
  15. import org.tribot.api2007.Magic;
  16. import org.tribot.api2007.Objects;
  17. import org.tribot.api2007.PathFinding;
  18. import org.tribot.api2007.Skills;
  19. import org.tribot.api2007.Walking;
  20. import org.tribot.api2007.WebWalking;
  21. import org.tribot.api2007.GameTab.TABS;
  22. import org.tribot.api2007.Skills.SKILLS;
  23. import org.tribot.api2007.ext.Filters;
  24. import org.tribot.api2007.types.RSInterface;
  25. import org.tribot.api2007.types.RSInterfaceChild;
  26. import org.tribot.api2007.types.RSObject;
  27. import org.tribot.api2007.types.RSTile;
  28. import org.tribot.api2007.util.DPathNavigator;
  29. import org.tribot.script.Script;
  30.  
  31. public class Main extends Script {
  32.  
  33.     public static boolean running;
  34.     // *****userSet***** \\
  35.     public static int SAFE_HEALTH   = 0;
  36.     public static int FOOD_HEAL_AMT = 0;
  37.     public static int USERSET_DRINK_POINT;
  38.     public static String FOOD_NAME;
  39.     public static String ESSENCE_TYPE  = "Pure essence";
  40.     public static String ENERGY_ITEM;
  41.     public static String RUNE_TYPE;
  42.     public static final String[] ALTAR_NAMES   = { "Altar" };
  43.     public static boolean usingEmergencyTeleport = false;
  44.     public static boolean usingEnergyPotion = false;
  45.     public static boolean usingMountedGlory = false;
  46.     // *****userSetEnd***** \\
  47.        
  48.     private final RSTile[] TO_WILD_DITCH = {
  49.         new RSTile(3094, 3493, 0), new RSTile(3094, 3496, 0), new RSTile(3093, 3498, 0),
  50.         new RSTile(3093, 3500, 0), new RSTile(3096, 3500, 0), new RSTile(3097, 3501, 0),
  51.         new RSTile(3099, 3503, 0), new RSTile(3101, 3505, 0), new RSTile(3103, 3507, 0),
  52.         new RSTile(3103, 3508, 0), new RSTile(3102, 3510, 0), new RSTile(3102, 3513, 0),
  53.         new RSTile(3102, 3515, 0), new RSTile(3102, 3517, 0), new RSTile(3103, 3520, 0)
  54.     };
  55.  
  56.     private final RSTile[] TO_ZAMMY_MAGE = {
  57.             new RSTile(3103, 3524, 0), new RSTile(3103, 3527, 0), new RSTile(3104, 3530, 0),
  58.             new RSTile(3106, 3533, 0), new RSTile(3105, 3538, 0), new RSTile(3105, 3540, 0),
  59.             new RSTile(3105, 3542, 0), new RSTile(3105, 3545, 0), new RSTile(3105, 3548, 0),
  60.             new RSTile(3105, 3551, 0), new RSTile(3105, 3554, 0), new RSTile(3104, 3557, 0),
  61.             new RSTile(3105, 3558, 0)
  62.     };
  63.    
  64.     public static String[] ENERGY_ITEMS = {
  65.         "Strange fruit", "Super energy potion (4)", "Super energy potion (4)",
  66.         "Super energy potion (4)", "Super energy potion (4)", "Energy potion (4)",
  67.         "Energy potion (3)", "Energy potion (2)", "Energy potion (1)"
  68.     };
  69.    
  70.     public final static String[] GLORY = {
  71.         "Amulet of glory(4)", "Amulet of glory(3)",
  72.         "Amulet of glory(2)", "Amulet of glory(1)"
  73.     };
  74.    
  75.     public final String[] ROD = {
  76.         "Ring of dueling(8)", "Ring of dueling(7)",
  77.         "Ring of dueling(6)", "Ring of dueling(5)",
  78.         "Ring of dueling(4)", "Ring of dueling(3)",
  79.         "Ring of dueling(2)", "Ring of dueling(1)"
  80.     };
  81.    
  82.     public final static String[] GAMES_NECKLACE = {
  83.         "Games necklace(8)", "Games necklace(7)",
  84.         "Games necklace(6)", "Games necklace(5)",
  85.         "Games necklace(4)", "Games necklace(3)",
  86.         "Games necklace(2)", "Games necklace(1)"
  87.     };
  88.    
  89.     public static final String[] POUCHES = {
  90.         "Giant pouch", "Large pouch",
  91.         "Medium pouch", "Small pouch"
  92.     };
  93.    
  94.     private String[] DEGRADED_POUCHES = {
  95.            
  96.     }; //TODO
  97.    
  98.     public final static String[] TELE_TABS = {
  99.         "Lumbridge teleport", "Varrock teleport",
  100.         "Falador teleport", "Camelot teleport"
  101.     };
  102.  
  103.     private final int POUCH_SETTING      = 486;
  104.     private final int SMALL_FILLED_ID    = 1073741827;
  105.     private final int MED_FILLED_ID      = 1073741875;
  106.     private final int LRG_FILLED_ID      = 1073746483;
  107.     private final int GIANT_FILLED_ID    = 0;
  108.  
  109.     public static Area abyss = new Area(3000, 3100, 4804, 4900);
  110.     public static Area abyssInnerCircle = new Area(3022, 3056, 4815, 4848);
  111.     public static Area edgeville = new Area(3082, 3128, 3483, 3520);
  112.     public static Area wild = new Area(3066, 3143, 3523, 4000);
  113.     public static Area house = new Area(7000, 8000, 7000, 8000);
  114.    
  115.     public static boolean GUI_COMPLETE;
  116.  
  117.     enum STATE {
  118.     CRAFTING,
  119.     ENTERING_RIFT,
  120.     FIND_RIFT,
  121.     FINDING_SHORTCUT,
  122.     GEARING_UP,
  123.     OPENING_BANK,
  124.     PASSING_DITCH,
  125.     RECHARGING_POUCHES,
  126.     TELEPORTING,
  127.     TELEPORT_ZAMORAK_MAGE,
  128.     TO_ZAMORAK_MAGE,
  129.     TO_DITCH,
  130.     TO_ABYSS,
  131.     USING_SHORTCUT,
  132.     WAIT,  
  133.     }
  134.    
  135.     private String getRift() {      
  136.         switch (RUNE_TYPE) {
  137.         case "Air rune" :
  138.             return "Air rift";
  139.         case "Mind rune" :
  140.             return "Mind rift";
  141.         case "Body rune" :
  142.             return "Body rift";
  143.         case "Earth rune" :
  144.             return "Earth rift";
  145.         case "Fire rune" :
  146.             return "Fire rift";
  147.         case "Blood rune" :
  148.             return "Blood rift";
  149.         case "Cosmic rune" :
  150.             return "Cosmic rift";
  151.         case "Nature rune" :
  152.             return "Nature rift";
  153.         case "Chaos rune" :
  154.             return "Chaos rift";
  155.         case "Law rune" :
  156.             return "Law rift";
  157.         case "Death rune" :
  158.             return "Death rift";
  159.         case "Water rune" :
  160.             return "Water rift";
  161.         case "Soul rune" :
  162.             return "Soul rift";
  163.         }
  164.         return null;
  165.     }
  166.    
  167.     private String getAction() {
  168.         if (Equipment.find(Constants.IDs.Items.hatchets).length > 0 ||Inventory.find(Constants.IDs.Items.hatchets).length > 0) {
  169.             return "Chop";
  170.         }
  171.         else if (Equipment.find(Constants.IDs.Items.pickaxes).length > 0 || Inventory.find(Constants.IDs.Items.pickaxes).length > 0) {
  172.             return "Mine";
  173.         }
  174.         else if (Inventory.find("Tinderbox").length > 0) {
  175.             return "Burn";
  176.         }
  177.         else if (Skills.getActualLevel(SKILLS.THIEVING) >= 20) {
  178.             return "Distract";
  179.         }        
  180.         return null;
  181.     }
  182.  
  183.     public static int inventorySpace() {
  184.         return 28 - Inventory.getAll().length;
  185.     }
  186.    
  187.     public static int getFoodCount() {
  188.         return (Skills.getActualLevel(SKILLS.HITPOINTS)
  189.                 - Skills.getCurrentLevel(SKILLS.HITPOINTS)) / FOOD_HEAL_AMT;
  190.     }
  191.    
  192.     private RSObject getValidShortcut() {      
  193.         RSObject[] s = Objects.findNearest(200, Filters.Objects.actionsContains(getAction()));
  194.         return s.length > 0 ? s[0] : null;
  195.     }
  196.    
  197.     private STATE getState() {
  198.     if (canCraft()) {  
  199.             if (edgeville.inArea()) {              
  200.                 return STATE.PASSING_DITCH;                  
  201.             }                
  202.             else if (wild.inArea()) {
  203.                 return STATE.TO_ABYSS;                    
  204.             }                
  205.             else if (abyss.inArea()) {                  
  206.                 if (!abyssInnerCircle.inArea()) {                  
  207.                     if(getValidShortcut() != null && getValidShortcut().isOnScreen()){
  208.                     return STATE.USING_SHORTCUT;
  209.                     }                  
  210.                     else if(getValidShortcut() != null) {
  211.                     return STATE.FINDING_SHORTCUT;
  212.                     }
  213.                 }
  214.                 else if(Inventory.find(DEGRADED_POUCHES).length > 0){
  215.                     return STATE.RECHARGING_POUCHES;                  
  216.                 }                    
  217.                 else if (canSeeTeleporter()) {
  218.                     return STATE.ENTERING_RIFT;                      
  219.                 }                    
  220.                 else {
  221.                     return STATE.FIND_RIFT;
  222.                 }                  
  223.             }                
  224.             else if (atAltar()) {              
  225.                 return STATE.CRAFTING;                  
  226.             }                              
  227.         }            
  228.         else if (!Banking.isInBank()) {
  229.             return STATE.TELEPORTING;          
  230.         }          
  231.         else if(!Banking.isBankScreenOpen()){
  232.             return STATE.OPENING_BANK;             
  233.         }            
  234.         else {
  235.             return STATE.GEARING_UP;            
  236.         }    
  237.     return STATE.WAIT;
  238.     }
  239.    
  240.     private void GUI() {
  241.         new GUI();
  242.         while(!GUI_COMPLETE){
  243.             sleep(100);
  244.         }
  245.     }
  246.    
  247.     @Override
  248.     public void run() {
  249.  
  250.         GUI();
  251.         ABC abc = new ABC();
  252.  
  253.         while (running) {
  254.             abc.start();           
  255.             Mouse.setSpeed(General.random(135, 165));          
  256.            
  257.             switch (getState()){
  258.             case CRAFTING:
  259.                 craftRunes();
  260.                 break;
  261.             case ENTERING_RIFT:
  262.                 DezUtils.interactObject(getRift(), null, 10, new Condition(){
  263.                     @Override
  264.                     public boolean active() {
  265.                         return Objects.find(20, "Altar").length > 0;
  266.                     }                  
  267.                 }, General.random(4300, 5300));
  268.                 break;
  269.             case PASSING_DITCH:
  270.                 DezUtils.interactObject("Wilderness ditch", null, 10, new Condition(){
  271.                     @Override
  272.                     public boolean active() {
  273.                         return wild.inArea();
  274.                     }                  
  275.                 }, General.random(2300, 3300));
  276.                 break;
  277.             case USING_SHORTCUT:
  278.                 DezUtils.interactObject(getRift(), null, 10, new Condition(){
  279.                     @Override
  280.                     public boolean active() {
  281.                         return abyssInnerCircle.inArea();
  282.                     }                  
  283.                 }, General.random(300, 500));
  284.                 break;
  285.             case TELEPORT_ZAMORAK_MAGE:
  286.                 DezUtils.interactNpc("Mage of Zamorak", "Travel", new Condition() {
  287.                     @Override
  288.                     public boolean active() {
  289.                         return abyss.inArea();
  290.                     }                  
  291.                 }, General.random(2300, 4300));
  292.                 break;
  293.             case TO_DITCH:
  294.                 DezUtils.takePath(TO_WILD_DITCH);
  295.                 break;
  296.             case TO_ZAMORAK_MAGE:
  297.                 DezUtils.takePath(TO_ZAMMY_MAGE);
  298.                 break;
  299.             case FINDING_SHORTCUT:
  300.                 findShortcut(getValidShortcut());
  301.                 break;
  302.             case FIND_RIFT:
  303.                 findRift(Objects.findNearest(100, getRift()));
  304.                 break;
  305.             case GEARING_UP:
  306.                 CharacterPreparation.start();
  307.                 break;         
  308.             case RECHARGING_POUCHES:
  309.                 rechargePouches();
  310.                 break;
  311.             case TELEPORTING:
  312.                 toBank();
  313.                 break;
  314.             case WAIT:
  315.                 sleep(900);
  316.                 break;
  317.             default:
  318.                 break;
  319.             }
  320.             sleep(400, 600);
  321.         }
  322.     }
  323.    
  324.     private void craftRunes() {      
  325.         final int originalAmount = Inventory.find(RUNE_TYPE).length;
  326.         if(Inventory.find(ESSENCE_TYPE).length < 1 && pouchesFilled()){
  327.             emptyPouches();
  328.         }          
  329.         else {
  330.             DezUtils.interactObject("Altar", null, 20, new Condition(){
  331.         @Override
  332.         public boolean active() {
  333.             return Inventory.find(RUNE_TYPE).length > originalAmount;
  334.         }              
  335.             }, General.random(3300, 4700));
  336.         }
  337.     }
  338.  
  339.     private void emptyPouches() {      
  340.         if(Inventory.find(POUCHES[0]).length > 0){
  341.             if(Game.getSetting(POUCH_SETTING) == GIANT_FILLED_ID){
  342.                 if(Clicking.click("Empty", Inventory.find(POUCHES[0]))){
  343.                     sleep(1200, 1900);
  344.                 }
  345.             }
  346.         }
  347.         if(Inventory.find(POUCHES[1]).length > 0){
  348.             if(Game.getSetting(POUCH_SETTING) == LRG_FILLED_ID){
  349.                 if(Clicking.click("Empty", Inventory.find(POUCHES[1]))){
  350.                     sleep(1200, 1900);
  351.                 }
  352.             }
  353.         }
  354.         if(Inventory.find(POUCHES[2]).length > 0){
  355.             if(Game.getSetting(POUCH_SETTING) == MED_FILLED_ID){
  356.                 if(Clicking.click("Empty", Inventory.find(POUCHES[2]))){
  357.                 sleep(1200, 1900);
  358.             }
  359.             }
  360.         }
  361.         if(Inventory.find(POUCHES[3]).length > 0){
  362.             if(Game.getSetting(POUCH_SETTING) == SMALL_FILLED_ID){
  363.                 if(Clicking.click("Empty", Inventory.find(POUCHES[3]))){
  364.                     sleep(1200, 1900);
  365.                 }
  366.                 }
  367.         }  
  368.     }
  369.  
  370.     private void rechargePouches() {
  371.     if (!chatting()) {
  372.         DezUtils.interactNpc("Dark mage", "Repairs", new Condition() {
  373.             @Override
  374.             public boolean active() {
  375.             return chatting();
  376.             }              
  377.         }, General.random(1800, 2200));
  378.     }
  379.     else {
  380.         clickDialouge();
  381.     }
  382.     }
  383.  
  384.     private void clickDialouge() {
  385.     //*
  386.         /* Searches through all interfaces to determine
  387.          * what option to click, and repairs the pouch
  388.          */
  389.         RSInterfaceChild[][] chat = {
  390.             Interfaces.get(242).getChildren(), Interfaces.get(64).getChildren()
  391.         };
  392.         for (RSInterfaceChild[] i : chat) {
  393.             if (i != null) {
  394.                 for (RSInterface t : i) {
  395.                     if (t.getText().contains("continue")) {
  396.                         if (Clicking.click(t)){
  397.                             break;
  398.                         }                      
  399.                     }
  400.                 }
  401.             }
  402.         }
  403.     }
  404.        
  405.     private void findRift(RSObject[] rift) {
  406.         //*
  407.         /* attempts to traverse to a valid teleport rift
  408.          */
  409.         if (rift.length > 0) {
  410.             if (Walking.walkPath(new DPathNavigator().findPath(rift[0]))) {
  411.                 sleep(1400, 1600);
  412.             }
  413.         }
  414.     }
  415.  
  416.     private void findShortcut(RSObject shortcut) {  
  417.     //*
  418.         /* attempts to traverse to a valid shortcut
  419.          */
  420.         if(shortcut != null){
  421.         if (PathFinding.aStarWalk(shortcut.getPosition())){
  422.             sleep(400, 700);
  423.         }
  424.         }
  425.     }
  426.    
  427.     private void toBank() {
  428.         //*
  429.         /* Gets to bank based on the users banking desire
  430.          */
  431.         if (usingMountedGlory) {
  432.             if (!house.inArea()) {
  433.                 DezUtils.useTeleportTab("Teleport to house");
  434.             }
  435.             else {
  436.                 HouseNavigator.traverseToDestination("Amulet of Glory");
  437.             }
  438.         }
  439.         else if (wild.inArea() || abyss.inArea() || Objects.find(20, "Altar").length > 0) {
  440.             teleportOut();
  441.         }      
  442.         else if (!Banking.isInBank() && WebWalking.walkToBank()) {
  443.             sleep(2400, 3700);
  444.         }
  445.     }
  446.  
  447.     private void teleportOut() {  
  448.         //*
  449.         /* Teleports out based on various available telly methods
  450.          */
  451.         if (Equipment.isEquipped(GLORY)) {         
  452.             DezUtils.useJewlery("Edgeville", GLORY);
  453.         }        
  454.         else if (Equipment.isEquipped(ROD)) {
  455.             DezUtils.useJewlery("Casle Wars", ROD);
  456.         }        
  457.         else if(Inventory.find(TELE_TABS).length > 0){
  458.             DezUtils.useTeleportTab();
  459.         }        
  460.         else if (!abyss.inArea() && !wild.inArea() && GameTab.open(TABS.MAGIC)) {
  461.             if (Magic.selectSpell("Lumbridge Home Teleport")) {
  462.                 sleep(15000, 21000);
  463.             }
  464.         }
  465.     }
  466.  
  467.     private boolean canCraft() {    
  468.         // *
  469.         /* Checks if our pouches are filled, our inventory is full
  470.          * and our health is good. If we are at an altar it will return true
  471.          * if there are pouches still filled, or essence in inventory.
  472.          */
  473.         return  (Inventory.find(POUCHES).length > 0
  474.                 ? pouchesFilled() || (atAltar() && Inventory.find(ESSENCE_TYPE).length > 0)
  475.                 : true)
  476.                 &&  
  477.                 (Banking.isInBank()
  478.                 ? Inventory.find(ESSENCE_TYPE).length >= Inventory.find(ESSENCE_TYPE).length + inventorySpace()
  479.                 : Inventory.find(ESSENCE_TYPE).length > 0 || (atAltar() && pouchesFilled()))
  480.                 &&
  481.                 (Skills.getCurrentLevel(SKILLS.HITPOINTS) >= SAFE_HEALTH);
  482.     }
  483.    
  484.     public boolean pouchesFilled() {
  485.         // *
  486.         /* Determines if pouches are filled based off of game settings
  487.          * I use ternary so this method will always pass if they are not using
  488.          * pouches
  489.          */
  490.         return ((Inventory.find(POUCHES[3]).length > 0)
  491.                     ? Game.getSetting(POUCH_SETTING) >= SMALL_FILLED_ID : true)
  492.                 &&
  493.                 ((Inventory.find(POUCHES[2]).length > 0)
  494.                         ? Game.getSetting(POUCH_SETTING) >= MED_FILLED_ID : true)
  495.                 &&
  496.                 ((Inventory.find(POUCHES[1]).length > 0)
  497.                         ? Game.getSetting(POUCH_SETTING) >= LRG_FILLED_ID : true)            
  498.                 &&
  499.                 ((Inventory.find(POUCHES[0]).length > 0)
  500.                         ? Game.getSetting(POUCH_SETTING) >= GIANT_FILLED_ID : true);
  501.     }
  502.    
  503.     private boolean chatting() {
  504.     //Chatting with darkmage pouch repair
  505.     return Interfaces.isInterfaceValid(242) || Interfaces.isInterfaceValid(64)
  506.                 || Interfaces.isInterfaceValid(0); //TODO get all indicies
  507.     }
  508.  
  509.     private boolean canSeeTeleporter() {       
  510.         RSObject[] altarTeleport = Objects.findNearest(10, getRift());
  511.         return altarTeleport.length > 0 && altarTeleport[0].isOnScreen();
  512.     }
  513.  
  514.     public static boolean needEnergyPotion() { 
  515.         return Game.getRunEnergy() <= USERSET_DRINK_POINT;
  516.     }
  517.  
  518.     private boolean atAltar() {
  519.         return Objects.find(10, ALTAR_NAMES).length > 0;
  520.     }
  521. }
Advertisement
Add Comment
Please, Sign In to add comment