Advertisement
Guest User

FatalFighter.java

a guest
May 7th, 2011
1,891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 33.26 KB | None | 0 0
  1. import org.rsbot.util.GlobalConfiguration;
  2. import org.rsbot.event.events.MessageEvent;
  3. import org.rsbot.event.listeners.MessageListener;
  4. import org.rsbot.event.listeners.PaintListener;
  5. import org.rsbot.script.Script;
  6. import org.rsbot.script.ScriptManifest;
  7. import org.rsbot.script.wrappers.RSNPC;
  8. import org.rsbot.script.wrappers.RSComponent;
  9. import org.rsbot.script.wrappers.RSGroundItem;
  10. import org.rsbot.script.wrappers.RSObject;
  11. import org.rsbot.script.wrappers.RSPlayer;
  12. import org.rsbot.script.wrappers.RSTile;
  13. import org.rsbot.script.wrappers.RSItem;
  14. import org.rsbot.script.wrappers.RSInterface;
  15. import org.rsbot.script.wrappers.RSTilePath;
  16. import org.rsbot.script.methods.Skills;
  17. import org.rsbot.script.methods.Game;
  18. import org.rsbot.script.wrappers.RSArea;
  19. import org.rsbot.script.util.Timer;
  20. import org.rsbot.script.util.Filter;
  21.  
  22. import java.io.*;
  23. import java.net.URL;
  24. import java.util.List;
  25. import java.util.ArrayList;
  26. import javax.imageio.ImageIO;
  27. import java.text.NumberFormat;
  28. import java.awt.*;
  29. import java.awt.event.*;
  30. import javax.swing.*;
  31.  
  32. @ScriptManifest(authors = {"Robgob"}, keywords = {"fatal,fighter,robgob,combat,melee"}, name = "Fatal Fighter", version = 1.2, description = "Attacks NPCs, so you don't have to.")
  33. public class FatalFighter extends Script implements PaintListener, MessageListener, MouseListener {
  34.  
  35.     GUI gui;
  36.  
  37.     public Attack attack = new Attack();
  38.     public Looting loot = new Looting();
  39.     public Bones bones = new Bones();
  40.     public Skill[] skill = new Skill[7];
  41.     public Skill topSkill;
  42.  
  43.     public Rectangle button = new Rectangle(0,0,0,0);
  44.  
  45.     private boolean wait = true, start = true, noFoodLogout = false, showSkills = true, looting = false, buryBones = false, antiban = true, multiAttack = false;
  46.     public Theme theme = new Theme(Color.WHITE, Color.BLACK, Color.RED);
  47.     public Food food = new Food();
  48.     public Timer startTimer = new Timer(0); // The time set doesn't matter, we just need a elapsed time
  49.     public Timer timer = new Timer(3600000); // Loops every hour
  50.     public Timer breakTimer = new Timer(random(600000, 900000)); // Default 10-15 minute timer
  51.     private int failedEat = 0, radius = 0;
  52.     public RSTile startTile;
  53.     public String status = "Waiting for input...";
  54.  
  55.  
  56.  
  57.     public boolean onStart() {
  58.         for (int i = 0; i < skill.length; i++) {
  59.             skill[i] = new Skill(i);
  60.         }
  61.         gui = new GUI();
  62.         while (wait) {
  63.             sleep(500);
  64.         }
  65.         startTile = getMyPlayer().getLocation();
  66.         return start;
  67.     }
  68.  
  69.     @Override
  70.     public int loop() {
  71.         if (getContinueInterface() != null) {
  72.             status("Clicking continue");
  73.             clickContinue();
  74.             return random(1200, 1600);
  75.         }
  76.         if (game.getCurrentTab() != Game.TAB_INVENTORY) {
  77.             status("Opening inventory");
  78.             game.openTab(Game.TAB_INVENTORY);
  79.             return random(700, 1500);
  80.         }
  81.         if (random(0,50) == 25) {
  82.             mouse.setSpeed(random(2, 5));
  83.         }
  84.         if(food.needFood()) {
  85.             if (food.haveFood()) {
  86.                 status("Eating Food");
  87.                 failedEat = 0;
  88.                 food.eatFood();
  89.                 return random(1100, 1600);
  90.             } else if (food.haveB2pTab() && food.haveBones()) {
  91.                 status("Breaking tablet");
  92.                 food.breakB2pTab();
  93.                 return random(2600, 3000);
  94.             } else {
  95.                 if (noFoodLogout) {
  96.                     failedEat++;
  97.                     if (failedEat > 5) {
  98.                         log.severe("You ran out of food!");
  99.                         quit();
  100.                         return random(600, 800);
  101.                     }
  102.                 }
  103.             }
  104.         }
  105.         if (!walking.isRunEnabled() && walking.getEnergy() > random(60, 85)) {
  106.             walking.setRun(true);
  107.             return random(1200, 1600);
  108.         }
  109.         if (bones.checkBones()) {
  110.             return random(50,450);
  111.         }
  112.         antiban();
  113.         if (loot.canPickup()) {
  114.             return loot.pickupItem();
  115.         }
  116.         if (!inRadius() && !attack.inCombat()) {
  117.             status("Walking to starter zone");
  118.             walking.walkTo(startTile);
  119.             return random(1000, 2000);
  120.         }
  121.         if(!attack.inCombat()) {
  122.             attack.attackNpc();
  123.             return random(1000, 1500);
  124.         }
  125.         return random(250, 350);
  126.     }
  127.  
  128.     public boolean inRadius() {
  129.         if(radius == 0)
  130.             return true;
  131.         return calc.distanceBetween(getMyPlayer().getLocation(), startTile) <= radius;
  132.     }
  133.  
  134.     private void quit() {
  135.         try {
  136.             String[] args = startTimer.toElapsedString().split(":");
  137.             int hours = Integer.parseInt(args[0]);
  138.             int mins = Integer.parseInt(args[1]);
  139.             int secs = Integer.parseInt(args[2]);
  140.             String hour = (hours > 0 ? hours + " " + (hours == 1 ? "hour" : "hours") + ", " : "");
  141.             String minutes = (mins != 0 ? mins + " mins" : "");
  142.             String seconds = (hours == 0 ? ", " + secs + " and seconds" : "");
  143.             log("You ran the script for " + hour + "" + minutes + "" + "" + seconds + " and earned " + getExpGained() + " Experience and " + getLevelsGained() + " levels!");
  144.         } catch(Exception e) {
  145.             log("Thank you for using Fatal Fighter!");
  146.         }
  147.         stopScript(true);
  148.     }
  149.  
  150.     public void moving() {
  151.         long start = System.currentTimeMillis();
  152.         while (System.currentTimeMillis() - start < 1500 && !getMyPlayer().isMoving()) {
  153.             sleep(random(50, 200));
  154.         }
  155.         while (getMyPlayer().isMoving()) {
  156.             sleep(random(20, 50));
  157.         }
  158.     }
  159.  
  160.     public void status(String s) {
  161.         status = s;
  162.     }
  163.  
  164.     public void antiban() {
  165.         if(!antiban)
  166.             return;
  167.         int b = random(0, 10);
  168.         switch (b) {
  169.             case 1:
  170.                 if (random(0, 10) == 5) {
  171.                     status("Moving mouse");
  172.                     mouse.moveSlightly();
  173.                     sleep(200, 600);
  174.                     mouse.moveRandomly(150, 350);
  175.                 }
  176.                 break;
  177.             case 2:
  178.                 if (random(0, 13) == 2) {
  179.                     status("Rotating camera");
  180.                     camera.setAngle(random(30, 70));
  181.                     sleep(400, 1200);
  182.                 }
  183.                 break;
  184.             case 3:
  185.                 if (random(0, 24) == 6) {
  186.                     status("Moving mouse off-Screen");
  187.                     mouse.moveOffScreen();
  188.                     sleep(600, random(1200, 2000));
  189.                 }
  190.                 break;
  191.             case 4:
  192.                 if (random(0, 18) == 3) {
  193.                     status("Checking Skill");
  194.                     game.openTab(1);
  195.                     skills.doHover(skill[random(0,6)].getID());
  196.                     sleep(2100, 3400);
  197.                 }
  198.                 break;
  199.             default:
  200.                 status(attack.inCombat() ? "Fighting..." : "Routing..");
  201.                 break;
  202.         }
  203.     }
  204.  
  205.     //Paint
  206.     public void onRepaint(Graphics g1) {
  207.         Graphics2D g = (Graphics2D)g1;
  208.  
  209.         // Draw Mouse
  210.         g.setColor(theme.getBorder());
  211.         g.drawLine(0, (int) (mouse.getLocation().getY()), 800, (int) (mouse.getLocation().getY()));
  212.         g.drawLine((int) (mouse.getLocation().getX()), 0, (int) (mouse.getLocation().getX()), 800);
  213.  
  214.         RSComponent inter = interfaces.get(137).getComponent(0);
  215.         int x = inter.getLocation().x;
  216.         int y = inter.getLocation().y;
  217.  
  218.         int width = 490;
  219.         int height = 15;
  220.  
  221.         //Draw title info
  222.         g.setColor(theme.getBackground());
  223.         g.fillRect(x, y, width, height+10);
  224.         g.setColor(theme.getBorder());
  225.         g.drawString("Fatal Fighter - Exp Gained: " + getExpGained() + " - Levels Gained: " + getLevelsGained() + "  Run Time:" + startTimer.toElapsedString(), x+10, y+17);
  226.         g.setColor(theme.getBorder());
  227.         g.drawRect(x, y, width, height+10);
  228.         y += 25;
  229.  
  230.         // Draw Skills
  231.         if (showSkills) {
  232.             if (topSkill == null) {
  233.                 for (Skill s : skill) {
  234.                     if (s != null && s.active()) {
  235.                     s.draw(g, x, y, width, height);
  236.                         y += height;
  237.                     }
  238.                 }
  239.             } else {
  240.                 width = 490;
  241.                 height = 88;
  242.                 topSkill.drawClick(g, x, y, width, height);
  243.                 y += height;
  244.             }
  245.         }
  246.  
  247.         //Status + Hide/show Button
  248.         g.setColor(theme.getBackground());
  249.         g.fillRect(x, y, 490, 15);
  250.         g.setColor(theme.getBorder());
  251.         g.drawString("Status: " + status, x+10, y+15-2);
  252.         if(getExpGained() > 0)
  253.             g.drawString("Click here to " + (showSkills ? "hide" : "show") + " stats!", x+350, y+15-2);
  254.         g.drawRect(x, y, 490, 15);
  255.         button = new Rectangle(x, y, 490, 15);
  256.    
  257.     }
  258.  
  259.     @Override
  260.     public void messageReceived(MessageEvent e) {
  261.         String s = e.getMessage().toLowerCase();
  262.         if(s.contains("just advanced a"))
  263.             log.severe("Congradulations! Fatal Fighter just got you another level! <3");
  264.         if (s.contains("log out until 10 seconds after")) {
  265.             //log.severe("Can't log out yet, waiting til out of combat.");
  266.         }
  267.     }
  268.  
  269.     public int getExpGained() {
  270.         int exp = 0;
  271.         for (Skill s : skill) {
  272.             if(s != null)
  273.                 exp += s.getExpGained();
  274.         }
  275.         return exp;
  276.     }
  277.  
  278.     public int getLevelsGained() {
  279.         int lvl = 0;
  280.         for (Skill s : skill) {
  281.             if(s != null)
  282.                 lvl += s.getLevelsGained();
  283.         }
  284.         return lvl;
  285.     }
  286.  
  287.     public String format(long time) {
  288.         final NumberFormat f = NumberFormat.getInstance();
  289.         final long t_seconds = time / 1000;
  290.         final long t_minutes = t_seconds / 60;
  291.         final long t_hours = t_minutes / 60;
  292.         final long seconds = t_seconds % 60;
  293.         final long minutes = t_minutes % 60;
  294.         final long hours = t_hours;
  295.         return (f.format(hours) + ":" + f.format(minutes) + ":" + f.format(seconds));
  296.     }
  297.  
  298.     private RSComponent getContinueInterface() {
  299.         for(RSInterface iface : interfaces.getAll()) {
  300.             //skip chat
  301.             if(iface.getIndex() == 137)
  302.                 continue;
  303.             for(RSComponent c : iface.getComponents()) {
  304.                 if(c != null && c.isValid() && c.containsText("Click here to continue")
  305.                         && c.getAbsoluteX() > 100 && c.getAbsoluteY() > 300)
  306.                     return c;
  307.             }
  308.         }
  309.         return null;
  310.     }
  311.  
  312.     private boolean clickContinue() {
  313.         RSComponent c = getContinueInterface();
  314.         if(c != null)
  315.             return c.doClick();
  316.         return false;
  317.     }
  318.  
  319.     class Attack {
  320.  
  321.         public int failed = 0;
  322.         public int[] npcIDs = new int[0];
  323.         public String[] npcNames = new String[0];
  324.  
  325.         private void attackNpc() {
  326.             status("Looking for Npc");
  327.             RSNPC npc = getNpc();
  328.             if (npc != null) {
  329.                 camera.turnTo(npc);
  330.                 if(!npc.isOnScreen() && random(0,4) == 2)
  331.                     walking.walkTo(calc.getTileOnScreen(npc.getLocation()));
  332.                 if(!inCombat())
  333.                     npc.doAction("Attack");
  334.                 mouse.moveSlightly();
  335.                 status("Attacking " + npc.getName());
  336.                 failed = 0;
  337.                 moving();
  338.                 long t = System.currentTimeMillis();
  339.                 while(System.currentTimeMillis() - t < 2500 && getMyPlayer().getAnimation() == -1 && (System.currentTimeMillis() - t < 1000 || getMyPlayer().getInteracting() != null))
  340.                     sleep(random(50, 100));
  341.             } else {
  342.                 failed++;
  343.                 if (failed == 200) {
  344.                     log.severe("Failed to find the npc.");
  345.                     quit();
  346.                 }
  347.                 antiban();
  348.             }
  349.         }
  350.  
  351.         public RSNPC getNpc() {
  352.  
  353.             return npcs.getNearest(filter);
  354.         }
  355.  
  356.         public boolean validNpc(RSNPC n) {
  357.             if (n != null) {
  358.                 for (int id : npcIDs) {
  359.                     if (id == n.getID())
  360.                         return true;
  361.                 }
  362.                 for (String s : npcNames) {
  363.                     if (n.getName().toLowerCase().contains(s.toLowerCase()))
  364.                         return true;
  365.                 }
  366.             }
  367.             return false;
  368.         }
  369.  
  370.         public boolean inCombat() {
  371.             return getMyPlayer().getInteracting() != null || getMyPlayer().isInCombat() || (getMyPlayer().getAnimation() != -1 && getMyPlayer().getAnimation() != 827);
  372.         }
  373.  
  374.  
  375.         public final Filter<RSNPC> filter = new Filter<RSNPC>() {
  376.             public boolean accept(RSNPC n) {
  377.                 return (validNpc(n) && (radius == 0 || calc.distanceBetween(n.getLocation(), startTile) < radius) && (multiAttack || (!n.isInCombat() && n.getInteracting() == null)) && n.getHPPercent() != 0);
  378.             }
  379.         };
  380.  
  381.     }
  382.  
  383.     class Bones {
  384.  
  385.         private final int[] BONE_IDS = new int[] {
  386.             526, 528, 530, 532, 534, 536, 2859, 3123, 3125, 3183, 6182 , 20268, 20266, 20264
  387.         };
  388.  
  389.         public boolean bury = false;
  390.  
  391.         public boolean hasBones() {
  392.             return inventory.getCount(BONE_IDS) > 0;
  393.         }
  394.  
  395.         public boolean checkBones() {
  396.             if(!buryBones || attack.inCombat())
  397.                 return false;
  398.             if (hasBones()) {
  399.                 if (bury || inventory.isFull()) {
  400.                     bury = true;
  401.                     status("Burying bones!");
  402.                     for (RSItem item : inventory.getItems(BONE_IDS)) {
  403.                         item.doClick(true);
  404.                         if(random(0,4) == 2)
  405.                             mouse.moveSlightly();
  406.                         waitForBury();
  407.                         return true;
  408.                     }
  409.                 }
  410.             } else {
  411.                 bury = false;
  412.             }
  413.             return false;
  414.         }
  415.  
  416.         public void waitForBury() {
  417.             int i = inventory.getCount(true);
  418.             while (inventory.getCount(true) == i) {
  419.                 sleep(random(20, 70));
  420.             }
  421.             sleep(50, 300);
  422.         }
  423.     }
  424.  
  425.     class Looting {
  426.  
  427.         private int[] itemIDs = new int[0];
  428.         private String[] itemNames = new String[0];
  429.  
  430.         private RSGroundItem lootItem = null;
  431.  
  432.         public int pickupItem() {
  433.             status("Looking for items...");
  434.             int origCount = inventory.getCount(true);
  435.             String name = lootItem.getItem().getName();
  436.             int count = lootItem.getItem().getStackSize();
  437.             int result = takeItem(lootItem);
  438.             if (result == 0 || result == 1) {
  439.                 moving();
  440.             }
  441.             return random(50, 200);
  442.         }
  443.  
  444.         public boolean canPickup() {
  445.             return (lootItem = getLoot()) != null && !inventory.isFull();
  446.         }
  447.  
  448.         private RSGroundItem getLoot() {
  449.             return groundItems.getNearest(filter);
  450.         }
  451.  
  452.         private int takeItem(RSGroundItem item) {
  453.             if (item == null)
  454.                 return -1;
  455.             status("Picking up Item: " + item.getItem().getName());
  456.             String action = "Take " + item.getItem().getName();
  457.             if (item.isOnScreen()) {
  458.                 for (int i = 0; i < 5; i++) {
  459.                     if (menu.isOpen())
  460.                         mouse.moveRandomly(300, 500);
  461.                     Point p = calc.tileToScreen(item.getLocation(), random(0.48, 0.52), random(0.48, 0.52), 0);
  462.                     if (!calc.pointOnScreen(p))
  463.                         continue;
  464.                     mouse.move(p, 3, 3);
  465.                     if (menu.contains(action)) {
  466.                         if (menu.getItems()[0].contains(action)) {
  467.                             mouse.click(true);
  468.                             return 0;
  469.                         } else {
  470.                             mouse.click(false);
  471.                             sleep(random(100, 200));
  472.                             if (menu.doAction(action))
  473.                                 return 0;
  474.                         }
  475.                     }
  476.                 }
  477.             } else {
  478.                 walking.walkTileMM(walking.getClosestTileOnMap(item.getLocation()));
  479.                 return 1;
  480.             }
  481.             return -1;
  482.         }
  483.  
  484.         private final Filter<RSGroundItem> filter = new Filter<RSGroundItem>() {
  485.             public boolean accept(RSGroundItem t) {
  486.                 //Skip if we can't hold it
  487.                 RSItem i;
  488.                 if (inventory.isFull() && ((i = inventory.getItem(t.getItem().getID())) == null || i.getStackSize() <= 1)) {
  489.                     return false;
  490.                 }
  491.                 //Skip if its out of radius or far away
  492.                 if (radius > 0 && calc.distanceBetween(t.getLocation(), startTile) > radius
  493.                         || calc.distanceTo(t.getLocation()) > 25) {
  494.                     return false;
  495.                 }
  496.                 //Check ID/name
  497.                 int id = t.getItem().getID();
  498.                 for (int iD : itemIDs) {
  499.                     if (iD == id)
  500.                         return true;
  501.                 }
  502.                 String name = t.getItem().getName();
  503.                 for (String s : itemNames) {
  504.                     if (name != null && name.toLowerCase().contains(s.toLowerCase()))
  505.                         return true;
  506.                 }
  507.                 return false;
  508.             }
  509.         };
  510.  
  511.     }
  512.  
  513.     class Skill {
  514.  
  515.         private int id;
  516.         private int startExp;
  517.         private int startLevel;
  518.         public Rectangle area = new Rectangle(0, 0, 0, 0);
  519.  
  520.         public Skill(int index) {
  521.             this.id = index;
  522.             this.startExp = skills.getCurrentExp(index);
  523.             this.startLevel = skills.getRealLevel(index);
  524.         }
  525.  
  526.         public void draw(Graphics2D g, int x, int y, int width, int height) {
  527.             area = new Rectangle(x, y, width, height);
  528.             g.setColor(theme.getBackground());
  529.             g.fillRect(x, y, width, height);
  530.  
  531.             g.setColor(getColor());
  532.             g.drawString(getName() + "(" + skills.getRealLevel(id) + "): " + getExpGained() + " Exp Earned - " + getExpPerHour() + " EXP P/H", x+10, y+height-2);
  533.  
  534.             //XPBar
  535.             g.setColor(theme.getOther());
  536.             g.fillRect(x+(width-101), y+1, 101, height-2);
  537.             g.setColor(theme.getBorder());
  538.             g.fillRect(x+(width-101), y+1, getPercent(), height-2);
  539.             g.setColor(new Color(0, 0, 0, 50));
  540.             g.fillRect(x+(width-101), y+8, 101, height-9);
  541.             g.setColor(theme.getOther());
  542.             g.drawRect(x+(width-101), y+1, 101, height-2);
  543.             g.setColor(theme.getBackground());
  544.             g.drawString(getPercent() + "%", x+(width-50), y+height-2);
  545.  
  546.             g.setColor(theme.getBorder());
  547.             g.drawRect(x, y, width, height);
  548.  
  549.         }
  550.  
  551.         public void drawClick(Graphics2D g, int x, int y, int width, int height) {
  552.             //Draw background
  553.             g.setColor(theme.getBackground());
  554.             g.fillRect(x, y, width, height);
  555.  
  556.             //Draw content
  557.             g.setColor(getColor());
  558.             g.setFont(new Font("Arial", Font.PLAIN, 24));
  559.             g.drawString(getName(), x+35, y+26);
  560.             g.setFont(new Font("Dialog", Font.BOLD, 16));
  561.             g.drawString("Exp Per Hour: " + getExpPerHour(), x+50, y+50);
  562.             g.drawString("Exp Gained: " + getExpGained(), x+50, y+70);
  563.             g.drawString("XP till Level+: " + getExpToNextLevel(), x+250, y+50);
  564.             g.drawString("Lvls Gained: " + getLevelsGained(), x+250, y+70);
  565.  
  566.             //XPBar
  567.             g.setFont(new Font("Dialog", Font.BOLD, 14));
  568.             g.setColor(theme.getOther());
  569.             g.fillRect(x+190, y+8, 291, 20);
  570.             g.setColor(theme.getBorder());
  571.             g.fillRect(x+190, y+8, ((int)(getPercent()*2.90)), 20);
  572.             g.setColor(new Color(0, 0, 0, 50)); // Shadow
  573.             g.fillRect(x+190, y+18, 291, 10);
  574.             g.setColor(theme.getOther());
  575.             g.drawRect(x+190, y+8, 291, 20);
  576.             g.setColor(theme.getBackground());
  577.             g.drawString(getPercent() + "%", x+310, y+24);
  578.             g.setFont(new Font("Dialog", Font.PLAIN, 12));
  579.  
  580.             g.setColor(getColor());
  581.             g.drawString("Time till next level: " + timeTillLevelString(), x+170, y+84);
  582.  
  583.             //Draw Border
  584.             g.setColor(theme.getBorder());
  585.             g.drawRect(x, y, width, height);
  586.             area = new Rectangle(x, y, width, height);
  587.         }
  588.  
  589.         public String getName() {
  590.             String s = skills.SKILL_NAMES[id];
  591.             s = Character.toUpperCase(s.charAt(0)) + s.substring(1);
  592.             return s;
  593.         }
  594.  
  595.         public boolean active() {
  596.             return getExp() > getStartExp();
  597.         }
  598.  
  599.         public int getID() {
  600.             return id;
  601.         }
  602.  
  603.         public int getStartExp() {
  604.             return startExp;
  605.         }
  606.  
  607.         public int getExp() {
  608.             return skills.getCurrentExp(id);
  609.         }
  610.  
  611.         public int getExpGained() {
  612.             return getExp() - getStartExp();
  613.         }
  614.  
  615.         public int getExpPerHour() {
  616.             return (int) (getExpGained() * 3600000D / startTimer.getElapsed());
  617.         }
  618.  
  619.         public int getExpToNextLevel() {
  620.             return skills.getExpToNextLevel(id);
  621.         }
  622.  
  623.         public int getStartLevel() {
  624.             return startLevel;
  625.         }
  626.  
  627.         public int getLevel() {
  628.             return skills.getRealLevel(id);
  629.         }
  630.  
  631.         public int getLevelsGained() {
  632.             return getLevel() - getStartLevel();
  633.         }
  634.  
  635.         public int getLevelsPerHour() {
  636.             return (int) (getLevelsGained() * 3600000D / startTimer.getElapsed());
  637.         }
  638.  
  639.         public long timeTillLevel() {
  640.             return (int)(((double)getExpToNextLevel() / (double)getExpPerHour()) * 3600000);
  641.         }
  642.  
  643.         public String timeTillLevelString() {
  644.             return format(timeTillLevel());
  645.         }
  646.  
  647.         public int getPercent() {
  648.             return skills.getPercentToNextLevel(id);
  649.         }
  650.  
  651.         public Rectangle getArea() {
  652.             return area;
  653.         }
  654.  
  655.         public Color getColor() {
  656.             switch(id) {
  657.                 case 0: // Attack
  658.                     return new Color(145, 25, 25).brighter();
  659.                 case 1: // Defence
  660.                     return new Color(95, 115, 185);
  661.                 case 2: // Strength
  662.                     return Color.GREEN.darker();
  663.                 case 3: // Constitution
  664.                     return Color.WHITE.darker();
  665.                 case 4: // Range
  666.                     return new Color(70, 95, 20).brighter();
  667.                 case 5: // Prayer
  668.                     return new Color(95, 115, 230);
  669.                 case 6: // Magic
  670.                     return theme.getBorder();
  671.             }
  672.             return theme.getBorder();
  673.         }
  674.  
  675.     }
  676.  
  677.     /*
  678.      * Holds the basic theme for the Script(Paint)
  679.      */
  680.     class Theme {
  681.  
  682.         private Color border;
  683.         private Color background;
  684.         private Color other;
  685.  
  686.         public Theme(Color border, Color background, Color other) {
  687.             this.border = border;
  688.             this.background = background;
  689.             this.other = other;
  690.         }
  691.         public Color getBorder() {
  692.             return border;
  693.         }
  694.         public Color getBackground() {
  695.             return background;
  696.         }
  697.         public Color getOther() {
  698.             return other;
  699.         }
  700.     }
  701.  
  702.     // From TFigherEE
  703.     private class Food {
  704.  
  705.         public boolean logout = false;
  706.  
  707.         private final int[] B2P_TAB_ID = new int[]{8015};
  708.         private final int[] BONES_ID = new int[]{526, 532, 530, 528, 3183, 2859};
  709.  
  710.         private int toEatAtPercent = getRandomEatPercent();
  711.  
  712.         private int getRandomEatPercent() {
  713.             return random(45, 60);
  714.         }
  715.  
  716.         private boolean haveB2pTab() {
  717.             return inventory.getCount(B2P_TAB_ID) > 0;
  718.         }
  719.  
  720.         private void breakB2pTab() {
  721.             RSItem i = inventory.getItem(B2P_TAB_ID);
  722.             if (i != null)
  723.                 i.doClick(true);
  724.         }
  725.  
  726.         private boolean haveBones() {
  727.             return inventory.getCount(BONES_ID) > 0;
  728.         }
  729.  
  730.         private boolean haveFood() {
  731.             return getFood() != null;
  732.         }
  733.  
  734.         private RSItem getFood() {
  735.             for (RSItem i : inventory.getItems()) {
  736.                 if (i == null || i.getID() == -1)
  737.                     continue;
  738.                 if (i.getComponent().getActions() == null || i.getComponent().getActions()[0] == null)
  739.                     continue;
  740.                 if (i.getComponent().getActions()[0].contains("Eat"))
  741.                     return i;
  742.             }
  743.             return null;
  744.         }
  745.  
  746.         private boolean eatFood() {
  747.             RSItem i = getFood();
  748.             for (int j = 0; j < 3; j++) {
  749.                 if (i == null)
  750.                     break;
  751.                 if (i.doAction("Eat")) {
  752.                     return true;
  753.                 }
  754.             }
  755.             return false;
  756.         }
  757.  
  758.         private boolean needFood() {
  759.             if(getHPPercent() <= getRandomEatPercent()) {
  760.                 return true;
  761.             }
  762.             return false;
  763.         }
  764.  
  765.         public int getHPPercent() {
  766.             try {
  767.                 return ((int) ((Integer.parseInt(interfaces.get(748).getComponent(8).getText().trim()) / (double)(skills.getRealLevel(Skills.CONSTITUTION) * 10)) * 100));
  768.             } catch (Exception e) {
  769.                 return 100;
  770.             }
  771.         }
  772.     }
  773.  
  774.     class GUI extends JFrame {
  775.  
  776.         public GUI() {
  777.             initComponents();
  778.         }
  779.  
  780.         @SuppressWarnings("unchecked")
  781.         private void initComponents() {
  782.  
  783.             setTitle("Fatal Fighter");
  784.  
  785.             TITLE_LABEL = new javax.swing.JLabel();
  786.             NPCS_LABEL = new javax.swing.JLabel();
  787.             NPCS_TEXT = new javax.swing.JTextField();
  788.             THEME_BOX = new javax.swing.JComboBox();
  789.             THEME_LABEL = new javax.swing.JLabel();
  790.             FOOD_LOGOUT_CHECKBOX = new javax.swing.JCheckBox();
  791.             XTILE_CHECKBOX = new javax.swing.JCheckBox();
  792.             XTILE_TEXT = new javax.swing.JTextField();
  793.             ANTIBAN_CHECKBOX = new javax.swing.JCheckBox();
  794.             MULTI_ATTACK_CHECKBOX = new javax.swing.JCheckBox();
  795.             START_BUTTON = new javax.swing.JButton();
  796.             CANCEL_BUTTON = new javax.swing.JButton();
  797.             LOOT_CHECKBOX = new javax.swing.JCheckBox();
  798.             LOOT_TEXT = new javax.swing.JTextField();
  799.  
  800.             setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
  801.             setBounds(new java.awt.Rectangle(200, 100, 0, 0));
  802.             setResizable(false);
  803.  
  804.             TITLE_LABEL.setFont(new java.awt.Font("Arial Black", 0, 24));
  805.             TITLE_LABEL.setText("Fatal Fighter");
  806.  
  807.             NPCS_LABEL.setText("Enter the npc ID's and Names:");
  808.             NPCS_LABEL.setToolTipText("Enter a NPC ID or name separated by commas(107,Scorpion,60,Giant spider)");
  809.  
  810.             NPCS_TEXT.setText("91,Skeleton");
  811.             NPCS_TEXT.setToolTipText("Enter a NPC ID or name separated by commas(107,Scorpion,60,Giant spider)");
  812.  
  813.             THEME_BOX.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Default", "Bloody", "Funky", "Sunny", "Sexy", "White", "Grass" }));
  814.             THEME_BOX.setToolTipText("Select a paint theme!");
  815.  
  816.             THEME_LABEL.setText("Theme Select:");
  817.             THEME_LABEL.setToolTipText("Select a paint theme!");
  818.  
  819.             FOOD_LOGOUT_CHECKBOX.setSelected(true);
  820.             FOOD_LOGOUT_CHECKBOX.setText("Logout when out of food");
  821.  
  822.             XTILE_CHECKBOX.setSelected(true);
  823.             XTILE_CHECKBOX.setText("Stay within a radius of:");
  824.             XTILE_CHECKBOX.setToolTipText("If you you move out of the radious(10+ steps) you will walk back to yor location.");
  825.  
  826.             XTILE_TEXT.setText("10");
  827.             XTILE_TEXT.setToolTipText("If you you move out of the radious(10+ steps) you will walk back to yor location.");
  828.  
  829.             ANTIBAN_CHECKBOX.setSelected(true);
  830.             ANTIBAN_CHECKBOX.setText("Anti-Ban");
  831.             ANTIBAN_CHECKBOX.setToolTipText("Prevents you from getting banned by performing random tasks.");
  832.  
  833.             MULTI_ATTACK_CHECKBOX.setText("Multi-Attack");
  834.             MULTI_ATTACK_CHECKBOX.setToolTipText("Instead of having a mouse speed of 5-6, we would make your speed 2-3 for crack addicted clicking!");
  835.  
  836.             START_BUTTON.setText("Start");
  837.             START_BUTTON.setToolTipText("Start the script!");
  838.             START_BUTTON.addActionListener(new java.awt.event.ActionListener() {
  839.                 public void actionPerformed(java.awt.event.ActionEvent evt) {
  840.                     startAction();
  841.                 }
  842.             });
  843.  
  844.             CANCEL_BUTTON.setText("Quit");
  845.             CANCEL_BUTTON.setToolTipText("To Quit and not run the script, click here!");
  846.             CANCEL_BUTTON.addActionListener(new java.awt.event.ActionListener() {
  847.                 public void actionPerformed(java.awt.event.ActionEvent evt) {
  848.                     cancelAction();
  849.                 }
  850.             });
  851.  
  852.             LOOT_CHECKBOX.setText("Loot:");
  853.  
  854.             LOOT_TEXT.setText("995,Coins");
  855.  
  856.             javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  857.             getContentPane().setLayout(layout);
  858.             layout.setHorizontalGroup(
  859.                 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  860.                 .addGroup(layout.createSequentialGroup()
  861.                     .addContainerGap()
  862.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  863.                         .addGroup(layout.createSequentialGroup()
  864.                             .addComponent(LOOT_CHECKBOX)
  865.                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  866.                             .addComponent(LOOT_TEXT, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
  867.                             .addGap(22, 22, 22))
  868.                         .addGroup(layout.createSequentialGroup()
  869.                             .addComponent(TITLE_LABEL, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
  870.                             .addContainerGap())
  871.                         .addGroup(layout.createSequentialGroup()
  872.                             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  873.                                 .addGroup(layout.createSequentialGroup()
  874.                                     .addComponent(XTILE_CHECKBOX)
  875.                                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  876.                                     .addComponent(XTILE_TEXT, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
  877.                                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
  878.                                 .addComponent(FOOD_LOGOUT_CHECKBOX, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
  879.                                 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  880.                                     .addComponent(ANTIBAN_CHECKBOX, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
  881.                                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  882.                                     .addComponent(MULTI_ATTACK_CHECKBOX, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
  883.                                 .addGroup(layout.createSequentialGroup()
  884.                                     .addComponent(THEME_LABEL)
  885.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  886.                                     .addComponent(THEME_BOX, 0, 107, Short.MAX_VALUE)
  887.                                     .addGap(10, 10, 10))
  888.                                 .addGroup(layout.createSequentialGroup()
  889.                                     .addGap(25, 25, 25)
  890.                                     .addComponent(START_BUTTON)
  891.                                     .addGap(18, 18, 18)
  892.                                     .addComponent(CANCEL_BUTTON)
  893.                                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)))
  894.                             .addGap(4, 4, 4))
  895.                         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  896.                             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  897.                                 .addComponent(NPCS_LABEL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
  898.                                 .addComponent(NPCS_TEXT, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE))
  899.                             .addContainerGap())))
  900.             );
  901.             layout.setVerticalGroup(
  902.                 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  903.                 .addGroup(layout.createSequentialGroup()
  904.                     .addContainerGap()
  905.                     .addComponent(TITLE_LABEL)
  906.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  907.                     .addComponent(NPCS_LABEL)
  908.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  909.                     .addComponent(NPCS_TEXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  910.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  911.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  912.                         .addComponent(LOOT_CHECKBOX)
  913.                         .addComponent(LOOT_TEXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  914.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 2, Short.MAX_VALUE)
  915.                     .addComponent(FOOD_LOGOUT_CHECKBOX)
  916.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  917.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  918.                         .addComponent(XTILE_CHECKBOX)
  919.                         .addComponent(XTILE_TEXT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  920.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  921.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  922.                         .addComponent(ANTIBAN_CHECKBOX)
  923.                         .addComponent(MULTI_ATTACK_CHECKBOX))
  924.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  925.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  926.                         .addComponent(THEME_LABEL, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
  927.                         .addComponent(THEME_BOX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  928.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  929.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  930.                         .addComponent(START_BUTTON)
  931.                         .addComponent(CANCEL_BUTTON))
  932.                     .addContainerGap())
  933.             );
  934.  
  935.             pack();
  936.             setVisible(true);
  937.         }// </editor-fold>
  938.  
  939.         private void startAction() {
  940.             String t = THEME_BOX.getSelectedItem().toString();
  941.  
  942.             if (t.equals("Default")) {
  943.                 theme = new Theme(Color.CYAN.darker(), Color.BLACK, Color.RED);
  944.             } else if (t.equals("Bloody")) {
  945.                 theme = new Theme(Color.RED.darker(), Color.BLACK, new Color(100, 0, 0));
  946.             } else if (t.equals("Funky")) {
  947.                 theme = new Theme(Color.YELLOW, Color.BLACK, Color.MAGENTA);
  948.             } else if (t.equals("Sunny")) {
  949.                 theme = new Theme(Color.ORANGE, Color.BLACK, Color.RED);
  950.             } else if (t.equals("Sexy")) {
  951.                 theme = new Theme(Color.MAGENTA, Color.BLACK, Color.CYAN.darker());
  952.             } else if (t.equals("White")) {
  953.                 theme = new Theme(Color.WHITE, Color.BLACK, new Color(100, 100, 100));
  954.             } else if (t.equals("Grass")) {
  955.                 theme = new Theme(Color.GREEN.darker(), Color.BLACK, Color.RED.darker());
  956.             }
  957.  
  958.             antiban = ANTIBAN_CHECKBOX.isSelected();
  959.             multiAttack = MULTI_ATTACK_CHECKBOX.isSelected();
  960.             noFoodLogout = FOOD_LOGOUT_CHECKBOX.isSelected();
  961.             if (XTILE_CHECKBOX.isSelected()) {
  962.                 try {
  963.                     radius = Integer.parseInt(XTILE_TEXT.getText());
  964.                 } catch(Exception e) {
  965.                     radius = 10;
  966.                     log("Error setting radius! Setting radius to default!(10)");
  967.                 }
  968.             }
  969.  
  970.             String[] ids = NPCS_TEXT.getText().split(",");
  971.             ArrayList<Integer> id = new ArrayList<Integer>();
  972.             ArrayList<String> names = new ArrayList<String>();
  973.             for (int i = 0; i < ids.length; i++) {
  974.                 if (ids[i] != null && !ids[i].equals("")) {
  975.                     try {
  976.                         int index = Integer.parseInt(ids[i]);
  977.                         id.add(index);
  978.                     } catch (Exception e1) {
  979.                         names.add(ids[i]);
  980.                     }
  981.                 }
  982.             }
  983.             attack.npcIDs = id.size() > 0 ? toIntArray(id.toArray(new Integer[0])) : new int[0];
  984.             attack.npcNames = names.size() > 0 ? names.toArray(new String[0]) : new String[0];
  985.  
  986.             if (LOOT_CHECKBOX.isSelected()) {
  987.                 boolean bones = false;
  988.                 looting = true;
  989.                 ids = LOOT_TEXT.getText().split(",");
  990.                 id = new ArrayList<Integer>();
  991.                 names = new ArrayList<String>();
  992.                 for (int i = 0; i < ids.length; i++) {
  993.                     if (ids[i] != null && !ids[i].equals("")) {
  994.                         try {
  995.                             int index = Integer.parseInt(ids[i]);
  996.                             id.add(index);
  997.                             if(!bones)
  998.                                 bones = isBone(index);
  999.                         } catch (Exception e1) {
  1000.                             names.add(ids[i]);
  1001.                             if(!bones)
  1002.                                 bones = isBone(ids[i]);
  1003.                         }
  1004.                     }
  1005.                 }
  1006.                 loot.itemIDs = id.size() > 0 ? toIntArray(id.toArray(new Integer[0])) : new int[0];
  1007.                 loot.itemNames = names.size() > 0 ? names.toArray(new String[0]) : new String[0];
  1008.                 if(bones)
  1009.                     buryBones = (JOptionPane.showConfirmDialog(this, "Would you like to bury those bones?", "Loot", JOptionPane.YES_NO_OPTION) == 0);
  1010.             }
  1011.             wait = false;
  1012.             dispose();
  1013.         }
  1014.  
  1015.         private void cancelAction() {
  1016.             wait = false;
  1017.             start = false;
  1018.             dispose();
  1019.             log("Thank you for selecting Fatal Fighter! Hope you run this next time.");
  1020.         }
  1021.  
  1022.         private int[] toIntArray(Integer[] ints) {
  1023.             int[] done = new int[ints.length];
  1024.             for (int i = 0; i < done.length; i++) {
  1025.                 done[i] = ints[i].intValue();
  1026.             }
  1027.             return done;
  1028.         }
  1029.  
  1030.         private JCheckBox ANTIBAN_CHECKBOX;
  1031.         private JButton CANCEL_BUTTON;
  1032.         private JCheckBox FOOD_LOGOUT_CHECKBOX;
  1033.         private JCheckBox LOOT_CHECKBOX;
  1034.         private JTextField LOOT_TEXT;
  1035.         private JCheckBox MULTI_ATTACK_CHECKBOX;
  1036.         private JLabel NPCS_LABEL;
  1037.         private JTextField NPCS_TEXT;
  1038.         private JButton START_BUTTON;
  1039.         private JComboBox THEME_BOX;
  1040.         private JLabel THEME_LABEL;
  1041.         private JLabel TITLE_LABEL;
  1042.         private JCheckBox XTILE_CHECKBOX;
  1043.         private JTextField XTILE_TEXT;
  1044.  
  1045.         public boolean isBone(int i) {
  1046.             for (int bone : bones.BONE_IDS) {
  1047.                 if(i == bone)
  1048.                     return true;
  1049.             }
  1050.             return false;
  1051.         }
  1052.         public boolean isBone(String s) {
  1053.             return s.toLowerCase().contains("bones");
  1054.         }
  1055.  
  1056.     }
  1057.  
  1058.  
  1059.     public void mouseClicked(MouseEvent e) {}
  1060.     public void mouseEntered(MouseEvent e) {}
  1061.     public void mouseExited(MouseEvent e) {}
  1062.     public void mouseReleased(MouseEvent e) {}
  1063.  
  1064.     public void mousePressed(MouseEvent e) {
  1065.         Point p = e.getPoint();
  1066.  
  1067.         if (button.contains(p)) {
  1068.             showSkills = !showSkills;
  1069.             return;
  1070.         }
  1071.  
  1072.         if (topSkill != null && showSkills) {
  1073.             if (topSkill.getArea().contains(p)) {
  1074.                 topSkill = null;
  1075.             }
  1076.             return;
  1077.         }
  1078.  
  1079.         for (Skill s : skill) {
  1080.             if (s != null && s.active() && showSkills) {
  1081.                 if (s.getArea().contains(p)) {
  1082.                     topSkill = s;
  1083.                     return;
  1084.                 }
  1085.             }
  1086.         }
  1087.     }
  1088.  
  1089. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement