Search in sources :

Example 1 with SpellProhibitor

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

the class SpellProhibitorFacet method dataAdded.

/**
	 * Adds the SpellProhibitor objects granted by PCClasses added to the Player
	 * Character to this SpellProhibitorFacet.
	 * 
	 * Triggered when one of the Facets to which SpellProhibitorFacet listens
	 * fires a DataFacetChangeEvent to indicate a PCClass was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, PCClass> dfce) {
    PCClass pcc = dfce.getCDOMObject();
    CharID id = dfce.getCharID();
    Object source = dfce.getSource();
    for (SpellProhibitor prohibit : pcc.getSafeListFor(ListKey.PROHIBITED_SPELLS)) {
        add(id, pcc, prohibit, source);
    }
    for (SpellProhibitor prohibit : pcc.getSafeListFor(ListKey.SPELL_PROHIBITOR)) {
        add(id, pcc, prohibit, source);
    }
}
Also used : PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) SpellProhibitor(pcgen.core.SpellProhibitor)

Example 2 with SpellProhibitor

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

the class PCGVer2Parser method parseClassLine.

/*
	 * ###############################################################
	 * Character Class(es) methods
	 * ###############################################################
	 */
private void parseClassLine(final String line) throws PCGParseException {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        /*
			 * Classes are critical for characters,
			 * need to stop the load process
			 *
			 * Thomas Behr 14-08-02
			 */
        throw new PCGParseException("parseClassLine", line, //$NON-NLS-1$
        pcgpex.getMessage());
    }
    PCClass aPCClass = null;
    String tag;
    PCGElement element;
    final Iterator<PCGElement> it = tokens.getElements().iterator();
    // the first element defines the class key name!!!
    if (it.hasNext()) {
        element = it.next();
        String classKey = EntityEncoder.decode(element.getText());
        // First check for an existing class, say from a racial casting ability
        aPCClass = thePC.getClassKeyed(classKey);
        if (aPCClass == null) {
            aPCClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKey);
            if (aPCClass != null) {
                // Icky: Need to redesign the way classes work!
                // Icky: Having to clone the class here is UGLY!
                aPCClass = aPCClass.clone();
            } else {
                final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                "Warnings.PCGenParser.CouldntAddClass", element.getText());
                warnings.add(msg);
                return;
            }
        }
    }
    int level = -1;
    int skillPool = -1;
    String subClassKey = Constants.NONE;
    while (it.hasNext()) {
        element = it.next();
        tag = element.getName();
        if (IOConstants.TAG_SUBCLASS.equals(tag)) {
            subClassKey = EntityEncoder.decode(element.getText());
            if ((!subClassKey.isEmpty()) && !subClassKey.equals(Constants.NONE)) {
                SubClass sc = aPCClass.getSubClassKeyed(subClassKey);
                if (sc == null) {
                    if (subClassKey.equals(aPCClass.getKeyName())) {
                        subClassKey = Constants.NONE;
                    } else {
                        final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                        "Warnings.PCGenParser.InvalidSubclass", element.getText());
                        warnings.add(msg);
                    }
                }
            }
        }
        if (IOConstants.TAG_LEVEL.equals(tag)) {
            try {
                level = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
                final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                "Warnings.PCGenParser.InvalidLevel", element.getText());
                warnings.add(msg);
            }
        } else if (IOConstants.TAG_SKILLPOOL.equals(tag)) {
            try {
                skillPool = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
                final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                "Warnings.PCGenParser.InvalidSkillPool", element.getText());
                warnings.add(msg);
            }
        } else if (IOConstants.TAG_CANCASTPERDAY.equals(tag)) {
        // TODO
        } else if (IOConstants.TAG_SPELLBASE.equals(tag)) {
            final String spellBase = EntityEncoder.decode(element.getText());
            if (!Constants.NONE.equals(spellBase)) {
                Globals.getContext().unconditionallyProcess(aPCClass, "SPELLSTAT", spellBase);
            }
        } else if (IOConstants.TAG_PROHIBITED.equals(tag)) {
            String prohib = EntityEncoder.decode(element.getText());
            StringTokenizer st = new StringTokenizer(prohib, Constants.COMMA);
            while (st.hasMoreTokens()) {
                String choice = st.nextToken();
                if (!"None".equalsIgnoreCase(choice)) {
                    SpellProhibitor prohibSchool = new SpellProhibitor();
                    prohibSchool.setType(ProhibitedSpellType.SCHOOL);
                    prohibSchool.addValue(choice);
                    SpellProhibitor prohibSubSchool = new SpellProhibitor();
                    prohibSubSchool.setType(ProhibitedSpellType.SUBSCHOOL);
                    prohibSubSchool.addValue(choice);
                    thePC.addProhibitedSchool(prohibSchool, aPCClass);
                    thePC.addProhibitedSchool(prohibSubSchool, aPCClass);
                }
            }
        }
    }
    if (level > -1) {
        thePC.addClass(aPCClass);
        if (StringUtils.isNotBlank(subClassKey) && !subClassKey.equals(Constants.NONE)) {
            SubClassApplication.setSubClassKey(thePC, aPCClass, subClassKey);
        }
        for (int i = 0; i < level; ++i) {
            PCLevelInfo levelInfo = thePC.addLevelInfo(aPCClass.getKeyName());
            aPCClass.addLevel(false, false, thePC, true);
        }
    }
    //Must process ADD after CLASS is added to the PC
    for (PCGElement e : new PCGTokenizer(line).getElements()) {
        tag = e.getName();
        if (tag.equals(IOConstants.TAG_ADDTOKEN)) {
            parseAddTokenInfo(e, aPCClass);
        }
    }
    if (skillPool > -1) {
        thePC.setSkillPool(aPCClass, skillPool);
    }
}
Also used : SubClass(pcgen.core.SubClass) StringTokenizer(java.util.StringTokenizer) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor)

Example 3 with SpellProhibitor

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

the class PCGVer2Creator method appendClassLines.

/*
	 * ###############################################################
	 * Character Class(es) methods
	 * ###############################################################
	 */
private void appendClassLines(StringBuilder buffer) {
    Cache specials = new Cache();
    for (PCClass pcClass : charDisplay.getClassSet()) {
        int classLevel = charDisplay.getLevel(pcClass);
        buffer.append(IOConstants.TAG_CLASS).append(':');
        buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        final String subClassKey = charDisplay.getSubClassName(pcClass);
        if (subClassKey != null && !Constants.EMPTY_STRING.equals(subClassKey)) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SUBCLASS).append(':');
            buffer.append(EntityEncoder.encode(subClassKey));
        }
        buffer.append('|');
        buffer.append(IOConstants.TAG_LEVEL).append(':');
        buffer.append(classLevel);
        buffer.append('|');
        buffer.append(IOConstants.TAG_SKILLPOOL).append(':');
        Integer currentPool = thePC.getSkillPool(pcClass);
        buffer.append(currentPool == null ? 0 : currentPool);
        // determine if this class can cast spells
        boolean isCaster = false;
        if (!thePC.getSpellSupport(pcClass).canCastSpells(thePC)) {
            isCaster = true;
        }
        boolean isPsionic = thePC.getSpellSupport(pcClass).hasKnownList() && !isCaster;
        if (isCaster || isPsionic) {
            buffer.append('|');
            buffer.append(IOConstants.TAG_SPELLBASE).append(':');
            buffer.append(EntityEncoder.encode(pcClass.getSpellBaseStat()));
            buffer.append('|');
            buffer.append(IOConstants.TAG_CANCASTPERDAY).append(':');
            buffer.append(StringUtil.join(thePC.getSpellSupport(pcClass).getCastListForLevel(classLevel), ","));
        }
        Collection<? extends SpellProhibitor> prohib = charDisplay.getProhibitedSchools(pcClass);
        if (prohib != null) {
            Set<String> set = new TreeSet<>();
            for (SpellProhibitor sp : prohib) {
                set.addAll(sp.getValueList());
            }
            if (!set.isEmpty()) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_PROHIBITED).append(':');
                buffer.append(EntityEncoder.encode(StringUtil.join(set, ",")));
            }
        }
        appendAddTokenInfo(buffer, pcClass);
        buffer.append(IOConstants.LINE_SEP);
        String spec = thePC.getAssoc(pcClass, AssociationKey.SPECIALTY);
        if (spec != null) {
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + '0', spec);
        }
        String key;
        key = pcClass.getKeyName() + IOConstants.TAG_SAVE + '0';
        List<? extends SpecialAbility> salist = charDisplay.getUserSpecialAbilityList(pcClass);
        if (salist != null && !salist.isEmpty()) {
            SpecialAbility sa = salist.get(0);
            specials.put(pcClass.getKeyName() + IOConstants.TAG_SA + 0, sa.getKeyName());
        }
        for (BonusObj save : thePC.getSaveableBonusList(pcClass)) {
            specials.put(key, "BONUS|" + save);
        }
        for (int i = 1; i <= charDisplay.getLevel(pcClass); i++) {
            key = pcClass.getKeyName() + IOConstants.TAG_SAVE + (i - 1);
            PCClassLevel pcl = charDisplay.getActiveClassLevel(pcClass, i);
            for (BonusObj save : thePC.getSaveableBonusList(pcl)) {
                specials.put(key, "BONUS|" + save);
            }
        }
    }
    //
    for (PCLevelInfo pcl : charDisplay.getLevelInfo()) {
        final String classKeyName = pcl.getClassKeyName();
        int lvl = pcl.getClassLevel() - 1;
        PCClass pcClass = thePC.getClassKeyed(classKeyName);
        buffer.append(IOConstants.TAG_CLASSABILITIESLEVEL).append(':');
        if (pcClass == null) {
            pcClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKeyName);
            if (pcClass != null) {
                pcClass = thePC.getClassKeyed(pcClass.get(ObjectKey.EX_CLASS).get().getKeyName());
            }
        }
        if (pcClass != null) {
            buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
        } else {
            //$NON-NLS-1$
            buffer.append(EntityEncoder.encode("???"));
        }
        buffer.append('=').append(lvl + 1);
        if (pcClass != null) {
            String aKey = charDisplay.getSubstitutionClassName(charDisplay.getActiveClassLevel(pcClass, lvl + 1));
            if (aKey != null) {
                buffer.append('|');
                buffer.append(IOConstants.TAG_SUBSTITUTIONLEVEL).append(':');
                buffer.append(aKey);
            }
            buffer.append('|');
            buffer.append(IOConstants.TAG_HITPOINTS).append(':');
            PCClassLevel classLevel = charDisplay.getActiveClassLevel(pcClass, lvl);
            Integer hp = charDisplay.getHP(classLevel);
            buffer.append(hp == null ? 0 : hp);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SAVE + lvl), IOConstants.TAG_SAVES, IOConstants.TAG_SAVE, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SPECIALTY + lvl), IOConstants.TAG_SPECIALTIES, IOConstants.TAG_SPECIALTY, lvl);
            appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + lvl), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, lvl);
            if (lvl == 0) {
                appendSpecials(buffer, specials.get(pcClass.getKeyName() + IOConstants.TAG_SA + (lvl - 1)), IOConstants.TAG_SPECIALABILITIES, IOConstants.TAG_SA, -1);
            }
            //
            // Remember what choices were made for each of the ADD: tags
            //
            appendAddTokenInfo(buffer, charDisplay.getActiveClassLevel(pcClass, lvl + 1));
        }
        List<PCLevelInfoStat> statList = pcl.getModifiedStats(true);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        statList = pcl.getModifiedStats(false);
        if (statList != null) {
            for (PCLevelInfoStat stat : statList) {
                buffer.append('|').append(IOConstants.TAG_PRESTAT).append(':').append(stat.toString());
            }
        }
        int sp = pcl.getSkillPointsGained(thePC);
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSGAINED).append(':').append(sp);
        }
        sp = pcl.getSkillPointsRemaining();
        //if (sp != 0)
        {
            buffer.append('|').append(IOConstants.TAG_SKILLPOINTSREMAINING).append(':').append(sp);
        }
        buffer.append(IOConstants.LINE_SEP);
    }
}
Also used : PCLevelInfoStat(pcgen.core.pclevelinfo.PCLevelInfoStat) BonusObj(pcgen.core.bonus.BonusObj) SpecialAbility(pcgen.core.SpecialAbility) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor) PCClassLevel(pcgen.cdom.inst.PCClassLevel) TreeSet(java.util.TreeSet) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 4 with SpellProhibitor

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

the class SubClassApplication method checkForSubClass.

public static void checkForSubClass(PlayerCharacter aPC, PCClass cl) {
    List<SubClass> subClassList = cl.getListFor(ListKey.SUB_CLASS);
    if (subClassList == null || subClassList.isEmpty()) {
        return;
    }
    List<PCClass> availableList = new ArrayList<>();
    String subClassKey = aPC.getSubClassName(cl);
    boolean subClassSelected = subClassKey != null && !subClassKey.equals(Constants.NONE) && !subClassKey.equals("");
    for (SubClass sc : subClassList) {
        if (!PrereqHandler.passesAll(sc.getPrerequisiteList(), aPC, cl)) {
            continue;
        }
        // If a subclass has already been selected, only add that one
        if (!subClassSelected || sc.getKeyName().equals(aPC.getSubClassName(cl))) {
            availableList.add(sc);
        }
    }
    // add base class to the chooser
    if (cl.getSafe(ObjectKey.ALLOWBASECLASS) && (!subClassSelected || cl.getKeyName().equals(aPC.getSubClassName(cl)))) {
        availableList.add(0, cl);
    }
    /*
		 * REFACTOR This makes an assumption that SubClasses are ONLY Schools, which may
		 * not be a fabulous assumption
		 */
    List<PCClass> selectedSubClasses;
    CDOMChooserFacadeImpl<PCClass> chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
    LanguageBundle.getString("in_schoolSpecChoice"), //$NON-NLS-1$
    availableList, new ArrayList<>(), 1);
    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
    chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
    if (availableList.size() == 1) {
        selectedSubClasses = availableList;
    } else if (availableList.isEmpty()) {
        if (Logging.isLoggable(Logging.WARNING)) {
            Logging.log(Logging.WARNING, "No subclass choices avaialble for " + cl);
        }
        return;
    } else {
        ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
        selectedSubClasses = chooserFacade.getFinalSelected();
    }
    if (!cl.getSafe(ObjectKey.ALLOWBASECLASS)) {
        while (selectedSubClasses.isEmpty()) {
            ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
            selectedSubClasses = chooserFacade.getFinalSelected();
        }
    }
    if (selectedSubClasses.isEmpty()) {
        return;
    }
    PCClass subselected = selectedSubClasses.get(0);
    if (subselected instanceof SubClass) {
        aPC.removeProhibitedSchools(cl);
        /*
			 * CONSIDER What happens to this reset during PCClass/PCClassLevel split
			 */
        aPC.removeAssoc(cl, AssociationKey.SPECIALTY);
        SubClass sc = (SubClass) subselected;
        availableList.clear();
        for (SubClass sub : subClassList) {
            if (sub.equals(sc)) {
                //Skip the selected specialist school
                continue;
            }
            if (!PrereqHandler.passesAll(sub.getPrerequisiteList(), aPC, cl)) {
                continue;
            }
            int displayedCost = sub.getProhibitCost();
            if (displayedCost == 0) {
                continue;
            }
            availableList.add(sub);
        }
        setSubClassKey(aPC, cl, sc.getKeyName());
        if (sc.get(ObjectKey.CHOICE) != null) {
            aPC.setAssoc(cl, AssociationKey.SPECIALTY, sc.getChoice());
        }
        if (sc.getSafe(IntegerKey.COST) != 0) {
            chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
            LanguageBundle.getString("in_schoolProhibitChoice"), availableList, new ArrayList<>(), sc.getSafe(IntegerKey.COST));
            chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
            chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
            chooserFacade.setRequireCompleteSelection(true);
            ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
            selectedSubClasses = chooserFacade.getFinalSelected();
            for (PCClass choice : chooserFacade.getFinalSelected()) {
                sc = (SubClass) choice;
                SpellProhibitor prohibSchool = new SpellProhibitor();
                prohibSchool.setType(ProhibitedSpellType.SCHOOL);
                prohibSchool.addValue(sc.getChoice());
                SpellProhibitor prohibSubSchool = new SpellProhibitor();
                prohibSubSchool.setType(ProhibitedSpellType.SUBSCHOOL);
                prohibSubSchool.addValue(sc.getChoice());
                aPC.addProhibitedSchool(prohibSchool, cl);
                aPC.addProhibitedSchool(prohibSubSchool, cl);
            }
        }
    }
}
Also used : SubClass(pcgen.core.SubClass) CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor) Gui2InfoFactory(pcgen.gui2.facade.Gui2InfoFactory)

Example 5 with SpellProhibitor

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

the class ProhibitedToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer elements = new StringTokenizer(value, Constants.COMMA);
    while (elements.hasMoreTokens()) {
        String aValue = elements.nextToken();
        if (!aValue.equalsIgnoreCase("None")) {
            SpellProhibitor prohibSchool = new SpellProhibitor();
            prohibSchool.setType(ProhibitedSpellType.SCHOOL);
            prohibSchool.addValue(aValue);
            context.getObjectContext().addToList(pcc, ListKey.PROHIBITED_SPELLS, prohibSchool);
            SpellProhibitor prohibSubSchool = new SpellProhibitor();
            prohibSubSchool.setType(ProhibitedSpellType.SUBSCHOOL);
            prohibSubSchool.addValue(aValue);
            context.getObjectContext().addToList(pcc, ListKey.PROHIBITED_SPELLS, prohibSubSchool);
        }
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) SpellProhibitor(pcgen.core.SpellProhibitor)

Aggregations

SpellProhibitor (pcgen.core.SpellProhibitor)22 TreeSet (java.util.TreeSet)6 Test (org.junit.Test)6 PCClass (pcgen.core.PCClass)6 StringTokenizer (java.util.StringTokenizer)4 ProhibitedSpellType (pcgen.util.enumeration.ProhibitedSpellType)4 ArrayList (java.util.ArrayList)2 SubClass (pcgen.core.SubClass)2 PCLevelInfo (pcgen.core.pclevelinfo.PCLevelInfo)2 CharID (pcgen.cdom.enumeration.CharID)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 Domain (pcgen.core.Domain)1 SpecialAbility (pcgen.core.SpecialAbility)1 SpellSupportForPCClass (pcgen.core.SpellSupportForPCClass)1 BonusObj (pcgen.core.bonus.BonusObj)1 CDOMChooserFacadeImpl (pcgen.core.chooser.CDOMChooserFacadeImpl)1 PCLevelInfoStat (pcgen.core.pclevelinfo.PCLevelInfoStat)1 Prerequisite (pcgen.core.prereq.Prerequisite)1 Gui2InfoFactory (pcgen.gui2.facade.Gui2InfoFactory)1 HtmlInfoBuilder (pcgen.gui2.util.HtmlInfoBuilder)1