Search in sources :

Example 21 with BonusObj

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

the class BonusAddition method removeBonus.

/**
	 * Remove the bonus from this objects list of bonuses.
	 * 
	 * @param bonusString
	 *            The string representing the bonus
	 * @param aPC
	 *            The player character to remove th bonus from.
	 */
public static void removeBonus(String bonusString, PlayerCharacter aPC, CDOMObject target) {
    BonusObj toRemove = null;
    BonusObj aBonus = Bonus.newBonus(Globals.getContext(), bonusString);
    String bonusStrRep = String.valueOf(aBonus);
    for (BonusObj listBonus : aPC.getSaveableBonusList(target)) {
        if (listBonus.toString().equals(bonusStrRep)) {
            toRemove = listBonus;
        }
    }
    if (toRemove != null) {
        aPC.removeSaveableBonus(toRemove, target);
    } else {
        Logging.errorPrint("removeBonus: Could not find bonus: " + bonusString + " in bonusList " + aPC.getSaveableBonusList(target));
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

Example 22 with BonusObj

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

the class BonusCalc method bonusTo.

public static double bonusTo(PObject po, String aType, String aName, final Object obj, final Collection<BonusObj> aBonusList, final PlayerCharacter aPC) {
    if ((aBonusList == null) || (aBonusList.isEmpty())) {
        return 0;
    }
    double retVal = 0;
    aType = aType.toUpperCase();
    aName = aName.toUpperCase();
    final String aTypePlusName = new StringBuilder(aType).append('.').append(aName).append('.').toString();
    if (!BonusCalc.dontRecurse && (po instanceof Ability) && (AbilityUtilities.isFeat(obj)) && !Globals.checkRule(RuleConstants.FEATPRE)) {
        // SUCK!  This is horrid, but bonusTo is actually recursive with respect to
        // passesPreReqToGain and there is no other way to do this without decomposing the
        // dependencies.  I am loathe to break working code.
        // This addresses bug #709677 -- Feats give bonuses even if you no longer qualify
        BonusCalc.dontRecurse = true;
        boolean returnZero = false;
        if (!po.qualifies(aPC, po)) {
            returnZero = true;
        }
        BonusCalc.dontRecurse = false;
        if (returnZero) {
            return 0;
        }
    }
    int iTimes = 1;
    if (aPC != null && "VAR".equals(aType)) {
        iTimes = Math.max(1, aPC.getConsolidatedAssociationList(po).size());
    }
    for (BonusObj bonus : aBonusList) {
        String bString = bonus.toString().toUpperCase();
        if (aPC != null && !aPC.getConsolidatedAssociationList(po).isEmpty()) {
            int span = 4;
            int idx = bString.indexOf("%VAR");
            if (idx == -1) {
                idx = bString.indexOf("%LIST|");
                span = 5;
            }
            if (idx >= 0) {
                final String firstPart = bString.substring(0, idx);
                final String secondPart = bString.substring(idx + span);
                for (String assoc : aPC.getConsolidatedAssociationList(po)) {
                    final String xString = new StringBuilder(50).append(firstPart).append(assoc).append(secondPart).toString().toUpperCase();
                    retVal += BonusCalc.calcBonus(po, xString, aType, aName, aTypePlusName, obj, iTimes, bonus, aPC);
                }
            }
        } else {
            retVal += BonusCalc.calcBonus(po, bString, aType, aName, aTypePlusName, obj, iTimes, bonus, aPC);
        }
    }
    return retVal;
}
Also used : Ability(pcgen.core.Ability) BonusObj(pcgen.core.bonus.BonusObj)

Example 23 with BonusObj

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

the class PCClassKeyChange method renameBonusTarget.

private static void renameBonusTarget(CDOMObject cdo, String oldClass, String newClass) {
    //
    // Go through the bonus list (BONUS) and adjust the class to the new
    // name
    //
    List<BonusObj> bonusList = cdo.getListFor(ListKey.BONUS);
    if (bonusList != null) {
        for (BonusObj bonusObj : bonusList) {
            final String bonus = bonusObj.toString();
            int offs = -1;
            for (; ; ) {
                offs = bonus.indexOf('=' + oldClass, offs + 1);
                if (offs < 0) {
                    break;
                }
                LoadContext context = Globals.getContext();
                final BonusObj aBonus = Bonus.newBonus(context, bonus.substring(0, offs + 1) + newClass + bonus.substring(offs + oldClass.length() + 1));
                if (aBonus != null) {
                    cdo.addToListFor(ListKey.BONUS, aBonus);
                }
                cdo.removeFromListFor(ListKey.BONUS, bonusObj);
            }
        }
    }
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

Example 24 with BonusObj

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

the class BonusCheckingFacet method calcBonus.

/**
	 * Calculates the bonus for the Player Character identified by the given
	 * CharID. The Bonus is calculated based on the BonusObj objects passed in
	 * the given map. The value in the map indicates the source object of the
	 * BonusObj.
	 * 
	 * This method is reference-semantic in that ownership of the Map which is
	 * passed to this method is not transferred to this method. This method
	 * guarantees that no modifications are made to the provided Map, and no
	 * reference to the given Map will be retained by BonusCheckingFacet.
	 * 
	 * @param id
	 *            The CharID of the Player Character for which the bonus should
	 *            be calculated
	 * @param map
	 *            A Map indicating the BonusObj objects to be used in the
	 *            calculation and the source CDOMObjects for those BonusObj
	 *            objects
	 * @return The bonus for the Player Character identified by the given
	 *         CharID, calculated from the BonusObj objects provided in the
	 *         given Map
	 * 
	 */
public double calcBonus(CharID id, Map<BonusObj, ? extends CDOMObject> map) {
    double iBonus = 0;
    for (Map.Entry<BonusObj, ? extends CDOMObject> me : map.entrySet()) {
        BonusObj bonus = me.getKey();
        CDOMObject source = me.getValue();
        iBonus += getBonusValue(id, bonus, source.getQualifiedKey()).doubleValue();
    }
    return iBonus;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) CDOMObject(pcgen.cdom.base.CDOMObject) Map(java.util.Map)

Example 25 with BonusObj

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

the class BonusCheckingFacet method getExpandedBonusInfo.

/**
	 * Get back a Collection of bonus info with %LIST entries replaced with the
	 * choices made.
	 * 
	 * This method is value-semantic in that ownership of the returned
	 * Collection is transferred to the class calling this method. Since this is
	 * a remove all function, modification of the returned Collection will not
	 * modify this BonusCheckingFacet and modification of this
	 * BonusCheckingFacet will not modify the returned Collection. Modifications
	 * to the returned Collection will also not modify any future or previous
	 * objects returned by this (or other) methods on BonusCheckingFacet. If you
	 * wish to modify the information stored in this BonusCheckingFacet, you
	 * must use the add*() and remove*() methods of BonusCheckingFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the list
	 *            of bonus information should be returned
	 * @param bonusName
	 *            The Bonus name used to select which Bonus objects to expand to
	 *            get their information
	 * @return A Collection of bonus info with %LIST entries replaced with the
	 *         choices made
	 */
public Collection<String> getExpandedBonusInfo(CharID id, String bonusName) {
    PlayerCharacter pc = trackingFacet.getPC(id);
    List<String> list = new ArrayList<>();
    for (BonusObj bonus : pc.getActiveBonusList()) {
        if (bonus.getTypeOfBonus().equals(bonusName)) {
            String bonusInfo = bonus.getBonusInfo();
            if (bonusInfo.contains("%LIST")) {
                // We have a %LIST that needs to be expanded
                List<BonusPair> bpList = pc.getStringListFromBonus(bonus);
                for (BonusPair bonusPair : bpList) {
                    String key = bonusPair.fullyQualifiedBonusType;
                    // Strip off the bonus name and the trailing . 
                    if (key.startsWith(bonusName)) {
                        key = key.substring(bonusName.length() + 1);
                    }
                    list.add(key);
                }
            } else {
                list.add(bonus.getBonusInfo());
            }
        }
    }
    return list;
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) BonusPair(pcgen.core.bonus.BonusPair)

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