Search in sources :

Example 11 with PObject

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

the class PCCountSpellsLevelsInBookTermEvaluator method resolve.

@Override
public Float resolve(PlayerCharacter pc) {
    String bookName = Globals.getDefaultSpellBook();
    if (sbookNum > 0) {
        bookName = pc.getDisplay().getSpellBookNames().get(sbookNum);
    }
    final PObject pObj = pc.getSpellClassAtIndex(classNum);
    int levelNum = 0;
    if (pObj != null) {
        for (; levelNum >= 0; ++levelNum) {
            final List<CharacterSpell> aList = pc.getCharacterSpells(pObj, null, bookName, levelNum);
            if (aList.size() < 1) {
                break;
            }
        }
    }
    return (float) levelNum;
}
Also used : PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 12 with PObject

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

the class ExportHandler method replaceTokenSpellListBook.

/**
	 * Helper method to deal with the SpellListBook token
	 * 
	 * @param aString
	 * @param aPC
	 * @return 0
	 */
private int replaceTokenSpellListBook(String aString, PlayerCharacter aPC) {
    int sbookNum = 0;
    final StringTokenizer aTok = new StringTokenizer(aString, ".");
    final int classNum = Integer.parseInt(aTok.nextToken());
    final int levelNum = Integer.parseInt(aTok.nextToken());
    // Get the spell book number
    if (aTok.hasMoreTokens()) {
        sbookNum = Integer.parseInt(aTok.nextToken());
    }
    // Set the spell book name
    String bookName = Globals.getDefaultSpellBook();
    if (sbookNum > 0) {
        bookName = aPC.getDisplay().getSpellBookNames().get(sbookNum);
    }
    canWrite = false;
    final PObject aObject = aPC.getSpellClassAtIndex(classNum);
    if (aObject != null) {
        final List<CharacterSpell> aList = aPC.getCharacterSpells(aObject, null, bookName, levelNum);
        canWrite = !aList.isEmpty();
    }
    return 0;
}
Also used : StringTokenizer(java.util.StringTokenizer) PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 13 with PObject

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

the class SpellListBookToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    StringBuilder retValue = new StringBuilder();
    SpellListTokenParams params = new SpellListTokenParams(tokenSource, SpellListToken.SPELLTAG_BOOK);
    final PObject aObject = pc.getSpellClassAtIndex(params.getClassNum());
    if (aObject != null) {
        String bookName = Globals.getDefaultSpellBook();
        if (params.getBookNum() > 0) {
            bookName = pc.getDisplay().getSpellBookNames().get(params.getBookNum());
        }
        final List<CharacterSpell> spells = pc.getCharacterSpells(aObject, null, bookName, params.getLevel());
        boolean needcomma = false;
        for (CharacterSpell cs : spells) {
            if (needcomma) {
                retValue.append(", ");
            }
            needcomma = true;
            retValue.append(OutputNameFormatting.getOutputName(cs.getSpell()));
        }
        if (!needcomma && eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
    }
    return retValue.toString();
}
Also used : PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 14 with PObject

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

the class PObjectLoaderTest method testParsePreClear.

public void testParsePreClear() throws Exception {
    PObject object = new PObject();
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(object, "PREVARLT", "GreaterRage,1");
    context.unconditionallyProcess(object, "PREFEAT", "1,Dodge");
    List<Prerequisite> list = object.getPrerequisiteList();
    assertEquals(2, list.size());
    context.unconditionallyProcess(object, "PRE", Constants.LST_DOT_CLEAR);
    list = object.getPrerequisiteList();
    assertNotNull("Prereq list should never be null as it is used in foreach loops directly.", list);
    assertTrue("Prereqlist should be empty after the clear", list.isEmpty());
}
Also used : PObject(pcgen.core.PObject) LoadContext(pcgen.rules.context.LoadContext) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 15 with PObject

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

the class SpellBuilderFacadeImpl method buildLists.

/**
	 * Use the parsed rules to build up the lists that will not change, 
	 * such as class/domain list and metamagic feats.
	 */
private void buildLists() {
    List<PCClass> classes = new ArrayList<>();
    List<Domain> domains = new ArrayList<>();
    if (classList != null) {
        for (String classKey : classList) {
            PObject obj = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKey);
            if (obj == null) {
                obj = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, classKey);
                if (obj != null) {
                    domains.add((Domain) obj);
                }
            } else {
                classes.add((PCClass) obj);
            }
        }
    } else {
        for (Spell spell : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Spell.class)) {
            if (isSpellOfSubType(spell)) {
                addSpellInfoToList(spell, classes, domains, reqSpellType);
            }
        }
        for (PCClass aClass : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCClass.class)) {
            if (!aClass.getSpellType().equals(Constants.NONE)) {
                // Only adds if the class can cast
                if (character.getSpellSupport(aClass).canCastSpells(character)) {
                    continue;
                }
                if (!("".equals(reqSpellType)) && (!reqSpellType.contains(aClass.getSpellType()))) {
                    continue;
                }
                if (!classes.contains(aClass)) {
                    classes.add(aClass);
                }
            }
        }
    }
    if (spellBooks != null) {
        for (int i = classes.size() - 1; i >= 0; --i) {
            PCClass obj = classes.get(i);
            if (// can't have books
            !spellBooks) {
                if (obj.getSafe(ObjectKey.SPELLBOOK)) {
                    classes.remove(i);
                }
            } else // must have books
            {
                if (!(obj instanceof PCClass) || !obj.getSafe(ObjectKey.SPELLBOOK)) {
                    classes.remove(i);
                }
            }
        }
        if (spellBooks) {
            domains.clear();
        }
    }
    List<InfoFacade> allObjects = new ArrayList<>();
    Globals.sortPObjectListByName(classes);
    allObjects.addAll(classes);
    Globals.sortPObjectListByName(domains);
    allObjects.addAll(domains);
    availClasses.setContents(allObjects);
    // Spell levels
    List<Integer> spellLevelValues = new ArrayList<>();
    if ((levelList != null) && (!levelList.isEmpty())) {
        for (int i = minSpellLevel; i < levelList.size(); ++i) {
            spellLevelValues.add(Integer.valueOf(levelList.get(i)));
        }
    } else {
        for (int i = minSpellLevel; i <= maxSpellLevel; i++) {
            spellLevelValues.add(i);
        }
    }
    availSpellLevels.setContents(spellLevelValues);
    // Caster levels
    updateAvailCasterLevels(1, 20);
    //Metamagic
    if (metaAllowed) {
        List<Ability> metamagicFeats = new ArrayList<>();
        for (Ability anAbility : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, AbilityCategory.FEAT).getAllObjects()) {
            if (anAbility.isType("Metamagic")) {
                metamagicFeats.add(anAbility);
            }
        }
        Globals.sortPObjectListByName(metamagicFeats);
        availMetamagicFeats.setContents(metamagicFeats);
    }
}
Also used : Ability(pcgen.core.Ability) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell) InfoFacade(pcgen.facade.core.InfoFacade) PObject(pcgen.core.PObject) Domain(pcgen.core.Domain)

Aggregations

PObject (pcgen.core.PObject)15 CharacterSpell (pcgen.core.character.CharacterSpell)7 ArrayList (java.util.ArrayList)6 Spell (pcgen.core.spell.Spell)5 PCClass (pcgen.core.PCClass)4 Ability (pcgen.core.Ability)3 Domain (pcgen.core.Domain)3 SpellInfo (pcgen.core.character.SpellInfo)3 StringTokenizer (java.util.StringTokenizer)2 SpellBook (pcgen.core.character.SpellBook)2 InfoFacade (pcgen.facade.core.InfoFacade)2 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 HashMapToList (pcgen.base.util.HashMapToList)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMList (pcgen.cdom.base.CDOMList)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 TransitionChoice (pcgen.cdom.base.TransitionChoice)1 CNAbility (pcgen.cdom.content.CNAbility)1 AvailableSpell (pcgen.cdom.helper.AvailableSpell)1