예제 #1
0
  @Override
  protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
    Formula count = FormulaFactory.getFormulaFor(tok.nextToken());
    if (!count.isValid()) {
      return new ParseResult.Fail(
          "Count in " + getTokenName() + " was not valid: " + count.toString(), context);
    }
    if (!count.isStatic() || count.resolveStatic().intValue() <= 0) {
      return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0", context);
    }
    if (!tok.hasMoreTokens()) {
      return new ParseResult.Fail(
          getTokenName()
              + " must have a | separating "
              + "count from the list of possible values: "
              + value,
          context);
    }
    List<CDOMReference<ClassSkillList>> refs = new ArrayList<>();

    while (tok.hasMoreTokens()) {
      String token = tok.nextToken();
      CDOMReference<ClassSkillList> ref;
      if (Constants.LST_ALL.equals(token)) {
        ref = context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS);
      } else {
        ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, token);
      }
      refs.add(ref);
    }

    ReferenceChoiceSet<ClassSkillList> rcs = new ReferenceChoiceSet<>(refs);
    if (!rcs.getGroupingState().isValid()) {
      return new ParseResult.Fail(
          "Non-sensical " + getTokenName() + ": Contains ANY and a specific reference: " + value);
    }
    ChoiceSet<ClassSkillList> cs = new ChoiceSet<>(getTokenName(), rcs);
    cs.setTitle("Select class whose class-skills this class will inherit");
    TransitionChoice<ClassSkillList> tc = new ConcreteTransitionChoice<>(cs, count);
    context.getObjectContext().put(pcc, ObjectKey.SKILLLIST_CHOICE, tc);
    tc.setRequired(false);
    return ParseResult.SUCCESS;
  }
예제 #2
0
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    AbilityCategory category = AbilityCategory.FEAT;
    Nature nature = Nature.NORMAL;

    ParsingSeparator sep = new ParsingSeparator(value, '|');
    String activeValue = sep.next();
    Formula count;
    if (!sep.hasNext()) {
      count = FormulaFactory.ONE;
    } else {
      count = FormulaFactory.getFormulaFor(activeValue);
      if (!count.isValid()) {
        return new ParseResult.Fail(
            "Count in " + getTokenName() + " was not valid: " + count.toString(), context);
      }
      if (!count.isValid()) {
        return new ParseResult.Fail(
            "Count in " + getTokenName() + " was not valid: " + count.toString(), context);
      }
      if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
        return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
      }
      activeValue = sep.next();
    }
    if (sep.hasNext()) {
      return new ParseResult.Fail(
          getFullName() + " had too many pipe separated items: " + value, context);
    }
    if (isEmpty(activeValue) || hasIllegalSeparator(',', activeValue)) {
      return ParseResult.INTERNAL_ERROR;
    }

    List<CDOMReference<Ability>> refs = new ArrayList<CDOMReference<Ability>>();
    List<PrimitiveChoiceSet<CategorizedAbilitySelection>> pcs =
        new ArrayList<PrimitiveChoiceSet<CategorizedAbilitySelection>>();
    ParsingSeparator tok = new ParsingSeparator(activeValue, ',');

    boolean foundAny = false;
    boolean foundOther = false;

    ReferenceManufacturer<Ability> rm =
        context.ref.getManufacturer(ABILITY_CLASS, AbilityCategory.FEAT);

    while (tok.hasNext()) {
      CDOMReference<Ability> ab = null;
      String token = tok.next();
      if (Constants.LST_CHOICE.equals(token) || Constants.LST_ANY.equals(token)) {
        foundAny = true;
        ab = rm.getAllReference();
      } else if (token.startsWith("CLASS.") || token.startsWith("CLASS=")) {
        String className = token.substring(6);
        if (className.length() == 0) {
          return new ParseResult.Fail(
              getTokenName() + " must have Class name after " + token, context);
        }
        CDOMSingleRef<PCClass> pcc = context.ref.getCDOMReference(PCCLASS_CLASS, className);
        AbilityFromClassChoiceSet acs = new AbilityFromClassChoiceSet(pcc);
        pcs.add(acs);
      } else {
        foundOther = true;
        ab = TokenUtilities.getTypeOrPrimitive(rm, token);
        if (ab == null) {
          return new ParseResult.Fail(
              "  Error was encountered while parsing "
                  + getTokenName()
                  + ": "
                  + value
                  + " had an invalid reference: "
                  + token,
              context);
        }
      }
      if (ab != null) {
        refs.add(ab);
      }
    }

    if (foundAny && foundOther) {
      return new ParseResult.Fail(
          "Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value,
          context);
    }

    if (!refs.isEmpty()) {
      AbilityRefChoiceSet rcs = new AbilityRefChoiceSet(category, refs, nature);
      pcs.add(rcs);
    }
    if (pcs.isEmpty()) {
      return new ParseResult.Fail(
          "Internal Error: " + getFullName() + " did not have any references: " + value, context);
    }
    PrimitiveChoiceSet<CategorizedAbilitySelection> ascs;
    if (pcs.size() == 1) {
      ascs = pcs.get(0);
    } else {
      ascs = new CompoundOrChoiceSet<CategorizedAbilitySelection>(pcs, Constants.COMMA);
    }
    ChoiceSet<CategorizedAbilitySelection> cs =
        new ChoiceSet<CategorizedAbilitySelection>(getTokenName(), ascs, true);
    cs.setTitle("Select for removal");
    PersistentTransitionChoice<CategorizedAbilitySelection> tc =
        new ConcretePersistentTransitionChoice<CategorizedAbilitySelection>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.REMOVE, tc);
    tc.allowStack(true);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
  }