Search in sources :

Example 36 with CNAbility

use of pcgen.cdom.content.CNAbility 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 37 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class Gui2InfoFactory method getChoices.

@Override
public String getChoices(AbilityFacade abilityFacade) {
    if (abilityFacade == null || !(abilityFacade instanceof Ability)) {
        return EMPTY_STRING;
    }
    final Ability ability = (Ability) abilityFacade;
    final StringBuilder result = new StringBuilder(100);
    Collection<CNAbility> targetAbilities = pc.getMatchingCNAbilities(ability);
    if (ability.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        ChooseInformation<?> chooseInfo = ability.get(ObjectKey.CHOOSE_INFO);
        processAbilities(result, targetAbilities, chooseInfo);
    }
    return result.toString();
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 38 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class Aspect method getAspectText.

/**
	 * Gets the name string after having substituting all variables.
	 * 
	 * @param aPC The PlayerCharacter used to evaluate formulas.
	 * @param abilities the abilities for which the Aspect text should be compiled
	 * 
	 * @return The fully substituted description string.
	 */
public String getAspectText(final PlayerCharacter aPC, List<CNAbility> abilities) {
    final StringBuilder buf = new StringBuilder(50);
    if ((abilities == null) || (abilities.isEmpty())) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    if (!qualifies(aPC, sampleAbilityObject)) {
        return "";
    }
    for (final String comp : theComponents) {
        if (comp.startsWith(VAR_MARKER)) {
            final int ind = Integer.parseInt(comp.substring(VAR_MARKER.length()));
            if (theVariables == null || ind > theVariables.size()) {
                buf.append(Constants.EMPTY_STRING);
                continue;
            }
            final String var = theVariables.get(ind - 1);
            if (var.equals(VAR_NAME)) {
                buf.append(sampleAbilityObject.getOutputName());
            } else if (var.equals(VAR_LIST)) {
                List<String> assocList = new ArrayList<>();
                for (CNAbility cna : abilities) {
                    assocList.addAll(aPC.getAssociationList(cna));
                }
                String joinString;
                if (assocList.size() == 2) {
                    joinString = " and ";
                } else {
                    joinString = ", ";
                }
                Collections.sort(assocList);
                buf.append(StringUtil.joinToStringBuilder(assocList, joinString));
            } else if (//$NON-NLS-1$
            var.startsWith("\"")) {
                buf.append(var.substring(1, var.length() - 1));
            } else {
                //$NON-NLS-1$
                buf.append(aPC.getVariableValue(var, "Aspect").intValue());
            }
        } else {
            buf.append(comp);
        }
    }
    return buf.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) ArrayList(java.util.ArrayList) List(java.util.List)

Example 39 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class Aspect method printAspect.

public static String printAspect(PlayerCharacter pc, AspectName key, List<CNAbility> abilities, boolean printName) {
    if (abilities.isEmpty()) {
        return "";
    }
    Ability sampleAbilityObject = abilities.get(0).getAbility();
    StringBuilder buff = new StringBuilder(50);
    List<Aspect> aspects = sampleAbilityObject.get(MapKey.ASPECT, key);
    Aspect aspect = lastPassingAspect(aspects, pc, sampleAbilityObject);
    if (aspect != null) {
        if (printName) {
            buff.append(aspect.getName()).append(": ");
        }
        buff.append(aspect.getAspectText(pc, abilities));
    }
    return buff.toString();
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Example 40 with CNAbility

use of pcgen.cdom.content.CNAbility in project pcgen by PCGen.

the class CNAbilitySelectionUtilities method canCoExist.

public static boolean canCoExist(CNAbilitySelection cnas1, CNAbilitySelection cnas2) {
    CNAbility cna = cnas1.getCNAbility();
    Ability a = cna.getAbility();
    CNAbility ocna = cnas2.getCNAbility();
    if (!ocna.getAbilityCategory().getParentCategory().equals(cna.getAbilityCategory().getParentCategory())) {
        //This test is only required because Ability only checks key :/
        return true;
    }
    if (!ocna.getAbility().equals(a)) {
        //Different abilities, so doesn't matter...
        return true;
    }
    //Same ability here
    if (!a.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        //If MULT:NO, then can't coexist...
        return false;
    }
    //MULT:YES here
    if (a.getSafe(ObjectKey.STACKS)) {
        //Allows stacking, so always true (give or take NUMCHOICES?)
        return true;
    }
    //STACK:NO here
    if (cnas1.getSelection().equals(cnas2.getSelection())) {
        //enforce STACK:NO
        return false;
    }
    return true;
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility)

Aggregations

CNAbility (pcgen.cdom.content.CNAbility)131 Ability (pcgen.core.Ability)77 ArrayList (java.util.ArrayList)37 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)28 AbilityCategory (pcgen.core.AbilityCategory)26 Test (org.junit.Test)21 HashMapToList (pcgen.base.util.HashMapToList)16 List (java.util.List)15 PlayerCharacter (pcgen.core.PlayerCharacter)9 Language (pcgen.core.Language)7 HashSet (java.util.HashSet)5 Nature (pcgen.cdom.enumeration.Nature)5 SpecialAbility (pcgen.core.SpecialAbility)5 BonusObj (pcgen.core.bonus.BonusObj)5 BigDecimal (java.math.BigDecimal)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 LoadContext (pcgen.rules.context.LoadContext)4 StringTokenizer (java.util.StringTokenizer)3 GenericMapToList (pcgen.base.util.GenericMapToList)3 PCClass (pcgen.core.PCClass)3