Search in sources :

Example 81 with BonusObj

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

the class BonusManagerTest method testStackingNegativeFirst.

/**
	 * Validate that the setActiveBonusStack method will correctly calculate the value of 
	 * a negative bonus followed by a positive bonus to a non-stackable value.
	 */
@Test
public void testStackingNegativeFirst() {
    PCTemplate testObj = TestHelper.makeTemplate("PostiveFirst");
    LoadContext context = Globals.getContext();
    final BonusObj negBonus = Bonus.newBonus(context, "COMBAT|AC|-2|TYPE=Armor");
    testObj.addToListFor(ListKey.BONUS, negBonus);
    final BonusObj posBonus = Bonus.newBonus(context, "COMBAT|AC|5|TYPE=Armor");
    testObj.addToListFor(ListKey.BONUS, posBonus);
    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 82 with BonusObj

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

the class EquipmentModifierTest method test885958B.

/**
	 * Test -2 and +13
	 */
public void test885958B() {
    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, "+13");
    eqMod.addToListFor(ListKey.BONUS, aBonus);
    for (BonusObj bonusObj : eqMod.getBonusList(e)) {
        assertEquals("-2", bonusObj.getValue());
        final Prerequisite prereq = bonusObj.getPrerequisiteList().get(0);
        assertEquals("+13", 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 83 with BonusObj

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

the class BonusLst method process.

@Override
public boolean process(LoadContext context, CDOMObject obj) {
    List<BonusObj> bonusList = obj.getListFor(ListKey.BONUS);
    boolean returnValue = true;
    if (bonusList != null) {
        for (BonusObj bonus : bonusList) {
            String bonusName = bonus.getBonusName();
            if ("ABILITYPOOL".equalsIgnoreCase(bonusName)) {
                for (Object o : bonus.getBonusInfoList()) {
                    if (context.getReferenceContext().silentlyGetConstructedCDOMObject(ABILITY_CATEGORY_CLASS, o.toString()) == null) {
                        LoadContext dummyCtx = new RuntimeLoadContext(context.getReferenceContext(), new ConsolidatedListCommitStrategy());
                        dummyCtx.setSourceURI(obj.getSourceURI());
                        Logging.errorPrint("BONUS: " + bonus + " in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName() + " contained an invalid AbilityCategory " + o.toString(), dummyCtx);
                        returnValue = false;
                    }
                }
            } else if ("UDAM".equals(bonusName)) {
                for (Object o : bonus.getBonusInfoList()) {
                    String classKey = o.toString();
                    final PCClass aClass = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCCLASS_CLASS, classKey);
                    if (aClass == null) {
                        Logging.errorPrint("Could not find class '" + classKey + "' for UDAM token", context);
                    }
                }
            }
        }
    }
    try {
        obj.ownBonuses(obj);
    } catch (CloneNotSupportedException e) {
        Logging.errorPrint(e.getLocalizedMessage());
        return false;
    }
    return returnValue;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) ConsolidatedListCommitStrategy(pcgen.rules.context.ConsolidatedListCommitStrategy) LoadContext(pcgen.rules.context.LoadContext) RuntimeLoadContext(pcgen.rules.context.RuntimeLoadContext) CDOMObject(pcgen.cdom.base.CDOMObject) PCClass(pcgen.core.PCClass) RuntimeLoadContext(pcgen.rules.context.RuntimeLoadContext)

Example 84 with BonusObj

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

the class BonusLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    if (obj instanceof EquipmentModifier) {
        // EquipmentModifier bonuses are handled by plugin.lsttokens.equipmentmodifier.BonusToken
        return null;
    }
    Changes<BonusObj> changes = context.getObjectContext().getListChanges(obj, 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();
    Set<String> bonusSet = new TreeSet<>();
    for (BonusObj bonus : added) {
        if (tokenName.equals(bonus.getTokenSource())) {
            String bonusString = bonus.getLSTformat();
            bonusSet.add(bonusString);
        }
    }
    if (bonusSet.isEmpty()) {
        // This is okay - just no BONUSes from this token
        return null;
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : EquipmentModifier(pcgen.core.EquipmentModifier) BonusObj(pcgen.core.bonus.BonusObj) TreeSet(java.util.TreeSet)

Example 85 with BonusObj

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

the class BonusLst method parseToken.

@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
    if (obj instanceof Ungranted) {
        return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
    }
    if (value.indexOf("PREAPPLY:") != -1) {
        return new ParseResult.Fail("Use of PREAPPLY prohibited on a BONUS , " + "please use TEMPBONUS with: " + value);
    }
    final String v = value.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
    BonusObj bon = Bonus.newBonus(context, v);
    if (bon == null) {
        return new ParseResult.Fail(getTokenName() + " was given invalid bonus: " + value, context);
    }
    bon.setTokenSource(getTokenName());
    context.getObjectContext().addToList(obj, ListKey.BONUS, bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) Ungranted(pcgen.cdom.base.Ungranted)

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