コード例 #1
0
ファイル: CostpreToken.java プロジェクト: aroni125/pcgen-svn
 public String[] unparse(LoadContext context, EquipmentModifier mod) {
   Formula f = context.getObjectContext().getFormula(mod, FormulaKey.BASECOST);
   if (f == null) {
     return null;
   }
   return new String[] {f.toString()};
 }
コード例 #2
0
ファイル: LanguageToken.java プロジェクト: aroni125/pcgen-svn
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    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());
      }
      if (count.isStatic() && count.resolve(null, "").doubleValue() <= 0) {
        return new ParseResult.Fail("Count in " + getFullName() + " must be > 0");
      }
      activeValue = sep.next();
    }
    if (sep.hasNext()) {
      return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value);
    }
    ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue);
    if (!pr.passed()) {
      return pr;
    }

    List<CDOMReference<Language>> refs = new ArrayList<CDOMReference<Language>>();
    StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
    while (tok.hasMoreTokens()) {
      String tokText = tok.nextToken();
      CDOMReference<Language> lang = TokenUtilities.getReference(context, LANGUAGE_CLASS, tokText);
      if (lang == null) {
        return new ParseResult.Fail(
            "  Error was encountered while parsing "
                + getFullName()
                + ": "
                + value
                + " had an invalid reference: "
                + tokText);
      }
      refs.add(lang);
    }

    ReferenceChoiceSet<Language> rcs = new ReferenceChoiceSet<Language>(refs);
    if (!rcs.getGroupingState().isValid()) {
      return new ParseResult.Fail(
          "Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value);
    }

    ChoiceSet<Language> cs = new ChoiceSet<Language>(getTokenName(), rcs);
    cs.setTitle("Language Choice");
    PersistentTransitionChoice<Language> tc =
        new ConcretePersistentTransitionChoice<Language>(cs, count);
    context.getObjectContext().addToList(obj, ListKey.ADD, tc);
    tc.setChoiceActor(this);
    return ParseResult.SUCCESS;
  }
コード例 #3
0
ファイル: CostpreToken.java プロジェクト: aroni125/pcgen-svn
 @Override
 protected ParseResult parseNonEmptyToken(
     LoadContext context, EquipmentModifier mod, String value) {
   Formula formula = FormulaFactory.getFormulaFor(value);
   if (!formula.isValid()) {
     return new ParseResult.Fail(
         "Formula in " + getTokenName() + " was not valid: " + formula.toString());
   }
   context.getObjectContext().put(mod, FormulaKey.BASECOST, formula);
   return ParseResult.SUCCESS;
 }
コード例 #4
0
  /**
   * Sets the locked flag on a PC
   *
   * @param pc
   */
  public static void applyDomain(PlayerCharacter pc, Domain d) {
    ClassSource source = pc.getDomainSource(d);
    PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
    if (aClass != null) {
      int maxLevel;

      for (maxLevel = 0; maxLevel < 10; maxLevel++) {
        if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
          break;
        }
      }

      if (maxLevel > 0) {
        addSpellsToClassForLevels(pc, d, aClass, 0, maxLevel - 1);
      }

      if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
        DomainSpellList domainSpellList = d.get(ObjectKey.DOMAIN_SPELLLIST);
        final List<Spell> aList =
            pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));

        for (Spell gcs : aList) {
          if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
            pc.setDomainSpellCount(aClass, 1);
            break;
          }
        }
      }
    }

    Collection<CDOMReference<Spell>> mods = d.getSafeListMods(Spell.SPELLS);
    for (CDOMReference<Spell> ref : mods) {
      Collection<Spell> spells = ref.getContainedObjects();
      Collection<AssociatedPrereqObject> assoc = d.getListAssociations(Spell.SPELLS, ref);
      for (AssociatedPrereqObject apo : assoc) {
        if (!PrereqHandler.passesAll(apo.getPrerequisiteList(), pc, d)) {
          continue;
        }
        for (Spell s : spells) {
          String book = apo.getAssociation(AssociationKey.SPELLBOOK);
          List<CharacterSpell> aList = pc.getCharacterSpells(aClass, s, book, -1);

          if (aList.isEmpty()) {
            Formula times = apo.getAssociation(AssociationKey.TIMES_PER_UNIT);
            CharacterSpell cs = new CharacterSpell(d, s);
            int resolvedTimes = times.resolve(pc, d.getQualifiedKey()).intValue();
            cs.addInfo(1, resolvedTimes, book);
            pc.addCharacterSpell(aClass, cs);
          }
        }
      }
    }
  }
コード例 #5
0
ファイル: SkilllistToken.java プロジェクト: cpmeister/pcgen
  @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;
  }
コード例 #6
0
ファイル: LanguageToken.java プロジェクト: aroni125/pcgen-svn
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges =
        context.getObjectContext().getListChanges(obj, ListKey.ADD);
    Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
    if (addedItems == null || addedItems.isEmpty()) {
      // Zero indicates no Token
      return null;
    }
    List<String> addStrings = new ArrayList<String>();
    for (TransitionChoice<?> container : addedItems) {
      SelectableSet<?> cs = container.getChoices();
      if (cs.getName().equals(getTokenName()) && LANGUAGE_CLASS.equals(cs.getChoiceClass())) {
        Formula f = container.getCount();
        if (f == null) {
          context.addWriteMessage("Unable to find " + getFullName() + " Count");
          return null;
        }
        if (f.isStatic() && f.resolve(null, "").doubleValue() <= 0) {
          context.addWriteMessage("Count in " + getFullName() + " must be > 0");
          return null;
        }
        if (!cs.getGroupingState().isValid()) {
          context.addWriteMessage(
              "Non-sensical "
                  + getFullName()
                  + ": Contains ANY and a specific reference: "
                  + cs.getLSTformat());
          return null;
        }
        StringBuilder sb = new StringBuilder();
        if (!FormulaFactory.ONE.equals(f)) {
          sb.append(f).append(Constants.PIPE);
        }
        sb.append(cs.getLSTformat());
        addStrings.add(sb.toString());

        // assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
      }
    }
    return addStrings.toArray(new String[addStrings.size()]);
  }
コード例 #7
0
ファイル: ValuesToken.java プロジェクト: kne1p/pcgen
 private boolean processRange(KitTable kitTable, KitGear optionInfo, String range) {
   if (isEmpty(range) || hasIllegalSeparator(',', range)) {
     return false;
   }
   ParsingSeparator sep = new ParsingSeparator(range, ',');
   String minString = sep.next();
   String maxString;
   if (sep.hasNext()) {
     maxString = sep.next();
   } else {
     maxString = range;
   }
   if (sep.hasNext()) {
     return false;
   }
   Formula min = FormulaFactory.getFormulaFor(minString);
   if (!min.isValid()) {
     Logging.errorPrint("Min Formula in " + getTokenName() + " was not valid: " + min.toString());
     return false;
   }
   Formula max = FormulaFactory.getFormulaFor(maxString);
   if (!max.isValid()) {
     Logging.errorPrint("Max Formula in " + getTokenName() + " was not valid: " + max.toString());
     return false;
   }
   kitTable.addGear(optionInfo, min, max);
   return true;
 }
コード例 #8
0
ファイル: OptionToken.java プロジェクト: cpmeister/pcgen
 @Override
 public String[] unparse(LoadContext context, BaseKit kit) {
   Collection<OptionBound> bounds = kit.getBounds();
   if (bounds == null) {
     return null;
   }
   List<String> list = new ArrayList<>();
   for (OptionBound bound : bounds) {
     Formula min = bound.getOptionMin();
     Formula max = bound.getOptionMax();
     if (min == null || max == null) {
       // Error if only one is null
       return null;
     }
     StringBuilder sb = new StringBuilder();
     sb.append(min);
     if (!min.equals(max)) {
       sb.append(',').append(max);
     }
     list.add(sb.toString());
   }
   return new String[] {StringUtil.join(list, Constants.PIPE)};
 }
コード例 #9
0
ファイル: OptionToken.java プロジェクト: cpmeister/pcgen
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, BaseKit kit, String value) {
    ParsingSeparator pipeSep = new ParsingSeparator(value, '|');
    pipeSep.addGroupingPair('[', ']');
    pipeSep.addGroupingPair('(', ')');

    while (pipeSep.hasNext()) {
      String subTok = pipeSep.next();
      if (subTok.length() == 0) {
        return new ParseResult.Fail(
            getTokenName() + " arguments has invalid pipe separator: " + value, context);
      }
      ParseResult pr = checkForIllegalSeparator(',', subTok);
      if (!pr.passed()) {
        return pr;
      }
      ParsingSeparator commaSep = new ParsingSeparator(subTok, ',');
      commaSep.addGroupingPair('[', ']');
      commaSep.addGroupingPair('(', ')');
      String minString = commaSep.next();
      String maxString;
      if (commaSep.hasNext()) {
        maxString = commaSep.next();
      } else {
        maxString = subTok;
      }
      if (commaSep.hasNext()) {
        return new ParseResult.Fail("Token cannot have more than one separator ','", context);
      }
      Formula min = FormulaFactory.getFormulaFor(minString);
      if (!min.isValid()) {
        return new ParseResult.Fail(
            "Min Formula in " + getTokenName() + " was not valid: " + min.toString(), context);
      }
      Formula max = FormulaFactory.getFormulaFor(maxString);
      if (!max.isValid()) {
        return new ParseResult.Fail(
            "Max Formula in " + getTokenName() + " was not valid: " + max.toString(), context);
      }
      kit.setOptionBounds(min, max);
    }
    return ParseResult.SUCCESS;
  }
コード例 #10
0
ファイル: FeatToken.java プロジェクト: timoc/pcgen-svn
  @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;
  }