Advertisement
andee

MollySolver

Aug 20th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.33 KB | None | 0 0
  1. package org.vinsert.api.random.impl;
  2.  
  3. import org.vinsert.api.event.EventHandler;
  4. import org.vinsert.api.random.LoginRequired;
  5. import org.vinsert.api.random.RandomManifest;
  6. import org.vinsert.api.collection.Filter;
  7. import org.vinsert.api.event.MessageEvent;
  8. import org.vinsert.api.event.PaintEvent;
  9. import org.vinsert.api.random.RandomSolver;
  10. import org.vinsert.api.util.Utilities;
  11. import org.vinsert.api.wrappers.GameObject;
  12. import org.vinsert.api.wrappers.Npc;
  13. import org.vinsert.api.wrappers.Widget;
  14.  
  15. import java.awt.*;
  16.  
  17. @LoginRequired
  18. @RandomManifest(name = "Molly Solver", author = "ande", version = 0.1)
  19. public class MollyRandom extends RandomSolver {
  20.  
  21.     private Npc molly, suspect;
  22.     private GameObject claw, controlPanel;
  23.     private int modelId = 0;
  24.     private boolean usingControls = false, inRoom = false, done = false;
  25.     private int suspectX, suspectY, clawX, clawY;
  26.     private String debug = "";
  27.  
  28.     @Override
  29.     public boolean canRun() {
  30.         return npcs.find("Molly").single() != null || npcs.find("Suspect").single() != null;
  31.     }
  32.  
  33.     @Override
  34.     public void reset(){
  35.         molly = null;
  36.         suspect = null;
  37.         claw = null;
  38.         controlPanel = null;
  39.         modelId = 0;
  40.         usingControls = false;
  41.         inRoom = false;
  42.         done = false;
  43.         debug = "";
  44.     }
  45.  
  46.     @Override
  47.     public int run() {
  48.         if(!done) {
  49.             controlPanel = objects.find("Control panel").single();
  50.             usingControls = widgets.find().group(240).single() != null;
  51.             claw = objects.find("Evil claw").single();
  52.             suspect = npcs.find().filter(new Filter<Npc>() {
  53.                 @Override
  54.                 public boolean accept(Npc acceptable) {
  55.                     return acceptable.getComposite().getModelIds()[0] == modelId;
  56.                 }
  57.             }).single();
  58.  
  59.             if (modelId == 0) {
  60.                 debug = "Getting model id";
  61.                 molly = npcs.find("Molly").single();
  62.                 if (molly != null) {
  63.                     modelId = molly.getComposite().getModelIds()[0];
  64.                 }
  65.             } else if (!inRoom) {
  66.                 debug = "Entering room";
  67.                 GameObject door = objects.find("Door").single();
  68.                 if (door.isValid()) {
  69.                     switch (door.interact("Open")) {
  70.                         case NOT_ON_SCREEN:
  71.                             camera.turnTo(door);
  72.                             break;
  73.                     }
  74.                     Utilities.sleep(1200,1500);
  75.                 }
  76.                 while (inDialogue()) {
  77.                     completeDialogue();
  78.                 }
  79.                 if (walking.canReach(controlPanel)) {
  80.                     inRoom = true;
  81.                 }
  82.             }
  83.  
  84.             if (inRoom) {
  85.                 debug = "Catching Evil Twin";
  86.                 catchTwin();
  87.             }
  88.  
  89.         }else{
  90.             debug = "Finishing";
  91.             molly = npcs.find("Molly").single();
  92.             if(molly != null) {
  93.                 if (!walking.canReach(molly)) {
  94.                     GameObject door = objects.find("Door").single();
  95.                     if (door.isValid()) {
  96.                         switch (door.interact("Open")) {
  97.                             case NOT_ON_SCREEN:
  98.                                 camera.turnTo(door);
  99.                                 break;
  100.                         }
  101.                         Utilities.sleep(1200);
  102.                     }
  103.                 } else {
  104.                     molly.interact("Talk-to");
  105.                     while (inDialogue()) {
  106.                         completeDialogue();
  107.                     }
  108.                 }
  109.             }
  110.         }
  111.         return 200;
  112.     }
  113.  
  114.     public void catchTwin(){
  115.         if(suspect != null) {
  116.             suspectX = suspect.getX();
  117.             suspectY = suspect.getY();
  118.         }
  119.         if(claw != null) {
  120.             clawX = claw.getX();
  121.             clawY = claw.getY();
  122.         }
  123.  
  124.         if(controlPanel != null && !usingControls){
  125.             switch (controlPanel.interact("Use")){
  126.                 case NOT_ON_SCREEN:
  127.                     camera.turnTo(controlPanel);
  128.                     break;
  129.             }
  130.         }else{
  131.             if(suspectX - clawX > 0){
  132.                 useControl("left");
  133.             }else if(suspectX - clawX < 0){
  134.                 useControl("right");
  135.             }
  136.  
  137.             if(suspectY - clawY > 0){
  138.                 useControl("down");
  139.             }else if(suspectY - clawY < 0){
  140.                 useControl("up");
  141.             }
  142.             if(clawX == suspectX && clawY == suspectY){
  143.                 useControl("catch");
  144.             }
  145.         }
  146.     }
  147.  
  148.     public void useControl(String direction){
  149.         switch (direction){
  150.             case "up":
  151.                 widgets.find(240,6).single().interact("Ok");
  152.                 break;
  153.             case "down":
  154.                 widgets.find(240,11).single().interact("Ok");
  155.                 break;
  156.             case "left":
  157.                 widgets.find(240,16).single().interact("Ok");
  158.                 break;
  159.             case "right":
  160.                 widgets.find(240,21).single().interact("Ok");
  161.                 break;
  162.             case "catch":
  163.                 widgets.find(240,23).single().interact("Ok");
  164.                 break;
  165.         }
  166.         Utilities.sleep(200);
  167.     }
  168.  
  169.     public void completeDialogue(){
  170.         if(widgets.canContinue()){
  171.             widgets.clickContinue();
  172.             Utilities.sleep(600);
  173.         }
  174.         Widget option = widgets.find().text("Yes").single();
  175.         if(option != null && option.isValid()){
  176.             option.interact("Continue");
  177.         }
  178.     }
  179.  
  180.     public boolean inDialogue(){
  181.         return widgets.find(241,0).single() != null || widgets.find(242,0).single() != null || widgets.canContinue() || widgets.find().text("Select an Option").single() != null;
  182.     }
  183.  
  184.     @EventHandler
  185.     public void onMessage(MessageEvent evt) {
  186.         if(evt.getMessage().equals("You caught the Evil twin!")){
  187.             done = true;
  188.         }
  189.     }
  190.  
  191.     @EventHandler
  192.     public void onPaint(PaintEvent event) {
  193.         Graphics2D g = (Graphics2D) event.getGraphics();
  194.         g.setColor(Color.YELLOW);
  195.         g.drawString("Solving Molly.",10,80);
  196.         g.drawString(debug,10,100);
  197.     }
  198.  
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement