Search in sources :

Example 56 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class BonusManagerTest method testStackingPosNegPos.

/**
	 * Validate that the setActiveBonusStack method will correctly calculate the value of 
	 * a positive bonus, then a negative bonus followed by a positive bonus to a 
	 * non-stackable value.
	 */
@Test
public void testStackingPosNegPos() {
    PCTemplate testObj = TestHelper.makeTemplate("PosNegPos");
    LoadContext context = Globals.getContext();
    final BonusObj posBonus = Bonus.newBonus(context, "COMBAT|AC|5|TYPE=Armor");
    testObj.addToListFor(ListKey.BONUS, posBonus);
    final BonusObj negBonus = Bonus.newBonus(context, "COMBAT|AC|-2|TYPE=Armor");
    testObj.addToListFor(ListKey.BONUS, negBonus);
    final BonusObj posBonus2 = Bonus.newBonus(context, "COMBAT|AC|4|TYPE=Armor");
    testObj.addToListFor(ListKey.BONUS, posBonus2);
    PlayerCharacter pc = getCharacter();
    pc.addTemplate(testObj);
    // Run the check a few times to ensure no randomness issues 
    for (int i = 0; i < 10; i++) {
        pc.calcActiveBonuses();
        assertEquals("Incorrect bonus total", 3.0, pc.getTotalBonusTo("COMBAT", "AC"), 0.0001);
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) Test(org.junit.Test)

Example 57 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class EquipmentModifierTest method test885958A.

/**
	 * Test +13
	 */
public void test885958A() {
    LoadContext context = Globals.getContext();
    final EquipmentModifier eqMod = new EquipmentModifier();
    final BonusObj aBonus = Bonus.newBonus(context, "WEAPON|DAMAGE|((%CHOICE)MIN(STR))");
    eqMod.addToListFor(ListKey.BONUS, aBonus);
    final Equipment e = new Equipment();
    e.addAssociation(eqMod, "+13");
    for (BonusObj bonusObj : eqMod.getBonusList(e)) {
        assertEquals("((+13)MIN(STR))", bonusObj.getValue());
    }
    assertEquals("((%CHOICE)MIN(STR))", aBonus.getValue());
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

Example 58 with BonusObj

use of pcgen.core.bonus.BonusObj 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 59 with BonusObj

use of pcgen.core.bonus.BonusObj 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 60 with BonusObj

use of pcgen.core.bonus.BonusObj 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)

Aggregations

BonusObj (pcgen.core.bonus.BonusObj)126 LoadContext (pcgen.rules.context.LoadContext)48 PlayerCharacter (pcgen.core.PlayerCharacter)29 ArrayList (java.util.ArrayList)22 CDOMObject (pcgen.cdom.base.CDOMObject)18 PCClass (pcgen.core.PCClass)14 Prerequisite (pcgen.core.prereq.Prerequisite)13 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)13 EquipSet (pcgen.core.character.EquipSet)11 IdentityHashMap (java.util.IdentityHashMap)10 Map (java.util.Map)10 TreeSet (java.util.TreeSet)10 Ability (pcgen.core.Ability)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 TempBonusInfo (pcgen.core.BonusManager.TempBonusInfo)8 Equipment (pcgen.core.Equipment)8 HashMap (java.util.HashMap)7 Race (pcgen.core.Race)7 StringTokenizer (java.util.StringTokenizer)6 CNAbility (pcgen.cdom.content.CNAbility)6