Search in sources :

Example 96 with LoadContext

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

the class TempBonusTest method testANYPCTemporaryBonus.

public void testANYPCTemporaryBonus() throws PersistenceLayerException {
    LoadContext context = Globals.getContext();
    BonusObj bonus = Bonus.newBonus(context, "WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement");
    Spell spell = context.getReferenceContext().constructNowIfNecessary(Spell.class, "PCTempBonusItem");
    spell.addToListFor(ListKey.BONUS_ANYPC, bonus);
    assertTrue(TempBonusHelper.hasAnyPCTempBonus(spell));
    assertFalse(TempBonusHelper.hasPCTempBonus(spell));
    assertTrue(TempBonusHelper.hasNonPCTempBonus(spell));
    assertTrue(TempBonusHelper.hasCharacterTempBonus(spell));
    assertFalse(TempBonusHelper.hasEquipmentTempBonus(spell));
    try {
        assertTrue(TempBonusHelper.getEquipmentApplyString(spell).isEmpty());
    } catch (NullPointerException e) {
    //This is appropriate too
    }
}
Also used : LoadContext(pcgen.rules.context.LoadContext) Spell(pcgen.core.spell.Spell)

Example 97 with LoadContext

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

the class DomainChoiceManagerTest method test001.

/**
	 * Test the constructor
	 */
public void test001() {
    Race pObj = new Race();
    pObj.setName("My PObject");
    LoadContext context = Globals.getContext();
    Domain foo = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Foo");
    Domain bar = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Bar");
    Domain baz = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Baz");
    Domain qux = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Qux");
    Domain quux = context.getReferenceContext().constructCDOMObject(Domain.class, "KEY_Quux");
    context.unconditionallyProcess(pObj, "CHOOSE", "DOMAIN|KEY_Foo|KEY_Bar|KEY_Baz|KEY_Qux|KEY_Quux");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    assertNotNull(pObj.get(ObjectKey.CHOOSE_INFO));
    pObj.put(FormulaKey.NUMCHOICES, FormulaFactory.getFormulaFor(4));
    PlayerCharacter aPC = getCharacter();
    ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, aPC);
    is(choiceManager, not(eq(null)), "Found the chooser");
    List<Domain> aList = new ArrayList<>();
    List<Domain> sList = new ArrayList<>();
    choiceManager.getChoices(aPC, aList, sList);
    assertEquals(5, aList.size());
    assertTrue(aList.contains(foo));
    assertTrue(aList.contains(bar));
    assertTrue(aList.contains(baz));
    assertTrue(aList.contains(qux));
    assertTrue(aList.contains(quux));
    assertEquals(0, sList.size());
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Race(pcgen.core.Race) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext) Domain(pcgen.core.Domain)

Example 98 with LoadContext

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

the class PlayerCharacterTest method testMakeIntoExClass.

public void testMakeIntoExClass() {
    // Prepare class and ex-class
    LoadContext context = Globals.getContext();
    PCClass paladin = new PCClass();
    paladin.setName("Paladin");
    context.getReferenceContext().importObject(paladin);
    PCClass exPaladin = new PCClass();
    exPaladin.setName("exPaladin");
    context.getReferenceContext().importObject(exPaladin);
    paladin.put(ObjectKey.EX_CLASS, context.getReferenceContext().getCDOMReference(PCClass.class, exPaladin.getKeyName()));
    readyToRun();
    PlayerCharacter pc = getCharacter();
    // Add a level of the class
    pc.incrementClassLevel(2, paladin, true, false);
    PCClass pcPalClass = pc.getClassKeyed(paladin.getKeyName());
    pc.setHP(pc.getActiveClassLevel(pcPalClass, 0), 10);
    pc.setHP(pc.getActiveClassLevel(pcPalClass, 1), 6);
    // Make it into an ex-class
    pc.makeIntoExClass(pcPalClass);
    assertNull("Paladin class should not be held", pc.getClassKeyed(paladin.getKeyName()));
    PCClass pcExPalClass = pc.getClassKeyed(exPaladin.getKeyName());
    assertNotNull("Ex-Paladin class should be held", pcExPalClass);
    PCClassLevel pcLvl1 = pc.getActiveClassLevel(pcExPalClass, 0);
    assertNotNull("Level 1 should be Ex-Paladin", pcLvl1);
    assertEquals("Should still be level 2 character", 2, pc.getTotalLevels());
    assertEquals("Hp at first level incorrect", 10, (int) pc.getHP(pcLvl1));
}
Also used : LoadContext(pcgen.rules.context.LoadContext) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 99 with LoadContext

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

the class SizeAdjustmentTest method testSizeMod.

public void testSizeMod() throws Exception {
    Race race = new Race();
    race.setName("Race");
    PCTemplate template = new PCTemplate();
    template.setName("Template");
    Deity deity = new Deity();
    deity.setName("Deity");
    LoadContext context = Globals.getContext();
    context.getReferenceContext().importObject(template);
    context.unconditionallyProcess(race, "SIZE", "S");
    context.unconditionallyProcess(template, "SIZE", "D");
    context.unconditionallyProcess(deity, "BONUS", "SIZEMOD|NUMBER|1");
    context.resolveDeferredTokens();
    context.getReferenceContext().resolveReferences(null);
    PlayerCharacter pc = getCharacter();
    assertEquals("M", pc.getDisplay().getSize());
    pc.setRace(race);
    assertEquals("S", pc.getDisplay().getSize());
    pc.addTemplate(template);
    assertEquals("D", pc.getDisplay().getSize());
    pc.setDeity(deity);
    pc.calcActiveBonuses();
    assertEquals("T", pc.getDisplay().getSize());
}
Also used : LoadContext(pcgen.rules.context.LoadContext)

Example 100 with LoadContext

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

the class PreCheckBaseTest method testBonus.

public void testBonus() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    final BonusObj fortBonus = Bonus.newBonus(context, "SAVE|Fortitude|1");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortBonus);
    character.incrementClassLevel(1, myClass, true);
    character.calcActiveBonuses();
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRECHECKBASE:1,Fortitude=1");
    assertFalse("Character's base Fort save should be 0", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECKBASE:1,Will=2");
    assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECKBASE:1,Fortitude=1,Will=3");
    assertFalse("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECKBASE:2,Fortitude=1,Will=2");
    assertFalse("Character's base Fort save not 1", 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)

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