Search in sources :

Example 31 with BonusObj

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

the class AgeSet method getLSTformat.

public String getLSTformat() {
    StringBuilder sb = new StringBuilder();
    sb.append(index).append('|').append(name);
    if (bonuses != null) {
        for (BonusObj bo : bonuses) {
            sb.append('\t').append(bo.getLSTformat());
        }
    }
    if (kits != null) {
        for (TransitionChoice<Kit> tc : kits) {
            sb.append('\t').append(tc.getCount()).append(Constants.PIPE);
            sb.append(tc.getChoices().getLSTformat().replaceAll(Constants.COMMA, Constants.PIPE));
        }
    }
    return sb.toString();
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

Example 32 with BonusObj

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

the class Gui2InfoFactory method getHTMLInfo.

@Override
public String getHTMLInfo(TempBonusFacade tempBonusFacade) {
    if (tempBonusFacade == null) {
        return EMPTY_STRING;
    }
    if (!(tempBonusFacade instanceof TempBonusFacadeImpl)) {
        final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
        infoText.appendTitleElement(tempBonusFacade.toString());
        return infoText.toString();
    }
    TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) tempBonusFacade;
    CDOMObject originObj = tempBonus.getOriginObj();
    final HtmlInfoBuilder infoText;
    if (originObj instanceof Equipment) {
        infoText = getEquipmentHtmlInfo((Equipment) originObj);
    } else {
        infoText = new HtmlInfoBuilder();
        infoText.appendTitleElement(OutputNameFormatting.piString(originObj, false));
        //$NON-NLS-1$ //$NON-NLS-2$
        infoText.append(" (").append(tempBonus.getOriginType()).append(")");
    }
    if (tempBonus.getTarget() != null) {
        String targetName = charDisplay.getName();
        if (tempBonus.getTarget() instanceof CDOMObject) {
            targetName = ((CDOMObject) tempBonus.getTarget()).getKeyName();
        }
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement("in_itmInfoLabelTextTarget", targetName);
        StringBuilder bonusValues = new StringBuilder(100);
        Map<BonusObj, TempBonusInfo> bonusMap = pc.getTempBonusMap(originObj.getKeyName(), targetName);
        boolean first = true;
        List<BonusObj> bonusList = new ArrayList<>(bonusMap.keySet());
        bonusList.sort(new BonusComparator());
        for (BonusObj bonusObj : bonusList) {
            if (!first) {
                //$NON-NLS-1$
                bonusValues.append(", ");
            }
            first = false;
            //$NON-NLS-1$
            String adj = ADJ_FMT.format(bonusObj.resolve(pc, ""));
            //$NON-NLS-1$
            bonusValues.append(adj + " " + bonusObj.getDescription());
        }
        if (bonusValues.length() > 0) {
            infoText.appendLineBreak();
            infoText.appendI18nElement(//$NON-NLS-1$
            "in_itmInfoLabelTextEffect", bonusValues.toString());
        }
    }
    if (originObj instanceof Spell) {
        Spell aSpell = (Spell) originObj;
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement(//$NON-NLS-1$
        "in_spellDuration", aSpell.getListAsString(ListKey.DURATION));
        infoText.appendSpacer();
        //$NON-NLS-1$
        infoText.appendI18nElement(//$NON-NLS-1$
        "in_spellRange", aSpell.getListAsString(ListKey.RANGE));
        infoText.appendSpacer();
        //$NON-NLS-1$
        infoText.appendI18nElement(//$NON-NLS-1$
        "in_spellTarget", aSpell.getSafe(StringKey.TARGET_AREA));
    }
    String aString = originObj.getSafe(StringKey.TEMP_DESCRIPTION);
    if (StringUtils.isEmpty(aString) && originObj instanceof Spell) {
        Spell sp = (Spell) originObj;
        aString = DescriptionFormatting.piWrapDesc(sp, pc.getDescription(sp), false);
    } else if (StringUtils.isEmpty(aString) && originObj instanceof Ability) {
        Ability ab = (Ability) originObj;
        List<CNAbility> wrappedAbility = Collections.singletonList(CNAbilityFactory.getCNAbility(ab.getCDOMCategory(), Nature.NORMAL, ab));
        aString = DescriptionFormatting.piWrapDesc(ab, pc.getDescription(wrappedAbility), false);
    }
    if (!aString.isEmpty()) {
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement("in_itmInfoLabelTextDesc", aString);
    }
    aString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, originObj.getPrerequisiteList(), false);
    if (!aString.isEmpty()) {
        infoText.appendLineBreak();
        //$NON-NLS-1$
        infoText.appendI18nElement("in_requirements", aString);
    }
    infoText.appendLineBreak();
    infoText.appendI18nElement(//$NON-NLS-1$
    "in_itmInfoLabelTextSource", SourceFormat.getFormattedString(originObj, Globals.getSourceDisplay(), true));
    return infoText.toString();
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) List(java.util.List) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder)

Example 33 with BonusObj

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

the class MonskillToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCClass pcc, String value) {
    BonusObj bon = Bonus.newBonus(context, "MONSKILLPTS|NUMBER|" + value);
    if (bon == null) {
        return new ParseResult.Fail(getTokenName() + " was given invalid bonus value: " + value, context);
    }
    Prerequisite prereq = getPrerequisite("PRELEVELMAX:1");
    if (prereq == null) {
        return new ParseResult.Fail("Internal Error: " + getTokenName() + " had invalid prerequisite", context);
    }
    bon.addPrerequisite(prereq);
    bon.setTokenSource(getTokenName());
    context.getObjectContext().addToList(pcc, ListKey.BONUS, bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 34 with BonusObj

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

the class MonnonskillhdToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, PCClass pcc, String value) {
    BonusObj bon = Bonus.newBonus(context, "MONNONSKILLHD|NUMBER|" + value);
    if (bon == null) {
        return new ParseResult.Fail(getTokenName() + " was given invalid bonus value: " + value, context);
    }
    bon.setTokenSource(getTokenName());
    context.getObjectContext().addToList(pcc, ListKey.BONUS, bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

Example 35 with BonusObj

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

the class PreLevelMaxTest method testPCLevel.

/**
	 * Make sure BONUS:PCLEVEL is not counted
	 * @throws Exception
	 */
public void testPCLevel() throws Exception {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    character.incrementClassLevel(2, myClass, true);
    myClass = character.getClassKeyed("MY_CLASS");
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PRELEVELMAX:5");
    final BonusObj levelBonus = Bonus.newBonus(context, "PCLEVEL|MY_CLASS|2");
    myClass.addToListFor(ListKey.BONUS, levelBonus);
    character.calcActiveBonuses();
    assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

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