Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.21 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.FlowLayout;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Point;
  8. import java.awt.Polygon;
  9. import java.awt.RenderingHints;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseListener;
  14. import java.io.File;
  15. import java.io.FileInputStream;
  16. import java.io.FileOutputStream;
  17. import java.text.NumberFormat;
  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. import java.util.Properties;
  22.  
  23. import javax.swing.BorderFactory;
  24. import javax.swing.BoxLayout;
  25. import javax.swing.JButton;
  26. import javax.swing.JCheckBox;
  27. import javax.swing.JFrame;
  28. import javax.swing.JLabel;
  29. import javax.swing.JOptionPane;
  30. import javax.swing.JPanel;
  31. import javax.swing.JTextField;
  32.  
  33. import org.rsbot.event.listeners.PaintListener;
  34. import org.rsbot.script.Script;
  35. import org.rsbot.script.ScriptManifest;
  36. import org.rsbot.script.methods.Skills;
  37. import org.rsbot.script.util.Filter;
  38. import org.rsbot.script.wrappers.RSCharacter;
  39. import org.rsbot.script.wrappers.RSComponent;
  40. import org.rsbot.script.wrappers.RSGroundItem;
  41. import org.rsbot.script.wrappers.RSItem;
  42. import org.rsbot.script.wrappers.RSModel;
  43. import org.rsbot.script.wrappers.RSNPC;
  44. import org.rsbot.script.wrappers.RSPlayer;
  45. import org.rsbot.script.wrappers.RSTile;
  46. import org.rsbot.util.GlobalConfiguration;
  47.  
  48. /**
  49.  * Change log:
  50.  *  v0.94: Fixed eating.
  51.  *  v0.93: Hide paint by clicking it.
  52.  *  v0.92: Loot support, mainly. Many small changes.
  53.  *  v0.91: Oops, forgot to add mouse speed settings!
  54.  *  v0.9: Initial release
  55.  */
  56. @ScriptManifest(name = "TFighter", authors = "!@!@!", keywords = {"universal", "fighter", "!@!@!"}, version = 0.94)
  57. public class TFighter extends Script implements PaintListener, MouseListener {
  58.  
  59.     private final static ScriptManifest mani = TFighter.class.getAnnotation(ScriptManifest.class);
  60.     private final Util u = new Util();
  61.     private RSTile startTile;
  62.     private long nextAntiban = 0;
  63.     private int startTime = 0;
  64.     private int mouseSpeedMin = 4, mouseSpeedMax = 7;
  65.     private boolean startScript, showPaint;
  66.     private boolean onlyInRadius = false;
  67.     private boolean utilizeMultiwayCombat = false;
  68.    
  69.    
  70.     public boolean onStart() {
  71.         if(!game.isLoggedIn()) {
  72.             log("Start logged in.");
  73.             return false;
  74.         }
  75.         showPaint = true;
  76.         startScript = false;
  77.         FighterGUI gui = new FighterGUI();
  78.         while(!startScript) {
  79.             if(!gui.isVisible())
  80.                 return false;
  81.             sleep(100);
  82.         }
  83.        
  84.         startTile = getMyPlayer().getLocation();
  85.         u.sw.poll();
  86.         startTime = (int)System.currentTimeMillis();
  87.         return true;
  88.     }
  89.    
  90.     @Override
  91.     public int loop() {
  92.         if(random(0, 3) == 0 || mouse.getSpeed() < mouseSpeedMin || mouse.getSpeed() > mouseSpeedMax) {
  93.             mouse.setSpeed(random(mouseSpeedMin, mouseSpeedMax));
  94.         }
  95.         if(u.eat.needEat()) {
  96.             if(u.eat.haveFood()) {
  97.                 u.eat.eatFood();
  98.             } else if(u.eat.haveB2pTab() && u.eat.haveBones()) {
  99.                 u.eat.breakB2pTab();
  100.                 return random(2600, 3000);
  101.             } else {
  102.                 log("You ran out of food! Stopping.");
  103.                 stopScript();
  104.             }
  105.             return random(1200, 1600);
  106.         }
  107.         if(!walking.isRunEnabled() && walking.getEnergy() > random(60, 90)) {
  108.             walking.setRun(true);
  109.             return random(1200, 1600);
  110.         }
  111.         if(u.npcs.isInCombat()) {
  112.             antiban();
  113.             return random(50, 200);
  114.         }
  115.         RSGroundItem loot = u.loot.getLoot();
  116.         if(loot != null) {
  117.             int origCount = inventory.getCount(true);
  118.             String name = loot.getItem().getName();
  119.             int count = loot.getItem().getStackSize();
  120.             int result = u.loot.takeItem(loot);
  121.             if(result == 0) {
  122.                 waitWhileMoving();
  123.                 if(waitForInvChange(origCount)) {
  124.                     u.loot.addItem(name, count);
  125.                 }
  126.             } else if(result == 1) {
  127.                 waitWhileMoving();
  128.             }
  129.             return random(50, 200);
  130.         }
  131.         RSNPC inter = u.npcs.getInteracting();
  132.         RSNPC n = inter != null ? inter : u.npcs.getNPC();
  133.         if(n != null) {
  134.             int result = u.npcs.clickNPC(n, "Attack " + n.getName());
  135.             if(result == 0) {
  136.                 waitWhileMoving();
  137.                 return random(300, 500);
  138.             } else if(result == 1) {
  139.                 waitWhileMoving();
  140.                 return random(0, 200);
  141.             }
  142.         } else {
  143.             if(calc.distanceTo(startTile) > 5) {
  144.                 walking.walkTileMM(walking.getClosestTileOnMap(startTile));
  145.                 waitWhileMoving();
  146.             } else {
  147.                 antiban();
  148.             }
  149.         }
  150.         return random(50, 300);
  151.     }
  152.    
  153.     /**
  154.      * Waits until we are no longer moving.
  155.      */
  156.     private void waitWhileMoving() {
  157.         long start = System.currentTimeMillis();
  158.         while(System.currentTimeMillis() - start < 1500 && !getMyPlayer().isMoving()) {
  159.             sleep(random(50, 200));
  160.         }
  161.         while(getMyPlayer().isMoving()) {
  162.             sleep(random(20, 50));
  163.         }
  164.     }
  165.    
  166.     /**
  167.      * Waits until the inventory count changes
  168.      */
  169.     private boolean waitForInvChange(int origCount) {
  170.         long start = System.currentTimeMillis();
  171.         while(inventory.getCount(true) == origCount && System.currentTimeMillis() - start < 2000) {
  172.             sleep(random(20, 70));
  173.         }
  174.         return inventory.getCount(true) != origCount;
  175.     }
  176.    
  177.     /**
  178.      * Performs a random action, always.
  179.      * Actions: move mouse, move mouse off screen, move camera.
  180.      */
  181.     private void antiban() {
  182.         if(System.currentTimeMillis() > nextAntiban) {
  183.             nextAntiban = System.currentTimeMillis() + random(2000, 40000);
  184.         } else {
  185.             return;
  186.         }
  187.         switch(random(0, 4)) {
  188.             case 0:
  189.                 mouse.moveOffScreen();
  190.                 break;
  191.             case 1:
  192.                 mouse.move(random(0, game.getWidth()), random(0, game.getHeight()));
  193.                 break;
  194.             case 2:
  195.                 camera.setAngle(camera.getAngle() + random(-100, 100));
  196.                 break;
  197.             case 3:
  198.                 camera.setAngle(camera.getAngle() + random(-100, 100));
  199.                 break;
  200.         }
  201.     }
  202.    
  203.     @Override
  204.     public void onRepaint(Graphics g) {
  205.         if(!showPaint)
  206.             return;
  207.         final NumberFormat nf = NumberFormat.getIntegerInstance();
  208.         ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  209.         //Variables
  210.         RSComponent inter = interfaces.get(137).getComponent(0);
  211.         int x = inter.getLocation().x;
  212.         int y = inter.getLocation().y;
  213.        
  214.         //Counters
  215.         int runTime = (int)System.currentTimeMillis() - startTime;
  216.        
  217.         //Background
  218.         g.setColor(Color.BLACK);
  219.         g.fillRect(x, y, inter.getWidth() + 5, inter.getHeight() + 5);
  220.        
  221.         //Simple things
  222.         g.setColor(Color.WHITE);
  223.         g.setFont(new Font("Arial", Font.PLAIN, 18));
  224.         g.drawString("TFighter by !@!@! (v" + mani.version() + ")", x + 10, y += g.getFontMetrics().getMaxAscent() + 10);
  225.         g.setFont(new Font("Arial", Font.PLAIN, 12));
  226.         g.drawString("Run time: " + millisToTime(runTime), x + 20, y += g.getFontMetrics().getMaxAscent() + 5);
  227.    
  228.         //Exp gains
  229.         g.setFont(new Font("Arial", Font.BOLD, 12));
  230.         g.drawString("Experience gained:", x + 20, y += g.getFontMetrics().getMaxAscent() + 15);
  231.         g.setFont(new Font("Arial", Font.PLAIN, 11));
  232.         for(Map.Entry<String, Integer> entry : u.sw.getExpGainedMap().entrySet()) {
  233.             double expPerSec = entry.getValue() / (double)(runTime / 1000);
  234.             int expPerHour = (int)Math.round(expPerSec * 3600);
  235.             g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  236.                     " (p/hr: " + nf.format(expPerHour) + ")", x + 25, y += g.getFontMetrics().getMaxAscent());
  237.         }
  238.        
  239.         //Loot
  240.         y = inter.getLocation().y;
  241.         g.setFont(new Font("Arial", Font.BOLD, 12));
  242.         g.drawString("Loot taken:", x + 280, y += g.getFontMetrics().getMaxAscent() + 15);
  243.         g.setFont(new Font("Arial", Font.PLAIN, 11));
  244.         Map<String, Integer> loot = u.loot.getLootTaken();
  245.         for(Map.Entry<String, Integer> entry : loot.entrySet()) {
  246.             g.drawString(entry.getKey() + " x" + entry.getValue(), x + 285, y += g.getFontMetrics().getMaxAscent());
  247.         }
  248.     }
  249.    
  250.     /**
  251.      * Formats the given value into a clock format
  252.      * that follows the form of 00:00:00
  253.      *
  254.      * @param millis The total millis to be evaluated
  255.      * @return A String representation of millis, formatted as a clock
  256.      */
  257.     private String millisToTime(int millis) {
  258.         int hours = millis / (60 * 1000 * 60);
  259.         int minutes = (millis - (hours * 60 * 1000 * 60)) / (60 * 1000);
  260.         int seconds = (millis - (hours * 60 * 1000 * 60) - (minutes * 60 * 1000)) / 1000;
  261.         return (hours >= 10 ? hours + ":" : "0" + hours + ":")
  262.                 + (minutes >= 10 ? minutes + ":" : "0" + minutes + ":")
  263.                 + (seconds >= 10 ? seconds : "0" + seconds);
  264.     }
  265.    
  266.     private class Util {
  267.         private final NPCs npcs = new NPCs();
  268.         private final Eating eat = new Eating();
  269.         private final Loot loot = new Loot();
  270.         private final SkillWatcher sw = new SkillWatcher();
  271.     }
  272.    
  273.     private class NPCs {
  274.        
  275.         private int[] npcIDs = new int[0];
  276.         private String[] npcNames = new String[0];
  277.        
  278.         private int maxRadius = 10;
  279.        
  280.         /**
  281.          * Checks if we are in combat.
  282.          * @return True if we are in combat.
  283.          */
  284.         private boolean isInCombat() {
  285.             return getMyPlayer().getInteracting() instanceof RSNPC;
  286.         }
  287.        
  288.         /**
  289.          * Clicks an NPC based on its model.
  290.          * @param npc The NPC to click.
  291.          * @param action The action to perform.
  292.          * @return 0 if the NPC was clicked, 1 if we walked to it, or -1 if nothing happened.
  293.          */
  294.         private int clickNPC(RSNPC npc, String action) {
  295.             for(int i = 0; i < 10; i++) {
  296.                 if(isPartiallyOnScreen(npc.getModel())) {
  297.                     Point p = getPointOnScreen(npc.getModel(), false);
  298.                     if(!calc.pointOnScreen(p)) {
  299.                         continue;
  300.                     }
  301.                     mouse.move(p);
  302.                     if(menu.getItems()[0].contains(action)) {
  303.                         mouse.click(true);
  304.                         return 0;
  305.                     } else if(menu.contains(action)) {
  306.                         mouse.click(false);
  307.                         sleep(random(100, 200));
  308.                         for(int x = 0; x < 4; x++) {
  309.                             if(!menu.contains(action)) {
  310.                                 break;
  311.                             }
  312.                             if(menu.doAction(action)) {
  313.                                 return 0;
  314.                             }
  315.                         }
  316.                     }
  317.                 } else {
  318.                     walking.walkTileMM(closerTile(npc.getLocation() , 1), 2, 2);
  319.                     return 1;
  320.                 }
  321.             }
  322.             return -1;
  323.         }
  324.        
  325.         /**
  326.          * Checks if a model is partially on screen.
  327.          * @param m The RSModel to check.
  328.          * @return True if any point on the model is on screen.
  329.          */
  330.         private boolean isPartiallyOnScreen(RSModel m) {
  331.             return getPointOnScreen(m, true) != null;
  332.         }
  333.        
  334.         /**
  335.          * Gets a point on a model that is on screen.
  336.          * @param m The RSModel to test.
  337.          * @param first If true, it will return the first point that it finds on screen.
  338.          * @return A random point on screen of an object.
  339.          */
  340.         private Point getPointOnScreen(RSModel m, boolean first) {
  341.             if(m == null)
  342.                 return null;
  343.             ArrayList<Point> list = new ArrayList<Point>();
  344.             Polygon[] tris = m.getTriangles();
  345.             for(int i = 0; i < tris.length; i++) {
  346.                 Polygon p = tris[i];
  347.                 for(int j = 0; j < p.xpoints.length; j++) {
  348.                     Point pt = new Point(p.xpoints[j], p.ypoints[j]);
  349.                     if(calc.pointOnScreen(pt)) {
  350.                         if(first)
  351.                             return pt;
  352.                         list.add(pt);
  353.                     }
  354.                 }
  355.             }
  356.             return list.size() > 0 ? list.get(random(0, list.size())) : null;
  357.         }
  358.        
  359.         /**
  360.          * Gets a closer tile to us within dist.
  361.          * @param t The tile to start with.
  362.          * @param dist The max dist.
  363.          * @return A closer tile.
  364.          */
  365.         private RSTile closerTile(RSTile t, int dist) {
  366.             RSTile loc = getMyPlayer().getLocation();
  367.             int newX = t.getX(), newY = t.getY();
  368.             for(int i = 1; i < dist; i++) {
  369.                 newX = t.getX() != loc.getX() ? (t.getX() < loc.getX() ? newX-- : newX++) : newX;
  370.                 newY = t.getY() != loc.getY() ? (t.getY() < loc.getY() ? newY-- : newY++) : newY;
  371.             }
  372.             return new RSTile(newX, newY);
  373.         }
  374.        
  375.         /**
  376.          * Returns the nearest NPC.
  377.          * @return The nearest NPC that matches the filter.
  378.          */
  379.         private RSNPC getNPC() {
  380.             return npcs.getNearest(npcFilter);
  381.         }
  382.        
  383.         /**
  384.          * Returns the interacting NPC that matches our description, if any.
  385.          * @return The closest interacting NPC that matches the filter.
  386.          */
  387.         private RSNPC getInteracting() {
  388.             RSNPC npc = null;
  389.             int dist = 20;
  390.             for(RSNPC n : npcs.getAll()) {
  391.                 if(!isOurNPC(n))
  392.                     continue;
  393.                 RSCharacter inter = n.getInteracting();
  394.                 if(inter != null && inter instanceof RSPlayer && inter.equals(getMyPlayer()) && calc.distanceTo(n) < dist) {
  395.                     dist = calc.distanceTo(n);
  396.                     npc = n;
  397.                 }
  398.             }
  399.             return npc;
  400.         }
  401.        
  402.         private boolean isOurNPC(RSNPC t) {
  403.             int id = t.getID();
  404.             String name = t.getName();
  405.             boolean good = false;
  406.             for(int i : npcIDs) {
  407.                 if(id == i)
  408.                     good = true;
  409.             }
  410.             for(String s : npcNames) {
  411.                 if(name.toLowerCase().contains(s.toLowerCase()))
  412.                     good = true;
  413.             }
  414.             return good;
  415.         }
  416.        
  417.         /**
  418.          * The filter we use!
  419.          */
  420.         private final Filter<RSNPC> npcFilter = new Filter<RSNPC>() {
  421.             public boolean accept(RSNPC t) {
  422.                 if(!isOurNPC(t))
  423.                     return false;
  424.                 return (t.isValid() && (!onlyInRadius || calc.distanceBetween(t.getLocation(), startTile) < maxRadius) && (utilizeMultiwayCombat || !t.isInCombat() && t.getInteracting() == null) && t.getHPPercent() != 0);
  425.             }
  426.         };
  427.     }
  428.    
  429.     private class Eating {
  430.        
  431.         private final int[] B2P_TAB_ID = new int[] { 8015 };
  432.         private final int[] BONES_ID = new int[] { 526, 532, 530, 528, 3183, 2859 };
  433.        
  434.         /**
  435.          * Checks if we have at least one B2P tab.
  436.          * @return True if we have a tab.
  437.          */
  438.         private boolean haveB2pTab() {
  439.             return inventory.getCount(B2P_TAB_ID) > 0;
  440.         }
  441.        
  442.         /**
  443.          * Breaks a B2P tab.
  444.          */
  445.         private void breakB2pTab() {
  446.             RSItem i = inventory.getItem(B2P_TAB_ID);
  447.             if(i != null)
  448.                 i.doClick(true);
  449.         }
  450.        
  451.         /**
  452.          * Checks if the inventory contains bones, for B2P.
  453.          * @return True if we have bones.
  454.          */
  455.         private boolean haveBones() {
  456.             return inventory.getCount(BONES_ID) > 0;
  457.         }
  458.        
  459.         /**
  460.          * Checks if we have food.
  461.          * @return True if we have food.
  462.          */
  463.         private boolean haveFood() {
  464.             return getFood() != null;
  465.         }
  466.        
  467.         /**
  468.          * Finds food based on inventory actions.
  469.          * @return The RSItem of food, or null if none was found.
  470.          */
  471.         private RSItem getFood() {
  472.             for(RSItem i : inventory.getItems()) {
  473.                 if(i == null || i.getID() == -1)
  474.                     continue;
  475.                 if (i.getComponent().getActions() == null || i.getComponent().getActions()[0] == null)
  476.                     continue;
  477.                 if (i.getComponent().getActions()[0].contains("Eat"))
  478.                     return i;
  479.             }
  480.             return null;
  481.         }
  482.        
  483.         /**
  484.          * Attempts to eat food.
  485.          * @return True if we ate.
  486.          */
  487.         private boolean eatFood() {
  488.             RSItem i = getFood();
  489.             for(int j = 0; j < 3; j++) {
  490.                 if(i == null)
  491.                     break;
  492.                 if(i.doAction("Eat")) {
  493.                     return true;
  494.                 }
  495.             }
  496.             return false;
  497.         }
  498.        
  499.         /**
  500.          * Checks whether you need to eat or not.
  501.          * @return True if we need to eat.
  502.          */
  503.         private boolean needEat() {
  504.             return combat.getLifePoints() < ((skills.getRealLevel(Skills.CONSTITUTION) * 10) / 2);
  505.         }
  506.     }
  507.    
  508.     private class Loot {
  509.        
  510.         private int[] lootIDs = new int[0];
  511.         private String[] lootNames = new String[0];
  512.        
  513.         private Map<String, Integer> lootTaken = new HashMap<String, Integer>();
  514.        
  515.         /**
  516.          * Gets the nearest loot, based on the filter
  517.          * @return The nearest item to loot, or null if none.
  518.          */
  519.         private RSGroundItem getLoot() {
  520.             return groundItems.getNearest(lootFilter);
  521.         }
  522.        
  523.         /**
  524.          * Attempts to take an item.
  525.          * @param item The item to take.
  526.          * @return -1 if error, 0 if taken, 1 if walked
  527.          */
  528.         private int takeItem(RSGroundItem item) {
  529.             if(item == null)
  530.                 return -1;
  531.             String action = "Take " + item.getItem().getName();
  532.             if(item.isOnScreen()) {
  533.                 for(int i = 0; i < 5; i++) {
  534.                     if(menu.isOpen())
  535.                         mouse.moveRandomly(300, 500);
  536.                     Point p = calc.tileToScreen(item.getLocation());
  537.                     if(!calc.pointOnScreen(p))
  538.                         continue;
  539.                     mouse.move(p, 3, 3);
  540.                     if(menu.contains(action)) {
  541.                         if(menu.getItems()[0].contains(action)) {
  542.                             mouse.click(true);
  543.                             return 0;
  544.                         } else {
  545.                             mouse.click(false);
  546.                             sleep(random(100, 200));
  547.                             if(menu.doAction(action))
  548.                                 return 0;
  549.                         }
  550.                     }
  551.                 }
  552.             } else {
  553.                 walking.walkTileMM(walking.getClosestTileOnMap(item.getLocation()));
  554.                 return 1;
  555.             }
  556.             return -1;
  557.         }
  558.        
  559.         private void addItem(String name, int count) {
  560.             if(lootTaken.get(name) != null) {
  561.                 int newCount = count + lootTaken.get(name);
  562.                 lootTaken.remove(name);
  563.                 lootTaken.put(name, newCount);
  564.             } else {
  565.                 lootTaken.put(name, count);
  566.             }
  567.         }
  568.        
  569.         private Map<String, Integer> getLootTaken() {
  570.             HashMap<String, Integer> m = new HashMap<String, Integer>();
  571.             m.putAll(lootTaken);
  572.             return m;
  573.         }
  574.        
  575.         private final Filter<RSGroundItem> lootFilter = new Filter<RSGroundItem>() {
  576.             public boolean accept(RSGroundItem t) {
  577.                 //Skip if we can't hold it
  578.                 RSItem i;
  579.                 if(inventory.isFull() && ((i = inventory.getItem(t.getItem().getID())) == null || i.getStackSize() <= 1)) {
  580.                     return false;
  581.                 }
  582.                 //Skip if its out of radius or far away
  583.                 if(onlyInRadius && calc.distanceBetween(t.getLocation(), startTile) > u.npcs.maxRadius
  584.                         || calc.distanceTo(t.getLocation()) > 25) {
  585.                     return false;
  586.                 }
  587.                 //Check ID/name
  588.                 boolean good = false;
  589.                 int id = t.getItem().getID();
  590.                 for(int iD : lootIDs) {
  591.                     if(iD == id)
  592.                         good = true;
  593.                 }
  594.                 String name = t.getItem().getName();
  595.                 for(String s : lootNames) {
  596.                     if(name != null && name.toLowerCase().contains(s.toLowerCase()))
  597.                         good = true;
  598.                 }
  599.                 return good;
  600.             }
  601.         };
  602.        
  603.     }
  604.    
  605.     private class SkillWatcher {
  606.        
  607.         private Map<Integer, Integer> startExpMap = new HashMap<Integer, Integer>();
  608.         private final int[] SKILLS_TO_WATCH = new int[] { Skills.CONSTITUTION, Skills.ATTACK, Skills.STRENGTH, Skills.DEFENSE, Skills.RANGE, Skills.MAGIC };
  609.        
  610.         /**
  611.          * Basically sets start exp for all skills we are watching.
  612.          */
  613.         private void poll() {
  614.             for(int skill : SKILLS_TO_WATCH) {
  615.                 if(startExpMap.containsKey(skill))
  616.                     startExpMap.remove(skill);
  617.                 startExpMap.put(skill, skills.getCurrentExp(skill));
  618.             }
  619.         }
  620.        
  621.         /**
  622.          * Returns the amount of exp gained in the specified skill.
  623.          * @param skill The skill see Skills.*
  624.          * @return
  625.          */
  626.         private int getExpGainedIn(int skill) {
  627.             if(startExpMap.get(skill) == null)
  628.                 return -1;
  629.             return skills.getCurrentExp(skill) - startExpMap.get(skill);
  630.         }
  631.        
  632.         /**
  633.          * Returns a map of skill names and exp gained.
  634.          * @return A map of exp gains and skill names.
  635.          */
  636.         private Map<String, Integer> getExpGainedMap() {
  637.             Map<String, Integer> map = new HashMap<String, Integer>();
  638.             for(int i : SKILLS_TO_WATCH) {
  639.                 int gained = getExpGainedIn(i);
  640.                 if(gained != 0)
  641.                     map.put(Skills.SKILL_NAMES[i], gained);
  642.             }
  643.             return map;
  644.         }
  645.        
  646.     }
  647.    
  648.     @SuppressWarnings("serial")
  649.     private class FighterGUI extends JFrame {
  650.        
  651.         private final File file = new File(GlobalConfiguration.Paths.getSettingsDirectory() + System.getProperty("file.separator") + "TFighterProps.txt");
  652.        
  653.         private JCheckBox useMulti, useRadius;
  654.         private JTextField npcBox, lootBox, mouseSpeedBox;
  655.        
  656.         private FighterGUI() {
  657.             init();
  658.             pack();
  659.             setVisible(true);
  660.         }
  661.        
  662.         private void init() {
  663.             Properties props = loadProperties();
  664.             JPanel north = new JPanel(new FlowLayout());
  665.             north.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  666.             {
  667.                 JLabel title = new JLabel("TFighter by !@!@!");
  668.                 title.setFont(new Font("Arial", Font.PLAIN, 28));
  669.                 north.add(title);
  670.             }
  671.             add(north, BorderLayout.NORTH);
  672.            
  673.             JPanel center = new JPanel();
  674.             center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
  675.             center.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  676.             {
  677.                 mouseSpeedBox = new JTextField("4,7");
  678.                 useMulti = new JCheckBox("Utilize multiway combat");
  679.                 useRadius = new JCheckBox("Only attack within a radius");
  680.                 npcBox = new JTextField("2,5,1,Chicke");
  681.                 lootBox = new JTextField("arrow,feather");
  682.  
  683.                 if(props.getProperty("mouseSpeed") != null) {
  684.                     mouseSpeedBox.setText(props.getProperty("mouseSpeed"));
  685.                 }
  686.                 if(props.getProperty("useMulti") != null) {
  687.                     if(props.getProperty("useMulti").equals("true"))
  688.                         useMulti.setSelected(true);
  689.                 }
  690.                 if(props.getProperty("useRadius") != null) {
  691.                     if(props.getProperty("useRadius").equals("true"))
  692.                         useRadius.setSelected(true);
  693.                 }
  694.                 if(props.getProperty("npcBox") != null) {
  695.                     npcBox.setText(props.getProperty("npcBox"));
  696.                 }
  697.                 if(props.getProperty("lootBox") != null) {
  698.                     lootBox.setText(props.getProperty("lootBox"));
  699.                 }
  700.                
  701.                 center.add(new JLabel("Enter your desired mouse speed (max,min)"));
  702.                 center.add(mouseSpeedBox);
  703.                 center.add(useMulti);
  704.                 center.add(useRadius);
  705.                 center.add(new JLabel(" "));
  706.                 center.add(new JLabel("Enter the IDs and/or names of the NPCs to fight."));
  707.                 center.add(new JLabel("You can mix and match these, all in the same box!"));
  708.                 center.add(npcBox);
  709.                 center.add(new JLabel("Enter the IDs and/or names of items to loot."));
  710.                 center.add(lootBox);
  711.                
  712.             }
  713.             add(center, BorderLayout.CENTER);
  714.            
  715.             JPanel south = new JPanel(new FlowLayout());
  716.             south.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  717.             {
  718.                 JButton start = new JButton("Start script!");
  719.                 start.addActionListener(onStart);
  720.                 south.add(start);
  721.             }
  722.             add(south, BorderLayout.SOUTH);
  723.            
  724.             setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  725.             setTitle("TFighter GUI");
  726.         }
  727.        
  728.         private Properties loadProperties() {
  729.             try {
  730.                 if(!file.exists())
  731.                     file.createNewFile();
  732.                 Properties p = new Properties();
  733.                 p.load(new FileInputStream(file));
  734.                 return p;
  735.             } catch (Exception e) {
  736.                 e.printStackTrace();
  737.             }
  738.             return null;
  739.         }
  740.        
  741.         private void saveProperties() {
  742.             Properties p = new Properties();
  743.             p.put("mouseSpeed", mouseSpeedBox.getText());
  744.             p.put("useMulti", Boolean.toString(useMulti.isSelected()));
  745.             p.put("useRadius", Boolean.toString(useRadius.isSelected()));
  746.             p.put("npcBox", npcBox.getText());
  747.             p.put("lootBox", lootBox.getText());
  748.             try {
  749.                 p.store(new FileOutputStream(file), "");
  750.             } catch (Exception e) {
  751.                 e.printStackTrace();
  752.             }
  753.         }
  754.        
  755.         private ActionListener onStart = new ActionListener() {
  756.             @Override
  757.             public void actionPerformed(ActionEvent e) {
  758.                 saveProperties();
  759.                 startScript = true;
  760.                 mouseSpeedMin = Integer.parseInt(mouseSpeedBox.getText().split(",")[0]);
  761.                 mouseSpeedMax = Integer.parseInt(mouseSpeedBox.getText().split(",")[0]);
  762.                 utilizeMultiwayCombat = useMulti.isSelected();
  763.                 onlyInRadius = useRadius.isSelected();
  764.                 if(onlyInRadius) {
  765.                     u.npcs.maxRadius = Integer.parseInt(JOptionPane.showInputDialog("Enter the max radius. Example: 10"));
  766.                 }
  767.                 String[] ids = npcBox.getText().split(",");
  768.                 ArrayList<Integer> idList = new ArrayList<Integer>();
  769.                 ArrayList<String> nameList = new ArrayList<String>();
  770.                 for(int i = 0; i < ids.length; i++) {
  771.                     if(ids[i] != null && !ids[i].equals("")) {
  772.                         try {
  773.                             int id = Integer.parseInt(ids[i]);
  774.                             idList.add(id);
  775.                         } catch (Exception e1) {
  776.                             nameList.add(ids[i]);
  777.                         }
  778.                     }
  779.                 }
  780.                 u.npcs.npcIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[0])) : new int[0];
  781.                 u.npcs.npcNames = nameList.size() > 0 ? nameList.toArray(new String[0]) : new String[0];
  782.                
  783.                 ids = lootBox.getText().split(",");
  784.                 idList = new ArrayList<Integer>();
  785.                 nameList = new ArrayList<String>();
  786.                 for(int i = 0; i < ids.length; i++) {
  787.                     if(ids[i] != null && !ids[i].equals("")) {
  788.                         try {
  789.                             int id = Integer.parseInt(ids[i]);
  790.                             idList.add(id);
  791.                         } catch (Exception e1) {
  792.                             nameList.add(ids[i]);
  793.                         }
  794.                     }
  795.                 }
  796.                 u.loot.lootIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[0])) : new int[0];
  797.                 u.loot.lootNames = nameList.size() > 0 ? nameList.toArray(new String[0]) : new String[0];
  798.                 dispose();
  799.             }
  800.         };
  801.        
  802.         private int[] toIntArray(Integer[] ints) {
  803.             int[] done = new int[ints.length];
  804.             for(int i = 0; i < done.length; i++) {
  805.                 done[i] = ints[i].intValue();
  806.             }
  807.             return done;
  808.         }
  809.     }
  810.  
  811.     @Override
  812.     public void mouseClicked(MouseEvent e) {
  813.         RSComponent inter = interfaces.get(137).getComponent(0);
  814.         if(inter.getArea().contains(e.getPoint())) {
  815.             showPaint = !showPaint;
  816.         }
  817.     }
  818.  
  819.     @Override
  820.     public void mousePressed(MouseEvent e) { }
  821.  
  822.     @Override
  823.     public void mouseReleased(MouseEvent e) { }
  824.  
  825.     @Override
  826.     public void mouseEntered(MouseEvent e) { }
  827.  
  828.     @Override
  829.     public void mouseExited(MouseEvent e) { }
  830. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement