Search in sources :

Example 1 with ChoiceManagerList

use of pcgen.core.chooser.ChoiceManagerList in project pcgen by PCGen.

the class PCGVer2Parser method parseSkillLine.

/*
	 * ###############################################################
	 * Character Skills methods
	 * ###############################################################
	 */
private void parseSkillLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal Skill line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    Skill aSkill = null;
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the skill key name!!!
    String skillKey = "";
    if (it.hasNext()) {
        final PCGElement element = it.next();
        skillKey = EntityEncoder.decode(element.getText());
        aSkill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, skillKey);
    }
    while (it.hasNext()) {
        final PCGElement element = it.next();
        final String tag = element.getName();
        if (IOConstants.TAG_SYNERGY.equals(tag)) {
        // TODO
        // for now it's ok to ignore it!
        } else if (IOConstants.TAG_OUTPUTORDER.equals(tag)) {
            int outputindex = 0;
            try {
                outputindex = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
            // This is not critical.
            // Maybe warn the user?
            }
            if (aSkill != null) {
                thePC.setSkillOrder(aSkill, outputindex);
            }
        } else if (IOConstants.TAG_CLASSBOUGHT.equals(tag)) {
            PCGElement childClass = null;
            PCGElement childRanks = null;
            for (PCGElement child : element.getChildren()) {
                if (IOConstants.TAG_CLASS.equals(child.getName())) {
                    childClass = child;
                } else if (IOConstants.TAG_RANKS.equals(child.getName())) {
                    childRanks = child;
                }
            }
            if (childClass == null) {
                final String message = "Invalid class/ranks specification: " + line;
                warnings.add(message);
                continue;
            }
            if (childRanks == null) {
                final String message = "Invalid class/ranks specification: " + line;
                warnings.add(message);
                continue;
            }
            //None for a class is a special key word.  It is used when a familiar inherits a skill from its master
            PCClass aPCClass = null;
            if (//$NON-NLS-1$
            !childClass.getText().equals("None")) {
                final String childClassKey = EntityEncoder.decode(childClass.getText());
                aPCClass = thePC.getClassKeyed(childClassKey);
                if (aPCClass == null) {
                    final String message = "Could not find class: " + childClassKey;
                    warnings.add(message);
                    continue;
                }
            }
            if (aSkill == null) {
                // We only need to report this if the skill had ranks.
                final String message = "Could not add skill: " + skillKey;
                warnings.add(message);
                return;
            }
            try {
                double ranks = Double.parseDouble(childRanks.getText());
                SkillRankControl.modRanks(ranks, aPCClass, true, thePC, aSkill);
            } catch (NumberFormatException nfe) {
                final String message = "Invalid ranks specification: " + childRanks.getText();
                warnings.add(message);
                continue;
            }
        } else if (aSkill != null && IOConstants.TAG_ASSOCIATEDDATA.equals(tag)) {
            String key = EntityEncoder.decode(element.getText());
            ChoiceManagerList<Object> controller = ChooserUtilities.getConfiguredController(aSkill, thePC, null, new ArrayList<>());
            if (controller != null) {
                String[] assoc = key.split(Constants.COMMA, -1);
                for (String string : assoc) {
                    controller.restoreChoice(thePC, aSkill, string);
                }
            } else {
                warnings.add("Failed to find choose controller for skill " + aSkill);
            }
        } else if (aSkill != null && tag.equals(IOConstants.TAG_LEVELABILITY)) {
            parseLevelAbilityInfo(element, aSkill);
        } else if (aSkill != null && tag.equals(IOConstants.TAG_ADDTOKEN)) {
            parseAddTokenInfo(element, aSkill);
        }
    }
}
Also used : Skill(pcgen.core.Skill) ArrayList(java.util.ArrayList) ChoiceManagerList(pcgen.core.chooser.ChoiceManagerList) PCClass(pcgen.core.PCClass)

Example 2 with ChoiceManagerList

use of pcgen.core.chooser.ChoiceManagerList in project pcgen by PCGen.

the class RemoveFeatToken method applyChoice.

@Override
public void applyChoice(CDOMObject owner, CNAbilitySelection choice, PlayerCharacter pc) {
    CNAbility cna = choice.getCNAbility();
    Ability anAbility = cna.getAbility();
    boolean result = false;
    // adjust the associated List
    if (anAbility.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
        ChoiceManagerList cm = ChooserUtilities.getChoiceManager(cna, pc);
        remove(cm, pc, cna, choice.getSelection());
        result = pc.hasAssociations(cna);
    }
    // then remove the Feat
    if (!result) {
        pc.removeAbility(choice, UserSelection.getInstance(), UserSelection.getInstance());
        CDOMObjectUtilities.removeAdds(anAbility, pc);
        CDOMObjectUtilities.restoreRemovals(anAbility, pc);
    }
    pc.adjustMoveRates();
    double cost = cna.getAbility().getSafe(ObjectKey.SELECTION_COST).doubleValue();
    pc.adjustAbilities(AbilityCategory.FEAT, new BigDecimal(-cost));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) ChoiceManagerList(pcgen.core.chooser.ChoiceManagerList) BigDecimal(java.math.BigDecimal)

Aggregations

ChoiceManagerList (pcgen.core.chooser.ChoiceManagerList)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 CNAbility (pcgen.cdom.content.CNAbility)1 Ability (pcgen.core.Ability)1 PCClass (pcgen.core.PCClass)1 Skill (pcgen.core.Skill)1