Search in sources :

Example 16 with LoadContext

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

the class WeaponTokenTest method testWpnFinesse.

/**
	 * Test the processing of a finesseable weapon both with and without weapon finesse
	 * and temporary bonuses.
	 */
public void testWpnFinesse() {
    PlayerCharacter character = getCharacter();
    assertEquals("Prof should be longsword", "KEY_LONGSWORD", fineSword.get(ObjectKey.WEAPON_PROF).get().getKeyName());
    LoadContext context = Globals.getContext();
    character.addEquipment(fineSword);
    EquipSet es = new EquipSet("0.1.3", "Longsword (Fine)", fineSword.getName(), fineSword);
    character.addEquipSet(es);
    character.setCalcEquipmentList();
    // Test weapon profs effects on large weapons
    WeaponToken token = new WeaponToken();
    assertEquals("Fine sword", "+18/+13/+8/+3", token.getToken("WEAPON.3.BASEHIT", character, null));
    // Now apply weapon finess and check dex is used rather than str
    Ability wpnFinesse = new Ability();
    wpnFinesse.setName("Weapon Finesse");
    wpnFinesse.setCDOMCategory(AbilityCategory.FEAT);
    wpnFinesse.put(StringKey.KEY_NAME, "Weapon Finesse");
    final BonusObj wfBonus = Bonus.newBonus(context, "COMBAT|TOHIT.Finesseable|((max(STR,DEX)-STR)+SHIELDACCHECK)|TYPE=NotRanged");
    wpnFinesse.addToListFor(ListKey.BONUS, wfBonus);
    addAbility(AbilityCategory.FEAT, wpnFinesse);
    assertEquals("Fine sword", "+19/+14/+9/+4", token.getToken("WEAPON.3.BASEHIT", character, null));
    // Add a temp penalty to dex and check that it is applied
    character.setUseTempMods(true);
    Spell spell2 = new Spell();
    spell2.setName("Concrete Boots");
    final BonusObj aBonus = Bonus.newBonus(context, "STAT|DEX|-4");
    if (aBonus != null) {
        spell2.addToListFor(ListKey.BONUS, aBonus);
    }
    BonusObj penalty = spell2.getRawBonusList(character).get(0);
    character.addTempBonus(penalty, spell2, character);
    character.calcActiveBonuses();
    assertEquals("Fine sword", "+18/+13/+8/+3", token.getToken("WEAPON.3.BASEHIT", character, null));
}
Also used : Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) EquipSet(pcgen.core.character.EquipSet) LoadContext(pcgen.rules.context.LoadContext) Spell(pcgen.core.spell.Spell)

Example 17 with LoadContext

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

the class PCGVer2ParserCharacterTest method testRaceAddSpellcaster.

/**
	 * Check that a racial ADD:SPELLCASTER happens exactly once on character 
	 * load. Duplication of the association has occurred a couple of times in 
	 * the past.
	 * @throws Exception
	 */
public void testRaceAddSpellcaster() throws Exception {
    LoadContext context = Globals.getContext();
    Race rakshasha = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Rakshasa");
    PlayerCharacter pc = getCharacter();
    pc.setImporting(true);
    PCGVer2Parser pcgParser = new PCGVer2Parser(pc);
    String[] pcgLines = { "RACE:Rakshasa|ADD:[SPELLCASTER:Sorcerer|CHOICE:Sorcerer]" };
    pcgParser.parsePCG(pcgLines);
    PersistentTransitionChoice<?> tc = rakshasha.getListFor(ListKey.ADD).get(0);
    List<Object> assocList = pc.getAssocList(tc, AssociationListKey.ADD);
    assertEquals("Number of associations for ADD " + assocList, 1, assocList.size());
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext)

Example 18 with LoadContext

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

the class AbstractPreRoundRobin method runSimpleRoundRobin.

public static void runSimpleRoundRobin(String s, String d) {
    try {
        Prerequisite p = PreParserFactory.getInstance().parse(s);
        PrerequisiteWriterInterface writer = PrerequisiteWriterFactory.getInstance().getWriter(p.getKind());
        if (writer == null) {
            fail("Could not find Writer for: " + p.getKind());
        }
        StringWriter w = new StringWriter();
        writer.write(w, p);
        assertEquals(d, w.toString());
        /*
			 * Now try new system
			 */
        LoadContext context = new EditorLoadContext();
        CDOMObject obj = new ObjectCache();
        int colonLoc = s.indexOf(':');
        String key = s.substring(0, colonLoc);
        String value = s.substring(colonLoc + 1);
        if (context.processToken(obj, key, value)) {
            context.commit();
        } else {
            context.rollback();
            Logging.replayParsedMessages();
            fail();
        }
        Logging.clearParseMessages();
        Collection<String> output = context.unparse(obj);
        if (output == null || output.isEmpty()) {
            // Uh Oh
            fail("Unable to unparse: " + key + ":" + value);
        }
        assertEquals(1, output.size());
        assertEquals(d, output.iterator().next());
    } catch (PersistenceLayerException e) {
        e.printStackTrace();
        fail(e.getLocalizedMessage());
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) EditorLoadContext(pcgen.rules.context.EditorLoadContext) StringWriter(java.io.StringWriter) CDOMObject(pcgen.cdom.base.CDOMObject) ObjectCache(pcgen.cdom.inst.ObjectCache) EditorLoadContext(pcgen.rules.context.EditorLoadContext) LoadContext(pcgen.rules.context.LoadContext) PrerequisiteWriterInterface(pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 19 with LoadContext

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

the class PreBaseSizeTest method testBaseSizePlusMod.

/**
	 * Tests to make sure the base size does not includ SIZEMOD adjustments
	 * @throws Exception
	 */
public void testBaseSizePlusMod() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.setRace(race);
    final BonusObj sizeBonus = Bonus.newBonus(context, "SIZEMOD|NUMBER|1");
    race.addToListFor(ListKey.BONUS, sizeBonus);
    character.calcActiveBonuses();
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREBASESIZEEQ:Medium");
    assertTrue("Character's base size should be equal to Medium", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZELTEQ:Medium");
    assertTrue("Character's base size should be <= to Medium", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZEGTEQ:Medium");
    assertTrue("Character's base size should be >= to Medium", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZEGT:Small");
    assertTrue("Character's base size should be > to Small", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZELT:Large");
    assertTrue("Character's base size should be < to Large", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZELT:Medium");
    assertFalse("Character's base size should not be < to Medium", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREBASESIZEGT:Medium");
    assertFalse("Character's base size should not be > to Medium", 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 20 with LoadContext

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

the class PreClassTest method testSpellcasterTypeWrongCasePass.

/**
	 * Test to ensure that a spellcaster type check is case insensitive
	 * @throws Exception
	 */
public void testSpellcasterTypeWrongCasePass() throws Exception {
    LoadContext context = Globals.getContext();
    final PCClass pcClass = context.getReferenceContext().constructCDOMObject(PCClass.class, "MyClass");
    BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
    context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");
    context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().resolveReferences(null);
    context.loadCampaignFacets();
    final PlayerCharacter character = getCharacter();
    character.incrementClassLevel(1, pcClass);
    setPCStat(character, cha, 12);
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("class");
    prereq.setKey("Spellcaster.Arcane");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.GTEQ);
    final PreClassTester test = new PreClassTester();
    final int passes = test.passes(prereq, character, null);
    assertEquals(1, passes);
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreClassTester(plugin.pretokens.test.PreClassTester) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass)

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