Search in sources :

Example 51 with CampaignSourceEntry

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

the class VariableReport method processCampaign.

private List<File> processCampaign(Campaign campaign, List<VarDefine> varList, Map<String, Integer> varCountMap, Set<File> processedLstFiles) throws FileNotFoundException, IOException {
    List<CampaignSourceEntry> cseList = new ArrayList<>();
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_LST_EXCLUDE));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_RACE));
    //TODO: Handle class with a special processor that tracks the class, sublass and level 
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_CLASS));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_COMPANION_MOD));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_SKILL));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_ABILITY_CATEGORY));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_ABILITY));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_FEAT));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_DEITY));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_DOMAIN));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_WEAPON_PROF));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_ARMOR_PROF));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_SHIELD_PROF));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_EQUIP));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_SPELL));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_LANGUAGE));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_TEMPLATE));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_EQUIP_MOD));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_KIT));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_BIO_SET));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_VARIABLE));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_DYNAMIC));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_DATACTRL));
    cseList.addAll(campaign.getSafeListFor(ListKey.FILE_GLOBALMOD));
    List<File> missingLstFiles = new ArrayList<>();
    for (CampaignSourceEntry cse : cseList) {
        File lstFile = new File(cse.getURI());
        if (!lstFile.exists()) {
            missingLstFiles.add(lstFile);
            continue;
        }
        if (processedLstFiles.contains(lstFile)) {
            continue;
        }
        processedLstFiles.add(lstFile);
        processLstFile(varList, varCountMap, lstFile);
    }
    return missingLstFiles;
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) ArrayList(java.util.ArrayList) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 52 with CampaignSourceEntry

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

the class PCClassTest method testGetHighestLevelSpell.

/**
	 * Test the function of the getHighestLevelSpell method.
	 * @throws PersistenceLayerException
	 */
public void testGetHighestLevelSpell() throws PersistenceLayerException {
    LoadContext context = Globals.getContext();
    PCClass megaCasterClass = new PCClass();
    megaCasterClass.setName("MegaCaster");
    BuildUtilities.setFact(megaCasterClass, "SpellType", "Arcane");
    context.unconditionallyProcess(megaCasterClass, "SPELLSTAT", "CHA");
    megaCasterClass.put(ObjectKey.SPELLBOOK, false);
    megaCasterClass.put(ObjectKey.MEMORIZE_SPELLS, false);
    context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(1), "KNOWN", "4,2,2,3,4,5");
    context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(1), "CAST", "3,1,2,3,4,5");
    context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(2), "KNOWN", "4,2,2,3,4,5,6,7,8,9,10");
    context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(2), "CAST", "3,1,2,3,4,5,6,7,8,9,10");
    Globals.getContext().getReferenceContext().importObject(megaCasterClass);
    final PlayerCharacter character = getCharacter();
    assertEquals("Highest spell level for class", 10, character.getSpellSupport(megaCasterClass).getHighestLevelSpell());
    character.incrementClassLevel(1, megaCasterClass);
    PCClass charClass = character.getClassKeyed(megaCasterClass.getKeyName());
    assertEquals("Highest spell level for character's class", 10, character.getSpellSupport(charClass).getHighestLevelSpell());
    String sbook = Globals.getDefaultSpellBook();
    String cast = character.getSpellSupport(charClass).getCastForLevel(10, sbook, true, false, character) + character.getSpellSupport(charClass).getBonusCastForLevelString(10, sbook, character);
    assertEquals("Should not be able to cast 10th level spells at 1st level", "0", cast);
    cast = character.getSpellSupport(charClass).getCastForLevel(5, sbook, true, false, character) + character.getSpellSupport(charClass).getBonusCastForLevelString(5, sbook, character);
    assertEquals("Should be able to cast 5th level spells at 1st level", "5", cast);
    Ability casterFeat = new Ability();
    FeatLoader featLoader = new FeatLoader();
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    featLoader.parseLine(Globals.getContext(), casterFeat, "CasterBoost	TYPE:General	BONUS:SPELLCAST|CLASS=MegaCaster;LEVEL=11|1", source);
    casterFeat.setCDOMCategory(AbilityCategory.FEAT);
    context.getReferenceContext().importObject(casterFeat);
    AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, casterFeat, null);
    cast = character.getSpellSupport(charClass).getCastForLevel(11, sbook, true, false, character) + character.getSpellSupport(charClass).getBonusCastForLevelString(11, sbook, character);
    assertEquals("Should be able to cast 11th level spells with feat", "1", cast);
    assertEquals("Should be able to cast 11th level spells with feat", 11, character.getSpellSupport(charClass).getHighestLevelSpell(character));
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) FeatLoader(pcgen.persistence.lst.FeatLoader) LoadContext(pcgen.rules.context.LoadContext) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI)

Example 53 with CampaignSourceEntry

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

the class PObjectTest method testGetPCCText.

/**
	 * Test the processing of getPCCText to ensure that it correctly produces
	 * an LST representation of an object and that the LST can then be reloaded
	 * to recrete the object.
	 *
	 * @throws PersistenceLayerException
	 */
public void testGetPCCText() throws PersistenceLayerException {
    OrderedPairManager opManager = new OrderedPairManager();
    LoadContext context = Globals.getContext();
    context.getVariableContext().assertLegalVariableID(context.getActiveScope().getLegalScope(), opManager, "Face");
    Race race = new Race();
    race.setName("TestRace");
    race.put(ObjectKey.CHALLENGE_RATING, new ChallengeRating(FormulaFactory.getFormulaFor(5)));
    String racePCCText = race.getPCCText();
    assertNotNull("PCC Text for race should not be null", racePCCText);
    GenericLoader<Race> raceLoader = new GenericLoader<>(Race.class);
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    raceLoader.parseLine(context, null, racePCCText, source);
    Race reconstRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "TestRace");
    assertEquals("getPCCText should be the same after being encoded and reloaded", racePCCText, reconstRace.getPCCText());
    assertEquals("Racial CR was not restored after saving and reloading.", race.get(ObjectKey.CHALLENGE_RATING), reconstRace.get(ObjectKey.CHALLENGE_RATING));
    FactKey.getConstant("Abb", new StringManager());
    PCClass aClass = new PCClass();
    aClass.setName("TestClass");
    String classPCCText = aClass.getPCCText();
    assertNotNull("PCC Text for race should not be null", racePCCText);
    PCClassLoader classLoader = new PCClassLoader();
    PCClass reconstClass = classLoader.parseLine(context, null, classPCCText, source);
    assertEquals("getPCCText should be the same after being encoded and reloaded", classPCCText, reconstClass.getPCCText());
    assertEquals("Class abbrev was not restored after saving and reloading.", aClass.getAbbrev(), reconstClass.getAbbrev());
}
Also used : ChallengeRating(pcgen.cdom.content.ChallengeRating) GenericLoader(pcgen.persistence.lst.GenericLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) StringManager(pcgen.base.format.StringManager) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) OrderedPairManager(pcgen.base.format.OrderedPairManager) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Example 54 with CampaignSourceEntry

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

the class SpellLevelTest method testGetPCBasedBonusKnownSpells.

/**
	 * Test method for {@link pcgen.core.analysis.SpellLevel#getPCBasedBonusKnownSpells(pcgen.core.PlayerCharacter, pcgen.core.PCClass)}.
	 * @throws Exception 
	 */
public void testGetPCBasedBonusKnownSpells() throws Exception {
    LoadContext context = Globals.getContext();
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    final String classLine = "CLASS:Sorcerer	TYPE:Base.PC	SPELLSTAT:CHA	SPELLTYPE:Arcane	MEMORIZE:NO	BONUS:CASTERLEVEL|Sorcerer|CL";
    PCClassLoader classLoader = new PCClassLoader();
    PCClass pcc = classLoader.parseLine(context, null, classLine, source);
    Spell spell = TestHelper.makeSpell("Bless");
    String abilityLine = "Spell bonanza	CATEGORY:FEAT	SPELLKNOWN:CLASS|Sorcerer=3|KEY_Bless";
    AbilityLoader abilityLoader = new AbilityLoader();
    abilityLoader.parseLine(context, null, abilityLine, source);
    Ability ab1 = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, "Spell bonanza");
    // Do the post parsing cleanup
    context.resolveDeferredTokens();
    context.getReferenceContext().buildDeferredObjects();
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().validate(null);
    assertTrue(context.getReferenceContext().resolveReferences(null));
    PlayerCharacter aPC = getCharacter();
    Collection<Integer> levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
    assertEquals("Initial number of spell levels incorrect", 0, levels.size());
    addAbility(AbilityCategory.FEAT, ab1);
    // Now for the tests
    levels = listManagerFacet.getScopes2(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST));
    assertEquals("Incorrect number of spell levels returned", 1, levels.size());
    assertEquals("Incorrect spell level returned", Integer.valueOf(3), levels.iterator().next());
    Collection<Spell> result = listManagerFacet.getSet(aPC.getCharID(), pcc.get(ObjectKey.CLASS_SPELLLIST), 3);
    assertEquals("Incorrect number of spells returned", 1, result.size());
    assertEquals("Incorrect spell returned", spell, result.iterator().next());
}
Also used : Ability(pcgen.core.Ability) AbilityLoader(pcgen.persistence.lst.AbilityLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCClass(pcgen.core.PCClass) URI(java.net.URI) Spell(pcgen.core.spell.Spell) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) Campaign(pcgen.core.Campaign) PlayerCharacter(pcgen.core.PlayerCharacter) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader)

Example 55 with CampaignSourceEntry

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

the class PlayerCharacterSpellTest method additionalSetUp.

@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    CampaignSourceEntry source = TestHelper.createSource(getClass());
    // Spells
    classSpell = TestHelper.makeSpell("classSpell");
    domainSpell = TestHelper.makeSpell("domainSpell");
    final String classLine = "CLASS:MyClass	TYPE:Base.PC	SPELLSTAT:CHA	MEMORIZE:YES	SPELLBOOK:NO";
    PCClassLoader classLoader = new PCClassLoader();
    divineClass = classLoader.parseLine(context, null, classLine, source);
    BuildUtilities.setFact(divineClass, "SpellType", "Divine");
    classLoader.parseLine(context, divineClass, "CLASS:MyClass	KNOWNSPELLS:LEVEL=0|LEVEL=1|LEVEL=2|LEVEL=3|LEVEL=4|LEVEL=5|LEVEL=6|LEVEL=7|LEVEL=8|LEVEL=9	BONUS:CASTERLEVEL|Cleric|CL", source);
    classLoader.parseClassLevelLine(context, divineClass, 1, source, "CAST:5,4	BONUS:DOMAIN|NUMBER|2	BONUS:VAR|DomainLVL|CL");
    context.getReferenceContext().importObject(divineClass);
    final String domainLine = "Sun	SPELLLEVEL:DOMAIN|Sun=1|KEY_domainSpell";
    GenericLoader<Domain> domainLoader = new GenericLoader<>(Domain.class);
    domainLoader.parseLine(context, null, domainLine, source);
    sunDomain = context.getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, "Sun");
    CDOMReference<ClassSpellList> ref = TokenUtilities.getTypeOrPrimitive(context, ClassSpellList.class, divineClass.getKeyName());
    AssociatedPrereqObject edge = context.getListContext().addToMasterList("CLASSES", classSpell, ref, classSpell);
    edge.setAssociation(AssociationKey.SPELL_LEVEL, 1);
    context.commit();
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) ClassSpellList(pcgen.cdom.list.ClassSpellList) LoadContext(pcgen.rules.context.LoadContext) GenericLoader(pcgen.persistence.lst.GenericLoader) PCClassLoader(pcgen.persistence.lst.PCClassLoader) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

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