示例#1
0
  /*
   * (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);
  }
示例#2
0
 public static void clearConstants() {
   AspectName.clearConstants();
   Pantheon.clearConstants();
   RaceSubType.clearConstants();
   RaceType.clearConstants();
   Region.clearConstants();
   SubClassCategory.clearConstants();
   SubRace.clearConstants();
   SubRegion.clearConstants();
   Type.clearConstants();
   VariableKey.clearConstants();
 }
示例#3
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
      return new ParseResult.Fail(
          "Cannot use "
              + getTokenName()
              + " on an Ungranted object type: "
              + obj.getClass().getSimpleName(),
          context);
    }
    StringTokenizer tok = new StringTokenizer(value, LstUtils.PIPE);

    String companionType = tok.nextToken();

    if (!tok.hasMoreTokens()) {
      return new ParseResult.Fail(
          getTokenName() + " requires more than just a Type: " + value, context);
    }

    String list = tok.nextToken();

    ParseResult pr = checkForIllegalSeparator(',', list);
    if (!pr.passed()) {
      return pr;
    }

    StringTokenizer subTok = new StringTokenizer(list, LstUtils.COMMA);

    Set<CDOMReference<Race>> races = new HashSet<>();
    boolean foundAny = false;
    while (subTok.hasMoreTokens()) {
      String tokString = subTok.nextToken();
      if (Constants.LST_ANY.equalsIgnoreCase(tokString)) {
        foundAny = true;
        races.add(context.getReferenceContext().getCDOMAllReference(Race.class));
      } else if (tokString.startsWith("RACETYPE=")) {
        String raceType = tokString.substring(9);
        if (raceType.isEmpty()) {
          return new ParseResult.Fail(
              getTokenName() + " Error: RaceType was not specified.", context);
        }
        races.add(
            new ObjectMatchingReference<>(
                tokString,
                Race.class,
                context.getReferenceContext().getCDOMAllReference(Race.class),
                ObjectKey.RACETYPE,
                RaceType.getConstant(raceType)));
      } else if (tokString.startsWith("RACESUBTYPE=")) {
        String raceSubType = tokString.substring(12);
        if (raceSubType.isEmpty()) {
          return new ParseResult.Fail(
              getTokenName() + " Error: RaceSubType was not specified.", context);
        }
        races.add(
            new ListMatchingReference<>(
                tokString,
                Race.class,
                context.getReferenceContext().getCDOMAllReference(Race.class),
                ListKey.RACESUBTYPE,
                RaceSubType.getConstant(raceSubType)));
      } else if (looksLikeAPrerequisite(tokString)) {
        return new ParseResult.Fail(
            getTokenName() + " Error: " + tokString + " found where companion race expected.",
            context);
      } else {
        races.add(context.getReferenceContext().getCDOMReference(Race.class, tokString));
      }
    }
    if (foundAny && races.size() > 1) {
      return new ParseResult.Fail(
          "Non-sensical Race List includes Any and specific races: " + value, context);
    }

    if (!tok.hasMoreTokens()) {
      // No other args, so we're done
      finish(context, obj, companionType, races, null, null);
      return ParseResult.SUCCESS;
    }

    // The remainder of the elements are optional.
    Integer followerAdjustment = null;
    String optArg = tok.nextToken();
    while (true) {
      if (optArg.startsWith(FOLLOWERADJUSTMENT)) {
        if (followerAdjustment != null) {
          return new ParseResult.Fail(
              getTokenName() + " Error: Multiple " + FOLLOWERADJUSTMENT + " tags specified.",
              context);
        }

        int faStringLength = FOLLOWERADJUSTMENT.length();
        if (optArg.length() <= faStringLength + 1) {
          return new ParseResult.Fail(
              "Empty FOLLOWERADJUSTMENT value in " + getTokenName() + " is prohibited", context);
        }
        String adj = optArg.substring(faStringLength + 1);

        try {
          followerAdjustment = Integer.valueOf(adj);
        } catch (NumberFormatException nfe) {
          ComplexParseResult cpr = new ComplexParseResult();
          cpr.addErrorMessage("Expecting a number for FOLLOWERADJUSTMENT: " + adj);
          cpr.addErrorMessage("  was parsing Token " + getTokenName());
          return cpr;
        }
      } else if (looksLikeAPrerequisite(optArg)) {
        break;
      } else {
        return new ParseResult.Fail(
            getTokenName()
                + ": Unknown argument (was expecting FOLLOWERADJUSTMENT: or PRExxx): "
                + optArg,
            context);
      }
      if (!tok.hasMoreTokens()) {
        // No prereqs, so we're done
        finish(context, obj, companionType, races, followerAdjustment, null);
        return ParseResult.SUCCESS;
      }
      optArg = tok.nextToken();
    }

    List<Prerequisite> prereqs = new ArrayList<>();

    while (true) {
      Prerequisite prereq = getPrerequisite(optArg);
      if (prereq == null) {
        return new ParseResult.Fail(
            "   (Did you put items after the " + "PRExxx tags in " + getTokenName() + ":?)",
            context);
      }
      prereqs.add(prereq);
      if (!tok.hasMoreTokens()) {
        break;
      }
      optArg = tok.nextToken();
    }

    finish(context, obj, companionType, races, followerAdjustment, prereqs);
    return ParseResult.SUCCESS;
  }