Exemple #1
0
  @Override
  protected ParseResult parseTokenWithSeparator(
      LoadContext context, PCClassLevel po, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    while (tok.hasMoreTokens()) {
      String tokText = tok.nextToken();
      if ("HITDIE".equals(tokText)) {
        context.getObjectContext().put(po, ObjectKey.DONTADD_HITDIE, Boolean.TRUE);
      } else if ("SKILLPOINTS".equals(tokText)) {
        context.getObjectContext().put(po, ObjectKey.DONTADD_SKILLPOINTS, Boolean.TRUE);
      } else {
        ComplexParseResult pr = new ComplexParseResult();
        pr.addErrorMessage(getTokenName() + " encountered an invalid 'Do Not Add' type: " + value);
        pr.addErrorMessage("  Legal values are: HITDIE, SKILLPOINTS");
        return pr;
      }
    }

    return ParseResult.SUCCESS;
  }
  @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;
  }
Exemple #3
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    // value should be of the format:
    // Name1,TYPE.type1,Name3=Prof1|Name4,Name5=Prof2
    //
    // e.g.: TYPE.Hammer,Hand Axe=Simple|Urgosh,Waraxe=Martial

    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    List<ChangeProf> list = new ArrayList<ChangeProf>();

    while (tok.hasMoreTokens()) {
      String tokText = tok.nextToken();
      int equalLoc = tokText.indexOf('=');
      if (equalLoc < 0) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(
            "Improper "
                + getTokenName()
                + ": No = found. "
                + "Expect format to be <Prof>,<Prof>=<Prof Type>");
        cpr.addErrorMessage("  Token was: " + tokText);
        cpr.addErrorMessage("  Tag was: " + value);
        return cpr;
      } else if (equalLoc != tokText.lastIndexOf('=')) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(
            "Improper "
                + getTokenName()
                + ": Two = found.  "
                + "Expect format to be <Prof>,<Prof>=<Prof Type>");
        cpr.addErrorMessage("  Token was: " + tokText);
        cpr.addErrorMessage("  Tag was: " + value);
        return cpr;
      }

      String newType = tokText.substring(equalLoc + 1);
      if (newType.length() == 0) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(
            "Improper "
                + getTokenName()
                + ": Empty Result Type.  "
                + "Expect format to be <Prof>,<Prof>=<Prof Type>");
        cpr.addErrorMessage("  Token was: " + tokText);
        cpr.addErrorMessage("  Tag was: " + value);
        return cpr;
      }
      if (newType.indexOf(Constants.DOT) != -1) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(
            "Improper "
                + getTokenName()
                + ": Invalid (Compound) Result Type: cannot contain a period (.)  "
                + "Expect format to be <Prof>,<Prof>=<Prof Type>");
        cpr.addErrorMessage("  Token was: " + tokText);
        cpr.addErrorMessage("  Tag was: " + value);
        return cpr;
      }
      String[] val = {newType};

      CDOMGroupRef<WeaponProf> newTypeProf =
          context.getReferenceContext().getCDOMTypeReference(WEAPONPROF_CLASS, val);

      String profs = tokText.substring(0, equalLoc);
      if (profs.length() == 0) {
        ComplexParseResult cpr = new ComplexParseResult();
        cpr.addErrorMessage(
            "Improper "
                + getTokenName()
                + ": Empty Source Prof.  "
                + "Expect format to be <Prof>,<Prof>=<Prof Type>");
        cpr.addErrorMessage("  Token was: " + tokText);
        cpr.addErrorMessage("  Tag was: " + value);
        return cpr;
      }

      StringTokenizer pTok = new StringTokenizer(profs, Constants.COMMA);
      while (pTok.hasMoreTokens()) {
        CDOMReference<WeaponProf> wp =
            TokenUtilities.getTypeOrPrimitive(context, WEAPONPROF_CLASS, pTok.nextToken());
        list.add(new ChangeProf(wp, newTypeProf));
      }
    }
    for (ChangeProf cp : list) {
      context.getObjectContext().addToList(obj, ListKey.CHANGEPROF, cp);
    }
    return ParseResult.SUCCESS;
  }