Search in sources :

Example 6 with TempBonusInfo

use of pcgen.core.BonusManager.TempBonusInfo in project pcgen by PCGen.

the class PlayerCharacter method addTempBonus.

/**
	 * Adds a "temporary" bonus.
	 *
	 * @param aBonus The bonus object to add.
	 * @param source The source of the temporary bonus
	 * @param target The object getting the bonus (typically the PC, can also be equipment).
	 * @return The bonus info representing the added instance of the bonus.
	 */
public TempBonusInfo addTempBonus(final BonusObj aBonus, Object source, Object target) {
    TempBonusInfo tempBonusInfo = bonusManager.addTempBonus(aBonus, source, target);
    setDirty(true);
    return tempBonusInfo;
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo)

Example 7 with TempBonusInfo

use of pcgen.core.BonusManager.TempBonusInfo in project pcgen by PCGen.

the class PCGVer2Creator method appendEqSetBonuses.

/**
	 * For each EquipSet, check for a tempBonusList and if found, save each
	 * bonus
	 * 
	 * @param buffer
	 */
private void appendEqSetBonuses(StringBuilder buffer) {
    for (EquipSet eSet : charDisplay.getEquipSet()) {
        if (eSet.useTempBonusList()) {
            buffer.append(IOConstants.TAG_EQSETBONUS).append(':');
            buffer.append(eSet.getIdPath());
            List<String> trackList = new ArrayList<>();
            for (Map.Entry<BonusObj, BonusManager.TempBonusInfo> me : eSet.getTempBonusMap().entrySet()) {
                //BonusObj bObj = me.getKey();
                TempBonusInfo tbi = me.getValue();
                Object cObj = tbi.source;
                Object tObj = tbi.target;
                final String aName = tempBonusName(cObj, tObj);
                if (trackList.contains(aName)) {
                    continue;
                }
                trackList.add(aName);
                buffer.append('|');
                buffer.append(IOConstants.TAG_TEMPBONUSBONUS).append(':');
                buffer.append(EntityEncoder.encode(aName));
            }
            buffer.append(IOConstants.LINE_SEP);
        }
    }
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) BonusObj(pcgen.core.bonus.BonusObj) EquipSet(pcgen.core.character.EquipSet) ArrayList(java.util.ArrayList) CDOMListObject(pcgen.cdom.base.CDOMListObject) CDOMObject(pcgen.cdom.base.CDOMObject) Map(java.util.Map)

Example 8 with TempBonusInfo

use of pcgen.core.BonusManager.TempBonusInfo in project pcgen by PCGen.

the class TempBonusHelper method applyBonusToCharacterEquipment.

/**
	 * Apply the temporary bonus to the character's equipment. Generally
	 * equipment will be a 'temporary' equipment item created to show the item
	 * with the bonus.
	 * 
	 * @param aEq
	 *            The temporary equipment item to apply the bonus to.
	 * @param originObj
	 *            The rules object granting the bonus.
	 * @param theCharacter
	 *            The character the bonus is being applied to.
	 */
static TempBonusFacadeImpl applyBonusToCharacterEquipment(Equipment aEq, CDOMObject originObj, PlayerCharacter theCharacter) {
    TempBonusFacadeImpl appliedBonus = null;
    String repeatValue = EMPTY_STRING;
    for (EquipBonus eb : originObj.getListFor(ListKey.BONUS_EQUIP)) {
        BonusObj aBonus = eb.bonus;
        String oldValue = aBonus.toString();
        String newValue = oldValue;
        if (!originObj.getSafe(StringKey.TEMPVALUE).isEmpty()) {
            BonusInfo bi = TempBonusHelper.getBonusChoice(oldValue, originObj, repeatValue, theCharacter);
            if (bi == null) {
                return null;
            }
            newValue = bi.getBonusValue();
            repeatValue = bi.getRepeatValue();
        }
        BonusObj newB = Bonus.newBonus(Globals.getContext(), newValue);
        if (newB != null) {
            // if Target was this PC, then add
            // bonus to TempBonusMap
            theCharacter.setApplied(newB, PrereqHandler.passesAll(newB.getPrerequisiteList(), aEq, theCharacter));
            aEq.addTempBonus(newB);
            TempBonusInfo tempBonusInfo = theCharacter.addTempBonus(newB, originObj, aEq);
            if (appliedBonus == null) {
                String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
                appliedBonus = new TempBonusFacadeImpl(originObj, aEq, bonusName);
            }
        }
    }
    // then add it to the tempBonusItemList
    if (aEq != null) {
        theCharacter.addTempBonusItemList(aEq);
    }
    return appliedBonus;
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) EquipBonus(pcgen.core.bonus.EquipBonus) BonusObj(pcgen.core.bonus.BonusObj) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo)

Example 9 with TempBonusInfo

use of pcgen.core.BonusManager.TempBonusInfo in project pcgen by PCGen.

the class TempBonusHelper method applyBonusToCharacter.

/**
	 * Apply the temporary bonus to the character. The bonus is applied 
	 * directly to the character.  
	 *  
	 * @param originObj The rules object granting the bonus.
	 * @param theCharacter The character the bonus is being applied to.
	 */
static TempBonusFacadeImpl applyBonusToCharacter(CDOMObject originObj, PlayerCharacter theCharacter) {
    TempBonusFacadeImpl appliedBonus = null;
    String repeatValue = EMPTY_STRING;
    for (BonusObj aBonus : getTempCharBonusesFor(originObj)) {
        String oldValue = aBonus.toString();
        String newValue = oldValue;
        if (!originObj.getSafe(StringKey.TEMPVALUE).isEmpty()) {
            BonusInfo bi = TempBonusHelper.getBonusChoice(oldValue, originObj, repeatValue, theCharacter);
            if (bi == null) {
                return null;
            }
            newValue = bi.getBonusValue();
            repeatValue = bi.getRepeatValue();
        }
        BonusObj newB = Bonus.newBonus(Globals.getContext(), newValue);
        if (newB != null) {
            // if Target was this PC, then add
            // bonus to TempBonusMap
            theCharacter.setApplied(newB, newB.qualifies(theCharacter, null));
            TempBonusInfo tempBonusInfo = theCharacter.addTempBonus(newB, originObj, theCharacter);
            if (appliedBonus == null) {
                String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
                appliedBonus = new TempBonusFacadeImpl(originObj, theCharacter, bonusName);
            }
        }
    }
    return appliedBonus;
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) BonusObj(pcgen.core.bonus.BonusObj) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo)

Aggregations

TempBonusInfo (pcgen.core.BonusManager.TempBonusInfo)9 BonusObj (pcgen.core.bonus.BonusObj)7 CDOMObject (pcgen.cdom.base.CDOMObject)6 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Equipment (pcgen.core.Equipment)3 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)2 CDOMListObject (pcgen.cdom.base.CDOMListObject)2 CNAbility (pcgen.cdom.content.CNAbility)2 Ability (pcgen.core.Ability)2 PObject (pcgen.core.PObject)2 CharacterSpell (pcgen.core.character.CharacterSpell)2 Spell (pcgen.core.spell.Spell)2 HashSet (java.util.HashSet)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 TreeSet (java.util.TreeSet)1 AbilityCategory (pcgen.core.AbilityCategory)1 BonusManager (pcgen.core.BonusManager)1 ChronicleEntry (pcgen.core.ChronicleEntry)1