コード例 #1
0
ファイル: Account.java プロジェクト: Trowy/Travianize
  public void update() {

    if (!tasks.isEmpty() && tasks.peek().time < (int) (System.currentTimeMillis() / 1000)) {

      Task task = tasks.peek();
      try {

        if (task instanceof UpgradingFieldTask) {
          connection.upgradingField(((UpgradingFieldTask) task).idField);
        } else if (task instanceof UpgradingBuildingTask) {
          connection.upgradingBuilding(((UpgradingBuildingTask) task).idField);
        }
      } catch (LoadHttpPageException ex) {
        Logger.info("Can't load page");
        return;
      } catch (LoginException ex) {
        Logger.info("Can't login again. Was account information change?");
        return;
      } catch (UpgradingAvailableException ex) {
        if (buildingProductions != null && buildingProductions.length != 0) {
          int time = buildingProductions[buildingProductions.length - 1];
          task.time = buildingProductionsLastUpdate + time + 10;
          Logger.info("Already upgrading filed. Wait " + time + " sec");
        } else {

          UpgradingFieldPage page = ex.getUpgradingFieldPage();
          if (page.requiredResourses != null && resources != null && productions != null) {
            int time = 0;

            for (int i = 0; i < 4; i++) {
              int resorceTime =
                  (int)
                          Math.floor(
                              (page.requiredResourses[i] - resources[i])
                                  / (double) productions[i]
                                  * 3600)
                      + resourcesLastUpdate;

              if (time < resorceTime) {
                time = resorceTime;
              }
            }
            Logger.info("Wait resource to " + time + " ");
            task.time = time + 60;
          } else {
            task.time = task.time + 300;
          }
        }

        return;
      }
      tasks.poll();
    }
  }
コード例 #2
0
ファイル: Account.java プロジェクト: Trowy/Travianize
  public Account(String serverHostName, String login, String password) throws LoginException {

    this.login = login;
    this.password = password;
    this.host = serverHostName;

    try {
      connection = new TravianConnector(serverHostName, this);

      try {
        Logger.info("Try login...");
        connection.login(login, password);
        // Logger.info("Load tasks from file 'task_" + serverHostName + "_" + login + ".txt'");
        // tasks = loadTaskFromFile("task_" + serverHostName + "_" + login + ".txt");

      } catch (LoadHttpPageException e) {
        Logger.info("Can't load page");
        throw new LoginException();
      }

      Logger.info(
          "Success creation account '"
              + login
              + "', password: '******' for host '"
              + serverHostName
              + "'");

    } catch (UnknownHostException ex) {
      Logger.info("Unknown Host '" + serverHostName + "'");
      throw new LoginException();
    }
  }