Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 24.84 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.Graphics;
  2. import java.awt.Graphics2D;
  3. import java.awt.Point;
  4. import java.awt.RenderingHints;
  5. import java.util.logging.Level;
  6.  
  7. import org.rsbot.event.listeners.PaintListener;
  8. import org.rsbot.script.Script;
  9. import org.rsbot.script.ScriptManifest;
  10. import org.rsbot.script.methods.Game;
  11. import org.rsbot.script.util.Filter;
  12. import org.rsbot.script.wrappers.RSArea;
  13. import org.rsbot.script.wrappers.RSGroundItem;
  14. import org.rsbot.script.wrappers.RSItem;
  15. import org.rsbot.script.wrappers.RSNPC;
  16. import org.rsbot.script.wrappers.RSObject;
  17. import org.rsbot.script.wrappers.RSPlayer;
  18. import org.rsbot.script.wrappers.RSTile;
  19.  
  20. @ScriptManifest(authors = { "Pervy Shuya, Fusion89k" }, name = "AutoCowKiller", keywords = "Combat", version = 1.35, description = ("Kills cows at at any location"))
  21. public class AIOCows extends Script implements PaintListener {
  22.  
  23.     private final char beefyDir = 's', craftingDir = 's', farmingDir = 'n',
  24.             lumbyDir = 'e';
  25.     private final int beefyGate = 45206, craftingGate = 1553,
  26.             farmingGate = 7050, lumbyGate = 45210, wait1 = 150, wait2 = 200,
  27.             hideID = 1739, tolerance = 6;
  28.     private final String[] cows = { "Cow", "Cow calf" };
  29.     private final RSArea beefyArea = new RSArea(3152, 3315, 3210, 3343),
  30.             craftingArea = new RSArea(new RSTile(2914, 3267), new RSTile(2938,
  31.                     3291)), farmingArea = new RSArea(new RSTile(3021, 3297),
  32.                     new RSTile(3043, 3313)), lumbyArea = new RSArea(new RSTile(
  33.                     3253, 3255), new RSTile(3266, 3299));
  34.     private final RSTile atStair = new RSTile(3205, 3229);
  35.     RSNPC beefyBill;
  36.     private final RSTile[] beefyPath = { new RSTile(3206, 3228),
  37.             new RSTile(3219, 3218), new RSTile(3234, 3226),
  38.             new RSTile(3224, 3237), new RSTile(3218, 3250),
  39.             new RSTile(3216, 3263), new RSTile(3214, 3277),
  40.             new RSTile(3199, 3279), new RSTile(3190, 3290),
  41.             new RSTile(3187, 3305), new RSTile(3176, 3314) }, craftingPath = {
  42.             new RSTile(3012, 3356), new RSTile(3007, 3341),
  43.             new RSTile(3007, 3325), new RSTile(2998, 3314),
  44.             new RSTile(2986, 3304), new RSTile(2971, 3299),
  45.             new RSTile(2958, 3299), new RSTile(2944, 3300),
  46.             new RSTile(2929, 3297), new RSTile(2922, 3293) }, farmingPath = {
  47.             new RSTile(3012, 3356), new RSTile(3007, 3341),
  48.             new RSTile(3007, 3325), new RSTile(3021, 3319),
  49.             new RSTile(3032, 3315) }, lumbyPath = { new RSTile(3206, 3228),
  50.             new RSTile(3216, 3219), new RSTile(3228, 3219),
  51.             new RSTile(3234, 3226), new RSTile(3226, 3237),
  52.             new RSTile(3229, 3248), new RSTile(3235, 3261),
  53.             new RSTile(3246, 3262), new RSTile(3251, 3267) };
  54.     private final int[] foodID = { 1895, 1893, 1891, 4293, 2142, 291, 2140,
  55.             3228, 9980, 7223, 6297, 6293, 6295, 6299, 7521, 9988, 7228, 2878,
  56.             7568, 2343, 1861, 13433, 315, 325, 319, 3144, 347, 355, 333, 339,
  57.             351, 329, 3381, 361, 10136, 5003, 379, 365, 373, 7946, 385, 397,
  58.             391, 3369, 3371, 3373, 2309, 2325, 2333, 2327, 2331, 2323, 2335,
  59.             7178, 7180, 7188, 7190, 7198, 7200, 7208, 7210, 7218, 7220, 2003,
  60.             2011, 2289, 2291, 2293, 2295, 2297, 2299, 2301, 2303, 1891, 1893,
  61.             1895, 1897, 1899, 1901, 7072, 7062, 7078, 7064, 7084, 7082, 7066,
  62.             7068, 1942, 6701, 6703, 7054, 6705, 7056, 7060, 2130, 1985, 1993,
  63.             1989, 1978, 5763, 5765, 1913, 5747, 1905, 5739, 1909, 5743, 1907,
  64.             1911, 5745, 2955, 5749, 5751, 5753, 5755, 5757, 5759, 5761, 2084,
  65.             2034, 2048, 2036, 2217, 2213, 2205, 2209, 2054, 2040, 2080, 2277,
  66.             2225, 2255, 2221, 2253, 2219, 2281, 2227, 2223, 2191, 2233, 2092,
  67.             2032, 2074, 2030, 2281, 2235, 2064, 2028, 2187, 2185, 2229, 6883,
  68.             1971, 4608, 1883, 1885, 15266 };
  69.     private char dir;
  70.     private RSNPC cow;
  71.     private int bankID = 11758, gate, count, oldCount = -1, runRandom = random(
  72.             30, 60);
  73.     private RSArea area;
  74.     private RSTile[] path;
  75.     private String doing = "Starting Up", where;
  76.     private long startTime;
  77.     private boolean bankAgain;
  78.  
  79.     private enum ACTION {
  80.         TOBANK, FROMBANK, GATE, ATTACK, BANK, CLIMBUP, CLIMBDOWN, BANKBEEFY
  81.     };
  82.  
  83.     @Override
  84.     public boolean onStart() {
  85.         getNearest();
  86.         startTime = System.currentTimeMillis();
  87.         return true;
  88.     }
  89.  
  90.     @Override
  91.     public void onFinish() {
  92.  
  93.     }
  94.  
  95.     @Override
  96.     public int loop() {
  97.         beefyBill = npcs.getNearest(246);
  98.         cow = npcs.getNearest(new Filter<RSNPC>() {
  99.             @Override
  100.             public boolean accept(RSNPC npc) {
  101.                 for (String name : cows)
  102.  
  103.                     if (npc.getName().equals(name) && !npc.isInCombat())
  104.                         return true;
  105.  
  106.                 return false;
  107.             }
  108.         });
  109.         camera.setPitch(true);
  110.         if (getMyPlayer().isMoving()) {
  111.             if (area.contains(getMyPlayer().getLocation()))
  112.                 return random(wait1, wait2);
  113.             else if (isMoving())
  114.                 return random(wait1, wait2);
  115.         }
  116.  
  117.         if (path == null)
  118.             getNearest();
  119.         switch (getAction()) {
  120.         case TOBANK:
  121.             walk(true);
  122.             break;
  123.         case FROMBANK:
  124.             walk(false);
  125.             break;
  126.         case GATE:
  127.             if (objects.getNearest(gate) != null
  128.                     && objects.getNearest(gate).doAction("Open")) {
  129.                 if (objects.getNearest(gate) == null)
  130.                     walking.walkTileMM(area.getCentralTile());
  131.             } else {
  132.                 walking.walkTileMM(area.getCentralTile());
  133.             }
  134.             return random(1400, 1600);
  135.         case BANKBEEFY:
  136.             if (bankAgain) {
  137.                 if (inventory.contains(hideID)) {
  138.                     if (beefyBill == null) {
  139.                         walking.walkTileMM(walking.getClosestTileOnMap(area
  140.                                 .getCentralTile()));
  141.                     } else if (beefyBill != null && beefyBill.isOnScreen()) {
  142.                         if (interfaces.get(236).isValid()) {
  143.                             interfaces.getComponent(236, 1).doClick();
  144.                             bankAgain = false;
  145.                         } else {
  146.                             useItem(inventory.getItem(hideID), beefyBill);
  147.                         }
  148.                     } else {
  149.                         walking.walkTileMM(beefyBill.getLocation());
  150.                     }
  151.                 }
  152.             } else {
  153.                 if (inventory.isFull()) {
  154.                     if (beefyBill == null) {
  155.                         walking.walkTileMM(walking.getClosestTileOnMap(area
  156.                                 .getCentralTile()));
  157.                     } else if (beefyBill != null && beefyBill.isOnScreen()) {
  158.                         if (interfaces.get(451).isValid()) {
  159.                             interfaces.getComponent(451, 1).doClick();
  160.                             bankAgain = true;
  161.                         } else {
  162.                             useItem(inventory.getItem(hideID), beefyBill);
  163.                         }
  164.                     } else {
  165.                         walking.walkTileMM(beefyBill.getLocation());
  166.                     }
  167.                 }
  168.             }
  169.             return random(1400, 1600);
  170.         case BANK:
  171.             if (objects.getNearest(bankID) != null
  172.                     && objects.getNearest(bankID).isOnScreen()) {
  173.                 if (!bank.isOpen()) {
  174.                     doing = "Opening Bank";
  175.                     objects.getNearest(bankID).doAction("Use-quickly");
  176.                 } else {
  177.                     doing = "Depositing";
  178.                     bank.depositAll();
  179.                 }
  180.             } else {
  181.                 if (!getMyPlayer().isMoving())
  182.                     walking.walkTileMM(objects.getNearest(bankID).getLocation());
  183.             }
  184.             return random(1400, 1600);
  185.         case ATTACK:
  186.             if (peopleCheck()) {
  187.                 switchPlace();
  188.             } else {
  189.                 if (getMyPlayer().getInteracting() == null
  190.                         && getNearestLootInArea(area, hideID) != null) {
  191.                     hideCheck();
  192.                     return random(1500, 1700);
  193.                 }
  194.                 while (getMyPlayer().getInteracting() instanceof RSNPC
  195.                         || getMyPlayer().isInCombat()) {
  196.                 }
  197.                 attack();
  198.             }
  199.             return random(1400, 1800);
  200.         case CLIMBUP:
  201.             doing = "Climbing Up";
  202.             switch (game.getPlane()) {
  203.             case 0:
  204.                 atTile(new RSTile(atStair.getX() - 1, atStair.getY()),
  205.                         "Climb-up");
  206.                 return random(1400, 1800);
  207.             case 1:
  208.                 atTile(atStair, "Climb-up");
  209.                 return random(1400, 1800);
  210.             }
  211.             break;
  212.         case CLIMBDOWN:
  213.             doing = "Climbing Down";
  214.             atTile(atStair, "Climb-down");
  215.             return random(1400, 1800);
  216.         }
  217.         return random(wait1, wait2);
  218.     }
  219.  
  220.     private ACTION getAction() {
  221.         if (bankAgain) {
  222.             return ACTION.BANKBEEFY;
  223.         }
  224.         if (where.equals("Beefy Bill")) {
  225.             if (inventory.isFull()) {
  226.                 return ACTION.BANKBEEFY;
  227.             }
  228.         }
  229.         if (inventory.isFull() && !where.equals("Beefy Bill")) {
  230.             if (calc.distanceTo(path[0]) > 4) {
  231.                 if (game.getPlane() == 2)
  232.                     return ACTION.BANK;
  233.                 if (area.contains(getMyPlayer().getLocation())) {
  234.                     if (gateCheck())
  235.                         return ACTION.GATE;
  236.                     else
  237.                         return ACTION.FROMBANK;
  238.                 } else
  239.                     return ACTION.TOBANK;
  240.             } else if (dir == lumbyDir && game.getPlane() != 2)
  241.                 return ACTION.CLIMBUP;
  242.             return ACTION.BANK;
  243.         } else {
  244.             if (calc.distanceTo(path[path.length - 1]) > 4
  245.                     && !area.contains(getMyPlayer().getLocation())) {
  246.                 if (game.getPlane() != 0)
  247.                     return ACTION.CLIMBDOWN;
  248.                 else
  249.                     return ACTION.FROMBANK;
  250.             } else {
  251.                 if (!area.contains(getMyPlayer().getLocation()))
  252.                     return ACTION.GATE;
  253.                 else
  254.                     return ACTION.ATTACK;
  255.             }
  256.         }
  257.     }
  258.  
  259.     private boolean attack() {
  260.         runCheck();
  261.         if (getMyPlayer().getInteracting() != null
  262.                 || getMyPlayer().isInteractingWithLocalPlayer())
  263.             return false;
  264.         if (combat.getLifePoints() < combat.getLifePoints() / random(3, 5))
  265.             return inventory.getItem(foodID).doAction("Eat");
  266.         doing = "Finding Cow";
  267.         if (cow != null && getNearestLootInArea(area, hideID) == null) {
  268.             if (cow.isOnScreen() && clickNPC(cow, "Attack")) {
  269.                 doing = "Attacking Cow";
  270.                 return true;
  271.             } else {
  272.                 if (area.contains(cow.getLocation()) && !cow.isOnScreen())
  273.                     walking.walkTileMM(cow.getLocation());
  274.                 return false;
  275.             }
  276.         } else {
  277.             hideCheck();
  278.         }
  279.         return false;
  280.     }
  281.  
  282.     private boolean hideCheck() {
  283.         doing = "Picking up hides";
  284.         RSGroundItem hide = groundItems.getNearest(hideID);
  285.         if (hide != null && area.contains(hide.getLocation())) {
  286.             if (calc.tileOnScreen(hide.getLocation())) {
  287.                 if (getMyPlayer().getInteracting() == null)
  288.                     hide.doAction("Take Cowhide");
  289.                 return true;
  290.             } else if (!calc.tileOnScreen(hide.getLocation())) {
  291.                 walking.walkTo(hide.getLocation());
  292.                 return false;
  293.             }
  294.         }
  295.         return false;
  296.     }
  297.  
  298.     @SuppressWarnings("unused")
  299.     private boolean findLootItem(final int range, final int ids) {
  300.         int myX = getMyPlayer().getLocation().getX();
  301.         int myY = getMyPlayer().getLocation().getY();
  302.         int minX = myX - range;
  303.         int minY = myY - range;
  304.         int maxX = myX + range;
  305.         int maxY = myY + range;
  306.         for (int x = minX; x <= maxX; x++) {
  307.             for (int y = minY; y <= maxY; y++) {
  308.                 final RSGroundItem[] items = groundItems.getAllAt(x, y);
  309.                 for (final RSGroundItem item : items) {
  310.                     int itemID = item.getItem().getID();
  311.                     if (itemID == ids)
  312.                         return true;
  313.                 }
  314.             }
  315.         }
  316.         return false;
  317.     }
  318.  
  319.     private void getNearest() {
  320.         if (game.isLoggedIn()) {
  321.             int farm = calc.distanceTo(farmingPath[farmingPath.length - 1]), craft = calc
  322.                     .distanceTo(craftingPath[craftingPath.length - 1]), lumby = calc
  323.                     .distanceTo(lumbyPath[lumbyPath.length - 1]), beefy = calc
  324.                     .distanceTo(beefyPath[beefyPath.length - 1]);
  325.             if (farm <= craft && farm <= lumby && farm <= beefy) {
  326.                 dir = farmingDir;
  327.                 gate = farmingGate;
  328.                 area = farmingArea;
  329.                 path = farmingPath;
  330.                 where = "Farming";
  331.             } else if (craft <= lumby && farm <= beefy) {
  332.                 dir = craftingDir;
  333.                 gate = craftingGate;
  334.                 area = craftingArea;
  335.                 path = craftingPath;
  336.                 where = "Crafting";
  337.             } else if (beefy <= lumby) {
  338.                 dir = beefyDir;
  339.                 gate = beefyGate;
  340.                 area = beefyArea;
  341.                 path = beefyPath;
  342.                 where = "Beefy Bill";
  343.             } else {
  344.                 dir = lumbyDir;
  345.                 gate = lumbyGate;
  346.                 area = lumbyArea;
  347.                 path = lumbyPath;
  348.                 bankID = 36786;
  349.                 where = "Lumby";
  350.             }
  351.             log("Starting in: " + where);
  352.         } else
  353.             path = null;
  354.     }
  355.  
  356.     private boolean useItem(RSItem item, RSNPC npc) {
  357.         if (game.getCurrentTab() != Game.TAB_INVENTORY) {
  358.             game.openTab(Game.TAB_INVENTORY);
  359.         }
  360.         return item.doAction("Use") && npc.doAction("Use");
  361.     }
  362.  
  363.     private boolean peopleCheck() {
  364.         if (dir == lumbyDir)
  365.             return false;
  366.         int pCount = 0;
  367.         final RSPlayer[] validPlayers = players.getAll();
  368.  
  369.         for (final RSPlayer player : validPlayers) {
  370.             if (player == null)
  371.                 continue;
  372.             if (area.contains(player.getLocation()))
  373.                 pCount++;
  374.         }
  375.         return pCount >= tolerance;
  376.     }
  377.  
  378.     private void switchPlace() {
  379.         doing = "Switching Location";
  380.         if (area.contains(getMyPlayer().getLocation())
  381.                 && !calc.canReach(path[path.length - 1], false)) {
  382.             objects.getNearest(gate).doAction("Open");
  383.             switchPlace();
  384.         } else {
  385.             if (dir == craftingDir) {
  386.                 dir = farmingDir;
  387.                 gate = farmingGate;
  388.                 area = farmingArea;
  389.                 path = farmingPath;
  390.             } else {
  391.                 dir = craftingDir;
  392.                 gate = craftingGate;
  393.                 area = craftingArea;
  394.                 path = craftingPath;
  395.             }
  396.         }
  397.     }
  398.  
  399.     private boolean isMoving() {
  400.         if (!getMyPlayer().isMoving())
  401.             return false;
  402.         if (walking.getDestination() != null
  403.                 && (calc.distanceBetween(path[0], walking.getDestination()) > 5 && calc
  404.                         .distanceBetween(path[path.length - 1],
  405.                                 walking.getDestination()) > 5)) {
  406.             if (calc.distanceTo(walking.getDestination()) < (walking
  407.                     .isRunEnabled() ? 6 : 8))
  408.                 return false;
  409.         }
  410.         return true;
  411.     }
  412.  
  413.     private boolean gateCheck() {
  414.         final RSObject o = objects.getNearest(gate);
  415.         if (o == null)
  416.             return false;
  417.         if (o.getLocation().getX() >= path[path.length - 1].getX())
  418.             return true;
  419.         return false;
  420.     }
  421.  
  422.     private RSGroundItem getNearestLootInArea(RSArea area, final int id) {
  423.         RSGroundItem[] all = groundItems.getAll();
  424.         int dis = 1000;
  425.         RSGroundItem myLoot = null;
  426.         for (RSGroundItem loot : all) {
  427.             if (area.contains(loot.getLocation())) {
  428.                 if (loot.getItem().getID() == id) {
  429.                     if (calc.distanceBetween(getMyPlayer().getLocation(),
  430.                             loot.getLocation()) < dis) {
  431.                         dis = (int) calc.distanceBetween(getMyPlayer()
  432.                                 .getLocation(), loot.getLocation());
  433.                         myLoot = loot;
  434.                     }
  435.                 }
  436.             }
  437.         }
  438.         return myLoot;
  439.     }
  440.  
  441.     @SuppressWarnings("unused")
  442.     private RSNPC getNearestNPCInArea(RSArea area, final int... ids) {
  443.         RSNPC[] all = npcs.getAll();
  444.         int dis = 1000;
  445.         RSNPC myNPC = null;
  446.         for (RSNPC npc : all) {
  447.             if (area.contains(npc.getLocation())) {
  448.                 for (int i : ids) {
  449.                     if (npc.getID() == i) {
  450.                         if (calc.distanceBetween(getMyPlayer().getLocation(),
  451.                                 npc.getLocation()) < dis) {
  452.                             dis = (int) calc.distanceBetween(getMyPlayer()
  453.                                     .getLocation(), npc.getLocation());
  454.                             myNPC = npc;
  455.                         }
  456.                     }
  457.                 }
  458.             }
  459.         }
  460.         return myNPC;
  461.     }
  462.  
  463.     private boolean atTile(RSTile tile, String action) {
  464.         if (tile == null)
  465.             return false;
  466.         if (menu.isOpen()) {
  467.             menu.doAction("Cancel");
  468.             atTile(tile, action);
  469.         }
  470.         if (!calc.tileOnScreen(tile)) {
  471.             walking.walkTo(checkTile(randomTile(tile)));
  472.             return false;
  473.         }
  474.         Point click = calc.tileToScreen(tile);
  475.         mouse.move(randomPoint(click));
  476.         long begin = System.currentTimeMillis();
  477.         boolean exit = false;
  478.         while ((System.currentTimeMillis() - begin) < 2000) {
  479.             for (String act : menu.getItems()) {
  480.                 if (act.contains(action)) {
  481.                     exit = true;
  482.                     break;
  483.                 }
  484.             }
  485.             if (exit)
  486.                 break;
  487.             if (!calc.tileOnScreen(tile))
  488.                 walking.walkTo(randomTile(tile));
  489.             else
  490.                 mouse.move(randomPoint(click));
  491.         }
  492.         if (!menu.getItems()[0].contains(action)) {
  493.             mouse.click(randomPoint(click), false);
  494.             return menu.doAction(action);
  495.         } else
  496.             mouse.click(randomPoint(click), true);
  497.         return true;
  498.     }
  499.  
  500.     private boolean clickNPC(final RSNPC npc, final String action) {
  501.         if (npc == null)
  502.             return false;
  503.         final RSTile tile = npc.getLocation();
  504.         if (tile == null)
  505.             return false;
  506.  
  507.         try {
  508.             Point screenLoc = npc.getScreenLocation();
  509.             if (calc.distanceTo(tile) > 6 || !calc.pointOnScreen(screenLoc))
  510.                 camera.turnToTile(tile);
  511.             if (calc.distanceTo(tile) > 20) {
  512.                 walking.walkTileMM(tile);
  513.                 return false;
  514.             }
  515.             for (int i = 0; i < 12; i++) {
  516.                 screenLoc = npc.getScreenLocation();
  517.                 if (!npc.isValid() || !calc.pointOnScreen(screenLoc))
  518.                     return false;
  519.                 mouse.move(randomPoint(screenLoc));
  520.                 if (menu.getItems()[0].toLowerCase().contains(
  521.                         npc.getName().toLowerCase()))
  522.                     break;
  523.                 if (mouse.getLocation().equals(screenLoc))
  524.                     break;
  525.             }
  526.             String[] menuItems = menu.getItems();
  527.             if (menuItems.length == 0)
  528.                 return false;
  529.             for (String menuItem : menuItems)
  530.                 if (menuItem.toLowerCase()
  531.                         .contains(npc.getName().toLowerCase()))
  532.                     if (menuItems[0].toLowerCase().contains(
  533.                             action.toLowerCase())) {
  534.                         mouse.click(true);
  535.                         return true;
  536.                     } else {
  537.                         mouse.click(false);
  538.                         return menu.doAction(action);
  539.                     }
  540.         } catch (final Exception e) {
  541.             log.log(Level.SEVERE, "clickNPC(RSNPC, String) model error: ", e);
  542.             return false;
  543.         }
  544.         return false;
  545.     }
  546.  
  547.     private void walk(boolean toBank) {
  548.         doing = (walking.isRunEnabled() ? "Running" : "Walking") + " to "
  549.                 + (toBank ? "Bank" : "Cows");
  550.         camera.setCompass('n');
  551.         runCheck();
  552.         RSTile start = locate();
  553.         int loc = 0;
  554.         for (int i = 0; i < path.length; i++) {
  555.             if (start.equals(path[i])) {
  556.                 loc = i;
  557.                 break;
  558.             }
  559.         }
  560.         if (toBank) {
  561.             if (loc == 0)
  562.                 walking.walkTo(checkTile(randomTile(path[0], 1)));
  563.             else
  564.                 walking.walkTo(checkTile(randomTile(path[loc - 1])));
  565.         } else {
  566.             if (loc == path.length - 1)
  567.                 walking.walkTo(checkTile(randomTile(path[path.length - 1], 1)));
  568.             else
  569.                 walking.walkTo(checkTile(randomTile(path[loc + 1])));
  570.         }
  571.     }
  572.  
  573.     private RSTile locate() {
  574.         RSTile min = path[0];
  575.         for (int i = 1; i < path.length; i++) {
  576.             if (calc.distanceTo(path[i]) < calc.distanceTo(min))
  577.                 min = path[i];
  578.         }
  579.         return min;
  580.     }
  581.  
  582.     private RSTile randomTile(RSTile location) {
  583.         return randomTile(location, 1);
  584.     }
  585.  
  586.     private RSTile randomTile(RSTile location, int rand) {
  587.         return randomTile(location, rand, rand);
  588.     }
  589.  
  590.     // Randomizes tile by given x and y randoms
  591.     private RSTile randomTile(RSTile location, int xRand, int yRand) {
  592.         int x = location.getX(), y = location.getY();
  593.         return new RSTile(x + random((-1 * xRand), xRand), y
  594.                 + random((-1 * yRand), yRand));
  595.     }
  596.  
  597.     private Point randomPoint(Point click) {
  598.         int dif = 2;
  599.         return new Point(click.x + random(-dif, dif), click.y
  600.                 + random(-dif, dif));
  601.     }
  602.  
  603.     // Keeps finding midtile until the tile is onMap
  604.     private RSTile checkTile(RSTile tile) {
  605.         if (calc.tileOnMap(tile))
  606.             return tile;
  607.         RSTile loc = getMyPlayer().getLocation();
  608.         RSTile walk = new RSTile((loc.getX() + tile.getX()) / 2,
  609.                 (loc.getY() + tile.getY()) / 2);
  610.         return calc.tileOnMap(walk) ? walk : checkTile(walk);
  611.     }
  612.  
  613.     private void runCheck() {
  614.         if (!walking.isRunEnabled() && walking.getEnergy() >= runRandom) {
  615.             doing = "Setting run";
  616.             walking.setRun(true);
  617.             runRandom = random(30, 70);
  618.         } else {
  619.             if (walking.getEnergy() < random(15, 20)) {
  620.                 doing = "Resting";
  621.                 walking.rest(random(70, 90));
  622.             }
  623.         }
  624.     }
  625.  
  626.     @Override
  627.     public void onRepaint(Graphics g) {
  628.         ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  629.                 RenderingHints.VALUE_ANTIALIAS_ON);
  630.         if (game.isLoggedIn()) {
  631.             final int invCount = inventory.getCount(hideID);
  632.             if (oldCount < 0)
  633.                 oldCount = invCount;
  634.             else {
  635.                 if (invCount > oldCount)
  636.                     count += invCount - oldCount;
  637.                 oldCount = invCount;
  638.             }
  639.             long millis = System.currentTimeMillis() - startTime;
  640.             long hours = millis / (1000 * 60 * 60);
  641.             millis -= hours * (1000 * 60 * 60);
  642.             long minutes = millis / (1000 * 60);
  643.             millis -= minutes * (1000 * 60);
  644.             long seconds = millis / 1000;
  645.             int topX = 515 - 173, topY = 337 - 50, x = topX + 5, y = topY;
  646.             g.setColor(new Color(0, 100, 0, 100));
  647.             g.fill3DRect(topX, topY, 515 - topX, 337 - topY, true);
  648.             g.setColor(Color.green);
  649.             g.drawString("Runtime: " + hours + "h " + minutes + "min "
  650.                     + seconds + "sec.", x, y += 15);
  651.             g.drawString("Hides: " + count, x, y += 15);
  652.             g.drawString("Status: " + doing, x, y += 15);
  653.         }
  654.     }
  655. }