Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

MKF script

By: a guest on Aug 29th, 2012  |  syntax: None  |  size: 11.92 KB  |  views: 20  |  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.  * MonkeyKnifeKnocker.java
  2. *
  3. * Copyright (C) 2012 Alex Petrovich <alex@libslack.so>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19.  
  20. import java.awt.Color;
  21. import java.awt.Font;
  22. import java.awt.Graphics;
  23.  
  24. import org.powerbot.concurrent.Task;
  25. import org.powerbot.concurrent.strategy.Strategy;
  26.  
  27. import org.powerbot.game.api.ActiveScript;
  28. import org.powerbot.game.api.Manifest;
  29. import org.powerbot.game.api.methods.Calculations;
  30. import org.powerbot.game.api.methods.Tabs;
  31. import org.powerbot.game.api.methods.Walking;
  32. import org.powerbot.game.api.methods.Widgets;
  33. import org.powerbot.game.api.methods.input.Mouse;
  34. import org.powerbot.game.api.methods.interactive.NPCs;
  35. import org.powerbot.game.api.methods.interactive.Players;
  36. import org.powerbot.game.api.methods.node.Menu;
  37. import org.powerbot.game.api.methods.node.SceneEntities;
  38. import org.powerbot.game.api.methods.tab.Inventory;
  39. import org.powerbot.game.api.methods.tab.Skills;
  40. import org.powerbot.game.api.methods.widget.Camera;
  41. import org.powerbot.game.api.util.Random;
  42. import org.powerbot.game.api.util.Time;
  43. import org.powerbot.game.api.wrappers.Area;
  44. import org.powerbot.game.api.wrappers.Tile;
  45. import org.powerbot.game.api.wrappers.interactive.NPC;
  46. import org.powerbot.game.api.wrappers.map.TilePath;
  47. import org.powerbot.game.api.wrappers.node.Item;
  48. import org.powerbot.game.api.wrappers.widget.WidgetChild;
  49. import org.powerbot.game.bot.event.MessageEvent;
  50. import org.powerbot.game.bot.event.listener.MessageListener;
  51. import org.powerbot.game.bot.event.listener.PaintListener;
  52.  
  53. @Manifest(name = "Monkey Knife Knocker", description = "Knocks monkeys out and steals from them at Ape Atoll.", version = 1.3d, authors = { "Slackfag" })
  54. public final class MonkeyKnifeKnocker extends ActiveScript implements
  55. MessageListener, PaintListener {
  56. private final int[] FOOD = { 379, 4014, 4016, 361, 385, 7946, 15272, 347,
  57. 355, 333, 339, 351, 329, 365, 373, 15266, 1891, 1893, 1895 },
  58. JUNK = { 1329, 1923, 1331, 1333 }, GREEGREES = { 4026, 4027 };
  59. private final Tile[] PATH_TO_STORE = {
  60. new Tile(Random.nextInt(2751, 2753), 2794, 0),
  61. new Tile(Random.nextInt(2759, 2764), Random.nextInt(2789, 2792), 0),
  62. new Tile(2770, Random.nextInt(2790, 2791), 0) },
  63. PATH_FROM_JAIL = {
  64. new Tile(Random.nextInt(2766, 2768), Random.nextInt(2798,
  65. 2799), 0),
  66. new Tile(Random.nextInt(2759, 2762), Random.nextInt(2799,
  67. 2801), 0),
  68. new Tile(Random.nextInt(2750, 2755), Random.nextInt(2803,
  69. 2805), 0),
  70. new Tile(2749, 2803, 0),
  71. new Tile(Random.nextInt(2748, 2756), Random.nextInt(2796,
  72. 2802), 0) };
  73. private final Area JAIL_AREA = new Area(new Tile(2770, 2793, 0), new Tile(
  74. 2777, 2796, 0));
  75.  
  76. private String status = "Loading...";
  77. private boolean stunned = false, setup = false;
  78. private int failed = 0, succeeded = 0, runEnergy = 90;
  79. private long startedTime = 0L, startedXP = 0L;
  80.  
  81. @Override
  82. protected final void setup() {
  83. this.startedTime = System.currentTimeMillis();
  84. this.startedXP = Skills.getExperience(Skills.THIEVING);
  85.  
  86. super.provide(new Strategy(new Task() {
  87. @Override
  88. public final void run() {
  89. if (!Widgets.get(387, 2).isOnScreen()) {
  90. Tabs.EQUIPMENT.open();
  91. Time.sleep(Random.nextInt(500, 1250));
  92. Tabs.STATS.open();
  93. Time.sleep(Random.nextInt(2000, 2500));
  94. Tabs.INVENTORY.open();
  95. }
  96.  
  97. if (!isGorilla()) {
  98. log.severe("You are not a gorilla!");
  99. stop();
  100. return;
  101. }
  102.  
  103. setup = true;
  104. }
  105. }) {
  106. @Override
  107. public final boolean validate() {
  108. return !setup;
  109. }
  110. });
  111. super.provide(new Antiban());
  112. super.provide(new JailBreak());
  113. super.provide(new DropJunk());
  114. super.provide(new WaitForStun());
  115. super.provide(new Steal());
  116. }
  117.  
  118. @Override
  119. public final void messageReceived(final MessageEvent msg) {
  120. if (msg.getMessage().contains("fail")
  121. || msg.getMessage().contains("glances")) {
  122. stunned = true;
  123. failed++;
  124. } else if (msg.getMessage().contains("You steal from"))
  125. succeeded++;
  126. else if (msg.getMessage().contains("local guards"))
  127. failed++;
  128. }
  129.  
  130. @Override
  131. public final void onRepaint(final Graphics gfx) {
  132. final long xpGained = Skills.getExperience(Skills.THIEVING) - this.startedXP;
  133. final long timeRan = System.currentTimeMillis() - this.startedTime;
  134.  
  135. gfx.setColor(new Color(0, 0, 0));
  136. gfx.fillRect(8, 345, 509, 133);
  137.  
  138. gfx.setFont(new Font("Arial", Font.PLAIN, 12));
  139. gfx.setColor(new Color(255, 255, 255));
  140. gfx.drawString("Status: " + status, 20, 362);
  141. gfx.drawString("XP/hr: " + xpGained * (60 * 1000 * 60) / timeRan,
  142. 20, 382);
  143. gfx.drawString("XP gained: " + xpGained, 20, 402);
  144. gfx.drawString("Pickpockets: " + succeeded, 20, 422);
  145. gfx.drawString("Fails: " + failed, 20, 442);
  146. gfx.drawString("Ran for: " + Time.format(timeRan), 20, 472);
  147. }
  148.  
  149. private final class Antiban extends Strategy implements Task {
  150. @Override
  151. public final boolean validate() {
  152. return Random.nextInt(0, 100) > 50;
  153. }
  154.  
  155. @Override
  156. public final void run() {
  157. /**
  158. * This will probably need more complex or ‘human-like’ behavior
  159. * eventually. Good enough for now.
  160. */
  161. if (Random.nextInt(0, 100) > 90 && Random.nextInt(0, 100) > 95) {
  162. status = "Antiban active...";
  163. Camera.setAngle(Random.nextInt(20, 300));
  164. }
  165. if (Random.nextInt(0, 100) > 95 && Random.nextInt(0, 100) > 98
  166. && Tabs.getCurrent() != Tabs.STATS) {
  167. status = "Antiban active...";
  168. Tabs.STATS.open();
  169. Time.sleep(Random.nextInt(2000, 2500));
  170. Tabs.INVENTORY.open();
  171. }
  172. }
  173. }
  174.  
  175. private final class JailBreak extends Strategy implements Task {
  176. @Override
  177. public final boolean validate() {
  178. return JAIL_AREA.contains(Players.getLocal().getLocation());
  179. }
  180.  
  181. @Override
  182. public final void run() {
  183. status = "Breaking out of jail...";
  184. NPC guard = NPCs.getNearest(1431, 1432);
  185.  
  186. while (!guard.isOnScreen() || guard.getLocation().getX() > 2771
  187. || guard.getLocation().getY() > 2798) {
  188. status = "Waiting for jail guards to get into position...";
  189. Time.sleep(Random.nextInt(500, 1000));
  190. guard = NPCs.getNearest(1431, 1432);
  191. continue;
  192. }
  193.  
  194. while (JAIL_AREA.contains(Players.getLocal().getLocation())) {
  195. SceneEntities.getNearest(4799).click(true);
  196. Time.sleep(Random.nextInt(3000, 5000));
  197. }
  198.  
  199. status = "Running from jail...";
  200. walkTo(PATH_FROM_JAIL);
  201. }
  202. }
  203.  
  204. private final class DropJunk extends Strategy implements Task {
  205. @Override
  206. public final boolean validate() {
  207. return Inventory.getCount() >= 24;
  208. }
  209.  
  210. @Override
  211. public final void run() {
  212. status = "Dropping junk...";
  213. for (int i = 0; i < 4; i++)
  214. for (final Item item : Inventory.getItems())
  215. if (i >= 4)
  216. break;
  217. else if (isJunk(item)) {
  218. dropItem(item);
  219. Time.sleep(Random.nextInt(250, 500));
  220. i++;
  221. } else if (isEdible(item)) {
  222. eatItem(item);
  223. Time.sleep(Random.nextInt(1100, 1200));
  224. i++;
  225. }
  226. }
  227. }
  228.  
  229. private final class WaitForStun extends Strategy implements Task {
  230. @Override
  231. public final boolean validate() {
  232. return stunned
  233. && !JAIL_AREA.contains(Players.getLocal().getLocation());
  234. }
  235.  
  236. @Override
  237. public final void run() {
  238. status = "Stunned, waiting...";
  239. int sleep = 5500;
  240. if (Integer.parseInt(Widgets.get(748, 8).getText()) <= 300) {
  241. boolean ate = false;
  242. for (final Item item : Inventory.getItems())
  243. if (isEdible(item)) {
  244. eatItem(item);
  245. ate = true;
  246. break;
  247. }
  248. if (!ate) {
  249. log
  250. .warning("We are out of food and at critical health; going to go buy food.");
  251. status = "Buying food...";
  252. walkTo(PATH_TO_STORE);
  253. // walkPath(Walking.findPath(new
  254. // Tile(Random.nextInt(2769, 2770), Random.nextInt(2789,
  255. // 2790), 0)).getTilePath().toArray());
  256. Time.sleep(Random.nextInt(500, 1000));
  257.  
  258. final NPC shopkeep = NPCs.getNearest(1433);
  259. if (!shopkeep.isOnScreen()) {
  260. log
  261. .severe("Could not find shopkeeper; killing script.");
  262. stop();
  263. }
  264.  
  265. long lastTrade = 0L;
  266. do {
  267. if (System.currentTimeMillis() - lastTrade > 1000L) {
  268. shopkeep.interact("Trade");
  269. lastTrade = System.currentTimeMillis();
  270. } else
  271. Time.sleep(Random.nextInt(50, 100));
  272. } while (Widgets.get(1265, 5).isOnScreen()
  273. && lastTrade != 0L);
  274.  
  275. final WidgetChild items = Widgets.get(1265, 26);
  276.  
  277. while (!items.isOnScreen())
  278. Time.sleep(Random.nextInt(50, 100));
  279.  
  280. for (final WidgetChild item : items.getChildren()) {
  281. if (isEdible(item.getChildId())) {
  282. Mouse.click(item.getAbsoluteX(), item
  283. .getAbsoluteY() + 60, false);
  284. Menu.select("Buy 10");
  285. Time.sleep(Random.nextInt(100, 500));
  286. }
  287. }
  288. Time.sleep(Random.nextInt(100, 500));
  289.  
  290. Widgets.get(1265, 86).click(true);
  291.  
  292. // walkPath(Walking.findPath(new
  293. // Tile(Random.nextInt(2748, 2756), Random.nextInt(2796,
  294. // 2802), 0)).getTilePath().toArray());
  295. walkTo(new TilePath(PATH_TO_STORE).reverse().toArray());
  296. Time.sleep(Random.nextInt(500, 1000));
  297. }
  298. }
  299.  
  300. for (final Item item : Inventory.getItems())
  301. if (isJunk(item)) {
  302. dropItem(item);
  303. final int i = Random.nextInt(250, 500);
  304. sleep -= i;
  305. Time.sleep(i);
  306. }
  307. Time.sleep(Random.nextInt(sleep, sleep + 500));
  308. stunned = false;
  309. }
  310.  
  311. }
  312.  
  313. private final class Steal extends Strategy implements Task {
  314. @Override
  315. public final boolean validate() {
  316. return !isBusy()
  317. && !JAIL_AREA.contains(Players.getLocal().getLocation())
  318. && Inventory.getCount() < 24
  319. && !Players.getLocal().isMoving()
  320. && Players.getLocal().getAnimation() == -1 && isGorilla();
  321. }
  322.  
  323. @Override
  324. public final void run() {
  325. final NPC monkey = NPCs.getNearest(13211);
  326. if (!monkey.isOnScreen()) {
  327. status = "Waiting for monkeys to appear within screen range...";
  328. Time.sleep(Random.nextInt(2000, 2500));
  329. return;
  330. }
  331.  
  332. status = "Knocking monkey...";
  333. long lastPunch = 0L;
  334. int i = 0;
  335. do {
  336. if (isBusy())
  337. return;
  338. else if (System.currentTimeMillis() - lastPunch > 1500L) {
  339. monkey.interact("Punch");
  340. lastPunch = System.currentTimeMillis();
  341. } else
  342. Time.sleep(Random.nextInt(25, 50));
  343. } while (monkey.getAnimation() != 15050 && lastPunch != 0L);
  344.  
  345. for (i = 0; i < 2; i++)
  346. if (!isBusy() && monkey.getAnimation() == 15050
  347. && System.currentTimeMillis() - lastPunch < 2500L) {
  348. status = "Stealing...";
  349. if (!monkey.interact("Pickpocket"))
  350. break;
  351. Time.sleep(Random.nextInt(240, 250));
  352. }
  353.  
  354. while (!isBusy() && !monkey.getMessage().contains("ook"))
  355. Time.sleep(Random.nextInt(25, 50));
  356. }
  357. }
  358.  
  359. private final boolean isBusy() {
  360. return stunned || JAIL_AREA.contains(Players.getLocal().getLocation());
  361. }
  362.  
  363. private final boolean isGorilla() {
  364. for (final int greegree : GREEGREES)
  365. if (Widgets.get(387, 15).getChildId() == greegree)
  366. return true;
  367.  
  368. return false;
  369. }
  370.  
  371. private final boolean isEdible(final Item item) {
  372. return isEdible(item.getId());
  373. }
  374.  
  375. private final boolean isEdible(final int id) {
  376. for (final int food : FOOD)
  377. if (id == food)
  378. return true;
  379.  
  380. return false;
  381. }
  382.  
  383. private final boolean isJunk(final Item item) {
  384. for (final int junk : JUNK)
  385. if (item.getId() == junk)
  386. return true;
  387.  
  388. return false;
  389. }
  390.  
  391. private final void eatItem(final Item item) {
  392. status = "Eating...";
  393. if (Tabs.getCurrent() != Tabs.INVENTORY)
  394. Tabs.INVENTORY.open();
  395.  
  396. item.getWidgetChild().click(true);
  397. }
  398.  
  399. private final void dropItem(final Item item) {
  400. status = "Dropping items...";
  401. if (Tabs.getCurrent() != Tabs.INVENTORY)
  402. Tabs.INVENTORY.open();
  403.  
  404. item.getWidgetChild().interact("Drop");
  405. }
  406.  
  407. public final void turnOnRun() {
  408. if (Walking.isRunEnabled())
  409. return;
  410.  
  411. Walking.setRun(true);
  412. Time.sleep(100);
  413.  
  414. if (Walking.isRunEnabled())
  415. runEnergy = Random.nextInt(0, 100);
  416.  
  417. return;
  418. }
  419.  
  420. public final void walkTo(final Tile[] path) {
  421. for (final Tile tile : path) {
  422. if (!Walking.isRunEnabled() && Walking.getEnergy() >= runEnergy)
  423. turnOnRun();
  424. Walking.walk(tile);
  425.  
  426. int i = 0;
  427. while (Calculations
  428. .distance(Players.getLocal().getLocation(), tile) > Random
  429. .nextInt(1, 2)) {
  430. i++;
  431. Time.sleep(Random.nextInt(250, 500));
  432. if (i == 10) {
  433. i = 0;
  434. Walking.walk(tile);
  435. }
  436. }
  437. }
  438. return;
  439. }