Search in sources :

Example 46 with BonusObj

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

the class StartfeatsToken method unparse.

@Override
public String[] unparse(LoadContext context, Race race) {
    Changes<BonusObj> changes = context.getObjectContext().getListChanges(race, ListKey.BONUS);
    if (changes == null || changes.isEmpty()) {
        // Empty indicates no token present
        return null;
    }
    // CONSIDER need to deal with removed...
    Collection<BonusObj> added = changes.getAdded();
    String tokenName = getTokenName();
    Collection<String> bonusSet = new WeightedCollection<>(String.CASE_INSENSITIVE_ORDER);
    for (BonusObj bonus : added) {
        if (tokenName.equals(bonus.getTokenSource())) {
            bonusSet.add(bonus.getValue());
        }
    }
    if (bonusSet.isEmpty()) {
        // This is okay - just no BONUSes from this token
        return null;
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) WeightedCollection(pcgen.base.util.WeightedCollection)

Example 47 with BonusObj

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

the class BonusToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PointBuyMethod pbm, String value) {
    BonusObj bon = Bonus.newBonus(context, value);
    if (bon == null) {
        return new ParseResult.Fail(getTokenName() + " was given invalid bonus: " + value, context);
    }
    bon.setTokenSource(getTokenName());
    pbm.addBonus(bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

Example 48 with BonusObj

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

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

the class PreCheckTest 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("PRECHECK:1,Fortitude=1");
    assertTrue("Character's Fort save should be 1", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECK:1,Will=2");
    assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECK:1,Fortitude=1,Will=3");
    assertTrue("Character's Will save should be 2", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PRECHECK:2,Fortitude=2,Will=2");
    assertFalse("Character's 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 50 with BonusObj

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

the class PreCheckTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    LoadContext context = Globals.getContext();
    PCCheck obj = new PCCheck();
    obj.setName("Fortitude");
    Globals.getContext().getReferenceContext().importObject(obj);
    obj = new PCCheck();
    obj.setName("Reflex");
    Globals.getContext().getReferenceContext().importObject(obj);
    obj = new PCCheck();
    obj.setName("Will");
    Globals.getContext().getReferenceContext().importObject(obj);
    myClass.setName("My Class");
    myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
    final BonusObj fortRefBonus = Bonus.newBonus(context, "SAVE|BASE.Fortitude,BASE.Reflex|CL/3");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, fortRefBonus);
    final BonusObj willBonus = Bonus.newBonus(context, "SAVE|BASE.Will|CL/2+2");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, willBonus);
    Globals.getContext().getReferenceContext().importObject(myClass);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) PCCheck(pcgen.core.PCCheck)

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