Guest User

Combat Tasks

a guest
Mar 25th, 2020
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.37 KB | None | 0 0
  1. package testground;
  2.  
  3. //import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6.  
  7. import org.osbot.rs07.api.Inventory;
  8. import org.osbot.rs07.api.map.Area;
  9. import org.osbot.rs07.api.model.Entity;
  10. //import org.osbot.rs07.api.map.Position;
  11. import org.osbot.rs07.api.model.GroundItem;
  12. import org.osbot.rs07.api.model.Item;
  13. import org.osbot.rs07.api.model.NPC;
  14. import org.osbot.rs07.api.model.Player;
  15. import org.osbot.rs07.api.ui.Skill;
  16. import org.osbot.rs07.script.MethodProvider;
  17.  
  18. public class Tasks extends MethodProvider{
  19.  
  20.     //returns your HP Percentage
  21.     public int getHpPercent() {
  22.         double staticHP = getSkills().getStatic(Skill.HITPOINTS);
  23.         double dynamicHP = getSkills().getDynamic(Skill.HITPOINTS);
  24.         int hpPercent = (int)(100*(dynamicHP/staticHP));
  25.         //log("Your HP Percent is " + hpPercent);
  26.         return hpPercent;
  27.     }
  28.    
  29.     //returns you current HP
  30.     public int getHP() {
  31.         int dynamicHP = getSkills().getDynamic(Skill.HITPOINTS);
  32.         //log("Your Current HP is " + dynamicHP);
  33.         return dynamicHP;
  34.     }
  35.    
  36.     //returns your max HP
  37.     public int maxHP() {
  38.         int staticHP = getSkills().getStatic(Skill.HITPOINTS);
  39.         //log("Your Current HP is " + staticHP);
  40.         return staticHP;
  41.     }
  42.    
  43.     // Tells if you need to Eat Food
  44.     public boolean needToEat(String Food_Type) {
  45.         if (getHP() < maxHP() - (foodRestore(Food_Type) + random(1,4))) {
  46.             return true;
  47.         }else {;
  48.             return false;
  49.         }
  50.     }
  51.    
  52.     //gets an array of items in inventory printed to log
  53.     public void itemName() {
  54.         Item[] item = getInventory().getItems();
  55.         int itemLength = item.length;
  56.         //look at each item in the list, getName and getID
  57.         for (int i=0; i < itemLength; i++) {
  58.             String itemName = item[i].getName();
  59.             int itemID = item[i].getId();
  60.             log("Your number " + i+ "item is " + itemName);
  61.             log("It's ID is " + itemID);
  62.         }
  63.         return;
  64.     }
  65.    
  66.     //Handles eating
  67.     public void eatFood(String Food_Type) throws InterruptedException{
  68.         Inventory inven = getInventory();
  69.         if(isUnNoted(Food_Type) == true){
  70.             if (getHP() < maxHP() - (foodRestore(Food_Type) + random(1,4))
  71.                 ||getHpPercent() < random(45,65) ) {
  72.                 if(inven.getSelectedItemName() == null) {
  73.                     int foodID = inven.getItem(Food_Type).getUnnotedId();
  74.                     inven.getItem(foodID).interact("Eat");
  75.                     log("That was a tasty " + Food_Type);
  76.                     sleep(random(200,400));
  77.                 }else {
  78.                     inven.deselectItem();
  79.                 }
  80.             }else {
  81.                 log("You don't need to eat");
  82.             }
  83.         }else {
  84.             log("You're out of Food");
  85.         }
  86.     }
  87.  
  88.     //Takes in your Food_Type as a string and returns how much it heals
  89.     private int foodRestore(String Food_Type) {
  90.        
  91.         String[] three = {"Shrimps","Cooked chicken","Cooked meat", "Bread"}; // index 0
  92.         String[] seven = {"Cod","Trout"}; // 1
  93.         String[] eight = {"Pike"}; // 2
  94.         String[] nine = {"Salmon"}; // 3
  95.         String[] ten = {"Tuna"}; // 4
  96.         String[] eleven = {"Jug of wine","Rainbow fish", "Stew",
  97.                 "Summer pie","Half a sumer pie"}; // 5
  98.         String[] twelve = {"Lobster"}; // 6
  99.         String[] thirteen = {"Bass"}; // 7
  100.         String[] fourteen = {"Swordfish","Potato with butter"}; // 8
  101.         String[] fifteen = {}; // 9
  102.         String[] sixteen = {"Monkfish"}; // 10
  103.         String[] seventeen = {}; // 11
  104.         String[] eighteen = {"Cooked karambwan"}; // 12
  105.         String[] nineteen = {"Curry","Ugthanki kebab"}; // 13
  106.         String[] twenty = {"Shark","Mushroom potato"}; // 14
  107.        
  108.         if(Arrays.asList(twenty).contains(Food_Type)) {
  109.             //log("Your food will heal 20");
  110.             return 20;
  111.         }
  112.         else if(Arrays.asList(twelve).contains(Food_Type)) {
  113.             //log("Your food will heal 12");
  114.             return 12;
  115.         }
  116.         else if(Arrays.asList(sixteen).contains(Food_Type)) {
  117.             //log("Your food will heal 16");
  118.             return 16;
  119.         }
  120.         else if(Arrays.asList(fourteen).contains(Food_Type)) {
  121.             //log("Your food will heal 14");
  122.             return 14;
  123.         }
  124.         else if(Arrays.asList(eighteen).contains(Food_Type)) {
  125.             //log("Your food will heal 18");
  126.             return 18;
  127.         }
  128.         else if(Arrays.asList(thirteen).contains(Food_Type)) {
  129.             //log("Your food will heal 13");
  130.             return 13;
  131.         }
  132.         else if(Arrays.asList(three).contains(Food_Type)) {
  133.             //log("Your food will heal 3");
  134.             return 3;
  135.         }
  136.         else if(Arrays.asList(ten).contains(Food_Type)) {
  137.             //log("Your food will heal 10");
  138.             return 10;
  139.         }
  140.         else if(Arrays.asList(seven).contains(Food_Type)) {
  141.             //log("Your food will heal 7");
  142.             return 7;
  143.         }
  144.         else if(Arrays.asList(eight).contains(Food_Type)) {
  145.             //log("Your food will heal 8");
  146.             return 8;
  147.         }
  148.         else if(Arrays.asList(nine).contains(Food_Type)) {
  149.             //log("Your food will heal 9");
  150.             return 9;
  151.         }
  152.         else if(Arrays.asList(eleven).contains(Food_Type)) {
  153.             //log("Your food will heal 11");
  154.             return 11;
  155.         }
  156.         else if(Arrays.asList(nineteen).contains(Food_Type)) {
  157.             //log("Your food will heal 19");
  158.             return 19;
  159.         }
  160.         else if(Arrays.asList(fifteen).contains(Food_Type)) {
  161.             //log("Your food will heal 15");
  162.             return 15;
  163.         }
  164.         else if(Arrays.asList(seventeen).contains(Food_Type)) {
  165.             //log("Your food will heal 17");
  166.             return 17;
  167.         }else {
  168.             int staticHP = getSkills().getStatic(Skill.HITPOINTS);
  169.             log("Your Food_Type was not found");
  170.             return  staticHP + 100;
  171.         }
  172.     }
  173.    
  174.     //Checks to see if inventory contains un-noted item
  175.     public boolean isUnNoted(String Item_Name) {
  176.         Inventory inven = getInventory();
  177.         int unnotedID;
  178.        
  179.         if (inven.contains(Item_Name)){
  180.             unnotedID = inven.getItem(Item_Name).getUnnotedId();
  181.             //log(unnotedID);
  182.             if (inven.contains(unnotedID)) {
  183.                 //log(Item_Name + " is in inventory and not all are noted");
  184.                 return true;
  185.             }else {
  186.                 //log(Item_Name + " is in inventory and all is noted");
  187.                 return false;
  188.             }
  189.         }else {
  190.             //log("Item is not in your inventory");
  191.             return false;
  192.         }
  193.    
  194.     }
  195.    
  196.     //Checks to see if something can be attacked
  197.     //PROBABLY USELESS
  198.     public boolean canAttack(String Target_Name,
  199.             Area Target_Area) {
  200.          NPC target;
  201.          List<NPC> targetList;
  202.          final Area TARGET_AREA =  Target_Area;
  203.          int count = 0;
  204.          
  205.         targetList = getNpcs().getAll();
  206.         for (int i=0; i < targetList.size(); i++) {
  207.             if (targetList.get(i).getName().equals(Target_Name)
  208.                     && TARGET_AREA.contains(targetList.get(i))
  209.                     && !targetList.get(i).isHitBarVisible()
  210.                     && !targetList.get(i).isUnderAttack()
  211.                     && targetList.get(i).getHealthPercent() > 0) {
  212.                 target = targetList.get(i);
  213.                 log(target + " " + i + " has been acquired.");
  214.                 count++;
  215.                 }
  216.             }
  217.        
  218.         if (count > 0) {
  219.             return true;
  220.         } else {
  221.             return false;
  222.         }
  223.     }
  224.        
  225.     //Checks for and Attacks best Targetable NPC
  226.     @SuppressWarnings("unchecked")
  227.     public void attackBestTargetableNPC(String Target_Name,
  228.             Area Target_Area) throws InterruptedException{
  229.          
  230.         NPC target;
  231.         Player player = myPlayer();
  232.         //List<NPC> targetList;
  233.         //List<NPC> attackableTargets = new ArrayList<NPC>();
  234.         final Area TARGET_AREA =  Target_Area;
  235.            
  236.         if (!TARGET_AREA.contains(player)) {
  237.             getWalking().webWalk(TARGET_AREA);
  238.         }
  239.          
  240.         if (!player.isInteracting(player.getInteracting())
  241.                 && !player.isMoving()) {
  242.             target = npcs.getAll().stream().filter(n -> n.getName().equals(Target_Name)
  243.                     && TARGET_AREA.contains(n) && !n.isHitBarVisible() && !n.isUnderAttack()
  244.                     && n.getHealthPercent() > 0).findFirst().get();
  245.         } else {
  246.             target = npcs.closest(n -> n.getName().equals(Target_Name)
  247.                     && player.isInteracting(n));
  248.         }
  249.        
  250.         if(target != null && target.isVisible()) {
  251.             if (!player.isAnimating() && !player.isMoving()
  252.                     && !player.isUnderAttack()) {
  253.                 target.interact("Attack");
  254.                 sleep(random(1000,1500));
  255.             }
  256.         } else {
  257.             getCamera().toEntity(target);
  258.         }        
  259.     }
  260.    
  261.     //Does Loot Exist?
  262.     public boolean lootExists(String Item_Name, Area Target_Area) {
  263.         final Area TARGET_AREA =  Target_Area;
  264.         Player player = myPlayer();
  265.         Area playerArea = player.getArea(3);
  266.        
  267.         @SuppressWarnings("unchecked")
  268.         GroundItem loot = groundItems.closest(l -> l.getName().equals(Item_Name)
  269.                 && TARGET_AREA.contains(l) && playerArea.contains(l));
  270.         if(loot != null && loot.exists()) {
  271.             return true;
  272.         } else {
  273.             return false;
  274.         }
  275.    
  276.     }
  277.    
  278.     //Looting
  279.     public void lootClosest(String Item_Name,
  280.             Area Target_Area) throws InterruptedException{
  281.        
  282.         Player player = myPlayer();
  283.         Inventory inven = getInventory();
  284.         final Area TARGET_AREA =  Target_Area;
  285.         Area playerArea = player.getArea(7);
  286.        
  287.         @SuppressWarnings("unchecked")
  288.         GroundItem loot = groundItems.closest(l -> l.getName().equals(Item_Name) && playerArea.contains(l));
  289.        
  290.         if(!inven.isFull() && TARGET_AREA.contains(player)) {
  291.             if (loot != null && loot.exists() &&loot.isVisible()) {
  292.                 loot.interact("Take");
  293.                 sleep(random(500,1000));
  294.             }
  295.         }  else getCamera().toEntity(loot);
  296.     }
  297.    
  298.     //Do Banking
  299.     public void bankItems(Area Target_Bank, int Bank_Booth_ID, String Food_Type, int Food_Amount) throws InterruptedException {
  300.         Player player = myPlayer();
  301.         Entity bankbooth = objects.closest(Bank_Booth_ID);
  302.         if (Target_Bank.contains(player)) {
  303.             if(bank.isOpen()) {
  304.                 sleep(3000);
  305.                 bank.depositAll();
  306.                 sleep(3000);
  307.                 bank.depositAll();
  308.                 sleep (3000);
  309.                 bank.withdraw(Food_Type, Food_Amount);
  310.             } else if (bankbooth != null) {
  311.                 if(bankbooth.isVisible()) {
  312.                     bankbooth.interact("Bank");
  313.                     sleep (3000);
  314.                     bank.depositAll();
  315.                     sleep (3000);
  316.                     bank.depositAll();
  317.                     sleep (3000);
  318.                     bank.withdraw(Food_Type, Food_Amount);
  319.                 } else {
  320.                     getCamera().toEntity(bankbooth);   
  321.                     bankbooth.interact("Bank");
  322.                     sleep (3000);
  323.                     bank.depositAll();
  324.                     sleep (3000);
  325.                     bank.depositAll();
  326.                     sleep (3000);
  327.                     bank.withdraw(Food_Type, Food_Amount);
  328.                 }  
  329.             } else {
  330.                 getWalking().webWalk(Target_Bank);
  331.             }
  332.         }
  333.     }
  334.  
  335.    
  336.     // Is player in Specified Area?
  337.     public boolean inTargetArea(Area Target_Area){
  338.         Player player = myPlayer();
  339.         if (Target_Area.contains(player)) {
  340.             return true;
  341.         }else {
  342.             return false;
  343.         }
  344.     }
  345.    
  346.     //Go to Specified Area
  347.     public void goToTargetArea(Area Target_Area) {
  348.         if(!inTargetArea(Target_Area)) {
  349.             getWalking().webWalk(Target_Area);
  350.         } else {
  351.             log("You're already in the right area");
  352.         }
  353.     }
  354.  
  355.     public void dropItem(String Item_Name) throws InterruptedException{
  356.         Inventory inven = getInventory();
  357.         if(inven.getSelectedItemName() == null) {
  358.             int foodID = inven.getItem(Item_Name).getUnnotedId();
  359.             inven.getItem(foodID).interact("Drop");
  360.             sleep(random(200,400));
  361.         }else {
  362.             inven.deselectItem();
  363.         }
  364.     }
  365.    
  366.    
  367. }
Add Comment
Please, Sign In to add comment