Esempio n. 1
0
  public static final TurnCounter getExpiredCounter(GenericRequest request, boolean informational) {
    String URL = request.getURLString();
    KoLAdventure adventure = AdventureDatabase.getAdventureByURL(URL);

    String adventureId;
    int turnsUsed;

    if (adventure != null) {
      adventureId = adventure.getAdventureId();
      turnsUsed = adventure.getRequest().getAdventuresUsed();
    } else if (AdventureDatabase.getUnknownName(URL) != null) {
      adventureId = "";
      turnsUsed = 1;
    } else {
      adventureId = "";
      turnsUsed = TurnCounter.getTurnsUsed(request);
    }

    if (turnsUsed == 0) {
      return null;
    }

    int thisTurn = KoLCharacter.getCurrentRun();
    int currentTurns = thisTurn + turnsUsed - 1;

    synchronized (TurnCounter.relayCounters) {
      Iterator<TurnCounter> it = TurnCounter.relayCounters.iterator();

      while (it.hasNext()) {
        TurnCounter current = it.next();

        if (current.value > currentTurns
            || current.lastWarned == thisTurn
            || current.isExempt(adventureId) != informational) {
          continue;
        }

        if (informational
            && current.value > thisTurn) { // Defer until later, there's no point in reporting an
          // informational counter prior to actual expiration.
          continue;
        }

        if (current.value < thisTurn) {
          if (current.wander) {
            // This might not actually be necessary
            continue;
          }
          it.remove();
        }

        current.lastWarned = thisTurn;
        return current;
      }
    }

    return null;
  }
Esempio n. 2
0
  public static void logout() {
    if (LogoutManager.isRunning) {
      return;
    }

    LogoutManager.isRunning = true;

    // If there's no user to worry about, we're done now.

    String userName = KoLCharacter.getUserName();

    if (userName == null || userName.equals("")) {
      return;
    }

    if (!KoLmafia.isSessionEnding()) {
      LogoutManager.prepare();
    }

    KoLmafia.updateDisplay("Preparing for logout...");

    // Shut down chat-related activity

    BuffBotHome.setBuffBotActive(false);
    ChatManager.dispose();

    // Run on-logout scripts

    String scriptSetting = Preferences.getString("logoutScript");
    if (!scriptSetting.equals("")) {
      KoLmafia.updateDisplay("Executing logout script...");
      KoLmafiaCLI.DEFAULT_SHELL.executeLine(scriptSetting);
    }

    if (Preferences.getBoolean("sharePriceData")) {
      KoLmafia.updateDisplay("Sharing mall price data with other users...");
      KoLmafiaCLI.DEFAULT_SHELL.executeLine(
          "spade prices http://kolmafia.us/scripts/updateprices.php");
    }

    // Clear out user data

    RequestLogger.closeSessionLog();
    RequestLogger.closeMirror();

    GenericRequest.reset();
    KoLCharacter.reset("");

    // Execute the logout request

    RequestThread.postRequest(new LogoutRequest());
    KoLmafia.updateDisplay("Logout completed.");

    RequestLogger.closeDebugLog();

    LogoutManager.isRunning = false;
  }
Esempio n. 3
0
  public static final void printRequestData(final GenericRequest request) {
    if (request == null) {
      return;
    }

    boolean shouldOpenStream = !RequestLogger.isDebugging();
    if (shouldOpenStream) {
      RequestLogger.openDebugLog();
    }

    RequestLogger.updateDebugLog();
    RequestLogger.updateDebugLog("" + request.getClass() + ": " + request.getURLString());
    RequestLogger.updateDebugLog(
        KoLConstants.LINE_BREAK_PATTERN.matcher(request.responseText).replaceAll(""));
    RequestLogger.updateDebugLog();

    if (shouldOpenStream) {
      RequestLogger.closeDebugLog();
    }
  }
Esempio n. 4
0
  private static final int getTurnsUsed(GenericRequest request) {
    if (!(request instanceof RelayRequest)) {
      return request.getAdventuresUsed();
    }

    String urlString = request.getURLString();

    if (urlString.startsWith("adventure.php")) {
      // Assume unknown adventure locations take 1 turn each
      // This is likely not true under the Sea, for example,
      // but it's as good a guess as any we can make.

      return 1;
    }

    if (urlString.startsWith("inv_use.php") || urlString.startsWith("inv_eat.php")) {
      return UseItemRequest.getAdventuresUsed(urlString);
    }

    if (urlString.startsWith("runskillz.php")) {
      return UseSkillRequest.getAdventuresUsed(urlString);
    }

    if (urlString.startsWith("craft.php") || urlString.startsWith("guild.php")) {
      return CreateItemRequest.getAdventuresUsed(request);
    }

    if (urlString.startsWith("place.php?whichplace=chateau")
        && urlString.contains("action=chateau_painting")) {
      return Preferences.getBoolean("_chateauMonsterFought") ? 0 : 1;
    }

    if (urlString.startsWith("crimbo09.php")) {
      return Crimbo09Request.getTurnsUsed(request);
    }

    return 0;
  }
  public static final void solve() {
    if (DvorakDecorator.lastResponse == null) {
      KoLmafia.updateDisplay(MafiaState.ERROR, "You don't appear to be at the tiles puzzle");
      return;
    }

    // Examine the tiles and figure out which row we are on.
    KoLmafia.updateDisplay("Examining tiles...");

    char[][] tiles = new char[7][9];
    int currentRow = 0;

    Matcher matcher = DvorakDecorator.TILE_PATTERN.matcher(DvorakDecorator.lastResponse);
    int count = 0;
    while (matcher.find()) {
      int row = count / 9;
      int column = count % 9;
      if (row > 7) {
        KoLmafia.updateDisplay("Too many rows!");
        return;
      }
      if (matcher.group(1).equals("cell")) {
        currentRow = row;
      }
      tiles[row][column] = matcher.group(2).charAt(0);
      count++;
    }

    if (count != (7 * 9)) {
      KoLmafia.updateDisplay("Wrong number of cells!");
      return;
    }

    /*
    StringBuffer buffer = new StringBuffer();
    for ( int row = 0; row < 7; ++row )
    {
    	buffer.setLength( 0 );
    	buffer.append( "Row " );
    	buffer.append( String.valueOf( row + 1 ) );
    	buffer.append( ": " );
    	for ( int col = 0; col < 9; ++col )
    	{
    		buffer.append( tiles[ row ][ col ] );
    		buffer.append( " " );
    	}
    	if ( row == currentRow )
    	{
    		buffer.append( " ---you are here" );
    	}
    	RequestLogger.printLine( buffer.toString() );
    }
    */

    // Execute requests to jump to the end.
    String solution = "BANANAS";

    GenericRequest request = new GenericRequest("");
    for (int row = currentRow; row >= 0; --row) {
      char match = solution.charAt(6 - row);
      int found = -1;
      for (int col = 0; col < 9; ++col) {
        char tile = tiles[row][col];
        if (match == tile) {
          found = col;
          break;
        }
      }
      if (found == -1) {
        KoLmafia.updateDisplay("Could not find '" + match + "' in row " + (row + 1));
        return;
      }

      String url = "tiles.php?action=jump&whichtile=" + found;
      request.constructURLString(url).run();
    }

    KoLmafia.updateDisplay("Tile puzzle completed.");

    StringBuffer buffer = new StringBuffer(request.responseText);
    RequestEditorKit.getFeatureRichHTML(request.getURLString(), buffer);
    RelayRequest.specialCommandResponse = buffer.toString();
    RelayRequest.specialCommandIsAdventure = true;
    DvorakDecorator.lastResponse = null;
  }