Search in sources :

Example 1 with SignedInteger

use of pcgen.util.SignedInteger in project pcgen by PCGen.

the class EquipmentChoice method constructFromChoiceString.

/**
	 * Populate this EquipmentChoice object using data held in choiceString
	 * @param choiceString The string containing the info to be parsed and added
	 *                     to the chooser
	 * @param parent       the piece of Equipment that this Equipment Modifier
	 *                     will be added to
	 * @param available    used to adjust the pool
	 * @param numSelected  choices made so far
	 * @param forEqBuilder is this being constructed by the equipment builder,
	 *                      or for interaction with the user.
	 */
public void constructFromChoiceString(String choiceString, final Equipment parent, final int available, final int numSelected, final boolean forEqBuilder, PlayerCharacter pc) {
    final StringTokenizer titleTok = new StringTokenizer(choiceString, "|", false);
    while (!forEqBuilder && titleTok.hasMoreTokens()) {
        String workingkind = titleTok.nextToken();
        if (workingkind.startsWith("TITLE=")) {
            this.setTitle(workingkind.substring(6));
        }
    }
    int select = parent.getSafe(FormulaKey.SELECT).resolve(parent, true, pc, "").intValue();
    setMaxSelect(select);
    String originalkind = null;
    final StringTokenizer aTok = new StringTokenizer(choiceString, "|", false);
    boolean needStats = false;
    boolean needSkills = false;
    String category = null;
    while (!forEqBuilder && aTok.hasMoreTokens()) {
        String kind = aTok.nextToken();
        if (category == null) {
            if (kind.equals("ABILITY")) {
                category = aTok.nextToken();
            } else {
                category = "FEAT";
            }
        }
        this.adjustPool(available, numSelected);
        if (kind.startsWith("TITLE=")) {
        //Do nothing, handled above
        } else if (kind.startsWith("COUNT=")) {
        // Do nothing, handled above
        } else {
            if (originalkind == null) {
                originalkind = kind;
                needStats = originalkind.equals("STATBONUS");
                needSkills = originalkind.equals("SKILLBONUS");
            } else if (kind.startsWith("TYPE=") || kind.startsWith("TYPE.")) {
                if (originalkind.equals("SKILLBONUS") || originalkind.equals("SKILL")) {
                    //New Style
                    needSkills = false;
                    this.addChoicesByType(parent, available, numSelected, kind, "SKILL", "");
                } else if (originalkind.equals("EQUIPMENT") || originalkind.equals("FEAT") || originalkind.equals("ABILITY")) {
                    //New Style
                    this.addChoicesByType(parent, available, numSelected, kind, originalkind, category);
                } else {
                    //Old Style
                    this.addChoicesByType(parent, available, numSelected, kind, getTitle(), category);
                }
            } else if ("STAT".equals(kind)) {
                this.addStats();
            } else if ("SKILL".equals(kind) || originalkind.equals("SKILL") && "ANY".equals("SKILL")) {
                this.addSkills();
            } else if ("SKILL".equals(kind)) {
                this.addSkills();
            } else if ("SKIPZERO".equals(kind)) {
                skipZero = originalkind.equals("NUMBER");
            } else if ("MULTIPLE".equals(kind)) {
                this.setAllowDuplicates(true);
            } else if ("NOSIGN".equals(kind)) {
                this.setNoSign(true);
            } else if (kind.startsWith("MIN=")) {
                this.setMinValueFromString(kind);
            } else if (kind.startsWith("MAX=")) {
                this.setMaxValueFromString(kind);
            } else if (kind.startsWith("INCREMENT=")) {
                this.setIncrementValueFromString(kind);
            } else {
                needStats = false;
                needSkills = false;
                if (!this.getAvailableList().contains(kind)) {
                    this.getAvailableList().add(kind);
                }
            }
        }
    }
    if (needStats) {
        this.addStats();
    } else if (needSkills) {
        this.addSkills();
    }
    if (this.getTitle() == null) {
        this.setTitle(originalkind);
    }
    if (this.getMaxSelect() == Integer.MAX_VALUE) {
        this.setPool(this.getAvailableList().size() - numSelected);
        this.setBAdd(true);
    }
    if ((this.getAvailableList().isEmpty()) && (this.getMinValue() < this.getMaxValue())) {
        for (int j = this.getMinValue(); j <= this.getMaxValue(); j += this.getIncValue()) {
            if (!skipZero || j != 0) {
                if (this.isNoSign()) {
                    this.getAvailableList().add(j);
                } else {
                    this.getAvailableList().add(new SignedInteger(j));
                }
            }
        }
        this.setMinValue(this.getMaxValue());
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SignedInteger(pcgen.util.SignedInteger)

Example 2 with SignedInteger

use of pcgen.util.SignedInteger in project pcgen by PCGen.

the class EquipmentChoiceDriver method setChoice.

private static void setChoice(Equipment parent, EquipmentModifier eqMod, final List<Object> selectedList, final EquipmentChoice equipChoice) {
    parent.removeAllAssociations(eqMod);
    for (int i = 0; i < selectedList.size(); i++) {
        String aString = String.valueOf(selectedList.get(i));
        if (equipChoice.getMinValue() < equipChoice.getMaxValue()) {
            final int idx = aString.indexOf('|');
            if (idx < 0) {
                final List<SignedInteger> secondaryChoice = new ArrayList<>();
                for (int j = equipChoice.getMinValue(); j <= equipChoice.getMaxValue(); j += equipChoice.getIncValue()) {
                    if (j != 0) {
                        secondaryChoice.add(new SignedInteger(j));
                    }
                }
                String title = LanguageBundle.getFormattedString("in_equipChoiceSelectMod", //$NON-NLS-1$
                aString);
                CDOMChooserFacadeImpl<SignedInteger> chooserFacade = new CDOMChooserFacadeImpl<>(title, secondaryChoice, new ArrayList<>(), 1);
                chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
                chooserFacade.setAllowsDups(equipChoice.isAllowDuplicates());
                ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
                List<SignedInteger> chosenList = chooserFacade.getFinalSelected();
                if (chosenList.isEmpty()) {
                    continue;
                }
                aString += ('|' + chosenList.get(0).toString());
            }
        }
        if (equipChoice.isAllowDuplicates() || !parent.containsAssociated(eqMod, aString)) {
            parent.addAssociation(eqMod, aString);
        }
    }
}
Also used : CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) SignedInteger(pcgen.util.SignedInteger)

Aggregations

SignedInteger (pcgen.util.SignedInteger)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 CDOMChooserFacadeImpl (pcgen.core.chooser.CDOMChooserFacadeImpl)1