Search in sources :

Example 36 with LoadContext

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

the class EquipmentModifierTest method testChoice.

/**
	 * Test the expansion of the %CHOICE in a prereq for a bonus. Note as the
	 * options for the choice are processed in reverse order, we have to check the
	 * values in reverse order.
	 */
public void testChoice() {
    LoadContext context = Globals.getContext();
    final EquipmentModifier eqMod = new EquipmentModifier();
    final BonusObj aBonus = Bonus.newBonus(context, "WEAPON|TOHIT|-2|PREVARGT:%CHOICE,STR");
    final Equipment e = new Equipment();
    e.addAssociation(eqMod, "+1");
    e.addAssociation(eqMod, "+2");
    eqMod.addToListFor(ListKey.BONUS, aBonus);
    final List<BonusObj> list = eqMod.getBonusList(e);
    for (int j = list.size() - 1; j > 0; j--) {
        final BonusObj bonusObj = list.get(j);
        assertEquals("-2", bonusObj.getValue());
        final Prerequisite prereq = bonusObj.getPrerequisiteList().get(0);
        assertEquals("+" + (j + 1), prereq.getKey());
        assertEquals("STR", prereq.getOperand());
    }
    assertEquals("-2", aBonus.getValue());
    final Prerequisite prereq = aBonus.getPrerequisiteList().get(0);
    assertEquals("%CHOICE", prereq.getKey());
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 37 with LoadContext

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

the class SpellListTokenTest method setUp.

/*
	 * @see TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    SettingsHandler.getGame().setSpellBaseDC("10+SPELLLEVEL+BASESPELLSTAT");
    SimpleLoader<BonusSpellInfo> bonusSpellLoader = new SimpleLoader<>(BonusSpellInfo.class);
    try {
        URI testURI = new URI("file:/" + getClass().getName() + ".java");
        bonusSpellLoader.parseLine(context, "1	BASESTATSCORE:12	STATRANGE:8", testURI);
        bonusSpellLoader.parseLine(context, "2	BASESTATSCORE:14	STATRANGE:8", testURI);
        bonusSpellLoader.parseLine(context, "3	BASESTATSCORE:16	STATRANGE:8", testURI);
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    // Human
    human = new Race();
    final BonusObj bon = Bonus.newBonus(context, "FEAT|POOL|2");
    human.addToListFor(ListKey.BONUS, bon);
    arcaneClass = new PCClass();
    arcaneClass.setName("TestArcane");
    BuildUtilities.setFact(arcaneClass, "SpellType", "Arcane");
    context.unconditionallyProcess(arcaneClass, "SPELLSTAT", "CHA");
    arcaneClass.put(ObjectKey.SPELLBOOK, false);
    arcaneClass.put(ObjectKey.MEMORIZE_SPELLS, false);
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "KNOWN", "4,2,1");
    context.unconditionallyProcess(arcaneClass.getOriginalClassLevel(1), "CAST", "3,1,0");
    context.getReferenceContext().importObject(arcaneClass);
    divineClass = new PCClass();
    divineClass.setName("TestDivine");
    BuildUtilities.setFact(divineClass, "SpellType", "Divine");
    context.unconditionallyProcess(divineClass, "SPELLSTAT", "WIS");
    divineClass.put(ObjectKey.SPELLBOOK, false);
    divineClass.put(ObjectKey.MEMORIZE_SPELLS, true);
    context.unconditionallyProcess(divineClass.getOriginalClassLevel(1), "CAST", "3,1,0");
    context.unconditionallyProcess(divineClass, "SPELLLEVEL", "CLASS|SPELLCASTER.Divine=1|Cure Light Wounds");
    context.getReferenceContext().importObject(divineClass);
    context.resolveDeferredTokens();
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().resolveReferences(null);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) Race(pcgen.core.Race) BonusSpellInfo(pcgen.cdom.content.BonusSpellInfo) LoadContext(pcgen.rules.context.LoadContext) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) PCClass(pcgen.core.PCClass) URI(java.net.URI) SimpleLoader(pcgen.persistence.lst.SimpleLoader)

Example 38 with LoadContext

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

the class SkillSitTokenTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    PlayerCharacter character = getCharacter();
    final LevelInfo levelInfo = new LevelInfo();
    levelInfo.setLevelString("LEVEL");
    levelInfo.setMaxClassSkillString("LEVEL+3");
    levelInfo.setMaxCrossClassSkillString("(LEVEL+3)/2");
    GameMode gamemode = SettingsHandler.getGame();
    gamemode.addLevelInfo("Default", levelInfo);
    //Stats
    setPCStat(character, dex, 16);
    setPCStat(character, intel, 17);
    LoadContext context = Globals.getContext();
    BonusObj aBonus = Bonus.newBonus(context, "MODSKILLPOINTS|NUMBER|INT");
    if (aBonus != null) {
        intel.addToListFor(ListKey.BONUS, aBonus);
    }
    // Race
    Race testRace = new Race();
    testRace.setName("TestRace");
    character.setRace(testRace);
    // Class
    PCClass myClass = new PCClass();
    myClass.setName("My Class");
    myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
    character.incrementClassLevel(5, myClass, true);
    //Skills
    knowledge = new Skill[2];
    knowledge[0] = new Skill();
    context.unconditionallyProcess(knowledge[0], "CLASSES", "MyClass");
    knowledge[0].setName("KNOWLEDGE (ARCANA)");
    TestHelper.addType(knowledge[0], "KNOWLEDGE.INT");
    CDOMDirectSingleRef<PCStat> intelRef = CDOMDirectSingleRef.getRef(intel);
    knowledge[0].put(ObjectKey.KEY_STAT, intelRef);
    context.getReferenceContext().importObject(knowledge[0]);
    aBonus = Bonus.newBonus(context, "SITUATION|Tumble=On Hot Concrete|2");
    if (aBonus != null) {
        knowledge[0].addToListFor(ListKey.BONUS, aBonus);
    }
    SkillRankControl.modRanks(8.0, myClass, true, character, knowledge[0]);
    knowledge[1] = new Skill();
    context.unconditionallyProcess(knowledge[1], "CLASSES", "MyClass");
    knowledge[1].setName("KNOWLEDGE (RELIGION)");
    TestHelper.addType(knowledge[1], "KNOWLEDGE.INT");
    knowledge[1].put(ObjectKey.KEY_STAT, intelRef);
    aBonus = Bonus.newBonus(context, "SITUATION|Balance=On a Ball|2");
    if (aBonus != null) {
        knowledge[1].addToListFor(ListKey.BONUS, aBonus);
    }
    context.getReferenceContext().importObject(knowledge[1]);
    SkillRankControl.modRanks(5.0, myClass, true, character, knowledge[1]);
    tumble = new Skill();
    context.unconditionallyProcess(tumble, "CLASSES", "MyClass");
    tumble.setName("Tumble");
    tumble.addToListFor(ListKey.TYPE, Type.getConstant("DEX"));
    tumble.addToListFor(ListKey.SITUATION, "On Hot Concrete");
    tumble.addToListFor(ListKey.SITUATION, "Down a Mountain");
    CDOMDirectSingleRef<PCStat> dexRef = CDOMDirectSingleRef.getRef(dex);
    tumble.put(ObjectKey.KEY_STAT, dexRef);
    context.getReferenceContext().importObject(tumble);
    SkillRankControl.modRanks(7.0, myClass, true, character, tumble);
    balance = new Skill();
    context.unconditionallyProcess(balance, "CLASSES", "MyClass");
    balance.setName("Balance");
    balance.addToListFor(ListKey.TYPE, Type.getConstant("DEX"));
    balance.addToListFor(ListKey.SITUATION, "On a Ball");
    balance.put(ObjectKey.KEY_STAT, dexRef);
    aBonus = Bonus.newBonus(context, "SKILL|Balance|2|PRESKILL:1,Tumble=5|TYPE=Synergy.STACK");
    if (aBonus != null) {
        balance.addToListFor(ListKey.BONUS, aBonus);
    }
    context.getReferenceContext().importObject(balance);
    SkillRankControl.modRanks(4.0, myClass, true, character, balance);
    context.getReferenceContext().buildDerivedObjects();
    context.getReferenceContext().resolveReferences(null);
    character.calcActiveBonuses();
}
Also used : GameMode(pcgen.core.GameMode) Skill(pcgen.core.Skill) PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) LevelInfo(pcgen.core.LevelInfo) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext) PCClass(pcgen.core.PCClass) PCStat(pcgen.core.PCStat)

Example 39 with LoadContext

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

the class ACTokenTest method setUp.

/*
	 * @see TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    PlayerCharacter character = getCharacter();
    setPCStat(character, dex, 14);
    dex.removeListFor(ListKey.BONUS);
    BonusObj aBonus = Bonus.newBonus(context, "COMBAT|AC|10|TYPE=Base");
    if (aBonus != null) {
        dex.addToListFor(ListKey.BONUS, aBonus);
    }
    // Ignoring max dex
    aBonus = Bonus.newBonus(context, "COMBAT|AC|DEX|TYPE=Ability");
    if (aBonus != null) {
        dex.addToListFor(ListKey.BONUS, aBonus);
    }
    EquipSet def = new EquipSet("0.1", "Default");
    character.addEquipSet(def);
    character.setCalcEquipmentList();
    character.calcActiveBonuses();
    // Create non magic armor
    chainShirt = new Equipment();
    chainShirt.setName("Chain Shirt");
    chainShirt.put(StringKey.KEY_NAME, "KEY_Chain_Shirt");
    TestHelper.addType(chainShirt, "Armor.Light.Suit.Standard");
    chainShirt.put(IntegerKey.AC_CHECK, -2);
    aBonus = Bonus.newBonus(context, "COMBAT|AC|4|TYPE=Armor.REPLACE");
    if (aBonus != null) {
        chainShirt.addToListFor(ListKey.BONUS, aBonus);
    }
    // Create magic armor enhancement
    masterwork = new EquipmentModifier();
    masterwork.setName("Masterwork");
    masterwork.put(StringKey.KEY_NAME, "MWORKA");
    TestHelper.addType(masterwork, "Armor.Shield");
    masterwork.addToListFor(ListKey.ITEM_TYPES, "Masterwork");
    aBonus = Bonus.newBonus(context, "EQMARMOR|ACCHECK|1|TYPE=Enhancement");
    if (aBonus != null) {
        masterwork.addToListFor(ListKey.BONUS, aBonus);
    }
    context.getReferenceContext().importObject(masterwork);
    plus1 = new EquipmentModifier();
    plus1.setName("Plus 1 Enhancement");
    plus1.put(StringKey.KEY_NAME, "PLUS1A");
    TestHelper.addType(plus1, "Armor.Shield");
    plus1.put(IntegerKey.PLUS, 1);
    plus1.addToListFor(ListKey.ITEM_TYPES, "Enhancement");
    plus1.addToListFor(ListKey.ITEM_TYPES, "Magic");
    plus1.addToListFor(ListKey.ITEM_TYPES, "Plus1");
    aBonus = Bonus.newBonus(context, "COMBAT|AC|1|TYPE=Armor.REPLACE");
    if (aBonus != null) {
        plus1.addToListFor(ListKey.BONUS, aBonus);
    }
    Globals.getContext().getReferenceContext().importObject(plus1);
    // Load AC definitions - but only once
    final GameMode gamemode = SettingsHandler.getGame();
    if (!gamemode.isValidACType("Total")) {
        gamemode.addACAdds("Total", Collections.singletonList(new ACControl("TOTAL")));
        gamemode.addACAdds("Armor", Collections.singletonList(new ACControl("Armor")));
        gamemode.addACAdds("Ability", Collections.singletonList(new ACControl("Ability")));
    }
}
Also used : GameMode(pcgen.core.GameMode) EquipmentModifier(pcgen.core.EquipmentModifier) PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) Equipment(pcgen.core.Equipment) ACControl(pcgen.cdom.content.ACControl) EquipSet(pcgen.core.character.EquipSet) LoadContext(pcgen.rules.context.LoadContext)

Example 40 with LoadContext

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

the class BonusConvertPlugin method processBonus.

private String processBonus(TokenProcessEvent tpe, String key, String value) {
    try {
        LoadContext context = tpe.getContext();
        CDOMObject obj = tpe.getPrimary();
        if (context.processToken(obj, key, value)) {
            context.commit();
        } else {
            context.rollback();
            Logging.replayParsedMessages();
        }
        Logging.clearParseMessages();
        Collection<String> output = context.unparse(obj);
        if (output == null || output.isEmpty()) {
            // Uh Oh
            return ("Unable to unparse: " + key + ':' + value);
        }
        boolean needTab = false;
        for (String s : output) {
            if (needTab) {
                tpe.append('\t');
            }
            needTab = true;
            tpe.append(s);
        }
        tpe.consume();
    } catch (PersistenceLayerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CDOMObject(pcgen.cdom.base.CDOMObject) EditorLoadContext(pcgen.rules.context.EditorLoadContext) 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