Search in sources :

Example 61 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class ClassDataHandler method endElement.

/**
	 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
	 */
@Override
public void endElement(final String uri, final String localName, final String qName) {
    // start tag was obviously ignored.
    if (theState == ParserState.INIT) {
        return;
    }
    if (//$NON-NLS-1$
    "skills".equals(qName) && theState == ParserState.SKILLDATA) {
        if (remainingWeight > 0) {
            // Add all remaining skills at this weight.
            for (final Skill skill : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Skill.class)) {
                if (skill.getSafe(ObjectKey.VISIBILITY) == Visibility.DEFAULT) {
                    theCurrentData.addSkill(skill.getKeyName(), remainingWeight);
                }
            }
            remainingWeight = -1;
        }
        for (final String remove : removeList) {
            theCurrentData.removeSkill(remove);
        }
        removeList = new ArrayList<>();
        theState = ParserState.CLASSDATA;
    } else if (//$NON-NLS-1$
    "abilities".equals(qName) && theState == ParserState.ABILITYDATA) {
        if (remainingWeight > 0) {
            // Add all abilities at this weight.
            for (Ability ability : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, theCurrentCategory).getAllObjects()) {
                if (ability.getSafe(ObjectKey.VISIBILITY) == Visibility.DEFAULT) {
                    theCurrentData.addAbility(theCurrentCategory, ability, remainingWeight);
                }
            }
            remainingWeight = -1;
        }
        for (final String remove : removeList) {
            Ability ability = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, theCurrentCategory, remove);
            theCurrentData.removeAbility(theCurrentCategory, ability);
        }
        removeList = new ArrayList<>();
        theCurrentCategory = null;
        theState = ParserState.CLASSDATA;
    } else if (//$NON-NLS-1$
    "class".equals(qName) && theState != ParserState.INIT) {
        theList.add(theCurrentData);
        theState = ParserState.INIT;
    } else if (//$NON-NLS-1$
    "stats".equals(qName)) {
        theState = ParserState.CLASSDATA;
    } else if (//$NON-NLS-1$
    "level".equals(qName)) {
        if (remainingWeight > 0) {
            // Add all spells at this weight.
            final List<Spell> allSpells = getSpellsIn(theCurrentLevel, Collections.singletonList(theCurrentData.getPCClass().get(ObjectKey.CLASS_SPELLLIST)));
            for (final Spell spell : allSpells) {
                if (theCurrentSpellType == SpellType.KNOWN) {
                    theCurrentData.addKnownSpell(theCurrentLevel, spell, remainingWeight);
                } else if (theCurrentSpellType == SpellType.PREPARED) {
                    theCurrentData.addPreparedSpell(theCurrentLevel, spell, remainingWeight);
                }
            }
            remainingWeight = -1;
        }
        for (final String remove : removeList) {
            final Spell spell = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, remove);
            if (theCurrentSpellType == SpellType.KNOWN) {
                theCurrentData.removeKnownSpell(theCurrentLevel, spell);
            } else if (theCurrentSpellType == SpellType.PREPARED) {
                theCurrentData.removeKnownSpell(theCurrentLevel, spell);
            }
        }
        removeList = new ArrayList<>();
        theCurrentLevel = -1;
        theState = ParserState.SPELLDATA;
    } else if (//$NON-NLS-1$
    "spells".equals(qName)) {
        theState = ParserState.CLASSDATA;
        theCurrentSpellType = SpellType.KNOWN;
    } else if (//$NON-NLS-1$
    "subclasses".equals(qName)) {
        theState = ParserState.CLASSDATA;
    }
}
Also used : Ability(pcgen.core.Ability) Skill(pcgen.core.Skill) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell)

Example 62 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class KitAbilities method testApply.

@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    abilitiesToAdd = new ArrayList<>();
    double minCost = Double.MAX_VALUE;
    List<AbilitySelection> available = new ArrayList<>();
    for (CDOMReference<Ability> ref : abilities) {
        String choice = ref.getChoice();
        for (Ability a : ref.getContainedObjects()) {
            if (a == null) {
                warnings.add("ABILITY: " + ref + " could not be found.");
                minCost = 0;
                continue;
            }
            if (a.getCost() < minCost) {
                minCost = a.getCost();
            }
            if ((choice == null) && a.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
                available.add(new AbilitySelection(a, ""));
            } else {
                available.add(new AbilitySelection(a, choice));
            }
        }
    }
    int numberOfChoices = getSafeCount();
    // TODO this fails if SELECT != 1
    if (numberOfChoices > available.size()) {
        numberOfChoices = available.size();
    }
    /*
		 * this section needs to be rewritten once we determine how
		 * the new Ability Pools are going to work
		 */
    AbilityCategory category = catRef.get();
    boolean tooManyAbilities = false;
    // Don't allow choosing of more than allotted number of abilities
    int maxChoices = minCost > 0.0d ? aPC.getAvailableAbilityPool(category).divide(new BigDecimal(minCost)).intValue() : numberOfChoices;
    if (!isFree() && numberOfChoices > maxChoices) {
        numberOfChoices = maxChoices;
        tooManyAbilities = true;
    }
    if (!isFree() && numberOfChoices == 0) {
        warnings.add("ABILITY: Not enough " + category.getPluralName() + " available to take \"" + this + "\"");
        return false;
    }
    List<AbilitySelection> selected;
    if (numberOfChoices == available.size()) {
        selected = available;
    } else {
        selected = new ArrayList<>();
        // Force user to make enough selections
        while (true) {
            selected = Globals.getChoiceFromList("Choose abilities", available, new ArrayList<>(), numberOfChoices, aPC);
            if (!selected.isEmpty()) {
                break;
            }
        }
    }
    // Add to list of things to add to the character
    for (AbilitySelection as : selected) {
        Ability ability = as.ability;
        if (isFree()) {
            // Need to pay for it first
            if (free) {
                aPC.adjustAbilities(category, BigDecimal.ONE);
            }
        }
        if (ability.getCost() > aPC.getAvailableAbilityPool(category).doubleValue()) {
            tooManyAbilities = true;
        } else {
            CNAbility cna = CNAbilityFactory.getCNAbility(category, Nature.NORMAL, ability);
            CNAbilitySelection cnas = new CNAbilitySelection(cna, as.selection);
            abilitiesToAdd.add(cnas);
            aPC.addAbility(cnas, UserSelection.getInstance(), this);
        }
    }
    if (tooManyAbilities) {
        warnings.add("ABILITY: Some Abilities were not granted -- not enough remaining feats");
        return false;
    }
    return true;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) CNAbility(pcgen.cdom.content.CNAbility) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) AbilityCategory(pcgen.core.AbilityCategory)

Example 63 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class NPCGenerator method selectFeats.

private void selectFeats(final PlayerCharacter aPC, final WeightedCollection<Ability> aFeatList) {
    while ((int) aPC.getRemainingFeatPoolPoints() > 0) {
        final Ability ability = aFeatList.getRandomValue();
        if (!ability.qualifies(aPC, ability)) {
            // We will leave the feat because we may qualify later.
            continue;
        }
        AbilityUtilities.driveChooseAndAdd(CNAbilityFactory.getCNAbility(AbilityCategory.FEAT, Nature.NORMAL, ability), aPC, true);
    }
}
Also used : Ability(pcgen.core.Ability)

Example 64 with Ability

use of pcgen.core.Ability in project pcgen by PCGen.

the class AbilityIntegrationTest method construct.

@Override
protected void construct(LoadContext loadContext, String one) {
    Ability obj = loadContext.getReferenceContext().constructCDOMObject(Ability.class, one);
    loadContext.getReferenceContext().reassociateCategory(AbilityCategory.FEAT, obj);
}
Also used : Ability(pcgen.core.Ability)

Example 65 with Ability

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

Aggregations

Ability (pcgen.core.Ability)279 CNAbility (pcgen.cdom.content.CNAbility)128 AbilityCategory (pcgen.core.AbilityCategory)60 PlayerCharacter (pcgen.core.PlayerCharacter)54 Test (org.junit.Test)46 ArrayList (java.util.ArrayList)43 CNAbilitySelection (pcgen.cdom.helper.CNAbilitySelection)25 ParseResult (pcgen.rules.persistence.token.ParseResult)21 HashMapToList (pcgen.base.util.HashMapToList)15 PCClass (pcgen.core.PCClass)15 Spell (pcgen.core.spell.Spell)15 StringTokenizer (java.util.StringTokenizer)14 TestContext (plugin.lsttokens.editcontext.testsupport.TestContext)13 LoadContext (pcgen.rules.context.LoadContext)12 SpecialAbility (pcgen.core.SpecialAbility)11 CharacterSpell (pcgen.core.character.CharacterSpell)11 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)11 List (java.util.List)10 CDOMObject (pcgen.cdom.base.CDOMObject)10 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10