Search in sources :

Example 6 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreLevelMaxTest method testPCLevel.

/**
	 * Make sure BONUS:PCLEVEL is not counted
	 * @throws Exception
	 */
public void testPCLevel() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.incrementClassLevel(2, myClass, true);
    myClass = character.getClassKeyed("MY_CLASS");
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELEVELMAX:5");
    final BonusObj levelBonus = Bonus.newBonus(context, "PCLEVEL|MY_CLASS|2");
    myClass.addToListFor(ListKey.BONUS, levelBonus);
    character.calcActiveBonuses();
    assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

Example 7 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreLevelTest method testPCLevel.

/**
	 * Make sure BONUS:PCLEVEL is not counted
	 * @throws Exception
	 */
public void testPCLevel() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.incrementClassLevel(2, myClass, true);
    myClass = character.getClassKeyed("MY_CLASS");
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELEVEL:MIN=6");
    final BonusObj levelBonus = Bonus.newBonus(context, "PCLEVEL|MY_CLASS|2");
    myClass.addToListFor(ListKey.BONUS, levelBonus);
    character.calcActiveBonuses();
    assertFalse("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MAX=6");
    assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MAX=6");
    assertFalse("Character is less than 6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=5");
    assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MIN=4,MAX=6");
    assertTrue("Character has 4-6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRELEVEL:MIN=6,MAX=8");
    assertFalse("Character does not have 6-8 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PRELEVEL:MIN=6,MAX=8");
    assertTrue("Character is not 6-8 levels", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

Example 8 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreEquipTwoWeaponTest method testWield.

/**
	 * Test wield category tests
	 * @throws Exception
	 */
public void testWield() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Race race = new Race();
    race.setName("Test Race");
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
    race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    character.setRace(race);
    LoadContext context = Globals.getContext();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    longsword.setLocation(EquipmentLocation.EQUIPPED_TWO_HANDS);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equiptwoweapon");
    prereq.setKey("WIELDCATEGORY=OneHanded");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    // Test 3.0 Style
    longsword.put(ObjectKey.SIZE, mediumRef);
    longsword.put(ObjectKey.BASESIZE, mediumRef);
    assertTrue("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.SIZE, largeRef);
    longsword.put(ObjectKey.BASESIZE, largeRef);
    assertFalse("Weapon is L therefore TwoHanded", PrereqHandler.passes(prereq, character, null));
    // Test 3.5 style
    longsword.put(ObjectKey.SIZE, mediumRef);
    longsword.put(ObjectKey.BASESIZE, mediumRef);
    longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
    assertFalse("Weapon is TwoHanded", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
    assertTrue("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext) WieldCategory(pcgen.core.character.WieldCategory) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Example 9 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreFactSetTest method additionalSetUp.

@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    BuildUtilities.createFactSet(context, "PANTHEON", Deity.class);
    super.additionalSetUp();
}
Also used : LoadContext(pcgen.rules.context.LoadContext)

Example 10 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PreFactTest method additionalSetUp.

@Override
protected void additionalSetUp() throws Exception {
    LoadContext context = Globals.getContext();
    BuildUtilities.createFact(context, "Abb", Race.class);
    super.additionalSetUp();
}
Also used : LoadContext(pcgen.rules.context.LoadContext)

Aggregations

LoadContext (pcgen.rules.context.LoadContext)141 PlayerCharacter (pcgen.core.PlayerCharacter)58 BonusObj (pcgen.core.bonus.BonusObj)48 PCClass (pcgen.core.PCClass)32 URI (java.net.URI)25 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)25 URISyntaxException (java.net.URISyntaxException)20 Campaign (pcgen.core.Campaign)16 Race (pcgen.core.Race)16 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)16 Equipment (pcgen.core.Equipment)15 UnreachableError (pcgen.base.lang.UnreachableError)14 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)14 PCClassLoader (pcgen.persistence.lst.PCClassLoader)14 Spell (pcgen.core.spell.Spell)13 Ability (pcgen.core.Ability)12 PCTemplate (pcgen.core.PCTemplate)12 SizeAdjustment (pcgen.core.SizeAdjustment)10 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)9 Skill (pcgen.core.Skill)9