Search in sources :

Example 96 with BonusObj

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

the class Equipment method bonusTo.

/**
	 * Add bonuses
	 * 
	 * @param aPC
	 *          The PC that has this Equipment
	 * @param aType
	 *          The type of the Bonus
	 * @param aName
	 *          The name of the Bonus
	 * @param anObj
	 *          An object used in the bonus calculations, should be a 
	 *          PC or a piece of Equipment.
	 * @param bPrimary
	 *          If true get bonuses for primary head
	 * @return bonus
	 */
private double bonusTo(final PlayerCharacter aPC, final String aType, final String aName, final Object anObj, final boolean bPrimary) {
    StringBuilder sB = new StringBuilder(aType.toUpperCase());
    sB.append('.');
    sB.append(aName.toUpperCase());
    sB.append('.');
    final String aBonusKey = sB.toString();
    // entries that deal with this bonus request
    for (String aKey : getBonusMap().keySet()) {
        if (aKey.startsWith(aBonusKey)) {
            putBonusMap(aKey, "0");
        }
    }
    bonusPrimary = bPrimary;
    if (bPrimary) {
        BonusCalc.equipBonusTo(this, aType, aName, aPC);
        // now do temp bonuses
        final List<BonusObj> tbList = new ArrayList<>();
        for (BonusObj aBonus : getTempBonusList()) {
            if (!tbList.contains(aBonus)) {
                tbList.add(aBonus);
            }
        }
        BonusCalc.bonusTo(this, aType, aName, anObj, tbList, aPC);
    }
    // If using 3.5 weapon penalties, add them in also
    if (Globals.checkRule(RuleConstants.SYS_35WP)) {
        for (EqSizePenalty esp : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(EqSizePenalty.class)) {
            BonusCalc.bonusTo(this, aType, aName, this, esp.getBonuses(), aPC);
        }
    }
    final List<EquipmentModifier> eqModList = getEqModifierList(bPrimary);
    for (EquipmentModifier eqMod : eqModList) {
        eqMod.bonusTo(aPC, aType, aName, this);
    }
    double iBonus = 0;
    for (String key : getBonusMap().keySet()) {
        if (key.startsWith(aBonusKey)) {
            iBonus += Float.parseFloat(getBonusMap().get(key));
        }
    }
    return iBonus;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) EqSizePenalty(pcgen.cdom.inst.EqSizePenalty) ArrayList(java.util.ArrayList)

Example 97 with BonusObj

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

the class MonnonskillhdToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass obj) {
    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())) {
            StringBuilder sb = new StringBuilder();
            sb.append(bonus.getValue());
            if (bonus.hasPrerequisites()) {
                sb.append('|');
                sb.append(getPrerequisiteString(context, bonus.getPrerequisiteList()));
            }
            bonusSet.add(sb.toString());
        }
    }
    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) TreeSet(java.util.TreeSet)

Example 98 with BonusObj

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

the class MonskillToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass obj) {
    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())) {
            StringBuilder sb = new StringBuilder();
            sb.append(bonus.getValue());
            List<Prerequisite> prereqList = new ArrayList<>(bonus.getPrerequisiteList());
            Prerequisite prereq = getPrerequisite("PRELEVELMAX:1");
            prereqList.remove(prereq);
            if (!prereqList.isEmpty()) {
                sb.append('|');
                sb.append(getPrerequisiteString(context, prereqList));
            }
            bonusSet.add(sb.toString());
        }
    }
    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) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 99 with BonusObj

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

the class PrePCLevelTest method testPCLevel.

/**
	 * Make sure BONUS:PCLEVEL is not counted
	 * @throws Exception
	 */
public void testPCLevel() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.incrementClassLevel(2, myClass, true);
    myClass = character.getClassKeyed("MY_CLASS");
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREPCLEVEL:MIN=6");
    final BonusObj levelBonus = Bonus.newBonus(context, "PCLEVEL|MY_CLASS|2");
    myClass.addToListFor(ListKey.BONUS, levelBonus);
    character.calcActiveBonuses();
    assertFalse("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREPCLEVEL:MAX=6");
    assertTrue("Character has more than 6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PREPCLEVEL:MAX=6");
    assertFalse("Character is less than 6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PREPCLEVEL:MIN=5");
    assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREPCLEVEL:MIN=4,MAX=6");
    assertFalse("Character does not have 4-6 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREPCLEVEL:MIN=6,MAX=8");
    assertFalse("Character does not have 6-8 levels", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("!PREPCLEVEL:MIN=6,MAX=8");
    assertTrue("Character is not 6-8 levels", 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 100 with BonusObj

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

the class TestHelper method makeRace.

/**
	 * Set the important info about a Race
	 * @param name The race name
	 * @return The race (which has also been added to global storage)
	 */
public static Race makeRace(final String name) {
    final Race aRace = new Race();
    aRace.setName(name);
    aRace.put(StringKey.KEY_NAME, ("KEY_" + name));
    LoadContext context = Globals.getContext();
    final BonusObj bon = Bonus.newBonus(context, "FEAT|POOL|1");
    aRace.addToListFor(ListKey.BONUS, bon);
    context.getReferenceContext().importObject(aRace);
    return aRace;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) Race(pcgen.core.Race) 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