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;
}
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);
}
}
}
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;
}
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;
}
Aggregations