Advertisement
Guest User

Shitty code

a guest
Oct 26th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.74 KB | None | 0 0
  1. import org.osbot.rs07.api.*;
  2. import org.osbot.rs07.api.filter.Filter;
  3. import org.osbot.rs07.api.map.Area;
  4. import org.osbot.rs07.api.model.GroundItem;
  5. import org.osbot.rs07.api.model.NPC;
  6. import org.osbot.rs07.api.model.Player;
  7. import org.osbot.rs07.api.ui.Skill;
  8. import org.osbot.rs07.api.ui.Tab;
  9.  
  10. //Class used to, well, manage combat
  11. public class CombatManager {
  12.  
  13.     private String[] equipmentNames;
  14.     private Player player;
  15.     private Area a;
  16.     private String[] lootables;
  17.     private boolean lootingMode = false;
  18.  
  19.     public CombatManager(Player player, String[] equipment, Area area, String[] loot)
  20.     {
  21.         //For
  22.         this.player = player;
  23.         this.equipmentNames = equipment;
  24.         this.a = area;
  25.         this.lootables = loot;
  26.     }
  27.  
  28.     public boolean IsInArea()
  29.     {
  30.         if (!a.contains(player))
  31.         {
  32.             return false;
  33.         }
  34.         else {
  35.             return true;
  36.         }
  37.     }
  38.  
  39.     public void checkEquipped(Inventory inv, Equipment equip)
  40.     {
  41.         for (String x : equipmentNames)
  42.         {
  43.             if (inv.getItem(x) != null)
  44.             {
  45.                 inv.getItem(x).interact();
  46.             }
  47.         }
  48.     }
  49.  
  50.     public boolean LootableMode(GroundItem item)
  51.     {
  52.         boolean isLootable = false;
  53.         for (String x : lootables)
  54.         {
  55.             if (x == item.getName())
  56.             {
  57.                 isLootable = true;
  58.                 break;
  59.             }
  60.         }
  61.  
  62.         if(isLootable)
  63.         {
  64.             item.interact("Take");
  65.         }
  66.  
  67.     return isLootable;
  68.     }
  69.  
  70.     public void findNewTarget(NPCS npcs)
  71.     {
  72.         Filter<NPC> cowFilter = npc -> npc.getName().equalsIgnoreCase("Cow") &&
  73.         npc.isAttackable() &&
  74.                 !npc.isUnderAttack() &
  75.                         npc.isVisible();
  76.  
  77.         NPC cow = npcs.closest(cowFilter);
  78.  
  79.  
  80.         cow.interact("Attack");
  81.     }
  82.  
  83.     public void changeAttackStyle(Tabs tabs, int style, Configs config, Widgets widget)
  84.     {
  85.         tabs.open(Tab.ATTACK);
  86.  
  87.         if(style != config.get(43) && tabs.isOpen(Tab.ATTACK))
  88.         {
  89.             switch (style) {
  90.  
  91.                 case 0:
  92.  
  93.                     widget.get(593, 4).interact();
  94.  
  95.                 case 1:
  96.  
  97.                     widget.get(593, 9).interact();
  98.  
  99.                 case 2:
  100.  
  101.                     widget.get(593,12).interact();
  102.  
  103.                 case 3:
  104.  
  105.                     widget.get(593, 17).interact();
  106.             }
  107.  
  108.  
  109.         }
  110.         else if (!tabs.isOpen(Tab.ATTACK))
  111.         {
  112.             //if attack tab is not open, re-run function
  113.             changeAttackStyle(tabs,style,config,widget);
  114.         }
  115.     }
  116.  
  117.     public boolean checkHealth(int threshold, Skills skills)
  118.     {
  119.         if (skills.getDynamic(Skill.HITPOINTS) <= threshold)
  120.         {
  121.             return true;
  122.         }
  123.         else {
  124.             return false;
  125.         }
  126.     }
  127.  
  128. }
  129.  
  130. //Main Class Code (That is relevant to the error at hand)
  131.  
  132. //Script uses skills as states to swap behaviors
  133. private Area lummyCows = new Area(3253,3255,3265,3296);
  134. private String[] gearNames = {"Bronze sword"};
  135. private String[] lootables = {"Cowhide"};
  136. private CombatManager cm = new CombatManager(myPlayer(),gearNames,lummyCows,lootables);
  137. /*
  138. * Blah Blah Blah
  139. * Other Code that I know works goes here
  140. *
  141. */
  142.  
  143. else if (currState == Skill.ATTACK || currState == Skill.DEFENCE || currState == Skill.STRENGTH)
  144.         {
  145.             Tabs tabs = getTabs();
  146.             Configs configs = getConfigs();
  147.             Widgets widgets = getWidgets();
  148.             boolean isLooting = cm.checkHealth(3, getSkills());
  149.  
  150.             if (cm.IsInArea())
  151.             {
  152.                 cm.checkEquipped(getInventory(),getEquipment());
  153.                 if (currState == Skill.ATTACK)
  154.                 {
  155.                     cm.changeAttackStyle(tabs, 0, configs, widgets);
  156.                 }
  157.                 else if (currState == Skill.STRENGTH)
  158.                 {
  159.                     cm.changeAttackStyle(tabs, 1, configs, widgets);
  160.                 }
  161.                 else if (currState == Skill.DEFENCE)
  162.                 {
  163.                     cm.changeAttackStyle(tabs, 3, configs, widgets);
  164.                 }
  165.  
  166.                 if (isLooting)
  167.                 {
  168.                     boolean foundItem = cm.LootableMode(getGroundItems().closest("Cowhide"));
  169.                     log("Found Cowhide Status: " + foundItem);
  170.                 }
  171.                 else
  172.                 {
  173.                     cm.findNewTarget(getNpcs());
  174.                 }
  175.             }
  176.             else
  177.             {
  178.                 getWalking().webWalk(lummyCows);
  179.                 return random(1000,2500);
  180.             }
  181.             return random(500,1736);
  182.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement