Exemple #1
0
 @Override
 public boolean specialCase(Writer writer, Prerequisite prereq) throws IOException {
   if (prereq.getKind() != null) {
     return false;
   }
   String handled = kindHandled();
   String count = prereq.getOperand();
   try {
     int i = Integer.parseInt(count);
     if (prereq.getPrerequisiteCount() != i) {
       return false;
     }
   } catch (NumberFormatException e) {
     return false;
   }
   PrerequisiteOperator oper = null;
   for (Prerequisite p : prereq.getPrerequisites()) {
     //
     // ...with all PREARMORTYPE entries...
     //
     if (!handled.equalsIgnoreCase(p.getKind())) {
       return false;
     }
     //
     // ...and the same operator...
     //
     if (oper == null) {
       oper = p.getOperator();
     } else {
       if (!oper.equals(p.getOperator())) {
         return false;
       }
     }
   }
   writer.write("PREVAR");
   if (prereq.getOperator() == PrerequisiteOperator.LT) {
     writer.write(oper.invert().toString().toUpperCase());
   } else {
     writer.write(oper.toString().toUpperCase());
   }
   writer.write(':' + (prereq.isOverrideQualify() ? "Q:" : ""));
   boolean first = true;
   for (Prerequisite p : prereq.getPrerequisites()) {
     if (!first) {
       writer.write(',');
     }
     writer.write(p.getKey());
     writer.write(',');
     writer.write(p.getOperand());
     first = false;
   }
   return true;
 }
Exemple #2
0
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
   */
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source)
      throws PrerequisiteException {
    int runningTotal;
    try {
      final int targetHands = Integer.parseInt(prereq.getOperand());

      runningTotal = prereq.getOperator().compare(display.getHands(), targetHands);
    } catch (NumberFormatException nfe) {
      throw new PrerequisiteException(
          LanguageBundle.getFormattedString(
              "PreHands.error.badly_formed", prereq.getOperand())); // $NON-NLS-1$
    }
    return countedTotal(prereq, runningTotal);
  }
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#toHtmlString(pcgen.core.prereq.Prerequisite)
   */
  @Override
  public String toHtmlString(final Prerequisite prereq) {
    // Simplify the output when requiring a single source
    if (prereq.getOperator() == PrerequisiteOperator.GTEQ && ("1".equals(prereq.getOperand()))) {
      return prereq.getKey();
    }

    final String foo =
        LanguageBundle.getFormattedString(
            "PreFact.toHtml", //$NON-NLS-1$
            new Object[] {
              prereq.getOperator().toDisplayString(), prereq.getOperand(), prereq.getKey()
            });
    return foo;
  }
 /**
  * Process prereq keys wrapped in []. If the key is wrapped in [], the prereq will be negated to
  * check that the prereq is not passed, and the number of required matches is increased by the
  * number of negated tests. Can handle nested prereqs.
  *
  * @param prereq The prereq to be negated.
  */
 private void negateCampaignChoice(Prerequisite prereq) {
   int modified = 0;
   for (Prerequisite p : prereq.getPrerequisites()) {
     if (p.getKind() == null) // PREMULT
     {
       negateCampaignChoice(p);
     } else {
       String preKey = p.getKey();
       if (preKey.startsWith("[") && preKey.endsWith("]")) {
         preKey = preKey.substring(1, preKey.length() - 1);
         p.setKey(preKey);
         p.setOperator(p.getOperator().invert());
         ++modified;
       }
     }
   }
   if (modified > 0) {
     String oper = prereq.getOperand();
     try {
       oper = Integer.toString(Integer.parseInt(oper) + modified);
     } catch (NumberFormatException nfe) {
       oper = "(" + oper + ")+" + Integer.toString(modified);
     }
     prereq.setOperand(oper);
   }
 }
Exemple #5
0
 /* (non-Javadoc)
  * @see pcgen.core.prereq.PrerequisiteTest#toHtmlString(pcgen.core.prereq.Prerequisite)
  */
 @Override
 public String toHtmlString(final Prerequisite prereq) {
   return LanguageBundle.getFormattedString(
       "PreDeityAlign.toHtml",
       prereq.getOperator().toDisplayString(),
       getPCAlignment(prereq.getOperand()).getKeyName()); // $NON-NLS-1$
 }
Exemple #6
0
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
   */
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {

    //
    // If game mode doesn't support alignment, then pass the prereq
    //
    int runningTotal = 0;

    if (Globals.getGameModeAlignmentText().length() == 0) {
      runningTotal = 1;
    } else {
      CDOMSingleRef<PCAlignment> deityAlign = null; // $NON-NLS-1$
      Deity deity = display.getDeity();
      if (deity != null) {
        deityAlign = deity.get(ObjectKey.ALIGNMENT);
      }
      if (deityAlign != null) {
        String desiredAlignIdentifier = prereq.getOperand();
        PCAlignment desiredAlign = getPCAlignment(desiredAlignIdentifier);

        if (desiredAlign.equals(deityAlign.get())) {
          runningTotal = 1;
        }
      }
    }

    return countedTotal(prereq, runningTotal);
  }
  /* (non-Javadoc)
   * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
   */
  @Override
  public int passes(final Prerequisite prereq, final PlayerCharacter aPC, CDOMObject source)
      throws PrerequisiteException {
    final int number;
    try {
      number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException exceptn) {
      throw new PrerequisiteException(
          LanguageBundle.getFormattedString("PreFact.error", prereq.toString())); // $NON-NLS-1$
    }

    String location = prereq.getCategoryName();
    String[] locationElements = location.split("\\.");
    Iterable<Reducible> objModel =
        (Iterable<Reducible>) OutputDB.getIterable(aPC.getCharID(), locationElements);
    if (objModel == null) {
      throw new PrerequisiteException("Output System does not have model for: " + location);
    }

    String[] factinfo = prereq.getKey().split("=");
    FactKey<?> fk = FactKey.valueOf(factinfo[0]);
    Object targetVal = fk.getFormatManager().convertIndirect(factinfo[1]);

    int runningTotal = 0;
    for (Reducible r : objModel) {
      Indirect<?> cdoVal = r.getCDOMObject().get(fk);
      if (targetVal.equals(cdoVal)) {
        runningTotal++;
      }
    }

    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
   */
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {
    final int reqnumber = Integer.parseInt(prereq.getOperand());
    final String requiredRaceType = prereq.getKey();
    int runningTotal = 0;

    try {
      RaceType preRaceType = RaceType.valueOf(requiredRaceType);
      if (preRaceType.equals(display.getRace().get(ObjectKey.RACETYPE))) {
        runningTotal++;
      }
    } catch (IllegalArgumentException e) {
      // Can't match
    }
    if (getCritterType(display).indexOf(requiredRaceType) >= 0) {
      runningTotal++;
    }
    runningTotal = prereq.getOperator().compare(runningTotal, reqnumber);
    return countedTotal(prereq, runningTotal);
  }
Exemple #9
0
 /*
  * (non-Javadoc)
  *
  * @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer,
  *      pcgen.core.prereq.Prerequisite)
  */
 @Override
 public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
   try {
     writer.write("PREVAR");
     writer.write(prereq.getOperator().toString().toUpperCase());
     writer.write(':' + (prereq.isOverrideQualify() ? "Q:" : ""));
     writer.write(prereq.getKey());
     writer.write(',');
     writer.write(prereq.getOperand());
     // for (Iterator iter = prereq.getPrerequisites().iterator();
     // iter.hasNext(); )
     // {
     // final Prerequisite p = (Prerequisite) iter.next();
     // writer.write(',');
     // writer.write(p.getKey());
     // writer.write(',');
     // writer.write(p.getOperand());
     // }
   } catch (IOException e) {
     throw new PersistenceLayerException(e.getMessage());
   }
 }
Exemple #10
0
  // TODO Refactor this with all the equipment tests.
  @Override
  public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source)
      throws PrerequisiteException {
    final int number;
    try {
      number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException e) {
      throw new PrerequisiteException(
          LanguageBundle.getFormattedString(
              "PreItem.error.bad_operand", prereq.toString())); // $NON-NLS-1$
    }

    int runningTotal = 0;

    if (display.hasEquipment()) {
      // Work out exactlywhat we are going to test.
      final String aString = prereq.getKey();
      List<String> typeList = null;
      if (aString.startsWith(Constants.LST_TYPE_EQUAL)
          || aString.startsWith(Constants.LST_TYPE_DOT)) {
        String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE);
        typeList = CoreUtility.split(stripped, '.');
      }

      for (Equipment eq : display.getEquipmentSet()) {
        if (typeList != null) {
          // Check to see if the equipment matches
          // all of the types in the requested list;
          boolean bMatches = true;
          for (int i = 0, x = typeList.size(); i < x; ++i) {
            if (!eq.isType(typeList.get(i))) {
              bMatches = false;
              break;
            }
          }
          if (bMatches) {
            runningTotal++;
          }
        } else { // not a TYPE string
          final String eqName = eq.getName().toUpperCase();

          if (aString.indexOf('%') >= 0) {
            // handle wildcards (always assume
            // they end the line)
            final int percentPos = aString.indexOf('%');
            final String substring = aString.substring(0, percentPos).toUpperCase();
            if ((eqName.startsWith(substring))) {
              ++runningTotal;
              break;
            }
          } else if (eqName.equalsIgnoreCase(aString)) {
            // just a straight String compare
            ++runningTotal;
            break;
          }
        }
      }
    }

    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
  }