コード例 #1
0
ファイル: TurnCounter.java プロジェクト: holatuwol/kolmafia
  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;
  }
コード例 #2
0
ファイル: Type.java プロジェクト: alexanderkjall/kolmafia
  public Value allValues() {
    if (this.allValues != null) return this.allValues;

    ArrayList<Value> list = new ArrayList<Value>();
    switch (this.type) {
      case DataTypes.TYPE_BOOLEAN:
        this.addValues(list, DataTypes.BOOLEANS);
        break;
      case DataTypes.TYPE_ITEM:
        int limit = ItemDatabase.maxItemId();
        for (int i = 1; i <= limit; ++i) {
          if (i != 13 && ItemDatabase.getItemDataName(i) != null) {
            list.add(DataTypes.makeItemValue(i));
          }
        }
        break;
      case DataTypes.TYPE_LOCATION:
        this.addValues(list, AdventureDatabase.getAsLockableListModel());
        break;
      case DataTypes.TYPE_CLASS:
        this.addValues(list, DataTypes.CLASSES);
        break;
      case DataTypes.TYPE_STAT:
        this.addValues(list, DataTypes.STATS, 0, 3);
        break;
      case DataTypes.TYPE_SKILL:
        this.addValues(list, SkillDatabase.entrySet());
        break;
      case DataTypes.TYPE_EFFECT:
        this.addValues(list, EffectDatabase.entrySet());
        break;
      case DataTypes.TYPE_FAMILIAR:
        this.addValues(list, FamiliarDatabase.entrySet());
        break;
      case DataTypes.TYPE_SLOT:
        this.addValues(list, EquipmentRequest.slotNames);
        break;
      case DataTypes.TYPE_MONSTER:
        this.addValues(list, MonsterDatabase.entrySet());
        break;
      case DataTypes.TYPE_ELEMENT:
        this.addValues(list, MonsterDatabase.elementNames, 1, -1);
        break;
      case DataTypes.TYPE_COINMASTER:
        this.addValues(list, CoinmasterRegistry.MASTERS);
        break;
      case DataTypes.TYPE_PHYLUM:
        this.addValues(list, MonsterDatabase.phylumNames, 1, -1);
        break;
      default:
        return null;
    }
    this.allValues = new PluralValue(this, list);
    return this.allValues;
  }
コード例 #3
0
  /**
   * Initializes the <code>KoLmafia</code> session. Called after the login has been confirmed to
   * notify that the login was successful, the user-specific settings should be loaded, and the user
   * can begin adventuring.
   */
  public static void initialize(final String username) {
    // Load the JSON string first, so we can use it, if necessary.
    ActionBarManager.loadJSONString();

    // Initialize the variables to their initial states to avoid
    // null pointers getting thrown all over the place

    // Do this first to reset per-player item aliases
    ItemDatabase.reset();

    KoLCharacter.reset(username);

    // Get rid of cached password hashes in KoLAdventures
    AdventureDatabase.refreshAdventureList();

    // Reset all per-player information

    ChatManager.reset();
    MailManager.clearMailboxes();
    StoreManager.clearCache();
    DisplayCaseManager.clearCache();
    ClanManager.clearCache();

    CampgroundRequest.reset();
    MushroomManager.reset();
    HermitRequest.initialize();
    SpecialOutfit.forgetCheckpoints();

    KoLmafia.updateDisplay("Initializing session for " + username + "...");
    Preferences.setString("lastUsername", username);

    // Perform requests to read current character's data

    StaticEntity.getClient().refreshSession();

    // Reset the session tally and encounter list

    StaticEntity.getClient().resetSession();

    // Open the session log and indicate that we've logged in.

    RequestLogger.openSessionLog();

    if (Preferences.getBoolean("logStatusOnLogin")) {
      KoLmafiaCLI.DEFAULT_SHELL.executeCommand("log", "snapshot");
    }

    // If the password hash is non-null, then that means you
    // might be mid-transition.

    if (GenericRequest.passwordHash.equals("")) {
      PasswordHashRequest request = new PasswordHashRequest("lchat.php");
      RequestThread.postRequest(request);
    }

    ContactManager.registerPlayerId(username, String.valueOf(KoLCharacter.getUserId()));

    if (Preferences.getString("spadingData").length() > 10) {
      KoLmafia.updateDisplay(
          "Some data has been collected that may be of interest "
              + "to others.  Please type `spade' to examine and submit or delete this data.");
    }

    // Rebuild Scripts menu if needed
    GenericFrame.compileScripts();

    if (StaticEntity.getClient() instanceof KoLmafiaGUI) {
      KoLmafiaGUI.intializeMainInterfaces();
    } else if (Preferences.getString("initialFrames").indexOf("LocalRelayServer") != -1) {
      KoLmafiaGUI.constructFrame("LocalRelayServer");
    }

    String updateText;

    String holiday = HolidayDatabase.getHoliday(true);
    String moonEffect = HolidayDatabase.getMoonEffect();

    if (holiday.equals("")) {
      updateText = moonEffect;
    } else {
      updateText = holiday + ", " + moonEffect;
    }

    KoLmafia.updateDisplay(updateText);

    if (MailManager.hasNewMessages()) {
      KoLmafia.updateDisplay("You have new mail.");
    }
  }