Search in sources :

Example 91 with BonusObj

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

the class PCToken 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_PC, bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

Example 92 with BonusObj

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

the class PCToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, ListKey.BONUS_PC);
    Collection<BonusObj> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token (and no global clear, so nothing to do)
        return null;
    }
    Set<String> bonusSet = new TreeSet<>();
    for (BonusObj bonus : added) {
        bonusSet.add(bonus.getLSTformat());
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) TreeSet(java.util.TreeSet)

Example 93 with BonusObj

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

Example 94 with BonusObj

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

the class PreClassTest method testSpellcasterLevelsTwoClasses.

public void testSpellcasterLevelsTwoClasses() throws Exception {
    final PCClass pcClass = new PCClass();
    LoadContext context = Globals.getContext();
    pcClass.setName("MyClass");
    BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
    BonusObj aBonus = Bonus.newBonus(context, "CASTERLEVEL|MyClass|CL");
    if (aBonus != null) {
        pcClass.addToListFor(ListKey.BONUS, aBonus);
    }
    final PCClass pcClass2 = new PCClass();
    pcClass2.setName("MyClass2");
    BuildUtilities.setFact(pcClass2, "SpellType", "Divine");
    aBonus = Bonus.newBonus(context, "CASTERLEVEL|MyClass2|CL");
    if (aBonus != null) {
        pcClass.addToListFor(ListKey.BONUS, aBonus);
    }
    final PlayerCharacter character = getCharacter();
    final PreParserFactory factory = PreParserFactory.getInstance();
    Prerequisite prereq = factory.parse("PRECLASS:2,SPELLCASTER=1");
    character.incrementClassLevel(1, pcClass);
    assertEquals(false, PrereqHandler.passes(prereq, character, null));
    character.incrementClassLevel(1, pcClass2);
    assertEquals(true, 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) PCClass(pcgen.core.PCClass)

Example 95 with BonusObj

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

the class PreAttTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    myClass.setName("My Class");
    myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
    final BonusObj babClassBonus = Bonus.newBonus(context, "COMBAT|BASEAB|CL+5");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, babClassBonus);
    Globals.getContext().getReferenceContext().importObject(myClass);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

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