Ejemplo n.º 1
0
  public static final String getCounters(String label, int minTurns, int maxTurns) {
    label = label.toLowerCase();
    boolean checkExempt = label.length() == 0;
    minTurns += KoLCharacter.getCurrentRun();
    maxTurns += KoLCharacter.getCurrentRun();
    StringBuilder buf = new StringBuilder();

    synchronized (TurnCounter.relayCounters) {
      for (TurnCounter current : TurnCounter.relayCounters) {
        if (current.value < minTurns || current.value > maxTurns) {
          continue;
        }
        if (checkExempt && current.isExempt("")) {
          continue;
        }
        if (!current.parsedLabel.toLowerCase().contains(label)) {
          continue;
        }
        if (buf.length() != 0) {
          buf.append("\t");
        }
        buf.append(current.parsedLabel);
      }
    }

    return buf.toString();
  }
Ejemplo n.º 2
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;
  }