import bot.*;
public class AdmarFish extends Methods {
    long startTime;
    int fishLured, fails;
    
    public AdmarFish(Client mc) {super(mc);}
    public void main(String args[]) {
        startTime = System.currentTimeMillis();
        printMessage("@or2@Fisher: @yel@Admar swordfish fisher started");
        while(running()) {
            try {
         if(inventoryCount() < 30 && !paused()) {
					if(fatigue() >= 90L) {
						doSleep();
					}
                          
                             if ((fatigue() >= 80L) && (fatigue() <= 90L)) doSleep();
                             if (fatigue() >= 93L) stop();         
                    int[] pool = getObjectIndex(1219);
                    if(pool[0] != -1) {
                        useObject(pool[1], pool[2]);
                        wait(random(3000, 4000));
                    }
                    wait(50);
                }
                // walk to bank
                int x = random(225, 224);
                int y = random(846, 847);
                while(!imAt(x, y) && !paused()) {
                    walkTo(x, y);
                    wait(random(1000, 2000));
                }
                x = random(213, 214);
                y = random(846, 847);
                if(!imAt(x, y) && !paused()) {
                    walkTo(x, y);
                    wait(random(1000, 2000));
                }
                //do banking
                if(!questionMenu() && !paused()) {
                    talkToNPC(getNPCIndex(95)[0]);
                    wait(random(3000, 4000));
                }
                answerQuestion(0);
                if(!inBank())
                    wait(1000);
                if(mc.method58(369) > 0) {
                    depositAll(369);
                    wait(random(500, 1500));
                }
                wait(random(500, 1500));
                closeBank();
                // walk back
                x = random(231, 232);
                y = random(842, 844);
                if(!imAt(x, y) && !paused()) {
                    walkTo(x, y);
                    wait(random(1000, 2000));
                }
                x = random(244, 244);
                y = random(841, 841);
               if(!imAt(x, y) && !paused()) {
                    walkTo(x, y);
                    wait(random(1000, 2000));
                }
            }
            catch(Exception e) {}
        }
    }
    
    public void onStop() {
        handleCommand("status");
        printMessage("@or2@Fisher: @yel@stopped");
    }
    
    public boolean onServerMessage(String s) {
        s = s.toLowerCase();
        if(s.contains("you catch a")) {
            fishLured ++;
            return true;
        }
        else if(s.contains("you attempt to catch some"))
            return true;
        else if(s.contains("you fail to catch anything")) {
            fails ++;
            return true;
        }
        
        return false;
    }
   
   
    public void onChatMessage(int modstatus, String name, String message) {
        String s = name.toLowerCase();
        if (modstatus != 4 && modstatus != 7) {
        printMessage("@red@Warning: @whi@Mod detected!");
        }
    }

    public void modProtection() {  
        if (fatigue() == 100) {  
        printMessage("@red@A Mod has fatigued you!");  
        stop();  
        }  
    } 
      

    public void handleCommand(String s) {
        int index = s.indexOf(" ");
        String cmd = s;
        String args[] = new String[0];
        if(index != -1) {
            cmd = s.substring(0, index).trim();
            args = s.substring(index + 1).trim().split(" ");
        }
        
        if(cmd.equals("status")) {
            printMessage("@or2@Fisher: @yel@been running for: @or2@" + timeSince(startTime) + " @yel@fish lured: @or2@" + fishLured + " @yel@fails: @or2@" + fails);
        }
    }
}










