Package alexoft.OGameUltimate

Source Code of alexoft.OGameUltimate.OGameUltimate

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alexoft.OGameUltimate;

import jline.ConsoleReader;
import alexoft.OGame.BuildItem;
import alexoft.OGame.OGame;
import alexoft.OGame.OGamePlanet;
import alexoft.OGameUltimate.proxy.Proxy;

/**
*
* @author Alexandre
*/
public class OGameUltimate {
  public static ConsoleReader reader;
  public boolean running;
  public OGame api;

  public OGameUltimate(String user, String pass, String univ) {
    this.running = true;
    api = new OGame();
    // api.login("test", "12345678", "uni112.ogame.fr");
    api.login(user, pass, univ + ".ogame.fr");
    // api.login("Areku", "22021993", "uni50.ogame.fr");
    System.out.println("Ogame version " + api.getOGameVersion());
    System.out.println(api.getPlanets().size() + " planet(s)");
  }

  public void showPlanet(int index) {
    if (api.getPlanets().size() < index) {
      System.out.println("There is no planet no." + index);
    } else {
      System.out.println(api.getPlanets().get(index - 1).toString());
    }
  }

  public void showAll() {
    for (OGamePlanet p : api.getPlanets()) {
      System.out.println(p.toString());
    }
  }

  public void updateAll() {
    System.out.println("Updating all planets...");
    api.getResources();
  }

  public void updatePlanet(int index) {
    if (api.getPlanets().size() < index) {
      System.out.println("There is no planet no." + index);
    } else {
      OGamePlanet p = api.getPlanets().get(index - 1);
      System.out.println("Updating " + p.name);
      api.getResources(p, true);
    }
  }

  public void build(int index, String page, String item) {
    if (api.getPlanets().size() < index) {
      System.out.println("There is no planet no." + index);
    } else {
      api.tryBuild(api.getPlanets().get(index - 1), page, item);
    }
  }

  public void showBuildList() {
    if (api.getQueue().size() == 0) {
      System.out.println("Empty queue");
      return;
    }
    System.out.println("Build queue :");
    Object[] l = api.getQueue().toArray();
    for (int i = 0; i < api.getQueue().size(); i++) {
      System.out.println("\t" + i + ") " + ((BuildItem) l[i]).toString());
    }
  }

  public void stop() {
    this.running = false;
  }

  /**
   * @param args
   *            the command line arguments
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    if (args.length != 3) {
      System.out.println("Args format : <user> <pass> <univ>");
      return;
    }
    reader = new ConsoleReader();
    jline.Terminal.getTerminal().initializeTerminal();
    reader.setDefaultPrompt(">");
    System.out.println("Loading Ogame Ultimate");
    OGameUltimate ogameUltimate = new OGameUltimate(args[0], args[1],
        args[2]);
    Proxy p = new Proxy();
    p.baseURL = args[2];
    String c[];

    while (ogameUltimate.running) {
      c = reader.readLine().split(" ");
      if (c[0].equals("stop")) {
        ogameUltimate.stop();
      } else if (c[0].equals("show")) {
        if (c.length == 1) {
          System.out.println("Command format error");
        } else {
          if (c[1].equals("all")) {
            ogameUltimate.showAll();
          } else {
            try {
              int i = Integer.parseInt(c[1]);
              if (i < 1) {
                System.out.println("Command format error");
              } else {
                ogameUltimate.showPlanet(i);
              }
            } catch (NumberFormatException e) {
              System.out.println("Command format error");
            }
          }
        }
      } else if (c[0].equals("update")) {
        if (c.length == 1) {
          System.out.println("Command format error");
        } else {
          if (c[1].equals("all")) {
            ogameUltimate.updateAll();
          } else {
            try {
              int i = Integer.parseInt(c[1]);
              if (i < 1) {
                System.out.println("Command format error");
              } else {
                ogameUltimate.updatePlanet(i);
              }
            } catch (NumberFormatException e) {
              System.out.println("Command format error");
            }
          }
        }
      } else if (c[0].equals("add")) {
        if (c.length != 4) {
          System.out.println("Command format error");
        } else {
          try {
            int i = Integer.parseInt(c[1]);
            if (i < 1) {
              System.out.println("Command format error");
            } else {
              ogameUltimate.build(i, c[2], c[3]);
            }
          } catch (NumberFormatException e) {
            System.out.println("Command format error");
          }
        }
      } else if (c[0].equals("queue")) {
        if (c.length == 2) {
          if (c[1].equals("show")) {
            ogameUltimate.showBuildList();
          } else {
            System.out.println("Command format error");
          }
        } else {
          System.out.println("Command format error");
        }
      } else {
        System.out.println("Unknown command");
      }
    }
    System.exit(0);
  }
}
TOP

Related Classes of alexoft.OGameUltimate.OGameUltimate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.