Guest User

Untitled

a guest
Aug 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.04 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import javax.swing.GroupLayout.*;
  5. import javax.swing.LayoutStyle.*;
  6. import javax.swing.border.*;
  7. import org.powerbot.concurrent.strategy.*;
  8. import org.powerbot.concurrent.*;
  9. import org.powerbot.game.api.*;
  10. import org.powerbot.game.api.methods.Game;
  11. import org.powerbot.game.api.methods.Tabs;
  12. import org.powerbot.game.api.methods.Walking;
  13. import org.powerbot.game.api.methods.Widgets;
  14. import org.powerbot.game.api.methods.input.Keyboard;
  15. import org.powerbot.game.api.methods.input.Mouse;
  16. import org.powerbot.game.api.methods.interactive.Players;
  17. import org.powerbot.game.api.methods.node.SceneEntities;
  18. import org.powerbot.game.api.methods.tab.Inventory;
  19. import org.powerbot.game.api.methods.widget.Bank;
  20. import org.powerbot.game.api.methods.widget.Camera;
  21. import org.powerbot.game.api.util.Random;
  22. import org.powerbot.game.api.util.Time;
  23. import org.powerbot.game.api.wrappers.Area;
  24. import org.powerbot.game.api.wrappers.Tile;
  25. import org.powerbot.game.api.wrappers.widget.WidgetChild;
  26. import org.powerbot.game.bot.event.MessageEvent;
  27. import org.powerbot.game.bot.event.listener.*;
  28.  
  29. @Manifest(name = "DarkPrayer", description = "Prayer training at Player Owned Houses", version = 1.1d, authors = { "Dark``" })
  30. public class DarkPrayerAIO extends ActiveScript implements MessageListener,
  31.         PaintListener {
  32.     WidgetChild chatBox = null;
  33.     String[] invalidNames = { "" };
  34.     String entryAttempt = "";
  35.     String bankMethod = "";
  36.     String familiar = "";
  37.     String friendName = "";
  38.     String houseOption = "";
  39.  
  40.     boolean attemptingToEnter = false;
  41.     boolean hasUsedYanilleTeleport = false;
  42.     boolean isYanilleTeleportUnlocked = true;
  43.     boolean listeningForHost = false;
  44.     boolean idle = false;
  45.     boolean setup = false;
  46.     boolean isUsingFriendFirst = false;
  47.  
  48.     final int[] gildedAltarId = { 13197, 13199, 13198 };
  49.     final int wallGloryId = 13523;
  50.     final int yanillePortalId = 15482;
  51.     final int housePortalId = 13405;
  52.     final int dragonBoneId = 536;
  53.     final int frostBoneId = 3;
  54.     final int normalBoneId = 526;
  55.     final int animationTeleport = 16385;
  56.     int selectedBoneId = dragonBoneId;
  57.     int xpGained = 0;
  58.     int bonesSacrificed = 0;
  59.  
  60.     final Rectangle displayPaint = new Rectangle(418, 458, 50, 16);
  61.  
  62.     final Area edgevilleBank = new Area(new Tile(3087, 3502, 0), new Tile(3101,
  63.             3486, 0));
  64.     final Area yanillePortalArea = new Area(new Tile(2540, 3099, 0), new Tile(
  65.             2547, 3094, 0));
  66.     Area j = new Area();
  67.  
  68.     org.powerbot.game.api.util.Timer startTime = new org.powerbot.game.api.util.Timer(
  69.             0);
  70.     WidgetChild magicTab = null;
  71.  
  72.     @Override
  73.     protected void setup() {
  74.         log.info("Started DarkPrayer. Setting up the script..");
  75.         magicTab = Widgets.get(548).getChild(96);
  76.         chatBox = Widgets.get(752).getChild(11);
  77.         final OpenEdgevilleBank openBank = new OpenEdgevilleBank();
  78.  
  79.         final Strategy bankAction = new Strategy(openBank, openBank);
  80.         final TeleportToYanille teleport = new TeleportToYanille();
  81.         final Strategy teleportAction = new Strategy(teleport, teleport);
  82.         final WaitAtPortal waitAtPortal = new WaitAtPortal();
  83.         final Strategy waitPortalAction = new Strategy(waitAtPortal,
  84.                 waitAtPortal);
  85.         final UseBonesOnAltar offerBones = new UseBonesOnAltar();
  86.         final Strategy offerBonesAction = new Strategy(offerBones, offerBones);
  87.         final TeleportToEdgeville teleportBack = new TeleportToEdgeville();
  88.         final Strategy teleBackAction = new Strategy(teleportBack, teleportBack);
  89.         final Antiban antiban = new Antiban();
  90.         final Strategy antibanAction = new Strategy(antiban, antiban);
  91.         provide(bankAction);
  92.         provide(teleportAction);
  93.         provide(waitPortalAction);
  94.         provide(offerBonesAction);
  95.         provide(teleBackAction);
  96.         provide(antibanAction);
  97.     }
  98.  
  99.     private class OpenEdgevilleBank implements Task, Condition {
  100.  
  101.         @Override
  102.         public boolean validate() {
  103.             if (Tabs.getCurrent() != Tabs.INVENTORY)
  104.                 Tabs.INVENTORY.open();
  105.             return Inventory.getCount() == 0;
  106.         }
  107.  
  108.         @Override
  109.         public void run() {
  110.             idle = false;
  111.             if (SceneEntities.getNearest(42217) != null) {
  112.                 if (SceneEntities.getNearest(42217).isOnScreen()) {
  113.                     Bank.open();
  114.                     Time.sleep(604, 2583);
  115.                     Bank.withdraw(selectedBoneId, 28);
  116.                     Time.sleep(405, 1337);
  117.                     Bank.close();
  118.                 } else {
  119.                     Walking.findPath(
  120.                             SceneEntities.getNearest(42217).getLocation())
  121.                             .traverse();
  122.                 }
  123.             }
  124.  
  125.         }
  126.  
  127.     }
  128.  
  129.     private class TeleportToYanille implements Task, Condition {
  130.  
  131.         @Override
  132.         public void run() {
  133.             Tabs.MAGIC.open();
  134.             WidgetChild homeTeleport = Widgets.get(193).getChild(48);
  135.             idle = false;
  136.             if (hasUsedYanilleTeleport) {
  137.                 homeTeleport.interact("Previous-destination");
  138.                 Time.sleep(1374, 3847);
  139.             } else {
  140.                 homeTeleport.interact("Cast");
  141.                 Time.sleep(639, 2484);
  142.                 if (Widgets.get(1092).validate()) {
  143.                     Widgets.get(1092).getChild(52).interact("Teleport");
  144.                     Time.sleep(964, 1485);
  145.                     hasUsedYanilleTeleport = true;
  146.  
  147.                 }
  148.             }
  149.         }
  150.  
  151.         @Override
  152.         public boolean validate() {
  153.             return edgevilleBank.contains(Players.getLocal().getLocation())
  154.                     && Inventory.getCount(selectedBoneId) == 28
  155.                     && Players.getLocal().getAnimation() != animationTeleport;
  156.         }
  157.     }
  158.  
  159.     private class WaitAtPortal implements Task, Condition {
  160.  
  161.         @Override
  162.         public void run() {
  163.             if (!yanillePortalArea.contains(Players.getLocal().getLocation())) {
  164.                 log.info("NOT THERE");
  165.                 Walking.walk(yanillePortalArea.getTileArray()[Random.nextInt(0,
  166.                         yanillePortalArea.getTileArray().length)]);
  167.  
  168.                 Time.sleep(3357, 6947);
  169.             } else {
  170.                 idle = true;
  171.                 listeningForHost = true;
  172.                 if (!entryAttempt.isEmpty()) {
  173.                     Time.sleep(1243, 3975);
  174.                     SceneEntities.getNearest(yanillePortalId).interact("Enter");
  175.                     for (int i = 0; i < 10; i++) {
  176.                         if (Widgets.get(1188).validate()) {
  177.                             Time.sleep(725, 1583);
  178.                             break;
  179.                         } else {
  180.                             Time.sleep(1000);
  181.                         }
  182.  
  183.                     }
  184.                     Keyboard.sendKey('3');
  185.                     Time.sleep(2449, 4286);
  186.                     Keyboard.sendText(entryAttempt, true);
  187.                 }
  188.             }
  189.         }
  190.  
  191.         @Override
  192.         public boolean validate() {
  193.             return SceneEntities.getNearest(yanillePortalId) != null;
  194.         }
  195.     }
  196.  
  197.     private class UseBonesOnAltar implements Task, Condition {
  198.  
  199.         @Override
  200.         public void run() {
  201.             idle = false;
  202.             listeningForHost = false;
  203.             Area altarArea = new Area(new Tile(SceneEntities
  204.                     .getNearest(gildedAltarId).getLocation().getX() - 3,
  205.                     SceneEntities.getNearest(gildedAltarId).getLocation()
  206.                             .getY() - 3, Players.getLocal().getPlane()),
  207.                     new Tile(SceneEntities.getNearest(gildedAltarId)
  208.                             .getLocation().getX() + 3,
  209.                             SceneEntities.getNearest(gildedAltarId)
  210.                                     .getLocation().getY() + 3, Players
  211.                                     .getLocal().getPlane()));
  212.             j = altarArea;
  213.             if (!altarArea.contains(Players.getLocal().getLocation())) {
  214.                 Walking.walk(SceneEntities.getNearest(gildedAltarId)
  215.                         .getLocation());
  216.             }
  217.             Time.sleep(3173, 4826);
  218.             Inventory.getItem(selectedBoneId).getWidgetChild().interact("Use");
  219.             Time.sleep(488, 1274);
  220.             SceneEntities.getNearest(gildedAltarId).interact("Use");
  221.             for (int i = 0; i < 10; i++) {
  222.                 if (Widgets.get(905).validate()) {
  223.                     Time.sleep(243, 953);
  224.                     break;
  225.                 } else {
  226.                     Time.sleep(200);
  227.                 }
  228.             }
  229.             Time.sleep(500, 1350);
  230.             Widgets.get(905).getChild(14).interact("Offer all");
  231.             idle = true;
  232.             Time.sleep(2462, 4027);
  233.             if (Inventory.getCount(selectedBoneId) == 0) {
  234.                 if (SceneEntities.getNearest(wallGloryId) != null) {
  235.                     SceneEntities.getNearest(wallGloryId).interact("Rub");
  236.                 }
  237.             }
  238.         }
  239.  
  240.         @Override
  241.         public boolean validate() {
  242.             if (Tabs.getCurrent() != Tabs.INVENTORY)
  243.                 Tabs.INVENTORY.open();
  244.             return SceneEntities.getNearest(gildedAltarId) != null
  245.                     && Players.getLocal().getAnimation() != 3705
  246.                     && Inventory.getCount() != 0;
  247.         }
  248.  
  249.     }
  250.  
  251.     private class TeleportToEdgeville implements Task, Condition {
  252.  
  253.         @Override
  254.         public void run() {
  255.             // TODO Auto-generated method stub
  256.             if (!SceneEntities.getNearest(wallGloryId).isOnScreen()) {
  257.                 Walking.walk(SceneEntities.getNearest(wallGloryId)
  258.                         .getLocation());
  259.             } else {
  260.                 idle = false;
  261.                 SceneEntities.getNearest(wallGloryId).interact("Rub");
  262.                 // Time.sleep(1354, 2749);
  263.                 for (int i = 0; i < 10; i++) {
  264.                     if (Widgets.get(1188).validate()) {
  265.                         Time.sleep(725, 1583);
  266.                         break;
  267.                     } else {
  268.                         Time.sleep(300);
  269.                     }
  270.                 }
  271.                 if (Widgets.get(1188).validate()) {
  272.                     Keyboard.sendKey('1');
  273.                 }
  274.                 // org.powerbot.game.api.methods.node.Menu.
  275.             }
  276.         }
  277.  
  278.         @Override
  279.         public boolean validate() {
  280.             // TODO Auto-generated method stub
  281.             return SceneEntities.getNearest(wallGloryId) != null
  282.                     && Inventory.getCount(selectedBoneId) == 0 && !Players.getLocal().isMoving();
  283.         }
  284.  
  285.     }
  286.  
  287.     private class Antiban implements Task, Condition {
  288.  
  289.         @Override
  290.         public void run() {
  291.             if (Random.nextInt(1, 100) == 2)
  292.                 Camera.setAngle(Random.nextInt(1, 360));
  293.             if (Random.nextInt(1, 100) == 7)
  294.                 Mouse.move(Random.nextInt(1, Game.getDimensions().width),
  295.                         Random.nextInt(1, Game.getDimensions().height));
  296.         }
  297.  
  298.         @Override
  299.         public boolean validate() {
  300.             return Players.getLocal().getAnimation() != -1 || idle == true;
  301.         }
  302.  
  303.     }
  304.  
  305.     public boolean isInvalidName(String name) {
  306.         for (String entry : invalidNames) {
  307.             if (name.contains("[")) {
  308.                 if (entry.equals(name.substring(name.lastIndexOf("[") + 1,
  309.                         name.lastIndexOf("]")).toLowerCase())) {
  310.                     return true;
  311.                 }
  312.             } else {
  313.                 if (entry.equalsIgnoreCase(name)) {
  314.                     return true;
  315.                 }
  316.             }
  317.         }
  318.         return false;
  319.     }
  320.  
  321.     @Override
  322.     public void messageReceived(MessageEvent e) {
  323.         if (e.getId() == 2) {
  324.             if (listeningForHost) {
  325.                 String message = e.getMessage().toLowerCase();
  326.                 if (message.contains("at")) {
  327.                     if (message.substring(message.lastIndexOf("at") + 3)
  328.                             .replaceAll(String.valueOf(' '), "_")
  329.                             .replaceAll("-", "_").matches("\\w{1,12}")) {
  330.                         if (entryAttempt.isEmpty()) {
  331.                             if (!isInvalidName(message.substring(
  332.                                     message.lastIndexOf("at") + 3).trim())) {
  333.                                 attemptingToEnter = true;
  334.                                 entryAttempt = message.substring(
  335.                                         message.lastIndexOf("at") + 3).trim();
  336.                             }
  337.                         }
  338.                     }
  339.                 }
  340.                 if (message.contains("for") && message.contains("altar")) {
  341.                     if (message.substring(0, message.indexOf("for"))
  342.                             .replaceAll(String.valueOf(' '), "_")
  343.                             .replaceAll("-", "_").matches("\\w{1,12}")) {
  344.                         if (entryAttempt.isEmpty()) {
  345.                             if (!isInvalidName(message.substring(0,
  346.                                     message.indexOf("for")).trim())) {
  347.                                 attemptingToEnter = true;
  348.                                 entryAttempt = message.substring(0,
  349.                                         message.indexOf("for")).trim();
  350.                             }
  351.                         }
  352.                     }
  353.                 }
  354.                 if (message.contains("[") && message.contains("]")
  355.                         && message.lastIndexOf("]") > message.lastIndexOf("[")) {
  356.                     if (message
  357.                             .substring(message.lastIndexOf("[") + 1,
  358.                                     message.lastIndexOf("]"))
  359.                             .replaceAll(String.valueOf(' '), "_")
  360.                             .replaceAll("-", "_").matches("\\w{1,12}")) {
  361.                         if (entryAttempt.isEmpty()) {
  362.                             if (!isInvalidName(message.substring(
  363.                                     message.lastIndexOf("[") + 1,
  364.                                     message.lastIndexOf("]")))) {
  365.                                 attemptingToEnter = true;
  366.                                 entryAttempt = message.substring(
  367.                                         message.lastIndexOf("[") + 1,
  368.                                         message.lastIndexOf("]"));
  369.                             }
  370.                         }
  371.                     }
  372.                 }
  373.             }
  374.         }
  375.         if (e.getId() == 4) {
  376.             if (e.getMessage().contains(
  377.                     "That player is offline, or has privacy mode enabled.")) {
  378.                 log.info("Player invalid");
  379.                 invalidNames[invalidNames.length] = entryAttempt;
  380.                 entryAttempt = "";
  381.                 listeningForHost = true;
  382.             }
  383.         }
  384.         if (e.getId() == 109) {
  385.             if (e.getMessage().contains(
  386.                     "The gods are very pleased with your offering.")) {
  387.                 if (selectedBoneId == dragonBoneId) {
  388.                     xpGained = xpGained + 252;
  389.                     bonesSacrificed++;
  390.                 }
  391.                 if (selectedBoneId == frostBoneId) {
  392.                     xpGained = xpGained + 630;
  393.                     bonesSacrificed++;
  394.                 }
  395.                 if (selectedBoneId == normalBoneId) {
  396.                     xpGained = xpGained + 16;
  397.                     bonesSacrificed++;
  398.                 }
  399.             }
  400.             if (e.getMessage().contains(
  401.                     "The gods are pleased with your offering.")) {
  402.                 if (selectedBoneId == dragonBoneId) {
  403.                     xpGained = xpGained + 216;
  404.                     bonesSacrificed++;
  405.                 }
  406.                 if (selectedBoneId == frostBoneId) {
  407.                     xpGained = xpGained + 540;
  408.                     bonesSacrificed++;
  409.                 }
  410.                 if (selectedBoneId == normalBoneId) {
  411.                     xpGained = xpGained + 7;
  412.                     bonesSacrificed++;
  413.                 }
  414.             }
  415.         }
  416.         if (e.getId() == 0) {
  417.             if (e.getMessage()
  418.                     .equals("You'll need to activate the Yanille lodestone before you can Home Teleport there.")) {
  419.                 isYanilleTeleportUnlocked = false;
  420.             }
  421.             if (e.getMessage().contains(
  422.                     "They have locked their house to visitors.")) {
  423.                 entryAttempt = "";
  424.                 listeningForHost = true;
  425.             }
  426.         }
  427.     }
  428.  
  429.     @Override
  430.     public void onRepaint(Graphics g1) {
  431.         Graphics2D g = (Graphics2D) g1;
  432.         g.drawString("Animation: " + Players.getLocal().getAnimation(), 30, 30);
  433.         for (Tile t : j.getTileArray()) {
  434.             for (Polygon p : t.getBounds()) {
  435.                 g.drawPolygon(p);
  436.             }
  437.         }
  438.         g.setColor(Color.WHITE);
  439.         g.fill(displayPaint);
  440.         g.setColor(Color.cyan);
  441.         g.drawLine(Mouse.getX() - 5, Mouse.getY() - 5, Mouse.getX() + 5,
  442.                 Mouse.getY() + 5);
  443.         g.drawLine(Mouse.getX() - 5, Mouse.getY() + 5, Mouse.getX() + 5,
  444.                 Mouse.getY() - 5);
  445.         g.setColor(new Color(0, 0, 0, 230));
  446.         g.fill(chatBox.getBoundingRectangle());
  447.         g.setColor(new Color(255, 0, 0));
  448.         g.draw(chatBox.getBoundingRectangle());
  449.         g.setColor(new Color(255, 0, 0));
  450.         g.setFont(new Font("Calibri", Font.BOLD, 20));
  451.         g.drawString("DarkPrayerAIO", chatBox.getAbsoluteX() + 10,
  452.                 chatBox.getAbsoluteY() + 10 + 20);
  453.         g.setFont(new Font("Calibri", Font.PLAIN, 15));
  454.         g.drawString("Run time: " + (startTime.toElapsedString()),
  455.                 chatBox.getAbsoluteX() + 10, chatBox.getAbsoluteY() + 10 + 20
  456.                         + 10 + 15);
  457.         g.drawString("XP Gained: " + xpGained + " [Sacrificed "
  458.                 + bonesSacrificed + " bones]", chatBox.getAbsoluteX() + 10,
  459.                 chatBox.getAbsoluteY() + 10 + 20 + 10 + 15 + 10 + 15);
  460.     }
  461. }
Add Comment
Please, Sign In to add comment