Search in sources :

Example 86 with BonusObj

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

the class PCClassTest method testBypassClassPrereqsDeprecated.

/**
	 * Test the interaction of prerequisites on PCClasses and bonuses and the
	 * Bypass Class Prereqs flag.
	 * @throws Exception
	 */
public void testBypassClassPrereqsDeprecated() throws Exception {
    LoadContext context = Globals.getContext();
    // Setup class with prereqs and var based abilities with prereqs.
    final PreVariableParser parser = new PreVariableParser();
    final Prerequisite aPrereq = parser.parse("VARGTEQ", "Foo,1", false, false);
    final GameMode gameMode = SettingsHandler.getGame();
    RuleCheck aClassPreRule = gameMode.getModeContext().getReferenceContext().silentlyGetConstructedCDOMObject(RuleCheck.class, "CLASSPRE");
    if (aClassPreRule == null) {
        aClassPreRule = new RuleCheck();
        aClassPreRule.setName("CLASSPRE");
        gameMode.getModeContext().getReferenceContext().importObject(aClassPreRule);
    }
    aClassPreRule.setDefault(false);
    final PCClass aPrClass = new PCClass();
    aPrClass.setName("PreReqClass");
    aPrClass.put(StringKey.KEY_NAME, "KEY_PreReqClass");
    final BonusObj aBonus = Bonus.newBonus(context, "MISC|SR|10|PREVARGTEQ:Foo,2");
    if (aBonus != null) {
        aPrClass.addToListFor(ListKey.BONUS, aBonus);
    }
    aPrClass.addPrerequisite(aPrereq);
    final PCClass aQClass = new PCClass();
    aQClass.setName("QualClass");
    aQClass.put(StringKey.KEY_NAME, "KEY_QualClass");
    CDOMDirectSingleRef<PCClass> ref = CDOMDirectSingleRef.getRef(aPrClass);
    aQClass.addToListFor(ListKey.QUALIFY, new Qualifier(PCClass.class, ref));
    final PCClass aNqClass = new PCClass();
    aNqClass.setName("NonQualClass");
    aNqClass.put(StringKey.KEY_NAME, "KEY_NonQualClass");
    aNqClass.put(VariableKey.getConstant("Foo"), FormulaFactory.ONE);
    aNqClass.getOriginalClassLevel(2).put(VariableKey.getConstant("Foo"), FormulaFactory.getFormulaFor(2));
    // Setup character without prereqs
    final PlayerCharacter character = getCharacter();
    // Test no prereqs and no bypass fails class and var
    assertFalse("PC with no prereqs should fail class qual test.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with no prereqs should fail var qual test.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test no prereqs and bypass passes class and fails var
    aClassPreRule.setDefault(true);
    assertTrue("PC with no prereqs should pass class qual test when bypassing prereqs is on.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with no prereqs should fail var qual test when bypass prereqs is on.", 0.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test prereqs and bypass pass class and var
    character.incrementClassLevel(1, aNqClass);
    assertTrue("PC with prereqs and bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
    character.incrementClassLevel(1, aNqClass);
    assertEquals("PC with prereqs and bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
    // Test prereqs and no bypass passes class and var
    aClassPreRule.setDefault(false);
    assertTrue("PC with prereqs and no bypass should pass class qual test.", aPrClass.qualifies(character, aPrClass));
    assertEquals("PC with prereqs and no bypass should pass var qual test.", 10.0, aPrClass.getBonusTo("MISC", "SR", 1, character), 0.1);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) PreVariableParser(plugin.pretokens.parser.PreVariableParser) LoadContext(pcgen.rules.context.LoadContext) Qualifier(pcgen.cdom.reference.Qualifier) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 87 with BonusObj

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

the class PObjectTest method testDR.

/**
	 * Test DR
	 * @throws Exception
	 */
public void testDR() throws Exception {
    Race race = new Race();
    LoadContext context = Globals.getContext();
    race.setName("Race");
    PCTemplate template = new PCTemplate();
    race.setName("Template");
    //		race.setDR("5/Good");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(5), "Good"));
    assertEquals("Basic DR set.", "5/Good", race.getListFor(ListKey.DAMAGE_REDUCTION).get(0).toString());
    race.removeListFor(ListKey.DAMAGE_REDUCTION);
    //		race.setDR("0/-");
    race.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(0), "-"));
    assertEquals("Basic DR set.", "0/-", race.getListFor(ListKey.DAMAGE_REDUCTION).get(0).toString());
    //		template.setDR("0/-");
    template.addToListFor(ListKey.DAMAGE_REDUCTION, new DamageReduction(FormulaFactory.getFormulaFor(0), "-"));
    final BonusObj aBonus = Bonus.newBonus(context, "DR|-|1");
    if (aBonus != null) {
        template.addToListFor(ListKey.BONUS, aBonus);
    }
    PlayerCharacter pc = getCharacter();
    pc.setRace(race);
    pc.addTemplate(template);
    pc.calcActiveBonuses();
    assertEquals("Basic DR set.", "1/-", pc.getDisplay().calcDR());
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) DamageReduction(pcgen.cdom.content.DamageReduction)

Example 88 with BonusObj

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

the class PlayerCharacterTest method testGetPartialStatFor.

public void testGetPartialStatFor() {
    readyToRun();
    PlayerCharacter pc = getCharacter();
    LoadContext context = Globals.getContext();
    setPCStat(pc, str, 14);
    Ability strBonusAbility = TestHelper.makeAbility("Strength power up", AbilityCategory.FEAT, "General.Fighter");
    final BonusObj strBonus = Bonus.newBonus(context, "STAT|STR|2");
    strBonusAbility.addToListFor(ListKey.BONUS, strBonus);
    assertEquals("Before bonus, no temp no equip", 14, pc.getPartialStatFor(str, false, false));
    assertEquals("Before bonus, temp no equip", 14, pc.getPartialStatFor(str, true, false));
    AbstractCharacterTestCase.applyAbility(pc, AbilityCategory.FEAT, strBonusAbility, null);
    pc.calcActiveBonuses();
    assertEquals("After bonus, no temp no equip", 16, pc.getPartialStatFor(str, false, false));
    assertEquals("After bonus, temp no equip", 16, pc.getPartialStatFor(str, true, false));
//		final BonusObj strBonusViaList = Bonus.newBonus("STAT|%LIST|3");
//		strBonusAbility.addBonusList(strBonusViaList);
//		strBonusAbility.addAssociated("STR");
//		strBonusAbility.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
//		pc.calcActiveBonuses();
//
//		assertEquals("After list bonus, no temp no equip", 3, pc.getPartialStatBonusFor("STR", false, false));
//		assertEquals("After list bonus, temp no equip", 3, pc.getPartialStatBonusFor("STR", true, false));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

Example 89 with BonusObj

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

the class PlayerCharacterTest method testMaxValue.

/**
	 * Test the processing of the MAX function with respect to character stats.
	 */
public void testMaxValue() {
    readyToRun();
    PlayerCharacter pc = getCharacter();
    LoadContext context = Globals.getContext();
    setPCStat(pc, str, 8);
    setPCStat(pc, dex, 14);
    pc.setUseTempMods(true);
    assertEquals("STR", -1.0, pc.getVariableValue("STR", ""), 0.1);
    assertEquals("DEX", 2.0, pc.getVariableValue("DEX", ""), 0.1);
    assertEquals("max(STR,DEX)", 2.0, pc.getVariableValue("max(STR,DEX)", ""), 0.1);
    StatToken statTok = new StatToken();
    assertEquals("Total stat.", "14", statTok.getToken("STAT.1", pc, null));
    assertEquals("Temp stat.", "14", statTok.getToken("STAT.1.NOEQUIP", pc, null));
    assertEquals("Equip stat.", "14", statTok.getToken("STAT.1.NOTEMP", pc, null));
    assertEquals("No equip/temp stat.", "14", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    assertEquals("Base stat.", "14", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    final BonusObj raceBonus = Bonus.newBonus(context, "STAT|DEX|-2");
    giantClass.addToListFor(ListKey.BONUS, raceBonus);
    pc.setRace(giantRace);
    pc.incrementClassLevel(4, giantClass, true);
    assertEquals("Total stat.", "12", statTok.getToken("STAT.1", pc, null));
    assertEquals("Temp stat.", "12", statTok.getToken("STAT.1.NOEQUIP", pc, null));
    assertEquals("Base stat.", "12", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    assertEquals("DEX", 1.0, pc.getVariableValue("DEX", ""), 0.1);
    assertEquals("max(STR,DEX)", 1.0, pc.getVariableValue("max(STR,DEX)", ""), 0.1);
    Spell spell2 = new Spell();
    spell2.setName("Concrete Boots");
    final BonusObj aBonus = Bonus.newBonus(context, "STAT|DEX|-2");
    if (aBonus != null) {
        spell2.addToListFor(ListKey.BONUS, aBonus);
    }
    BonusObj penalty = spell2.getRawBonusList(pc).get(0);
    pc.addTempBonus(penalty, spell2, pc);
    pc.calcActiveBonuses();
    assertEquals("Total stat.", "10", statTok.getToken("STAT.1", pc, null));
    assertEquals("Temp stat.", "10", statTok.getToken("STAT.1.NOEQUIP", pc, null));
    assertEquals("Base stat.", "12", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    assertEquals("DEX", 0.0, pc.getVariableValue("DEX", ""), 0.1);
    assertEquals("max(STR,DEX)-STR", 1.0, pc.getVariableValue("max(STR,DEX)-STR", ""), 0.1);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) StatToken(pcgen.io.exporttoken.StatToken)

Example 90 with BonusObj

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

the class AnyPCToken method parseTokenWithSeparator.

@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    final String v = value.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
    BonusObj bon = Bonus.newBonus(context, v);
    if (bon == null) {
        return new ParseResult.Fail(getFullTokenName() + " was given invalid type: " + value, context);
    }
    bon.setTokenSource(getFullTokenName());
    context.getObjectContext().addToList(obj, ListKey.BONUS_ANYPC, bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

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