Search in sources :

Example 26 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class EquipmentTest method additionalSetUp.

@Override
public void additionalSetUp() throws PersistenceLayerException {
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    GenericLoader<Equipment> eqLoader = new GenericLoader<>(Equipment.class);
    eq = eqLoader.parseLine(Globals.getContext(), null, "Dummy	SIZE:M 	KEY:OrigKey	TYPE:Weapon", source);
    eq = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, OriginalKey);
    eqDouble = eqLoader.parseLine(Globals.getContext(), null, "Double	SIZE:M 	KEY:DoubleKey	TYPE:Weapon.Double", source);
    eqDouble = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, "DoubleKey");
    GenericLoader<EquipmentModifier> loader = new GenericLoader<>(EquipmentModifier.class);
    loader.parseLine(Globals.getContext(), null, "+1 (Enhancement to Weapon or Ammunition)	KEY:PLUS1W	FORMATCAT:MIDDLE	NAMEOPT:TEXT=+1	TYPE:Ammunition.Weapon	PLUS:1	VISIBLE:QUALIFY	ITYPE:Masterwork.Enhancement.Magic.Plus1	SOURCEPAGE:RSRD SpecialMaterials.rtf	BONUS:WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement	ASSIGNTOALL:NO", source);
    loader.parseLine(Globals.getContext(), null, "Masterwork		KEY:MWORKW	FORMATCAT:FRONT	NAMEOPT:NORMAL	TYPE:MasterworkQuality.Ammunition.Weapon	COST:0	VISIBLE:QUALIFY	ITYPE:Masterwork	SOURCEPAGE:SRDEquipmentI.rtf	BONUS:ITEMCOST|TYPE=Ammunition|6	BONUS:ITEMCOST|TYPE=Weapon|300	BONUS:WEAPON|TOHIT|1|TYPE=Enhancement	ASSIGNTOALL:YES", source);
    SettingsHandler.getGame().addPlusCalculation("WEAPON|(2000*PLUS*PLUS)+(2000*ALTPLUS*ALTPLUS)");
}
Also used : CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) GenericLoader(pcgen.persistence.lst.GenericLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI)

Example 27 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class PCClassTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    Campaign customCampaign = new Campaign();
    customCampaign.setName("Unit Test");
    customCampaign.setName("KEY_Unit Test");
    customCampaign.addToListFor(ListKey.DESCRIPTION, new Description("Unit Test data"));
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(customCampaign, new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    // Create the monseter class type
    GameMode gamemode = SettingsHandler.getGame();
    gamemode.addClassType("Monster		CRFORMULA:0			ISMONSTER:YES	XPPENALTY:NO");
    gamemode.setSkillMultiplierLevels("4");
    // Create the humanoid class
    String classDef = "CLASS:Humanoid	KEY:KEY_Humanoid	HD:8		CLASSTYPE:Monster	STARTSKILLPTS:1	" + "MODTOSKILLS:NO	MONSKILL:6+INT	MONNONSKILLHD:1|PRESIZELTEQ:M	" + "MONNONSKILLHD:2|PRESIZEEQ:L";
    PCClassLoader classLoader = new PCClassLoader();
    LoadContext context = Globals.getContext();
    humanoidClass = classLoader.parseLine(context, null, classDef, source);
    Globals.getContext().getReferenceContext().importObject(humanoidClass);
    classDef = "CLASS:Nymph		KEY:KEY_Nymph	CLASSTYPE:Monster	HD:6	STARTSKILLPTS:6	MODTOSKILLS:YES	";
    classLoader = new PCClassLoader();
    nymphClass = classLoader.parseLine(context, null, classDef, source);
    Globals.getContext().getReferenceContext().importObject(nymphClass);
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
    // Create the large size mod
    // Create the BugBear race
    bugbearRace = new Race();
    bugbearRace.setName("Bugbear");
    bugbearRace.put(StringKey.KEY_NAME, "KEY_Bugbear");
    bugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    bugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
    bugbearRace.put(IntegerKey.INITIAL_SKILL_MULT, 1);
    Globals.getContext().getReferenceContext().importObject(bugbearRace);
    bigBugbearRace = new Race();
    bigBugbearRace.setName("BigBugbear");
    bigBugbearRace.put(StringKey.KEY_NAME, "KEY_BigBugbear");
    bigBugbearRace.put(FormulaKey.SIZE, new FixedSizeFormula(largeRef));
    bigBugbearRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
    bigBugbearRace.put(IntegerKey.INITIAL_SKILL_MULT, 1);
    Globals.getContext().getReferenceContext().importObject(bigBugbearRace);
    // Create the Nymph race
    nymphRace = new Race();
    nymphRace.setName("Nymph");
    nymphRace.put(StringKey.KEY_NAME, "KEY_Nymph");
    nymphRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    nymphRace.addToListFor(ListKey.HITDICE_ADVANCEMENT, Integer.MAX_VALUE);
    nymphRace.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(nymphClass), FormulaFactory.getFormulaFor(0)));
    Globals.getContext().getReferenceContext().importObject(nymphRace);
    // Setup class with prereqs and var based abilities with prereqs.
    PreVariableParser parser = new PreVariableParser();
    prereq = parser.parse("VARGTEQ", "Foo,1", false, false);
    classPreRule = new RuleCheck();
    classPreRule.setName("CLASSPRE");
    classPreRule.setDefault(false);
    gamemode.getModeContext().getReferenceContext().importObject(classPreRule);
    prClass = new PCClass();
    prClass.setName("PreReqClass");
    prClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
    final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
    if (aBonus != null) {
        prClass.addToListFor(ListKey.BONUS, aBonus);
    }
    prClass.addPrerequisite(prereq);
    qClass = new PCClass();
    qClass.setName("QualClass");
    qClass.put(StringKey.KEY_NAME, "KEY_QualClass");
    CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(prClass);
    qClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
    nqClass = new PCClass();
    nqClass.setName("NonQualClass");
    nqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
    nqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
    nqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) BonusObj(pcgen.core.bonus.BonusObj) PreVariableParser(plugin.pretokens.parser.PreVariableParser) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) PCClassLoader(pcgen.persistence.lst.PCClassLoader) Qualifier(pcgen.cdom.reference.Qualifier)

Example 28 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class PCClassTest method testAddAbility.

/**
	 * Test the definition and application of abilities. 
	 * @throws PersistenceLayerException 
	 */
public void testAddAbility() throws PersistenceLayerException {
    LoadContext context = Globals.getContext();
    // Create some abilities to be added
    AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
    Ability ab1 = new Ability();
    ab1.setName("Ability1");
    ab1.setCDOMCategory(cat);
    context.getReferenceContext().importObject(ab1);
    Ability ab2 = new Ability();
    ab2.setName("Ability2");
    ab2.setCDOMCategory(cat);
    context.getReferenceContext().importObject(ab2);
    // Link them to a template
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    String classPCCText = "CLASS:Cleric	HD:8		CLASSTYPE:PC	TYPE:Base.PC	ABB:Clr	ABILITY:TestCat|AUTOMATIC|Ability1\n" + "CLASS:Cleric	STARTSKILLPTS:2\n" + "2	ABILITY:TestCat|AUTOMATIC|Ability2";
    PCClass pcclass = parsePCClassText(classPCCText, source);
    ab1.setCDOMCategory(cat);
    ab2.setCDOMCategory(cat);
    context.getReferenceContext().importObject(ab1);
    context.getReferenceContext().importObject(ab2);
    CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
    Collection<CDOMReference<Ability>> mods = pcclass.getListMods(autoList);
    assertEquals(1, mods.size());
    CDOMReference<Ability> ref = mods.iterator().next();
    Collection<Ability> abilities = ref.getContainedObjects();
    assertEquals(1, abilities.size());
    assertEquals(ab1, abilities.iterator().next());
    Collection<AssociatedPrereqObject> assocs = pcclass.getListAssociations(autoList, ref);
    assertEquals(1, assocs.size());
    PCClassLevel level = pcclass.getOriginalClassLevel(2);
    mods = level.getListMods(autoList);
    assertEquals(1, mods.size());
    ref = mods.iterator().next();
    abilities = ref.getContainedObjects();
    assertEquals(1, abilities.size());
    assertEquals(ab2, abilities.iterator().next());
    assocs = level.getListAssociations(autoList, ref);
    assertEquals(1, assocs.size());
    // Add the class to the character
    PlayerCharacter pc = getCharacter();
    pc.incrementClassLevel(1, pcclass, true);
    assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
    assertFalse("Character should not have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
    pc.incrementClassLevel(1, pcclass, true);
    assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
    assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
Also used : AbilityList(pcgen.cdom.list.AbilityList) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) PCClassLevel(pcgen.cdom.inst.PCClassLevel) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 29 with UnreachableError

use of pcgen.base.lang.UnreachableError 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 30 with UnreachableError

use of pcgen.base.lang.UnreachableError 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)

Aggregations

UnreachableError (pcgen.base.lang.UnreachableError)39 URI (java.net.URI)23 URISyntaxException (java.net.URISyntaxException)23 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)19 LoadContext (pcgen.rules.context.LoadContext)14 Field (java.lang.reflect.Field)9 Ability (pcgen.core.Ability)9 Campaign (pcgen.core.Campaign)9 CDOMReference (pcgen.cdom.base.CDOMReference)7 AbilityList (pcgen.cdom.list.AbilityList)6 CNAbility (pcgen.cdom.content.CNAbility)5 PlayerCharacter (pcgen.core.PlayerCharacter)4 FeatLoader (pcgen.persistence.lst.FeatLoader)4 ArrayList (java.util.ArrayList)3 PCClass (pcgen.core.PCClass)3 PCTemplate (pcgen.core.PCTemplate)3 QualifiedObject (pcgen.core.QualifiedObject)3 AbilityLoader (pcgen.persistence.lst.AbilityLoader)3 GenericLoader (pcgen.persistence.lst.GenericLoader)3 PCClassLoader (pcgen.persistence.lst.PCClassLoader)3