Search in sources :

Example 1 with EquipBonus

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

the class TempBonusHelper method getListOfApplicableEquipment.

/**
	 * Build a list of what equipment is possible to apply this bonus to.
	 * @param originObj The rules object providing the bonus.
	 * @param theCharacter The target character.
	 * @return The list of possible equipment.
	 */
public static List<InfoFacade> getListOfApplicableEquipment(CDOMObject originObj, PlayerCharacter theCharacter) {
    CharacterDisplay charDisplay = theCharacter.getDisplay();
    List<InfoFacade> possibleEquipment = new ArrayList<>();
    if (originObj == null) {
        return possibleEquipment;
    }
    boolean found = false;
    theCharacter.setCalcEquipmentList(theCharacter.getUseTempMods());
    for (Equipment aEq : charDisplay.getEquipmentSet()) {
        found = false;
        for (EquipBonus eb : originObj.getSafeListFor(ListKey.BONUS_EQUIP)) {
            String conditions = eb.conditions;
            boolean passesConditions = passesConditions(aEq, conditions);
            if (passesConditions && !found) {
                possibleEquipment.add(aEq);
                found = true;
            }
        }
    }
    return possibleEquipment;
}
Also used : EquipBonus(pcgen.core.bonus.EquipBonus) Equipment(pcgen.core.Equipment) InfoFacade(pcgen.facade.core.InfoFacade) CharacterDisplay(pcgen.core.display.CharacterDisplay) ArrayList(java.util.ArrayList)

Example 2 with EquipBonus

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

the class EQToken method parseTokenWithSeparator.

@Override
public ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail("Expected " + getFullTokenName() + ":<type>|<conditions>|BONUS but did not find a second pipe");
    }
    String constraints = value.substring(0, pipeLoc);
    String bonus = value.substring(pipeLoc + 1);
    final String v = bonus.replaceAll(Pattern.quote("<this>"), obj.getKeyName());
    BonusObj bon = Bonus.newBonus(context, v);
    if (bon == null) {
        return new ParseResult.Fail(getFullTokenName() + " was given invalid type: " + bonus, context);
    }
    bon.setTokenSource(getFullTokenName());
    EquipBonus eb = new EquipBonus(bon, constraints);
    context.getObjectContext().addToList(obj, ListKey.BONUS_EQUIP, eb);
    return ParseResult.SUCCESS;
}
Also used : EquipBonus(pcgen.core.bonus.EquipBonus) BonusObj(pcgen.core.bonus.BonusObj)

Example 3 with EquipBonus

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

the class EQToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<EquipBonus> changes = context.getObjectContext().getListChanges(obj, ListKey.BONUS_EQUIP);
    Collection<EquipBonus> added = changes.getAdded();
    if (added == null || added.isEmpty()) {
        // Zero indicates no Token (and no global clear, so nothing to do)
        return null;
    }
    Set<String> bonusSet = new TreeSet<>();
    for (EquipBonus eb : added) {
        String bonusText = eb.bonus.getLSTformat();
        bonusSet.add(eb.conditions + Constants.PIPE + bonusText);
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : EquipBonus(pcgen.core.bonus.EquipBonus) TreeSet(java.util.TreeSet)

Example 4 with EquipBonus

use of pcgen.core.bonus.EquipBonus 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)

Aggregations

EquipBonus (pcgen.core.bonus.EquipBonus)4 BonusObj (pcgen.core.bonus.BonusObj)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 TempBonusInfo (pcgen.core.BonusManager.TempBonusInfo)1 Equipment (pcgen.core.Equipment)1 CharacterDisplay (pcgen.core.display.CharacterDisplay)1 InfoFacade (pcgen.facade.core.InfoFacade)1