/** * Drops the inventory item of the specified column and row. * * @param col the column the inventory item is in * @param row the row the inventory item is in */ public static void dropItem(int col, int row) { if (col < 0 || col > 3 || row < 0 || row > 6) return; if (getAllItems()[col + row * 4].getId() == -1) return; Point p; p = Mouse.getLocation(); if (p.x < 563 + col * 42 || p.x >= 563 + col * 42 + 32 || p.y < 213 + row * 36 || p.y >= 213 + row * 36 + 32) { Mouse.move(getComponent().getComponents()[row * 4 + col].getCenter(), 10, 10); } Mouse.click(false); Task.sleep(Random.nextInt(10, 25)); Menu.click("Drop"); Task.sleep(Random.nextInt(25, 50)); }
/** * Drops all inventory items excepting those matching with any of the provided ids. * * @param leftToRight <tt>true</tt> to span row by row (horizontal precedence); <tt>false</tt> to * span column by column (vertical precedence). * @param itemIds the item ids to exclude */ public static void dropAllExcept(boolean leftToRight, int... itemIds) { if (getCountExcept(itemIds) != 0) { if (!leftToRight) { for (int c = 0; c < 4; c++) { for (int r = 0; r < 7; r++) { boolean found = false; for (int i = 0; i < itemIds.length && !found; ++i) { found = itemIds[i] == getAllItems()[c + r * 4].getId(); } if (!found) { dropItem(c, r); } } } } else { for (int r = 0; r < 7; r++) { for (int c = 0; c < 4; c++) { boolean found = false; for (int i = 0; i < itemIds.length && !found; ++i) { found = itemIds[i] == getAllItems()[c + r * 4].getId(); } if (!found) { dropItem(c, r); } } } } Task.sleep(Random.nextInt(500, 800)); } }
/** * Uses an inventory item on either another inventory item or a game object. * * @param item the inventory item to use * @param target the inventory item or the game object to be used on by the inventory item * @return <tt>true</tt> if the "Use" action had been used on both the inventory item and the game * object/other inventory item; otherwise <tt>false</tt> */ private static boolean useItem(Item item, Object target) { if (isItemSelected()) { Item selectedItem = getSelectedItem(); int selectedItemId = selectedItem.getId(); if (item.getId() != selectedItemId) { if (!selectedItem.interact("Cancel")) { return false; } } else if (target instanceof Item) { Item t = (Item) target; if (selectedItemId != t.getId() && selectedItemId != item.getId()) { if (!selectedItem.interact("Cancel")) { return false; } } } } for (int i = 0, r = Random.nextInt(5, 8); i < r; i++) { if (isItemSelected()) { boolean success = false; for (int j = 0, k = Random.nextInt(5, 8); j < k; j++) { try { Item t = (Item) target; if (t.interact("Use")) { success = true; break; } Task.sleep(150, 300); } catch (final ClassCastException e) { return false; } } return success; } item.interact("Use"); Task.sleep(150, 300); } return false; }
/** * Uses an item on a game object. * * @param item the item to use * @param target the game object to be used on by the item * @return <tt>true</tt> if the "Use" action had been used on both the inventory item and the game * object; otherwise <tt>false</tt> */ public static boolean useItem(Item item, GameObject target) { if (item != null && target != null) { for (int i = 0, r = Random.nextInt(5, 8); i < r; i++) { if (!isItemSelected()) { if (item.interact("Use")) { for (int j = 0; j < 10 && !isItemSelected(); j++) { Task.sleep(100, 200); } } else { return false; } } // just make sure in case something bad happened if (isItemSelected()) { final String itemName = item.getName(); final ObjectDefinition targetDef = target.getDef(); final Model targetModel = target.getModel(); if (targetDef != null && itemName != null && targetModel != null) { final String targetName = targetDef.getName(); Mouse.move(targetModel.getNextPoint()); final String action = "Use " + itemName.replace("<col=ff9040>", "") + " -> " + targetName.replace("<col=ff9040>", ""); for (int j = 0, s = Random.nextInt(5, 8); j < s; j++) { if (Menu.contains(action) && Menu.click(action)) { return true; } else { Mouse.move(targetModel.getNextPoint()); } } } // kay, since that failed, let's try just use if (target.interact("Use")) { return true; } } } } return false; }