Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * MonkeyKnifeKnocker.java
- *
- * Copyright (C) 2012 Alex Petrovich <alex@libslack.so>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import org.powerbot.concurrent.Task;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.Calculations;
- import org.powerbot.game.api.methods.Tabs;
- import org.powerbot.game.api.methods.Walking;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Mouse;
- import org.powerbot.game.api.methods.interactive.NPCs;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.node.Menu;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.methods.tab.Skills;
- import org.powerbot.game.api.methods.widget.Camera;
- import org.powerbot.game.api.util.Random;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.game.api.wrappers.Area;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.interactive.NPC;
- import org.powerbot.game.api.wrappers.map.TilePath;
- import org.powerbot.game.api.wrappers.node.Item;
- import org.powerbot.game.api.wrappers.widget.WidgetChild;
- import org.powerbot.game.bot.event.MessageEvent;
- import org.powerbot.game.bot.event.listener.MessageListener;
- import org.powerbot.game.bot.event.listener.PaintListener;
- @Manifest(name = "Monkey Knife Knocker", description = "Knocks monkeys out and steals from them at Ape Atoll.", version = 1.3d, authors = { "Slackfag" })
- public final class MonkeyKnifeKnocker extends ActiveScript implements
- MessageListener, PaintListener {
- private final int[] FOOD = { 379, 4014, 4016, 361, 385, 7946, 15272, 347,
- 355, 333, 339, 351, 329, 365, 373, 15266, 1891, 1893, 1895 },
- JUNK = { 1329, 1923, 1331, 1333 }, GREEGREES = { 4026, 4027 };
- private final Tile[] PATH_TO_STORE = {
- new Tile(Random.nextInt(2751, 2753), 2794, 0),
- new Tile(Random.nextInt(2759, 2764), Random.nextInt(2789, 2792), 0),
- new Tile(2770, Random.nextInt(2790, 2791), 0) },
- PATH_FROM_JAIL = {
- new Tile(Random.nextInt(2766, 2768), Random.nextInt(2798,
- 2799), 0),
- new Tile(Random.nextInt(2759, 2762), Random.nextInt(2799,
- 2801), 0),
- new Tile(Random.nextInt(2750, 2755), Random.nextInt(2803,
- 2805), 0),
- new Tile(2749, 2803, 0),
- new Tile(Random.nextInt(2748, 2756), Random.nextInt(2796,
- 2802), 0) };
- private final Area JAIL_AREA = new Area(new Tile(2770, 2793, 0), new Tile(
- 2777, 2796, 0));
- private String status = "Loading...";
- private boolean stunned = false, setup = false;
- private int failed = 0, succeeded = 0, runEnergy = 90;
- private long startedTime = 0L, startedXP = 0L;
- @Override
- protected final void setup() {
- this.startedTime = System.currentTimeMillis();
- this.startedXP = Skills.getExperience(Skills.THIEVING);
- super.provide(new Strategy(new Task() {
- @Override
- public final void run() {
- if (!Widgets.get(387, 2).isOnScreen()) {
- Tabs.EQUIPMENT.open();
- Time.sleep(Random.nextInt(500, 1250));
- Tabs.STATS.open();
- Time.sleep(Random.nextInt(2000, 2500));
- Tabs.INVENTORY.open();
- }
- if (!isGorilla()) {
- log.severe("You are not a gorilla!");
- stop();
- return;
- }
- setup = true;
- }
- }) {
- @Override
- public final boolean validate() {
- return !setup;
- }
- });
- super.provide(new Antiban());
- super.provide(new JailBreak());
- super.provide(new DropJunk());
- super.provide(new WaitForStun());
- super.provide(new Steal());
- }
- @Override
- public final void messageReceived(final MessageEvent msg) {
- if (msg.getMessage().contains("fail")
- || msg.getMessage().contains("glances")) {
- stunned = true;
- failed++;
- } else if (msg.getMessage().contains("You steal from"))
- succeeded++;
- else if (msg.getMessage().contains("local guards"))
- failed++;
- }
- @Override
- public final void onRepaint(final Graphics gfx) {
- final long xpGained = Skills.getExperience(Skills.THIEVING) - this.startedXP;
- final long timeRan = System.currentTimeMillis() - this.startedTime;
- gfx.setColor(new Color(0, 0, 0));
- gfx.fillRect(8, 345, 509, 133);
- gfx.setFont(new Font("Arial", Font.PLAIN, 12));
- gfx.setColor(new Color(255, 255, 255));
- gfx.drawString("Status: " + status, 20, 362);
- gfx.drawString("XP/hr: " + xpGained * (60 * 1000 * 60) / timeRan,
- 20, 382);
- gfx.drawString("XP gained: " + xpGained, 20, 402);
- gfx.drawString("Pickpockets: " + succeeded, 20, 422);
- gfx.drawString("Fails: " + failed, 20, 442);
- gfx.drawString("Ran for: " + Time.format(timeRan), 20, 472);
- }
- private final class Antiban extends Strategy implements Task {
- @Override
- public final boolean validate() {
- return Random.nextInt(0, 100) > 50;
- }
- @Override
- public final void run() {
- /**
- * This will probably need more complex or βhuman-likeβ behavior
- * eventually. Good enough for now.
- */
- if (Random.nextInt(0, 100) > 90 && Random.nextInt(0, 100) > 95) {
- status = "Antiban active...";
- Camera.setAngle(Random.nextInt(20, 300));
- }
- if (Random.nextInt(0, 100) > 95 && Random.nextInt(0, 100) > 98
- && Tabs.getCurrent() != Tabs.STATS) {
- status = "Antiban active...";
- Tabs.STATS.open();
- Time.sleep(Random.nextInt(2000, 2500));
- Tabs.INVENTORY.open();
- }
- }
- }
- private final class JailBreak extends Strategy implements Task {
- @Override
- public final boolean validate() {
- return JAIL_AREA.contains(Players.getLocal().getLocation());
- }
- @Override
- public final void run() {
- status = "Breaking out of jail...";
- NPC guard = NPCs.getNearest(1431, 1432);
- while (!guard.isOnScreen() || guard.getLocation().getX() > 2771
- || guard.getLocation().getY() > 2798) {
- status = "Waiting for jail guards to get into position...";
- Time.sleep(Random.nextInt(500, 1000));
- guard = NPCs.getNearest(1431, 1432);
- continue;
- }
- while (JAIL_AREA.contains(Players.getLocal().getLocation())) {
- SceneEntities.getNearest(4799).click(true);
- Time.sleep(Random.nextInt(3000, 5000));
- }
- status = "Running from jail...";
- walkTo(PATH_FROM_JAIL);
- }
- }
- private final class DropJunk extends Strategy implements Task {
- @Override
- public final boolean validate() {
- return Inventory.getCount() >= 24;
- }
- @Override
- public final void run() {
- status = "Dropping junk...";
- for (int i = 0; i < 4; i++)
- for (final Item item : Inventory.getItems())
- if (i >= 4)
- break;
- else if (isJunk(item)) {
- dropItem(item);
- Time.sleep(Random.nextInt(250, 500));
- i++;
- } else if (isEdible(item)) {
- eatItem(item);
- Time.sleep(Random.nextInt(1100, 1200));
- i++;
- }
- }
- }
- private final class WaitForStun extends Strategy implements Task {
- @Override
- public final boolean validate() {
- return stunned
- && !JAIL_AREA.contains(Players.getLocal().getLocation());
- }
- @Override
- public final void run() {
- status = "Stunned, waiting...";
- int sleep = 5500;
- if (Integer.parseInt(Widgets.get(748, 8).getText()) <= 300) {
- boolean ate = false;
- for (final Item item : Inventory.getItems())
- if (isEdible(item)) {
- eatItem(item);
- ate = true;
- break;
- }
- if (!ate) {
- log
- .warning("We are out of food and at critical health; going to go buy food.");
- status = "Buying food...";
- walkTo(PATH_TO_STORE);
- // walkPath(Walking.findPath(new
- // Tile(Random.nextInt(2769, 2770), Random.nextInt(2789,
- // 2790), 0)).getTilePath().toArray());
- Time.sleep(Random.nextInt(500, 1000));
- final NPC shopkeep = NPCs.getNearest(1433);
- if (!shopkeep.isOnScreen()) {
- log
- .severe("Could not find shopkeeper; killing script.");
- stop();
- }
- long lastTrade = 0L;
- do {
- if (System.currentTimeMillis() - lastTrade > 1000L) {
- shopkeep.interact("Trade");
- lastTrade = System.currentTimeMillis();
- } else
- Time.sleep(Random.nextInt(50, 100));
- } while (Widgets.get(1265, 5).isOnScreen()
- && lastTrade != 0L);
- final WidgetChild items = Widgets.get(1265, 26);
- while (!items.isOnScreen())
- Time.sleep(Random.nextInt(50, 100));
- for (final WidgetChild item : items.getChildren()) {
- if (isEdible(item.getChildId())) {
- Mouse.click(item.getAbsoluteX(), item
- .getAbsoluteY() + 60, false);
- Menu.select("Buy 10");
- Time.sleep(Random.nextInt(100, 500));
- }
- }
- Time.sleep(Random.nextInt(100, 500));
- Widgets.get(1265, 86).click(true);
- // walkPath(Walking.findPath(new
- // Tile(Random.nextInt(2748, 2756), Random.nextInt(2796,
- // 2802), 0)).getTilePath().toArray());
- walkTo(new TilePath(PATH_TO_STORE).reverse().toArray());
- Time.sleep(Random.nextInt(500, 1000));
- }
- }
- for (final Item item : Inventory.getItems())
- if (isJunk(item)) {
- dropItem(item);
- final int i = Random.nextInt(250, 500);
- sleep -= i;
- Time.sleep(i);
- }
- Time.sleep(Random.nextInt(sleep, sleep + 500));
- stunned = false;
- }
- }
- private final class Steal extends Strategy implements Task {
- @Override
- public final boolean validate() {
- return !isBusy()
- && !JAIL_AREA.contains(Players.getLocal().getLocation())
- && Inventory.getCount() < 24
- && !Players.getLocal().isMoving()
- && Players.getLocal().getAnimation() == -1 && isGorilla();
- }
- @Override
- public final void run() {
- final NPC monkey = NPCs.getNearest(13211);
- if (!monkey.isOnScreen()) {
- status = "Waiting for monkeys to appear within screen range...";
- Time.sleep(Random.nextInt(2000, 2500));
- return;
- }
- status = "Knocking monkey...";
- long lastPunch = 0L;
- int i = 0;
- do {
- if (isBusy())
- return;
- else if (System.currentTimeMillis() - lastPunch > 1500L) {
- monkey.interact("Punch");
- lastPunch = System.currentTimeMillis();
- } else
- Time.sleep(Random.nextInt(25, 50));
- } while (monkey.getAnimation() != 15050 && lastPunch != 0L);
- for (i = 0; i < 2; i++)
- if (!isBusy() && monkey.getAnimation() == 15050
- && System.currentTimeMillis() - lastPunch < 2500L) {
- status = "Stealing...";
- if (!monkey.interact("Pickpocket"))
- break;
- Time.sleep(Random.nextInt(240, 250));
- }
- while (!isBusy() && !monkey.getMessage().contains("ook"))
- Time.sleep(Random.nextInt(25, 50));
- }
- }
- private final boolean isBusy() {
- return stunned || JAIL_AREA.contains(Players.getLocal().getLocation());
- }
- private final boolean isGorilla() {
- for (final int greegree : GREEGREES)
- if (Widgets.get(387, 15).getChildId() == greegree)
- return true;
- return false;
- }
- private final boolean isEdible(final Item item) {
- return isEdible(item.getId());
- }
- private final boolean isEdible(final int id) {
- for (final int food : FOOD)
- if (id == food)
- return true;
- return false;
- }
- private final boolean isJunk(final Item item) {
- for (final int junk : JUNK)
- if (item.getId() == junk)
- return true;
- return false;
- }
- private final void eatItem(final Item item) {
- status = "Eating...";
- if (Tabs.getCurrent() != Tabs.INVENTORY)
- Tabs.INVENTORY.open();
- item.getWidgetChild().click(true);
- }
- private final void dropItem(final Item item) {
- status = "Dropping items...";
- if (Tabs.getCurrent() != Tabs.INVENTORY)
- Tabs.INVENTORY.open();
- item.getWidgetChild().interact("Drop");
- }
- public final void turnOnRun() {
- if (Walking.isRunEnabled())
- return;
- Walking.setRun(true);
- Time.sleep(100);
- if (Walking.isRunEnabled())
- runEnergy = Random.nextInt(0, 100);
- return;
- }
- public final void walkTo(final Tile[] path) {
- for (final Tile tile : path) {
- if (!Walking.isRunEnabled() && Walking.getEnergy() >= runEnergy)
- turnOnRun();
- Walking.walk(tile);
- int i = 0;
- while (Calculations
- .distance(Players.getLocal().getLocation(), tile) > Random
- .nextInt(1, 2)) {
- i++;
- Time.sleep(Random.nextInt(250, 500));
- if (i == 10) {
- i = 0;
- Walking.walk(tile);
- }
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement