示例#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();
  }
示例#2
0
 public int getTurnsRemaining() {
   int remain = this.value - KoLCharacter.getCurrentRun();
   if (remain < 0 && this.wander) {
     this.value = KoLCharacter.getCurrentRun();
     remain = 0;
   }
   return remain;
 }
示例#3
0
  public static final boolean isCounting(final String label, final int start, final int stop) {
    int begin = KoLCharacter.getCurrentRun() + start;
    int end = KoLCharacter.getCurrentRun() + stop;

    synchronized (TurnCounter.relayCounters) {
      for (TurnCounter current : TurnCounter.relayCounters) {
        if (current.parsedLabel.equals(label) && current.value >= begin && current.value <= end) {
          return true;
        }
      }
    }

    return false;
  }
示例#4
0
  public TurnCounter(final int value, final String label, final String image) {
    this.value = KoLCharacter.getCurrentRun() + value;
    this.label = label.replaceAll(":", "");
    this.image = image.replaceAll(":", "");
    this.lastWarned = -1;
    this.parsedLabel = this.label;
    int pos = this.parsedLabel.lastIndexOf(" ");
    while (pos != -1) {
      String word = this.parsedLabel.substring(pos + 1).trim();
      if (word.equals("loc=*")) {
        this.exemptions = TurnCounter.ALL_LOCATIONS;
      } else if (word.startsWith("loc=")) {
        if (this.exemptions == null) {
          this.exemptions = new HashSet<String>();
        }
        this.exemptions.add(word.substring(4));
      } else if (word.startsWith("type=")) {
        if (word.substring(5).equals("wander")) {
          this.wander = true;
        }
      } else if (word.contains(".php")) {
        this.URL = word;
      } else break;

      this.parsedLabel = this.parsedLabel.substring(0, pos).trim();
      pos = this.parsedLabel.lastIndexOf(" ");
    }
    if (this.parsedLabel.length() == 0) {
      this.parsedLabel = "Manual";
    }
  }
示例#5
0
  public static final String getUnexpiredCounters() {
    int currentTurns = KoLCharacter.getCurrentRun();
    StringBuilder counters = new StringBuilder();

    synchronized (TurnCounter.relayCounters) {
      for (TurnCounter current : TurnCounter.relayCounters) {
        if (current.value < currentTurns) {
          // Can't remove the counter - a counterScript
          // may still be waiting for it to be delivered.
          continue;
        }

        if (counters.length() > 0) {
          counters.append(KoLConstants.LINE_BREAK);
        }

        counters.append(current.parsedLabel);
        counters.append(" (");
        counters.append(current.value - currentTurns);
        counters.append(")");
      }
    }

    return counters.toString();
  }
示例#6
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;
  }
示例#7
0
  public static final boolean isCounting(final String label) {
    synchronized (TurnCounter.relayCounters) {
      for (TurnCounter current : TurnCounter.relayCounters) {
        if (current.parsedLabel.equals(label) && current.value >= KoLCharacter.getCurrentRun()) {
          return true;
        }
      }
    }

    return false;
  }
示例#8
0
  public static int turnsRemaining(final String label) {
    synchronized (TurnCounter.relayCounters) {
      for (TurnCounter current : TurnCounter.relayCounters) {
        if (current.parsedLabel.equals(label)) {
          return current.value - KoLCharacter.getCurrentRun();
        }
      }
    }

    return -1;
  }
示例#9
0
  public static final void loadCounters() {
    synchronized (TurnCounter.relayCounters) {
      TurnCounter.relayCounters.clear();

      String counters = Preferences.getString("relayCounters");
      if (counters.length() == 0) {
        return;
      }

      StringTokenizer tokens = new StringTokenizer(counters, ":");
      while (tokens.hasMoreTokens()) {
        int turns = StringUtilities.parseInt(tokens.nextToken()) - KoLCharacter.getCurrentRun();
        if (!tokens.hasMoreTokens()) break;
        String name = tokens.nextToken();
        if (!tokens.hasMoreTokens()) break;
        String image = tokens.nextToken();
        startCountingInternal(turns, name, image);
      }
    }
  }