Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Point;
  8. import java.awt.Rectangle;
  9.  
  10. import org.tribot.api.General;
  11. import org.tribot.api.Timing;
  12. import org.tribot.api.input.Keyboard;
  13. import org.tribot.api.input.Mouse;
  14. import org.tribot.api2007.Game;
  15. import org.tribot.api2007.GameTab;
  16. import org.tribot.api2007.GameTab.TABS;
  17. import org.tribot.api2007.Interfaces;
  18. import org.tribot.api2007.Inventory;
  19. import org.tribot.api2007.Login;
  20. import org.tribot.api2007.NPCChat;
  21. import org.tribot.api2007.NPCs;
  22. import org.tribot.api2007.Objects;
  23. import org.tribot.api2007.PathFinding;
  24. import org.tribot.api2007.Player;
  25. import org.tribot.api2007.Projection;
  26. import org.tribot.api2007.Walking;
  27. import org.tribot.api2007.types.RSInterfaceChild;
  28. import org.tribot.api2007.types.RSItem;
  29. import org.tribot.api2007.types.RSNPC;
  30. import org.tribot.api2007.types.RSObject;
  31. import org.tribot.api2007.types.RSTile;
  32. import org.tribot.script.Script;
  33. import org.tribot.script.ScriptManifest;
  34. import org.tribot.script.interfaces.Painting;
  35.  
  36. @ScriptManifest(authors = { "Moose" }, category = "Minigames", name = "Moose's Warriors Guild")
  37.  
  38. public class MoosesWarriorsGuild extends Script implements Painting {//411,
  39.     private boolean isRunning = true;
  40.     private final int[] SCIMITAR_IDS = {1321, 1323, 1325, 1327, 1329, 1331, 1333, 4587};
  41.     private final int[] WARHAMMER_IDS = {1335, 1337, 1339, 1341, 1343, 1345, 1347};
  42.     private final RSTile CATAPAULT_LOCATION = new RSTile(2840, 3552);
  43.     private final RSTile TARGET_TILE = new RSTile(2842, 3545);
  44.     private final RSTile CENTER_DUMMY_TILE = new RSTile(2857, 3551);
  45.     private final int SHIELD_ID = 8856;
  46.     private int successes = 0;
  47.     private int failures = 0;
  48.     private RSObject dummyObject = null;
  49.     private int currentAttackStyle = -1;
  50.     private String status = "Starting up..";
  51.     private CatapaultType currentCatapault = null;
  52.     private DummyType currentDummy = null;
  53.     private Task currentTask = null;
  54.     public enum Task {
  55.         CATAPAULT,
  56.         DUMMIES;
  57.         private Task() {
  58.            
  59.         }
  60.     }
  61.     public enum CatapaultType {
  62.         STAB(15617, 1),
  63.         BLUNT(15619, 2),
  64.         SLASH(15620, 3),
  65.         MAGIC(15618, 4);
  66.         private int objectID, interfaceID;
  67.         private CatapaultType(int objectID, int interfaceID) {
  68.             this.objectID = objectID;
  69.             this.interfaceID = interfaceID;
  70.         }
  71.         private int getObjectID() {
  72.             return this.objectID;
  73.         }
  74.         private int getInterfaceID() {
  75.             return this.interfaceID;
  76.         }
  77.         public static CatapaultType forId(int ID) {
  78.             for (CatapaultType type : CatapaultType.values()) {
  79.                 if (type.getObjectID() == ID) {
  80.                     return type;
  81.                 }
  82.             }
  83.             return null;
  84.         }
  85.     }
  86.    
  87.     public enum DummyType {
  88.         SLASH(15625, 2, 3, 5),
  89.         CRUSH(15628, 2, 3, 4, 5),
  90.         AGGRESSIVE(15626, 3),
  91.         STAB(15629, 4),
  92.         ACCURATE(15624, 2),
  93.         CONTROLLED(15627, 4),
  94.         DEFENSIVE(15630, 5);
  95.         private int objectID;
  96.         private int[] interfaceID;
  97.         private DummyType(int objectID, int... interfaceID) {
  98.             this.objectID = objectID;
  99.             this.interfaceID = interfaceID;
  100.         }
  101.         private int getObjectID() {
  102.             return this.objectID;
  103.         }
  104.         private int getInterfaceID() {
  105.             return this.interfaceID[0];
  106.         }
  107.         private int[] getInterfaceIDs() {
  108.             return this.interfaceID;
  109.         }
  110.         public boolean isCompatible(int interfaceID) {
  111.             for(int i = 0; i < getInterfaceIDs().length; i++) {
  112.                 if(this.interfaceID[i] == interfaceID)
  113.                     return true;
  114.             }
  115.             return false;
  116.         }
  117.         public static DummyType forId(int ID) {
  118.             for (DummyType type : DummyType.values()) {
  119.                 if (type.getObjectID() == ID) {
  120.                     return type;
  121.                 }
  122.             }
  123.             return null;
  124.         }
  125.     }
  126.     public RSObject getDummyObject() {
  127.         RSObject[] objects = Objects.sortByDistance(Player.getPosition(), Objects.getAll(10));
  128.         for(RSObject obj : objects) {
  129.             if(obj.getID() >= 15624 && obj.getID() <= 15630) {
  130.                 return obj;
  131.             }
  132.         }
  133.         return null;
  134.     }
  135.    
  136.     public void doDummies() {
  137.         Mouse.setSpeed(160);
  138.         if(attackedByNPC()) {
  139.             setStatus("Running from aggressive random!");
  140.             RSObject doors[] = Objects.getAt(new RSTile(2853, 3554, 0));
  141.             if(doors.length > 0) { /*Walk out the door, then hide behind a table and logout :D*/
  142.                 if(doors[0].getPosition().distanceTo(Player.getPosition()) > 2) {
  143.                     Walking.walkTo(new RSTile(2855, 3554, 0));
  144.                     sleep(500);
  145.                 } else {
  146.                     doors[0].getModel().click("Open");
  147.                     sleep(600, 900);
  148.                 }
  149.             } else {
  150.                 Walking.walkTo(new RSTile(2849, 3553, 0));
  151.                 sleep(15000, 20000);
  152.                 Login.logout();
  153.             }
  154.             return;
  155.         }
  156.         if(Player.getPosition().getX() < 2854 && Player.getPosition().getY() > 3550 && Player.getPosition().getX() > 2848) { //If we're in that little room
  157.             RSObject doors[] = Objects.getAt(new RSTile(2853, 3554, 0));
  158.             if(doors.length > 0) {
  159.                 if(doors[0].getPosition().distanceTo(Player.getPosition()) > 2) {
  160.                     Walking.walkTo(new RSTile(2852, 3554, 0));
  161.                     sleep(500);
  162.                 } else {
  163.                     doors[0].getModel().click("Open");
  164.                     sleep(600, 900);
  165.                 }
  166.             } else {
  167.                 Walking.walkTo(new RSTile(2857, 3552, 0));
  168.                     sleep(600, 900);
  169.             }
  170.             return;
  171.         }
  172.         if(!PathFinding.canReach(CENTER_DUMMY_TILE, false)) { /*We got lost but let's try to get back*/
  173.             setStatus("We seem to be stuck..");
  174.             if(Player.getPosition().distanceTo(new RSTile(2851, 3550)) < 2) {
  175.                 RSObject doors[] = Objects.getAt(new RSTile(2851, 3551, 0));
  176.                 if(doors.length > 1) { //There's more than 1 object here o.O
  177.                         doors[1].getModel().click("Open");
  178.                         sleep(600, 900);
  179.                 } else {
  180.                     Walking.walkTo(new RSTile(2852, 3553, 0)); 
  181.                     sleep(600, 900);
  182.                 }
  183.             } else if(PathFinding.canReach(new RSTile(2851, 3550), false)) {
  184.                 PathFinding.aStarWalk(new RSTile(2851, 3550));
  185.                 sleep(600, 900);
  186.             }
  187.             return;
  188.         }
  189.         if(Player.getPosition().distanceTo(CENTER_DUMMY_TILE) > 5) { /*We're not in the room but we can reach the tile*/
  190.             PathFinding.aStarWalk(CENTER_DUMMY_TILE);
  191.             sleep(600, 900);
  192.         }
  193.         if(!isRunOn() && General.random(0, 2000) == 1)
  194.             setRun();
  195.         dummyObject = getDummyObject();
  196.         if(dummyObject != null) {
  197.             if(DummyType.forId(dummyObject.getID()).equals(currentDummy)) {
  198.                 setStatus("Waiting..");
  199.                 return;
  200.             }
  201.             currentDummy = DummyType.forId(dummyObject.getID());
  202.             if(currentDummy.equals(DummyType.CRUSH) && !wearingItem(WARHAMMER_IDS)) {
  203.                 equipItem(WARHAMMER_IDS);
  204.             } else if(!wearingItem(SCIMITAR_IDS)) {
  205.                 equipItem(SCIMITAR_IDS);
  206.             }
  207.             if(!currentDummy.isCompatible(currentAttackStyle)) {
  208.                 setStatus("Switching attack styles");
  209.                 if(!GameTab.getOpen().equals(TABS.COMBAT))
  210.                     Keyboard.pressFunctionKey(1);
  211.                 if(!currentDummy.equals(DummyType.CRUSH)) {
  212.                 while(Interfaces.get(81) == null && !objectHasChanged(dummyObject))
  213.                     sleep(50);
  214.                     Interfaces.get(81, currentDummy.getInterfaceID()).click(null);
  215.                 }
  216.                 currentAttackStyle = currentDummy.getInterfaceID();
  217.             }
  218.                 setStatus("HULK SMAAAASH");
  219.                 while(!dummyObject.getModel().click("Hit") && !objectHasChanged(dummyObject));
  220.         }
  221.     }
  222.     public boolean objectHasChanged(RSObject o) {
  223.         RSObject[] object = Objects.getAt(o.getPosition());
  224.         if(object.length > 0) {
  225.             if(object[0] != null) {
  226.                 if(object[0].getID() == o.getID())
  227.                     return false;
  228.             }
  229.         }
  230.         return true;
  231.     }
  232.     public boolean equipItem(int... IDs) {
  233.         setStatus("Equipping new item");
  234.         if(!GameTab.getOpen().equals(TABS.INVENTORY))
  235.         Keyboard.pressFunctionKey(0);
  236.         RSItem[] warhammers = Inventory.find(IDs);
  237.         if(warhammers.length > 0) {
  238.             if(warhammers[0] == null)
  239.                 return false;
  240.             while(!warhammers[0].click("Wield"))
  241.                 return true;
  242.         }
  243.         return false;
  244.     }
  245.     public boolean wearingItem(int... IDS) {
  246.         RSItem[] equipped = getEquipment();
  247.         for(int j = 0; j < IDS.length; j++) {
  248.         for(RSItem i : equipped) {
  249.             if(i != null)
  250.                 if(i.getID() == IDS[j])
  251.                     return true;
  252.         }
  253.         }
  254.         return false;
  255.     }
  256.  
  257.     public boolean isRunOn() {
  258.         return (Game.getSettingsArray()[173] == 1);
  259.     }
  260.    
  261.     public void setRun() {
  262.         if(!isRunOn()) {
  263.             if(GameTab.getOpen() != GameTab.TABS.OPTIONS)
  264.                 GameTab.open(TABS.OPTIONS);
  265.             Mouse.clickBox(626,415,657,445,1);
  266.         }
  267.     }
  268.  
  269.     public void doCatapault() {
  270.         if(Player.isMoving()) {
  271.             sleep(500);
  272.             return;
  273.         }
  274.         if(attackedByNPC()) {
  275.                     setStatus("Running from aggressive random!");
  276.                     RSObject[] door = Objects.getAt(new RSTile(2842, 3542));
  277.                     if(door.length > 0) {
  278.                         if(door[0] != null)
  279.                             if(Player.getPosition().distanceTo(door[0].getPosition()) > 5) {
  280.                                 Walking.walkPath(Walking.generateStraightPath(door[0].getPosition()));
  281.                                 sleep(500, 800);
  282.                             } else if(PathFinding.canReach(door[0].getPosition(), true)) {
  283.                                 if(door[0].getModel().click("Open")) {
  284.                                     sleep(15000, 20000);
  285.                                     Login.logout();
  286.                                 }
  287.                             }
  288.                     }
  289.                 }
  290.         if(!Player.getPosition().equals(TARGET_TILE) && Inventory.getCount(SHIELD_ID) >  0) { //We need to walk to the "target" spot
  291.             if(PathFinding.canReach(TARGET_TILE, false)) {
  292.                 setStatus("Walking to target tile");
  293.                 if(Player.getPosition().distanceTo(TARGET_TILE) < 5)
  294.                     Walking.walkScreenPath(Walking.generateStraightScreenPath(TARGET_TILE));
  295.                 else
  296.                 PathFinding.aStarWalk(TARGET_TILE);
  297.             return;
  298.             }
  299.         }
  300.         if(!wearingItem(SHIELD_ID)) {
  301.             RSItem[] shield = Inventory.find(SHIELD_ID);
  302.             if(shield.length > 0) { //If we have the shield and we're in the proper spot weild it
  303.                 if(Player.getPosition().equals(TARGET_TILE)) {
  304.                 if(shield[0] == null)
  305.                     return;
  306.                 shield[0].click("Wield");
  307.                 sleep(700, 900);
  308.                 }
  309.             } else { //We don't have a shield, let's get one
  310.                 if(Player.getPosition().getY() > 3541) {
  311.                     RSObject[] door = Objects.getAt(new RSTile(2842, 3542));
  312.                     if(door.length > 0) {
  313.                         if(door[0] != null)
  314.                             if(Player.getPosition().distanceTo(door[0].getPosition()) > 5) {
  315.                                 Walking.walkPath(Walking.generateStraightPath(door[0].getPosition()));
  316.                                 sleep(500, 800);
  317.                             } else if(PathFinding.canReach(door[0].getPosition(), true)) {
  318.                                 door[0].getModel().click("Open");
  319.                                 sleep(600, 900);
  320.                             }
  321.                     }
  322.                     return;
  323.                 }
  324.                 if(NPCChat.clickContinue(true)) //Godfred's talking to us
  325.                     return;
  326.                 RSNPC[] gamfred = NPCs.find("Gamfred");
  327.                 if(gamfred.length > 0) {
  328.                     if(gamfred[0] == null)
  329.                         return;
  330.                     if(PathFinding.canReach(gamfred[0].getPosition(), false)) {
  331.                     gamfred[0].getModel().click("Claim-Shield");
  332.                     sleep(600, 900);
  333.                     return;
  334.                     }
  335.                 }
  336.             }
  337.         }
  338.         if(Player.getPosition().getY() < 3542) { // We are not in the catapault room, so let's go there.
  339.             setStatus("Traversing doors");
  340.             RSObject[] doors = Objects.sortByDistance(Player.getPosition(), Objects.find(20, 15647, 1530));
  341.             if(doors.length > 0) {
  342.                 if(doors[0] == null)
  343.                     return;
  344.                 if(doors[0].getPosition().distanceTo(Player.getPosition()) > 5) {
  345.                     if(PathFinding.canReach(doors[0].getPosition(), false))
  346.                         Walking.walkPath(Walking.generateStraightPath(doors[0].getPosition()));
  347.                 } else {
  348.                     doors[0].getModel().click("Open");
  349.                 }
  350.             }
  351.             return;
  352.         }
  353.         if(CatapaultType.forId(Objects.getAt(CATAPAULT_LOCATION)[0].getID()) != null) {
  354.         if(CatapaultType.forId(Objects.getAt(CATAPAULT_LOCATION)[0].getID()).equals(currentCatapault))
  355.             return;
  356.         currentCatapault = CatapaultType.forId(Objects.getAt(CATAPAULT_LOCATION)[0].getID());
  357.         setStatus("Defending from: "+currentCatapault.name());
  358.         sleep(1500, 3000);
  359.         Interfaces.get(411, currentCatapault.getInterfaceID()).click(null);
  360.         }
  361.     }
  362.    
  363.     public void loop() {
  364.         sleep(100);
  365.         if(!Login.getLoginState().equals(Login.STATE.INGAME)) {
  366.             setStatus("Not logged in...");
  367.             return;
  368.         }
  369.         if(Player.isMoving())
  370.             setStatus("Walking");
  371.         if(Player.getPosition().distanceTo(CENTER_DUMMY_TILE) > 50) {
  372.             setStatus("We're lost..");
  373.             return;
  374.         }
  375.         if(currentTask.equals(Task.CATAPAULT))
  376.             doCatapault();
  377.         if(currentTask.equals(Task.DUMMIES))
  378.             doDummies();
  379.     }
  380.    
  381.     @Override
  382.     public void run() {
  383.         try {
  384.         Mouse.setSpeed(150);
  385.         setRun();
  386.         if(Player.getRSPlayer().getPosition().getPlane() == 1 && Player.getPosition().distanceTo(TARGET_TILE) < 10)
  387.             currentTask = Task.CATAPAULT;
  388.         if(Player.getRSPlayer().getPosition().getPlane() == 0 && Player.getPosition().distanceTo(CENTER_DUMMY_TILE) < 10)
  389.             currentTask = Task.DUMMIES;
  390.         while(isRunning) {
  391.             try {
  392.             loop();
  393.             }catch(Exception e) {
  394.                
  395.             }
  396.         }
  397.         }catch(Exception e) {
  398.             println("Something bad has happened.");
  399.         }
  400.     }
  401.  
  402.     private RSItem[] getEquipment(){
  403.         RSInterfaceChild equip = Interfaces.get(387, 28);
  404.         RSItem[] items = null;
  405.         if(equip != null){
  406.             items = equip.getItems();
  407.         }
  408.         return items;
  409.     }
  410.    
  411.     public boolean attackedByNPC() {
  412.         RSNPC[] npcs = NPCs.getAll();
  413.         for(RSNPC npc: npcs) {
  414.             if(npc == null)
  415.                 continue;
  416.             if(npc.isInteractingWithMe() && Player.getRSPlayer().isInCombat()) {
  417.                 return true;
  418.             }
  419.         }
  420.         return false;
  421.     }
  422.  
  423.     public void setStatus(Object o) {
  424.         status = o.toString();
  425.     }
  426.  
  427.     public static RSTile getNearest(RSTile[] t){
  428.         RSTile nearest = null;
  429.         double distance = 9999999;
  430.         for (RSTile object : t){
  431.                 if (object.distanceTo(Player.getPosition()) < distance){
  432.                         nearest = object;
  433.                         distance = object.distanceTo(Player.getPosition());
  434.                 }
  435.         }
  436.         return nearest;
  437. }
  438.     @Override
  439.     public void onPaint(Graphics g1) {
  440.         // TODO Auto-generated method stub
  441.         Graphics2D g = (Graphics2D)g1;
  442.         g.setColor(Color.LIGHT_GRAY);
  443.         g.drawString("Moose's Warrior's guild - BETA", 10, 255);
  444.         g.drawString("Current activity: " +currentTask.name(), 10, 270);
  445.         if(status != null)
  446.         g.drawString("Status: " +status.toString(), 10, 285);
  447.         //g.drawString("Successes: " +successes, 10, 300);
  448.         //g.drawString("Fails: " +failures, 10, 315);
  449.         /* MessageListener doesn't even work properly, lol..*/
  450.         g.drawString("Runtime: " +Timing.msToString(this.getRunningTime()), 10, 300);
  451.  
  452.         if(currentTask.equals(Task.CATAPAULT)) {
  453.             if(Interfaces.get(411) != null) {
  454.             Rectangle r = Interfaces.get(411, currentCatapault.getInterfaceID()).getAbsoluteBounds();
  455.             g.setColor(Color.CYAN);
  456.             g.drawRect(r.x, r.y, r.width, r.height);
  457.             }
  458.             g.setColor(Color.RED);
  459.             g.drawPolygon(Projection.getTileBoundsPoly(TARGET_TILE, 0));
  460.         }
  461.         if(dummyObject != null) {
  462.             Point p = Projection.tileToScreen(dummyObject.getPosition(), 0);
  463.             g1.setColor(DummyType.forId(dummyObject.getID()).equals(currentDummy) && Player.getPosition().distanceTo(dummyObject.getPosition()) == 1 ? Color.GREEN : Color.RED);
  464.             g1.drawRect((int)p.getX() - 30, (int)p.getY() - 25, 60, 50);
  465.             g1.setColor(Color.YELLOW);
  466.             g1.setFont(new Font("Arial", Font.PLAIN, 10));
  467.             if(currentDummy != null) {
  468.             g1.drawString(currentDummy.name(), (int)p.getX() - 30, (int)p.getY() - 15);
  469.             if(Interfaces.get(81) != null)
  470.                 if(GameTab.getOpen().equals(TABS.COMBAT))
  471.                     for(int i = 0; i < currentDummy.getInterfaceIDs().length; i++) {
  472.                         Rectangle r = Interfaces.get(81, currentDummy.getInterfaceIDs()[i]).getAbsoluteBounds();
  473.                         g1.drawRect(r.x, r.y, r.width, r.height);
  474.                     }
  475.             }
  476.         }
  477.     }
  478.  
  479. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement