Search in sources :

Example 16 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class SpellBuilderFacadeImpl method addSpellInfoToList.

private void addSpellInfoToList(final Spell aSpell, List<PCClass> classes, List<Domain> domains, String spellType) {
    Set<String> unfoundItems = new HashSet<>();
    final HashMapToList<CDOMList<Spell>, Integer> levelInfo = character.getSpellLevelInfo(aSpell);
    if ((levelInfo == null) || (levelInfo.isEmpty())) {
        return;
    }
    for (CDOMList<Spell> spellList : levelInfo.getKeySet()) {
        if (spellList instanceof ClassSpellList) {
            String key = spellList.getKeyName();
            final PCClass aClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, key);
            if (aClass != null) {
                if (!("".equals(spellType)) && (!spellType.contains(aClass.getSpellType()))) {
                    continue;
                }
                if (!classes.contains(aClass)) {
                    classes.add(aClass);
                }
            } else {
                key = 'C' + key;
                if (!unfoundItems.contains(key)) {
                    unfoundItems.add(key);
                    Logging.errorPrint("Class " + key.substring(1) + " not found. Was used in spell " + aSpell);
                }
            }
        } else if (spellList instanceof DomainSpellList) {
            if (!("".equals(spellType)) && (!spellType.contains("Divine"))) {
                continue;
            }
            String key = spellList.getKeyName();
            final Domain aDomain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Domain.class, key);
            if (aDomain != null) {
                if (!domains.contains(aDomain)) {
                    domains.add(aDomain);
                }
            } else {
                key = 'D' + key;
                if (!unfoundItems.contains(key)) {
                    unfoundItems.add(key);
                    Logging.errorPrint("Domain " + key.substring(1) + " not found. Was used in spell " + aSpell);
                }
            }
        } else {
            Logging.errorPrint("Unknown spell source: " + spellList);
        }
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) ClassSpellList(pcgen.cdom.list.ClassSpellList) CDOMList(pcgen.cdom.base.CDOMList) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell) HashSet(java.util.HashSet)

Example 17 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class SpellBuilderFacadeImpl method processLevelChange.

/**
	 * Update lists that depend on the selected level of spell 
	 * e.g. the list of spells  
	 */
private void processLevelChange() {
    int baseSpellLevel = spellLevel.get();
    // List of available spells
    List<Spell> spellsOfLevel = new ArrayList<>();
    for (AvailableSpell availSpell : classSpells) {
        if (availSpell.getLevel() == baseSpellLevel) {
            spellsOfLevel.add(availSpell.getSpell());
        }
    }
    Globals.sortPObjectListByName(spellsOfLevel);
    availSpells.setContents(spellsOfLevel);
    InfoFacade selSpell = spell.get();
    if (selSpell == null || !spellsOfLevel.contains(selSpell)) {
        Spell newSpell = null;
        if (!spellsOfLevel.isEmpty()) {
            newSpell = spellsOfLevel.get(0);
        }
        selectSpell(newSpell);
    }
    // Spell type
    List<String> spellTypeList = getSpellTypeList();
    availSpellTypes.setContents(spellTypeList);
    spellType.set(spellTypeList.get(0));
}
Also used : AvailableSpell(pcgen.cdom.helper.AvailableSpell) InfoFacade(pcgen.facade.core.InfoFacade) ArrayList(java.util.ArrayList) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell)

Example 18 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class Gui2InfoFactory method getDescription.

@Override
public String getDescription(TempBonusFacade tempBonusFacade) {
    if (tempBonusFacade == null || !(tempBonusFacade instanceof TempBonusFacadeImpl)) {
        return EMPTY_STRING;
    }
    try {
        TempBonusFacadeImpl tempBonus = (TempBonusFacadeImpl) tempBonusFacade;
        CDOMObject originObj = tempBonus.getOriginObj();
        String desc = originObj.getSafe(StringKey.TEMP_DESCRIPTION);
        if (StringUtils.isEmpty(desc)) {
            if (originObj instanceof Spell) {
                Spell sp = (Spell) originObj;
                desc = DescriptionFormatting.piWrapDesc(sp, pc.getDescription(sp), false);
            } else if (originObj instanceof Ability) {
                Ability ab = (Ability) originObj;
                List<CNAbility> wrappedAbility = Collections.singletonList(CNAbilityFactory.getCNAbility(ab.getCDOMCategory(), Nature.NORMAL, ab));
                desc = DescriptionFormatting.piWrapDesc(ab, pc.getDescription(wrappedAbility), false);
            }
        }
        return desc;
    } catch (Exception e) {
        //$NON-NLS-1$
        Logging.errorPrint("Failed to get description for " + tempBonusFacade, e);
        return EMPTY_STRING;
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) List(java.util.List) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 19 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class KitSpells method testApply.

@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    theSpells = null;
    PCClass aClass = findDefaultSpellClass(castingClass, aPC);
    if (aClass == null) {
        warnings.add("SPELLS: Character does not have " + castingClass + " spellcasting class.");
        return false;
    }
    String workingBook = spellBook == null ? Globals.getDefaultSpellBook() : spellBook;
    List<KitSpellBookEntry> aSpellList = new ArrayList<>();
    if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS) && !workingBook.equals(Globals.getDefaultSpellBook())) {
        warnings.add("SPELLS: " + aClass.getDisplayName() + " can only add to " + Globals.getDefaultSpellBook());
        return false;
    }
    for (KnownSpellIdentifier ksi : spells.getKeySet()) {
        Collection<Spell> allSpells = ksi.getContainedSpells(aPC, Collections.singletonList(aClass.get(ObjectKey.CLASS_SPELLLIST)));
        Set<List<CDOMSingleRef<Ability>>> feats = spells.getSecondaryKeySet(ksi);
        for (Spell sp : allSpells) {
            for (List<CDOMSingleRef<Ability>> list : feats) {
                Integer count = spells.get(ksi, list);
                aSpellList.add(new KitSpellBookEntry(spellBook, sp, list, count));
            }
        }
    }
    final Formula choiceFormula = getCount();
    int numberOfChoices;
    if (choiceFormula == null) {
        numberOfChoices = aSpellList.size();
    } else {
        numberOfChoices = choiceFormula.resolve(aPC, "").intValue();
    }
    //
    if (numberOfChoices > aSpellList.size()) {
        numberOfChoices = aSpellList.size();
    }
    if (numberOfChoices == 0) {
        return false;
    }
    List<KitSpellBookEntry> xs;
    if (numberOfChoices == aSpellList.size()) {
        xs = aSpellList;
    } else {
        //
        while (true) {
            xs = Globals.getChoiceFromList("Choose " + aClass.getKeyName() + " spell(s) for " + workingBook, aSpellList, new ArrayList<>(), numberOfChoices, aPC);
            if (!xs.isEmpty()) {
                break;
            }
        }
    }
    //
    for (KitSpellBookEntry obj : xs) {
        if (obj != null) {
            obj.setPCClass(aClass);
            if (theSpells == null) {
                theSpells = new ArrayList<>();
            }
            theSpells.add(obj);
        } else {
            warnings.add("SPELLS: Non-existant spell chosen");
        }
    }
    if (theSpells != null && !theSpells.isEmpty()) {
        return true;
    }
    return false;
}
Also used : Ability(pcgen.core.Ability) KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) Formula(pcgen.base.formula.Formula) CDOMList(pcgen.cdom.base.CDOMList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class KitSpells method updatePCSpells.

/**
	 * Add spells from this Kit to the PC
	 *
	 * @param  pc       The PC to add the spells to
	 * @param  aSpell   A Spell to add to the PC
	 * @param  pcClass  The class instance the spells are to be added to.
	 */
private void updatePCSpells(final PlayerCharacter pc, final KitSpellBookEntry aSpell, final PCClass pcClass) {
    Spell spell = aSpell.getSpell();
    int spLevel = 99;
    // Check to see if we have any domains that have this spell.
    PObject owner = null;
    if (pc.hasDomains()) {
        for (Domain domain : pc.getDomainSet()) {
            List<? extends CDOMList<Spell>> lists = pc.getSpellLists(domain);
            int newLevel = SpellLevel.getFirstLevelForKey(spell, lists, pc);
            if (newLevel > 0 && newLevel < spLevel) {
                spLevel = newLevel;
                owner = domain;
            }
        }
    }
    if (spLevel == 99) {
        spLevel = SpellLevel.getFirstLevelForKey(spell, pc.getSpellLists(pcClass), pc);
        owner = pcClass;
    }
    if (spLevel < 0) {
        Logging.errorPrint("SPELLS: " + pcClass.getDisplayName() + " cannot cast spell \"" + spell.getKeyName() + "\"");
        return;
    }
    final CharacterSpell cs = new CharacterSpell(owner, spell);
    final List<CDOMSingleRef<Ability>> modifierList = aSpell.getModifiers();
    int adjustedLevel = spLevel;
    List<Ability> metamagicFeatList = new ArrayList<>();
    for (CDOMSingleRef<Ability> feat : modifierList) {
        Ability anAbility = feat.get();
        adjustedLevel += anAbility.getSafe(IntegerKey.ADD_SPELL_LEVEL);
        metamagicFeatList.add(anAbility);
    }
    if (metamagicFeatList.size() <= 0) {
        metamagicFeatList = null;
    }
    if (!pc.hasSpellBook(aSpell.getBookName())) {
        pc.addSpellBook(aSpell.getBookName());
    }
    for (int numTimes = 0; numTimes < aSpell.getCopies(); numTimes++) {
        final String aString = pc.addSpell(cs, metamagicFeatList, pcClass.getKeyName(), aSpell.getBookName(), adjustedLevel, spLevel);
        if (!aString.isEmpty()) {
            Logging.errorPrint("Add spell failed:" + aString);
            return;
        }
    }
}
Also used : Ability(pcgen.core.Ability) ArrayList(java.util.ArrayList) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell) Domain(pcgen.core.Domain)

Aggregations

Spell (pcgen.core.spell.Spell)87 CharacterSpell (pcgen.core.character.CharacterSpell)35 ArrayList (java.util.ArrayList)25 PCClass (pcgen.core.PCClass)24 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)16 CDOMReference (pcgen.cdom.base.CDOMReference)15 Ability (pcgen.core.Ability)15 LoadContext (pcgen.rules.context.LoadContext)13 CDOMList (pcgen.cdom.base.CDOMList)12 CDOMObject (pcgen.cdom.base.CDOMObject)11 Test (org.junit.Test)10 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)9 AvailableSpell (pcgen.cdom.helper.AvailableSpell)8 StringTokenizer (java.util.StringTokenizer)7 CNAbility (pcgen.cdom.content.CNAbility)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)7 DomainSpellList (pcgen.cdom.list.DomainSpellList)7 Formula (pcgen.base.formula.Formula)6 Domain (pcgen.core.Domain)6 PObject (pcgen.core.PObject)6