Search in sources :

Example 1 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class SubstitutionLevelSupport method levelArrayQualifies.

private static boolean levelArrayQualifies(int level, final PlayerCharacter pc, final String aLine, final SourceEntry tempSource, CDOMObject source) {
    final PCClassLoader classLoader = new PCClassLoader();
    PCClass dummyClass = new PCClass();
    try {
        classLoader.parseLine(Globals.getContext(), dummyClass, aLine, tempSource);
    } catch (PersistenceLayerException e) {
        Logging.errorPrint("Unable to parse line from levelArray: " + aLine);
    }
    return dummyClass.getOriginalClassLevel(level).qualifies(pc, source);
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PCClassLoader(pcgen.persistence.lst.PCClassLoader) PCClass(pcgen.core.PCClass)

Example 2 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class LSTConverter method load.

private String load(URI uri, Loader loader) throws InterruptedException, PersistenceLayerException {
    StringBuilder dataBuffer;
    context.setSourceURI(uri);
    context.setExtractURI(uri);
    try {
        dataBuffer = LstFileLoader.readFromURI(uri);
    } catch (PersistenceLayerException ple) {
        String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Errors.LstFileLoader.LoadError", uri, ple.getMessage());
        Logging.errorPrint(message);
        return null;
    }
    StringBuilder resultBuffer = new StringBuilder(dataBuffer.length());
    final String aString = dataBuffer.toString();
    String[] fileLines = aString.split(LstFileLoader.LINE_SEPARATOR_REGEXP);
    for (int line = 0; line < fileLines.length; line++) {
        String lineString = fileLines[line];
        if ((lineString.isEmpty()) || (lineString.charAt(0) == LstFileLoader.LINE_COMMENT_CHAR) || lineString.startsWith("SOURCE")) {
            resultBuffer.append(lineString);
        } else {
            List<CDOMObject> newObj = loader.process(resultBuffer, line, lineString, decider);
            if (newObj != null) {
                for (CDOMObject cdo : newObj) {
                    injected.addToListFor(loader, uri, cdo);
                }
            }
        }
        resultBuffer.append("\n");
    }
    return resultBuffer.toString();
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CDOMObject(pcgen.cdom.base.CDOMObject)

Example 3 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class LSTConverter method initCampaigns.

/**
	 * Initialise the list of campaigns. This will load the ability 
	 * categories in advance of the conversion.
	 * @param campaigns The campaigns or sources to be converted.
	 */
public void initCampaigns(List<Campaign> campaigns) {
    List<CampaignSourceEntry> dataDefFileList = new ArrayList<>();
    for (Campaign campaign : campaigns) {
        // mode
        try {
            catLoader.loadLstFiles(context, campaign.getSafeListFor(ListKey.FILE_ABILITY_CATEGORY));
            sizeLoader.loadLstFiles(context, campaign.getSafeListFor(ListKey.FILE_SIZE));
            statLoader.loadLstFiles(context, campaign.getSafeListFor(ListKey.FILE_STAT));
            savesLoader.loadLstFiles(context, campaign.getSafeListFor(ListKey.FILE_SAVE));
            alignmentLoader.loadLstFiles(context, campaign.getSafeListFor(ListKey.FILE_ALIGNMENT));
            alignmentLoader.loadLstFiles(Globals.getContext(), campaign.getSafeListFor(ListKey.FILE_ALIGNMENT));
        } catch (PersistenceLayerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        dataDefFileList.addAll(campaign.getSafeListFor(ListKey.FILE_DATACTRL));
    }
    // Load using the new LstFileLoaders
    try {
        SourceFileLoader.addDefaultDataControlIfNeeded(dataDefFileList);
        dataControlLoader.loadLstFiles(context, dataDefFileList);
        SourceFileLoader.processFactDefinitions(context);
    } catch (PersistenceLayerException e) {
        // TODO Auto-generated catch block
        Logging.errorPrint("LSTConverter.initCampaigns failed", e);
    }
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Campaign(pcgen.core.Campaign) ArrayList(java.util.ArrayList)

Example 4 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class GeneralSaveRestoreTest method testTemplateFeat.

public void testTemplateFeat() {
    //Represents CODE-2547
    TokenRegistration.register(new plugin.lsttokens.deprecated.TemplateFeatToken());
    TokenRegistration.register(new plugin.lsttokens.ability.StackToken());
    TokenRegistration.register(new plugin.exporttokens.deprecated.TemplateToken());
    Language lang = context.getReferenceContext().constructCDOMObject(Language.class, "English");
    Ability a = context.getReferenceContext().constructCDOMObject(Ability.class, "Ab");
    context.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, a);
    PCTemplate pct = context.getReferenceContext().constructCDOMObject(PCTemplate.class, "Templ");
    try {
        assertTrue(context.processToken(a, "MULT", "YES"));
        assertTrue(context.processToken(a, "STACK", "YES"));
        assertTrue(context.processToken(a, "CHOOSE", "LANG|English"));
        assertTrue(context.processToken(a, "AUTO", "LANG|%LIST"));
        assertTrue(context.processToken(pct, "FEAT", "Ab"));
    } catch (PersistenceLayerException e) {
        fail(e.getMessage());
    }
    finishLoad();
    pc.addTemplate(pct);
    assertTrue(pc.hasLanguage(lang));
    runRoundRobin(null);
    assertTrue(reloadedPC.hasLanguage(lang));
    List<CNAbility> cnaList = pc.getMatchingCNAbilities(a);
    assertEquals(1, cnaList.size());
    List<String> assocs = pc.getAssociationList(cnaList.get(0));
    assertEquals(1, assocs.size());
    assertEquals("English", assocs.get(0));
    cnaList = reloadedPC.getMatchingCNAbilities(a);
    assertEquals(1, cnaList.size());
    assocs = reloadedPC.getAssociationList(cnaList.get(0));
    assertEquals(1, assocs.size());
    assertEquals("English", assocs.get(0));
    assertEquals("Ab(English)", ExportHandler.getTokenString(pc, "TEMPLATE.0.FEAT"));
    assertEquals("Ab(English)", ExportHandler.getTokenString(reloadedPC, "TEMPLATE.0.FEAT"));
    reloadedPC.removeTemplate(pct);
    assertFalse(reloadedPC.hasLanguage(lang));
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CNAbility(pcgen.cdom.content.CNAbility) Language(pcgen.core.Language) PCTemplate(pcgen.core.PCTemplate)

Example 5 with PersistenceLayerException

use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.

the class PCClass method getBonusTo.

/**
	 * Returns the total bonus to the specified bonus type and name.
	 *
	 * <p>
	 * This method checks only bonuses associated with the class. It makes sure
	 * to return bonuses that are active only to the max level specified. What
	 * that means is that bonuses specified on class level lines will have a
	 * level parameter associated with them. Only bonuses specified on the level
	 * specified or lower will be totalled.
	 *
	 * @param argType
	 *            Bonus type e.g. <code>BONUS:<b>DOMAIN</b></code>
	 * @param argMname
	 *            Bonus name e.g. <code>BONUS:DOMAIN|<b>NUMBER</b></code>
	 * @param asLevel
	 *            The maximum level to apply bonuses for.
	 * @param aPC
	 *            The <tt>PlayerCharacter</tt> bonuses are being calculated
	 *            for.
	 *
	 * @return Total bonus value.
	 */
/*
	 * 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());
                }
                // as the prereqs are processed by the bonus loading code.
                while (breakOnPipes.hasMoreTokens()) {
                    final String bString = breakOnPipes.nextToken();
                    if (PreParserFactory.isPreReqString(bString)) {
                        Logging.debugPrint(//$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
                        "Why is this prerequisite '" + bString + "' parsed in '" + getClass().getName() + ".getBonusTo(String,String,int)' rather than in the persistence layer?");
                        try {
                            final PreParserFactory factory = PreParserFactory.getInstance();
                            localPreReqList.add(factory.parse(bString));
                        } catch (PersistenceLayerException ple) {
                            Logging.errorPrint(ple.getMessage(), ple);
                        }
                    }
                }
                // be referenced in Qualifies statements?
                if (PrereqHandler.passesAll(localPreReqList, aPC, null)) {
                    final double j = aPC.getVariableValue(aString, getQualifiedKey()).doubleValue();
                    i += j;
                }
            }
        }
    }
    return i;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringTokenizer(java.util.StringTokenizer) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

PersistenceLayerException (pcgen.persistence.PersistenceLayerException)180 IOException (java.io.IOException)74 Prerequisite (pcgen.core.prereq.Prerequisite)62 StringWriter (java.io.StringWriter)17 StringTokenizer (java.util.StringTokenizer)17 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)15 LoadContext (pcgen.rules.context.LoadContext)14 URI (java.net.URI)12 Campaign (pcgen.core.Campaign)11 ParseResult (pcgen.rules.persistence.token.ParseResult)11 PCClass (pcgen.core.PCClass)10 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 URISyntaxException (java.net.URISyntaxException)8 TreeSet (java.util.TreeSet)8 CDOMReference (pcgen.cdom.base.CDOMReference)8 PlayerCharacter (pcgen.core.PlayerCharacter)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8 PCClassLoader (pcgen.persistence.lst.PCClassLoader)8