Search in sources :

Example 56 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class PreArmorProfTest method testWithFeatThatGrantsBonus.

/**
	 * Test Preweaponprof with a feat that has a bonus tag
	 * This test was written to help find the source of bug 1699779.
	 * 
	 * @throws Exception the exception
	 */
public void testWithFeatThatGrantsBonus() throws Exception {
    final PlayerCharacter character = getCharacter();
    final FeatLoader featLoader = new FeatLoader();
    CampaignSourceEntry cse;
    try {
        cse = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    int baseHp = character.hitPoints();
    Ability bar = new Ability();
    final String barStr = "Bar	TYPE:General	DESC:See Text	BONUS:HP|CURRENTMAX|50";
    featLoader.parseLine(Globals.getContext(), bar, barStr, cse);
    addAbility(AbilityCategory.FEAT, bar);
    assertEquals("Character should have 50 bonus hp added.", baseHp + 50, character.hitPoints());
    final Ability martialProf = TestHelper.makeAbility("Shield Proficiency (Single)", "FEAT", "General");
    Globals.getContext().unconditionallyProcess(martialProf, "AUTO", "ARMORPROF|Full Plate");
    assertTrue(Globals.getContext().getReferenceContext().resolveReferences(null));
    AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, martialProf, null);
    Ability foo = new Ability();
    final String fooStr = "Foo	TYPE:General	DESC:See Text	BONUS:HP|CURRENTMAX|50|PREPROFWITHARMOR:1,Full Plate";
    featLoader.parseLine(Globals.getContext(), foo, fooStr, cse);
    addAbility(AbilityCategory.FEAT, foo);
    assertEquals("Character has the Full Plate proficiency so the bonus should be added", baseHp + 50 + 50, character.hitPoints());
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) Campaign(pcgen.core.Campaign) FeatLoader(pcgen.persistence.lst.FeatLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI)

Example 57 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class AbstractIntegrationTestCase method classSetUp.

@BeforeClass
public static final void classSetUp() throws URISyntaxException {
    OutputDB.reset();
    testCampaign = new CampaignSourceEntry(new Campaign(), new URI("file:/Test%20Case"));
    modCampaign = new CampaignSourceEntry(new Campaign(), new URI("file:/Test%20Case%20Modifier"));
    classSetUpFired = true;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 58 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class CampaignFeatToken method unparse.

@Override
public String[] unparse(LoadContext context, Campaign campaign) {
    Changes<CampaignSourceEntry> cseChanges = context.getObjectContext().getListChanges(campaign, ListKey.FILE_FEAT);
    Collection<CampaignSourceEntry> added = cseChanges.getAdded();
    if (added == null) {
        //empty indicates no token
        return null;
    }
    Set<String> set = new TreeSet<>();
    for (CampaignSourceEntry cse : added) {
        set.add(cse.getLSTformat());
    }
    return set.toArray(new String[set.size()]);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) TreeSet(java.util.TreeSet)

Example 59 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class PreCampaignTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    sourceCamp = buildCampaign("Source");
    camp1 = buildCampaign("Camp1");
    camp2KeyParent = buildCampaign("Camp2");
    camp3 = buildCampaign("Camp3");
    CampaignSourceEntry cse = new CampaignSourceEntry(camp3, camp3.getSourceURI());
    camp2KeyParent.addToListFor(ListKey.FILE_PCC, cse);
    camp4Wild = buildCampaign("Camp4");
    camp4Wild.addToListFor(ListKey.BOOK_TYPE, "Wild");
    camp6TypeParent = buildCampaign("Camp5");
    cse = new CampaignSourceEntry(camp4Wild, camp4Wild.getSourceURI());
    camp6TypeParent.addToListFor(ListKey.FILE_PCC, cse);
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry)

Example 60 with CampaignSourceEntry

use of pcgen.persistence.lst.CampaignSourceEntry in project pcgen by PCGen.

the class LSTConverter method startItem.

private void startItem(final Campaign campaign) {
    for (final Loader loader : loaders) {
        List<CampaignSourceEntry> files = loader.getFiles(campaign);
        for (final CampaignSourceEntry cse : files) {
            final URI uri = cse.getURI();
            setChanged();
            notifyObservers(uri);
            if (!"file".equalsIgnoreCase(uri.getScheme())) {
                Logging.log(Logging.WARNING, "Skipping campaign " + uri + " from " + campaign.getSourceURI() + " as it is not a local file.");
                continue;
            }
            File in = new File(uri);
            // Use canonical name to stop reruns for the same file referred to using .. 
            URI canonicalUri;
            try {
                canonicalUri = in.getCanonicalFile().toURI();
            } catch (IOException e1) {
                Logging.log(Logging.WARNING, "Skipping campaign " + uri + " from " + campaign.getSourceURI() + " as it could not be made canonical. " + e1.getMessage());
                continue;
            }
            if (written.contains(canonicalUri)) {
                continue;
            }
            written.add(canonicalUri);
            File base = findSubRoot(rootDir, in);
            if (base == null) {
                Logging.log(Logging.WARNING, "Skipping campaign " + uri + " from " + campaign.getSourceURI() + " as it is not in the selected source directory.");
                continue;
            }
            String relative = in.toString().substring(base.toString().length() + 1);
            if (!in.exists()) {
                Logging.log(Logging.WARNING, "Skipping campaign " + uri + " from " + campaign.getSourceURI() + " as it does not exist. Campaign is " + cse.getCampaign().getSourceURI());
                continue;
            }
            File outFile = new File(outDir, File.separator + relative);
            if (outFile.exists()) {
                Logging.log(Logging.WARNING, "Won't overwrite: " + outFile);
                continue;
            }
            ensureParents(outFile.getParentFile());
            try {
                changeLogWriter.append("\nProcessing " + in + "\n");
                String result = load(uri, loader);
                if (result != null) {
                    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
                    out.write(result);
                    out.close();
                }
            } catch (PersistenceLayerException | IOException | InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
Also used : SelfCopyLoader(pcgen.gui2.converter.loader.SelfCopyLoader) ClassLoader(pcgen.gui2.converter.loader.ClassLoader) GenericLoader(pcgen.persistence.lst.GenericLoader) BasicLoader(pcgen.gui2.converter.loader.BasicLoader) AbilityLoader(pcgen.gui2.converter.loader.AbilityLoader) EquipmentLoader(pcgen.gui2.converter.loader.EquipmentLoader) CopyLoader(pcgen.gui2.converter.loader.CopyLoader) AbilityCategoryLoader(pcgen.persistence.lst.AbilityCategoryLoader) SourceFileLoader(pcgen.persistence.SourceFileLoader) LstFileLoader(pcgen.persistence.lst.LstFileLoader) CDOMControlLoader(pcgen.rules.persistence.CDOMControlLoader) IOException(java.io.IOException) URI(java.net.URI) BufferedWriter(java.io.BufferedWriter) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Aggregations

CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)95 URI (java.net.URI)54 Campaign (pcgen.core.Campaign)44 URISyntaxException (java.net.URISyntaxException)27 LoadContext (pcgen.rules.context.LoadContext)25 UnreachableError (pcgen.base.lang.UnreachableError)19 BeforeClass (org.junit.BeforeClass)16 PCClassLoader (pcgen.persistence.lst.PCClassLoader)15 TreeSet (java.util.TreeSet)12 PlayerCharacter (pcgen.core.PlayerCharacter)11 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)11 ArrayList (java.util.ArrayList)9 PCClass (pcgen.core.PCClass)9 File (java.io.File)8 GenericLoader (pcgen.persistence.lst.GenericLoader)8 CDOMReference (pcgen.cdom.base.CDOMReference)7 SourceEntry (pcgen.persistence.lst.SourceEntry)7 Ability (pcgen.core.Ability)6 FeatLoader (pcgen.persistence.lst.FeatLoader)6 AbilityList (pcgen.cdom.list.AbilityList)5