コード例 #1
0
ファイル: LoadContextInst.java プロジェクト: kidaa/pcgen
 public <T extends Loadable> void unconditionallyProcess(T cdo, String key, String value) {
   try {
     if (processToken(cdo, key, value)) {
       commit();
     } else {
       rollback();
       Logging.replayParsedMessages();
     }
     Logging.clearParseMessages();
   } catch (PersistenceLayerException e) {
     Logging.errorPrint("Error in token parse: " + e.getLocalizedMessage());
   }
 }
コード例 #2
0
  @Test
  public void testUnbalancedBracket() {
    PreMultParser parser = new PreMultParser();

    try {
      Prerequisite prereq =
          parser.parse(
              "mult",
              "1,[PREPROFWITHARMOR:1,TYPE.Medium],[PREFEAT:1,Armor Proficiency (Medium)",
              false,
              false);
      fail("Expected unbalanced bracket to be detected.");
    } catch (PersistenceLayerException e) {
      assertEquals(
          "Unbalanced [] in PREMULT '[PREPROFWITHARMOR:1,TYPE.Medium],[PREFEAT:1,Armor Proficiency (Medium)'.",
          e.getMessage());
    }
  }
コード例 #3
0
ファイル: ValuesToken.java プロジェクト: kne1p/pcgen
  @Override
  protected ParseResult parseNonEmptyToken(LoadContext context, KitTable kitTable, String value) {
    ParsingSeparator sep = new ParsingSeparator(value, '|');
    while (sep.hasNext()) {
      String thing = sep.next();
      if (thing.length() == 0) {
        return new ParseResult.Fail(
            getTokenName() + " arguments has invalid pipe separator: " + value, context);
      }
      KitGear optionInfo = new KitGear();
      for (String s : thing.split("[\\[\\]]")) {
        if (s.length() == 0) {
          continue;
        }
        int colonLoc = s.indexOf(':');
        if (colonLoc == -1) {
          return new ParseResult.Fail(
              "Expected colon in Value item: " + s + " within: " + value, context);
        }
        String key = s.substring(0, colonLoc);
        String thingValue = s.substring(colonLoc + 1);
        try {
          boolean passed = context.processToken(optionInfo, key, thingValue);
          if (!passed) {
            return new ParseResult.Fail("Failure in token: " + key, context);
          }
        } catch (PersistenceLayerException e) {
          return new ParseResult.Fail("Failure in token: " + key + " " + e.getMessage(), context);
        }
      }
      if (!sep.hasNext()) {
        return new ParseResult.Fail("Odd token count in Value: " + value, context);
      }
      String range = sep.next();
      if (!processRange(kitTable, optionInfo, range)) {
        return new ParseResult.Fail(
            "Invalid Range in Value: " + range + " within " + value, context);
      }
    }

    return ParseResult.SUCCESS;
  }
コード例 #4
0
ファイル: ActypeToken.java プロジェクト: cpmeister/pcgen
 private Collection<ACControl> parseACControl(String str) {
   StringTokenizer st = new StringTokenizer(str, Constants.PIPE);
   List<ACControl> acTypes = new ArrayList<>();
   String token;
   while (true) {
     token = st.nextToken();
     if (PreParserFactory.isPreReqString(token)) {
       break;
     }
     acTypes.add(new ACControl(token));
     if (!st.hasMoreTokens()) {
       return acTypes;
     }
   }
   if (acTypes.isEmpty()) {
     Logging.errorPrint("No types found in actype control: " + str);
     return null;
   }
   while (true) {
     try {
       PreParserFactory factory = PreParserFactory.getInstance();
       Prerequisite prereq = factory.parse(token);
       for (ACControl acc : acTypes) {
         acc.addPrerequisite(prereq);
       }
     } catch (PersistenceLayerException ple) {
       Logging.errorPrint(ple.getMessage(), ple);
       return null;
     }
     if (!st.hasMoreTokens()) {
       break;
     }
     token = st.nextToken();
     if (!PreParserFactory.isPreReqString(token)) {
       Logging.errorPrint("ERROR: Type found after" + " PRExxx in actype control: " + str);
       return null;
     }
   }
   return acTypes;
 }
コード例 #5
0
ファイル: AbilityLst.java プロジェクト: oiml/pcgen
  @Override
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Collection<CDOMReference<? extends CDOMList<?>>> changedLists =
        context.getListContext().getChangedLists(obj, AbilityList.class);
    Changes<ListKey<ChooseSelectionActor<?>>> actors =
        context.getObjectContext().getListChanges(obj, ListKey.GA_CAKEYS);
    Set<String> returnSet = new TreeSet<String>();
    TripleKeyMapToList<
            Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>>
        m =
            new TripleKeyMapToList<
                Nature,
                CDOMSingleRef<AbilityCategory>,
                List<Prerequisite>,
                CDOMReference<Ability>>();
    TripleKeyMapToList<
            Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>>
        clear =
            new TripleKeyMapToList<
                Nature,
                CDOMSingleRef<AbilityCategory>,
                List<Prerequisite>,
                CDOMReference<Ability>>();

    Changes<ChooseSelectionActor<?>> listChanges =
        context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
      for (ChooseSelectionActor<?> csa : listAdded) {
        if (csa.getSource().equals(getTokenName())) {
          try {
            AbilitySelector as = (AbilitySelector) csa;
            StringBuilder sb = new StringBuilder();
            sb.append(as.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
            sb.append(as.getNature()).append(Constants.PIPE);
            sb.append(as.getLstFormat());
            returnSet.add(sb.toString());
          } catch (PersistenceLayerException e) {
            context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
            return null;
          }
        }
      }
    }

    for (CDOMReference ref : changedLists) {
      AssociatedChanges<CDOMReference<Ability>> changes =
          context.getListContext().getChangesInList(getTokenName(), obj, ref);
      if (changes.includesGlobalClear()) {
        CDOMDirectSingleRef<AbilityList> dr = (CDOMDirectSingleRef<AbilityList>) ref;
        AbilityList al = dr.get();
        StringBuilder sb = new StringBuilder();
        sb.append(al.getCategory().getLSTformat(false)).append(Constants.PIPE);
        sb.append(al.getNature()).append(Constants.PIPE);
        sb.append(Constants.LST_DOT_CLEAR);
        returnSet.add(sb.toString());
      }
      MapToList<CDOMReference<Ability>, AssociatedPrereqObject> mtl =
          changes.getAddedAssociations();
      if (mtl != null) {
        for (CDOMReference<Ability> ab : mtl.getKeySet()) {
          for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
            Nature nature = assoc.getAssociation(AssociationKey.NATURE);
            CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
            m.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
          }
        }
      }
      mtl = changes.getRemovedAssociations();
      if (mtl != null) {
        for (CDOMReference<Ability> ab : mtl.getKeySet()) {
          for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
            Nature nature = assoc.getAssociation(AssociationKey.NATURE);
            CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
            clear.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
          }
        }
      }
    }

    for (Nature nature : m.getKeySet()) {
      for (CDOMSingleRef<AbilityCategory> category : m.getSecondaryKeySet(nature)) {
        for (List<Prerequisite> prereqs : m.getTertiaryKeySet(nature, category)) {
          StringBuilder sb = new StringBuilder();
          sb.append(category.getLSTformat(false)).append(Constants.PIPE);
          sb.append(nature);
          List<CDOMReference<Ability>> clearList = clear.removeListFor(nature, category, prereqs);
          if (clearList != null && !clearList.isEmpty()) {
            sb.append(Constants.PIPE);
            sb.append(Constants.LST_DOT_CLEAR_DOT);
            sb.append(
                ReferenceUtilities.joinLstFormat(
                    clearList, Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
          }
          sb.append(Constants.PIPE);
          sb.append(
              ReferenceUtilities.joinLstFormat(
                  m.getListFor(nature, category, prereqs), Constants.PIPE));
          if (prereqs != null && !prereqs.isEmpty()) {
            sb.append(Constants.PIPE);
            sb.append(getPrerequisiteString(context, prereqs));
          }
          returnSet.add(sb.toString());
        }
      }
    }
    for (Nature nature : clear.getKeySet()) {
      for (CDOMSingleRef<AbilityCategory> category : clear.getSecondaryKeySet(nature)) {
        for (List<Prerequisite> prereqs : clear.getTertiaryKeySet(nature, category)) {
          StringBuilder sb = new StringBuilder();
          sb.append(category.getLSTformat(false)).append(Constants.PIPE);
          sb.append(nature).append(Constants.PIPE).append(Constants.LST_DOT_CLEAR_DOT);
          sb.append(
              ReferenceUtilities.joinLstFormat(
                  clear.getListFor(nature, category, prereqs),
                  Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
          if (prereqs != null && !prereqs.isEmpty()) {
            sb.append(Constants.PIPE);
            sb.append(getPrerequisiteString(context, prereqs));
          }
          returnSet.add(sb.toString());
        }
      }
    }
    Collection<ListKey<ChooseSelectionActor<?>>> addedActors = actors.getAdded();
    if (addedActors != null) {
      for (ListKey<ChooseSelectionActor<?>> lk : addedActors) {
        Changes<ChooseSelectionActor<?>> cras = context.getObjectContext().getListChanges(obj, lk);
        for (ChooseSelectionActor<?> cra : cras.getAdded()) {
          if (getTokenName().equals(cra.getSource())) {
            try {
              AbilityTargetSelector ats = (AbilityTargetSelector) cra;
              StringBuilder sb = new StringBuilder();
              sb.append(ats.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
              sb.append(ats.getNature()).append(Constants.PIPE).append(cra.getLstFormat());
              List<Prerequisite> prereqs = ats.getPrerequisiteList();
              if (prereqs != null && !prereqs.isEmpty()) {
                sb.append(Constants.PIPE);
                sb.append(getPrerequisiteString(context, prereqs));
              }
              returnSet.add(sb.toString());
            } catch (PersistenceLayerException e) {
              context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
              return null;
            }
          }
        }
      }
    }
    if (returnSet.isEmpty()) {
      return null;
    }
    return returnSet.toArray(new String[returnSet.size()]);
  }
コード例 #6
0
ファイル: PCClass.java プロジェクト: grimreaper/pcgen
  /*
   * REFACTOR There is potentially redundant information here - level and PC...
   * is this ever out of sync or can this method be removed/made private??
   */
  public double getBonusTo(
      final String argType, final String argMname, final int asLevel, final PlayerCharacter aPC) {
    double i = 0;

    List<BonusObj> rawBonusList = getRawBonusList(aPC);

    for (int lvl = 1; lvl < asLevel; lvl++) {
      rawBonusList.addAll(aPC.getActiveClassLevel(this, lvl).getRawBonusList(aPC));
    }
    if ((asLevel == 0) || rawBonusList.isEmpty()) {
      return 0;
    }

    final String type = argType.toUpperCase();
    final String mname = argMname.toUpperCase();

    for (final BonusObj bonus : rawBonusList) {
      final StringTokenizer breakOnPipes =
          new StringTokenizer(bonus.toString().toUpperCase(), Constants.PIPE, false);
      final String theType = breakOnPipes.nextToken();

      if (!theType.equals(type)) {
        continue;
      }

      final String str = breakOnPipes.nextToken();
      final StringTokenizer breakOnCommas = new StringTokenizer(str, Constants.COMMA, false);

      while (breakOnCommas.hasMoreTokens()) {
        final String theName = breakOnCommas.nextToken();

        if (theName.equals(mname)) {
          final String aString = breakOnPipes.nextToken();
          final List<Prerequisite> localPreReqList = new ArrayList<>();
          if (bonus.hasPrerequisites()) {
            localPreReqList.addAll(bonus.getPrerequisiteList());
          }

          // TODO: This code should be removed after the 5.8 release
          // as the prereqs are processed by the bonus loading code.
          while (breakOnPipes.hasMoreTokens()) {
            final String bString = breakOnPipes.nextToken();

            if (PreParserFactory.isPreReqString(bString)) {
              Logging.debugPrint(
                  "Why is this prerequisite '"
                      + bString
                      + "' parsed in '"
                      + getClass().getName()
                      + ".getBonusTo(String,String,int)' rather than in the persistence layer?"); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
              try {
                final PreParserFactory factory = PreParserFactory.getInstance();
                localPreReqList.add(factory.parse(bString));
              } catch (PersistenceLayerException ple) {
                Logging.errorPrint(ple.getMessage(), ple);
              }
            }
          }

          // must meet criteria for bonuses before adding them in
          // TODO: This is a hack to avoid VARs etc in class defs
          // being qualified for when Bypass class prereqs is
          // selected.
          // Should we be passing in the BonusObj here to allow it to
          // be referenced in Qualifies statements?
          if (PrereqHandler.passesAll(localPreReqList, aPC, null)) {
            final double j = aPC.getVariableValue(aString, getQualifiedKey()).doubleValue();
            i += j;
          }
        }
      }
    }

    return i;
  }
コード例 #7
0
ファイル: FeatToken.java プロジェクト: kidaa/pcgen
  @Override
  public String[] unparse(LoadContext context, CDOMObject obj) {
    Set<String> returnSet = new TreeSet<String>();
    List<String> returnList = new ArrayList<String>();
    MapToList<List<Prerequisite>, CDOMReference<Ability>> m =
        new HashMapToList<List<Prerequisite>, CDOMReference<Ability>>();
    AbilityCategory category = AbilityCategory.FEAT;
    Nature nature = Nature.AUTOMATIC;

    CDOMReference<AbilityList> abilList = AbilityList.getAbilityListReference(category, nature);
    AssociatedChanges<CDOMReference<Ability>> changes =
        context.getListContext().getChangesInList(getFullName(), obj, abilList);
    Collection<CDOMReference<Ability>> removedItems = changes.getRemoved();
    if (changes.includesGlobalClear()) {
      if (removedItems != null && !removedItems.isEmpty()) {
        context.addWriteMessage(
            "Non-sensical relationship in "
                + getTokenName()
                + ": global .CLEAR and local .CLEAR. performed");
        return null;
      }
      returnList.add(Constants.LST_DOT_CLEAR);
    } else if (removedItems != null && !removedItems.isEmpty()) {
      returnList.add(
          Constants.LST_DOT_CLEAR_DOT
              + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR.", true));
    }

    Changes<ChooseSelectionActor<?>> listChanges =
        context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
      for (ChooseSelectionActor<?> csa : listAdded) {
        if (csa.getSource().equals(SOURCE)) {
          try {
            returnList.add(csa.getLstFormat());
          } catch (PersistenceLayerException e) {
            context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
            return null;
          }
        }
      }
    }

    MapToList<CDOMReference<Ability>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
    if (mtl != null) {
      for (CDOMReference<Ability> ab : mtl.getKeySet()) {
        for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
          m.addToListFor(assoc.getPrerequisiteList(), ab);
        }
      }
    }

    for (List<Prerequisite> prereqs : m.getKeySet()) {
      StringBuilder sb = new StringBuilder();
      sb.append(ReferenceUtilities.joinLstFormat(m.getListFor(prereqs), Constants.PIPE));
      if (prereqs != null && !prereqs.isEmpty()) {
        sb.append(Constants.PIPE);
        sb.append(getPrerequisiteString(context, prereqs));
      }
      returnSet.add(sb.toString());
    }
    returnList.addAll(returnSet);
    return returnList.toArray(new String[returnList.size()]);
  }