Search in sources :

Example 11 with PCClass

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

the class SpellLevel method isLevel.

/**
	 * isLevel(int aLevel)
	 *
	 * @param aLevel
	 *            level of the spell
	 * @param aPC
	 * @return true if the spell is of the given level in any spell list
	 */
public static boolean isLevel(Spell sp, int aLevel, PlayerCharacter aPC) {
    Integer levelKey = aLevel;
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    for (PCClass pcc : aPC.getClassSet()) {
        ClassSpellList csl = pcc.get(ObjectKey.CLASS_SPELLLIST);
        Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(csl, sp);
        if (assoc != null) {
            for (AssociatedPrereqObject apo : assoc) {
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
                    if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
                        return true;
                    }
                }
            }
        }
    }
    for (Domain domain : aPC.getDomainSet()) {
        DomainSpellList dsl = domain.get(ObjectKey.DOMAIN_SPELLLIST);
        Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(dsl, sp);
        if (assoc != null) {
            for (AssociatedPrereqObject apo : assoc) {
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
                    if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) MasterListInterface(pcgen.cdom.base.MasterListInterface) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 12 with PCClass

use of pcgen.core.PCClass 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 13 with PCClass

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

the class DomainApplication method removeDomain.

/**
	 * Remove a domain from the character.
	 * @param pc The character
	 * @param domain The domain.
	 */
public static void removeDomain(PlayerCharacter pc, Domain domain) {
    ClassSource source = pc.getDomainSource(domain);
    PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
    if (aClass != null) {
        int maxLevel;
        for (maxLevel = 0; maxLevel < 10; maxLevel++) {
            if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
                break;
            }
        }
        if (maxLevel > 0) {
            removeSpellsFromClassForLevels(pc, domain, aClass);
        }
        if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
            DomainSpellList domainSpellList = domain.get(ObjectKey.DOMAIN_SPELLLIST);
            final List<Spell> aList = pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));
            for (Spell gcs : aList) {
                if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
                    pc.removeDomainSpellCount(aClass);
                    break;
                }
            }
        }
    }
    if (!pc.isImporting()) {
        BonusActivation.deactivateBonuses(domain, pc);
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) PCClass(pcgen.core.PCClass) ClassSource(pcgen.cdom.helper.ClassSource) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 14 with PCClass

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

the class SubstitutionLevelSupport method levelArrayQualifies.

private static boolean levelArrayQualifies(int level, final PlayerCharacter pc, final String aLine, final SourceEntry tempSource, CDOMObject source) {
    final PCClassLoader classLoader = new PCClassLoader();
    PCClass dummyClass = new PCClass();
    try {
        classLoader.parseLine(Globals.getContext(), dummyClass, aLine, tempSource);
    } catch (PersistenceLayerException e) {
        Logging.errorPrint("Unable to parse line from levelArray: " + aLine);
    }
    return dummyClass.getOriginalClassLevel(level).qualifies(pc, source);
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) PCClassLoader(pcgen.persistence.lst.PCClassLoader) PCClass(pcgen.core.PCClass)

Example 15 with PCClass

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

the class ExportHandler method processSpellcasterExpression.

/**
	 * Deal with SPELLCASTER.
	 *  
	 * Could look like one of the following:
	 * 
	 * Arcane
	 * Chaos
	 * Divine
	 * EleMage
	 * Psionic
	 * Wizard
	 * Prepare
	 * !Prepare
	 * 0=Wizard    (%classNum=className)
	 * 0=Divine    (%classNum=spell_type)
	 * 0=Prepare   (%classNum=preparation_type)
	 *
	 * @param expr1 Expression to evaluate
	 * @param aPC PC containing values to help evaluate the expression
	 * @return true if the expression was evaluated successfully, else false
	 */
private static boolean processSpellcasterExpression(String expr1, PlayerCharacter aPC) {
    final String fString = expr1.substring(12).trim();
    // If the SPELLCASTER expression has an '=' sign
    if (fString.indexOf('=') != -1) {
        final StringTokenizer aTok = new StringTokenizer(fString, "=", false);
        final int i = Integer.parseInt(aTok.nextToken());
        final String cs = aTok.nextToken();
        final List<PCClass> cList = aPC.getClassList();
        if (i >= cList.size()) {
            return false;
        }
        final PCClass aClass = cList.get(i);
        if (cs.equalsIgnoreCase(aClass.getSpellType())) {
            return true;
        }
        if (cs.equalsIgnoreCase(aClass.getKeyName())) {
            return true;
        }
        if ("!Prepare".equalsIgnoreCase(cs) && aClass.getSafe(ObjectKey.MEMORIZE_SPELLS)) {
            return true;
        }
        if ("Prepare".equalsIgnoreCase(cs) && (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS))) {
            return true;
        }
    } else {
        for (final PCClass pcClass : aPC.getClassSet()) {
            if (fString.equalsIgnoreCase(pcClass.getSpellType())) {
                return true;
            }
            if (fString.equalsIgnoreCase(pcClass.getKeyName())) {
                return true;
            }
            if ("!Prepare".equalsIgnoreCase(fString) && pcClass.getSafe(ObjectKey.MEMORIZE_SPELLS)) {
                return true;
            }
            if ("Prepare".equalsIgnoreCase(fString) && (!pcClass.getSafe(ObjectKey.MEMORIZE_SPELLS))) {
                return true;
            }
        }
    }
    Logging.errorPrint("Should have exited before this in ExportHandler::processSpellcasterExpression");
    return false;
}
Also used : StringTokenizer(java.util.StringTokenizer) PCClass(pcgen.core.PCClass)

Aggregations

PCClass (pcgen.core.PCClass)359 Test (org.junit.Test)96 PlayerCharacter (pcgen.core.PlayerCharacter)61 Skill (pcgen.core.Skill)55 ArrayList (java.util.ArrayList)35 Domain (pcgen.core.Domain)30 LoadContext (pcgen.rules.context.LoadContext)28 PCClassLevel (pcgen.cdom.inst.PCClassLevel)26 CDOMObject (pcgen.cdom.base.CDOMObject)23 CharacterSpell (pcgen.core.character.CharacterSpell)20 Spell (pcgen.core.spell.Spell)20 StringTokenizer (java.util.StringTokenizer)19 CharID (pcgen.cdom.enumeration.CharID)19 ClassSource (pcgen.cdom.helper.ClassSource)19 PreClassTester (plugin.pretokens.test.PreClassTester)16 SkillCost (pcgen.cdom.enumeration.SkillCost)15 ParseResult (pcgen.rules.persistence.token.ParseResult)15 Ability (pcgen.core.Ability)14 Race (pcgen.core.Race)14 BonusObj (pcgen.core.bonus.BonusObj)14