Search in sources :

Example 16 with BonusObj

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

the class PCClass method addFeatPoolBonus.

/**
	 * Add the bonus to the character's feat pool that is granted by the class.
	 * NB: LEVELSPERFEAT is now handled via PLayerCHaracter.getNumFeatsFromLevels()
	 * rather than bonuses. Only the standard feat progression for the gamemode is
	 * handled here.
	 * @param aPC The character to bonus.
	 */
void addFeatPoolBonus(final PlayerCharacter aPC) {
    Integer mLevPerFeat = get(IntegerKey.LEVELS_PER_FEAT);
    int startLevel;
    int rangeLevel;
    int divisor;
    if (mLevPerFeat == null) {
        String aString = Globals.getBonusFeatString();
        StringTokenizer aTok = new StringTokenizer(aString, "|", false);
        startLevel = Integer.parseInt(aTok.nextToken());
        rangeLevel = Integer.parseInt(aTok.nextToken());
        divisor = rangeLevel;
        if (divisor > 0) {
            StringBuilder aBuf = new StringBuilder("FEAT|PCPOOL|").append("max(CL");
            // Make sure we only take off the startlevel value once
            if (this == aPC.getClassKeyed(aPC.getLevelInfoClassKeyName(0))) {
                aBuf.append("-").append(startLevel);
                aBuf.append("+").append(rangeLevel);
            }
            aBuf.append(",0)/").append(divisor);
            //						Logging.debugPrint("Feat bonus for " + this + " is "
            //							+ aBuf.toString());
            BonusObj bon = Bonus.newBonus(Globals.getContext(), aBuf.toString());
            aPC.addBonus(bon, this);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) BonusObj(pcgen.core.bonus.BonusObj)

Example 17 with BonusObj

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

the class PCClass method inheritAttributesFrom.

/*
	 * REFACTOR Some derivative of this method will be in PCClass only as part
	 * of the factory creation of a PCClassLevel... or perhaps in PCClassLevel
	 * so it can steal some information from other PCClassLevels of that
	 * PCClass. Either way, this will be far from its current form in the final
	 * solution.
	 */
/*
	 * CONSIDER Why does this not inherit classSkillChoices?
	 */
public void inheritAttributesFrom(final PCClass otherClass) {
    Boolean hbss = otherClass.get(ObjectKey.HAS_BONUS_SPELL_STAT);
    if (hbss != null) {
        put(ObjectKey.HAS_BONUS_SPELL_STAT, hbss);
        CDOMSingleRef<PCStat> bss = otherClass.get(ObjectKey.BONUS_SPELL_STAT);
        if (bss != null) {
            put(ObjectKey.BONUS_SPELL_STAT, bss);
        }
    }
    Boolean usbs = otherClass.get(ObjectKey.USE_SPELL_SPELL_STAT);
    if (usbs != null) {
        put(ObjectKey.USE_SPELL_SPELL_STAT, usbs);
    }
    Boolean cwss = otherClass.get(ObjectKey.CASTER_WITHOUT_SPELL_STAT);
    if (cwss != null) {
        put(ObjectKey.CASTER_WITHOUT_SPELL_STAT, cwss);
    }
    CDOMSingleRef<PCStat> ss = otherClass.get(ObjectKey.SPELL_STAT);
    if (ss != null) {
        put(ObjectKey.SPELL_STAT, ss);
    }
    TransitionChoice<CDOMListObject<Spell>> slc = otherClass.get(ObjectKey.SPELLLIST_CHOICE);
    if (slc != null) {
        put(ObjectKey.SPELLLIST_CHOICE, slc);
    }
    List<QualifiedObject<CDOMReference<Equipment>>> e = otherClass.getListFor(ListKey.EQUIPMENT);
    if (e != null) {
        addAllToListFor(ListKey.EQUIPMENT, e);
    }
    List<WeaponProfProvider> wp = otherClass.getListFor(ListKey.WEAPONPROF);
    if (wp != null) {
        addAllToListFor(ListKey.WEAPONPROF, wp);
    }
    QualifiedObject<Boolean> otherWP = otherClass.get(ObjectKey.HAS_DEITY_WEAPONPROF);
    if (otherWP != null) {
        put(ObjectKey.HAS_DEITY_WEAPONPROF, otherWP);
    }
    List<ArmorProfProvider> ap = otherClass.getListFor(ListKey.AUTO_ARMORPROF);
    if (ap != null) {
        addAllToListFor(ListKey.AUTO_ARMORPROF, ap);
    }
    List<ShieldProfProvider> sp = otherClass.getListFor(ListKey.AUTO_SHIELDPROF);
    if (sp != null) {
        addAllToListFor(ListKey.AUTO_SHIELDPROF, sp);
    }
    List<BonusObj> bonusList = otherClass.getListFor(ListKey.BONUS);
    if (bonusList != null) {
        addAllToListFor(ListKey.BONUS, bonusList);
    }
    try {
        ownBonuses(this);
    } catch (CloneNotSupportedException ce) {
        // TODO Auto-generated catch block
        ce.printStackTrace();
    }
    for (VariableKey vk : otherClass.getVariableKeys()) {
        put(vk, otherClass.get(vk));
    }
    if (otherClass.containsListFor(ListKey.CSKILL)) {
        removeListFor(ListKey.CSKILL);
        addAllToListFor(ListKey.CSKILL, otherClass.getListFor(ListKey.CSKILL));
    }
    if (otherClass.containsListFor(ListKey.LOCALCCSKILL)) {
        removeListFor(ListKey.LOCALCCSKILL);
        addAllToListFor(ListKey.LOCALCCSKILL, otherClass.getListFor(ListKey.LOCALCCSKILL));
    }
    removeListFor(ListKey.KIT_CHOICE);
    addAllToListFor(ListKey.KIT_CHOICE, otherClass.getSafeListFor(ListKey.KIT_CHOICE));
    remove(ObjectKey.REGION_CHOICE);
    if (otherClass.containsKey(ObjectKey.REGION_CHOICE)) {
        put(ObjectKey.REGION_CHOICE, otherClass.get(ObjectKey.REGION_CHOICE));
    }
    removeListFor(ListKey.SAB);
    addAllToListFor(ListKey.SAB, otherClass.getSafeListFor(ListKey.SAB));
    /*
		 * TODO Does this need to have things from the Class Level objects?
		 * I don't think so based on deferred processing of levels...
		 */
    addAllToListFor(ListKey.DAMAGE_REDUCTION, otherClass.getListFor(ListKey.DAMAGE_REDUCTION));
    for (CDOMReference<Vision> ref : otherClass.getSafeListMods(Vision.VISIONLIST)) {
        for (AssociatedPrereqObject apo : otherClass.getListAssociations(Vision.VISIONLIST, ref)) {
            putToList(Vision.VISIONLIST, ref, apo);
        }
    }
    /*
		 * TODO This is a clone problem, but works for now - thpr 10/3/08
		 */
    if (otherClass instanceof SubClass) {
        levelMap.clear();
        copyLevelsFrom(otherClass);
    }
    addAllToListFor(ListKey.NATURAL_WEAPON, otherClass.getListFor(ListKey.NATURAL_WEAPON));
    put(ObjectKey.LEVEL_HITDIE, otherClass.get(ObjectKey.LEVEL_HITDIE));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) CDOMListObject(pcgen.cdom.base.CDOMListObject) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) VariableKey(pcgen.cdom.enumeration.VariableKey) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 18 with BonusObj

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

the class PCClass method getBonusTo.

/**
	 * Returns the total bonus to the specified bonus type and name.
	 *
	 * <p>
	 * This method checks only bonuses associated with the class. It makes sure
	 * to return bonuses that are active only to the max level specified. What
	 * that means is that bonuses specified on class level lines will have a
	 * level parameter associated with them. Only bonuses specified on the level
	 * specified or lower will be totalled.
	 *
	 * @param argType
	 *            Bonus type e.g. <code>BONUS:<b>DOMAIN</b></code>
	 * @param argMname
	 *            Bonus name e.g. <code>BONUS:DOMAIN|<b>NUMBER</b></code>
	 * @param asLevel
	 *            The maximum level to apply bonuses for.
	 * @param aPC
	 *            The <tt>PlayerCharacter</tt> bonuses are being calculated
	 *            for.
	 *
	 * @return Total bonus value.
	 */
/*
	 * REFACTOR There is potentially redundant information here - level and PC...
	 * is this ever out of sync or can this method be removed/made private??
	 */
public double getBonusTo(final String argType, final String argMname, final int asLevel, final PlayerCharacter aPC) {
    double i = 0;
    List<BonusObj> rawBonusList = getRawBonusList(aPC);
    for (int lvl = 1; lvl < asLevel; lvl++) {
        rawBonusList.addAll(aPC.getActiveClassLevel(this, lvl).getRawBonusList(aPC));
    }
    if ((asLevel == 0) || rawBonusList.isEmpty()) {
        return 0;
    }
    final String type = argType.toUpperCase();
    final String mname = argMname.toUpperCase();
    for (final BonusObj bonus : rawBonusList) {
        final StringTokenizer breakOnPipes = new StringTokenizer(bonus.toString().toUpperCase(), Constants.PIPE, false);
        final String theType = breakOnPipes.nextToken();
        if (!theType.equals(type)) {
            continue;
        }
        final String str = breakOnPipes.nextToken();
        final StringTokenizer breakOnCommas = new StringTokenizer(str, Constants.COMMA, false);
        while (breakOnCommas.hasMoreTokens()) {
            final String theName = breakOnCommas.nextToken();
            if (theName.equals(mname)) {
                final String aString = breakOnPipes.nextToken();
                final List<Prerequisite> localPreReqList = new ArrayList<>();
                if (bonus.hasPrerequisites()) {
                    localPreReqList.addAll(bonus.getPrerequisiteList());
                }
                // as the prereqs are processed by the bonus loading code.
                while (breakOnPipes.hasMoreTokens()) {
                    final String bString = breakOnPipes.nextToken();
                    if (PreParserFactory.isPreReqString(bString)) {
                        Logging.debugPrint(//$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
                        "Why is this prerequisite '" + bString + "' parsed in '" + getClass().getName() + ".getBonusTo(String,String,int)' rather than in the persistence layer?");
                        try {
                            final PreParserFactory factory = PreParserFactory.getInstance();
                            localPreReqList.add(factory.parse(bString));
                        } catch (PersistenceLayerException ple) {
                            Logging.errorPrint(ple.getMessage(), ple);
                        }
                    }
                }
                // be referenced in Qualifies statements?
                if (PrereqHandler.passesAll(localPreReqList, aPC, null)) {
                    final double j = aPC.getVariableValue(aString, getQualifiedKey()).doubleValue();
                    i += j;
                }
            }
        }
    }
    return i;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringTokenizer(java.util.StringTokenizer) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 19 with BonusObj

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

the class EquipmentModifier method getActiveBonuses.

/**
	 * returns all BonusObjs that are "active", for example, ones that pass all
	 * prerequisite tests and should be applied.
	 *
	 * @param   caller  The object that will be used to test prerequisites
	 *                  against to determine if a bonus should be applied.
	 * @param   aPC     The PC that the prerequisites will be applied against to
	 *                  determine if a bonus is active
	 *
	 * @return  returns all BonusObjs that are "active"
	 */
public List<BonusObj> getActiveBonuses(final Equipment caller, final PlayerCharacter aPC) {
    final List<BonusObj> aList = new ArrayList<>();
    for (BonusObj bonus : getBonusList(caller)) {
        if (PrereqHandler.passesAll(bonus.getPrerequisiteList(), caller, aPC)) {
            aPC.setApplied(bonus, true);
            aList.add(bonus);
        }
    }
    return aList;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList)

Example 20 with BonusObj

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

the class EquipmentModifier method getBonusList.

private List<BonusObj> getBonusList(List<BonusObj> bonusList, List<String> associations) {
    ArrayList<BonusObj> myBonusList = new ArrayList<>(bonusList);
    for (int i = myBonusList.size() - 1; i > -1; i--) {
        final BonusObj aBonus = myBonusList.get(i);
        final String aString = aBonus.toString();
        final int idx = aString.indexOf("%CHOICE");
        if (idx >= 0) {
            // Add an entry for each of the associated list entries
            for (String assoc : associations) {
                final BonusObj newBonus = Bonus.newBonus(Globals.getContext(), aString.replaceAll(PERCENT_CHOICE_PATTERN, assoc));
                if (aBonus.hasPrerequisites()) {
                    newBonus.clearPrerequisiteList();
                    for (Prerequisite prereq : aBonus.getPrerequisiteList()) {
                        try {
                            newBonus.addPrerequisite(prereq.specify(assoc));
                        } catch (CloneNotSupportedException e) {
                        // TODO Handle this?
                        }
                    }
                }
                myBonusList.add(newBonus);
            }
            myBonusList.remove(aBonus);
        }
    }
    return myBonusList;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

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