Esempio 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();
  }
Esempio 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;
  }
Esempio n. 3
0
  public static final void removeWarning(final String label) {
    synchronized (TurnCounter.relayCounters) {
      Iterator<TurnCounter> it = TurnCounter.relayCounters.iterator();

      while (it.hasNext()) {
        TurnCounter counter = it.next();
        if (counter.parsedLabel.equals(label) && counter.exemptions == null) {
          counter.exemptions = TurnCounter.ALL_LOCATIONS;
          counter.label += " loc=*";
        }
      }

      TurnCounter.saveCounters();
    }
  }
Esempio n. 4
0
 public static final void handleTemporaryCounters(final String type, final String encounter) {
   String temp = Preferences.getString("_tempRelayCounters");
   if (temp.equals("")) {
     return;
   }
   int snarfblat = KoLAdventure.lastAdventureId();
   if (snarfblat == 0
       || snarfblat == AdventurePool.THE_SHORE
       || snarfblat == AdventurePool.TRAINING_SNOWMAN
       || snarfblat == AdventurePool.DIRE_WARREN
       || (snarfblat >= AdventurePool.GINGERBREAD_CIVIC
           && snarfblat <= AdventurePool.GINGERBREAD_SEWERS)) {
     return;
   }
   if (type.equals("Combat")) {
     if (EncounterManager.isNoWanderMonster(encounter)) {
       return;
     }
   }
   String[] counters = temp.split("\\|");
   for (String counter : counters) {
     if (counter.equals("")) continue;
     String[] values = counter.split(":");
     TurnCounter.startCounting(StringUtilities.parseInt(values[0]), values[1], values[2]);
   }
   Preferences.setString("_tempRelayCounters", "");
 }
Esempio n. 5
0
  public static final void deleteByHash(final int hash) {
    synchronized (TurnCounter.relayCounters) {
      Iterator<TurnCounter> it = TurnCounter.relayCounters.iterator();

      while (it.hasNext()) {
        if (System.identityHashCode(it.next()) == hash) {
          it.remove();
        }
      }

      TurnCounter.saveCounters();
    }
  }
Esempio n. 6
0
  public static final void stopCounting(final String label) {
    synchronized (TurnCounter.relayCounters) {
      Iterator<TurnCounter> it = TurnCounter.relayCounters.iterator();

      while (it.hasNext()) {
        TurnCounter current = it.next();
        if (current.parsedLabel.equals(label)) {
          it.remove();
        }
      }

      TurnCounter.saveCounters();
    }
  }
Esempio n. 7
0
 public static final void startCounting(final int value, final String label, final String image) {
   synchronized (TurnCounter.relayCounters) {
     TurnCounter.startCountingInternal(value, label, image);
     TurnCounter.saveCounters();
   }
 }
Esempio n. 8
0
 public static final void clearCounters() {
   synchronized (TurnCounter.relayCounters) {
     TurnCounter.relayCounters.clear();
     TurnCounter.saveCounters();
   }
 }