Search in sources :

Example 6 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef 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 7 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef 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)

Example 8 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class KitSpells method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    if (castingClass != null) {
        sb.append(castingClass.getLSTformat(false));
    }
    sb.append(' ').append(spellBook).append(": ");
    boolean needComma = false;
    for (KnownSpellIdentifier ksi : spells.getKeySet()) {
        if (needComma) {
            sb.append(',');
        }
        needComma = true;
        sb.append(ksi.getLSTformat());
        Set<List<CDOMSingleRef<Ability>>> abilities = spells.getSecondaryKeySet(ksi);
        for (List<CDOMSingleRef<Ability>> list : abilities) {
            if (list != null) {
                sb.append(" [");
                sb.append(ReferenceUtilities.joinLstFormat(list, ","));
                sb.append(']');
            }
            Integer count = spells.get(ksi, list);
            if (count > 1) {
                sb.append(" (").append(count).append(")");
            }
        }
    }
    return sb.toString();
}
Also used : Ability(pcgen.core.Ability) KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) CDOMList(pcgen.cdom.base.CDOMList) ArrayList(java.util.ArrayList) List(java.util.List) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 9 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class KitStat method testApply.

@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
    for (Map.Entry<CDOMSingleRef<PCStat>, Formula> me : statMap.entrySet()) {
        PCStat mapStat = me.getKey().get();
        int sVal = me.getValue().resolve(aPC, "").intValue();
        for (PCStat currentStat : aPC.getStatSet()) {
            if (!aPC.isNonAbility(currentStat) && currentStat.equals(mapStat)) {
                aPC.setStat(currentStat, sVal);
                if ("INT".equals(currentStat.getKeyName())) {
                    recalculateSkillPoints(aPC);
                }
                break;
            }
        }
    }
    return true;
}
Also used : Formula(pcgen.base.formula.Formula) PCStat(pcgen.core.PCStat) HashMap(java.util.HashMap) Map(java.util.Map) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 10 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class KitTemplate method buildSelectedTemplateMap.

/**
	 * Extract the templates to be applied and their choices
	 * @param aPC The PC the kit is being applied to.
	 * @param apply Is this a real application, false if a test run. 
	 * @return The map of templates and child templates to be added
	 */
private HashMapToList<PCTemplate, PCTemplate> buildSelectedTemplateMap(PlayerCharacter aPC, boolean apply) {
    boolean tempShowHP = SettingsHandler.getShowHPDialogAtLevelUp();
    SettingsHandler.setShowHPDialogAtLevelUp(false);
    if (!apply) {
        ChooserFactory.pushChooserClassname(//$NON-NLS-1$
        "pcgen.util.chooser.RandomChooser");
    }
    HashMapToList<PCTemplate, PCTemplate> selectedMap = new HashMapToList<>();
    for (CDOMSingleRef<PCTemplate> ref : templateList.getKeySet()) {
        PCTemplate templateToAdd = ref.get();
        List<CDOMSingleRef<PCTemplate>> subList = templateList.getListFor(ref);
        List<PCTemplate> subAdded = new ArrayList<>();
        if (subList != null) {
            for (CDOMSingleRef<PCTemplate> subRef : subList) {
                PCTemplate ownedTemplate = subRef.get();
                subAdded.add(ownedTemplate);
                aPC.setTemplatesAdded(templateToAdd, ownedTemplate);
            }
        }
        aPC.addTemplate(templateToAdd);
        selectedMap.initializeListFor(templateToAdd);
        selectedMap.addAllToListFor(templateToAdd, subAdded);
    }
    if (!apply) {
        ChooserFactory.popChooserClassname();
    }
    SettingsHandler.setShowHPDialogAtLevelUp(tempShowHP);
    return selectedMap;
}
Also used : HashMapToList(pcgen.base.util.HashMapToList) ArrayList(java.util.ArrayList) PCTemplate(pcgen.core.PCTemplate) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Aggregations

CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)38 ArrayList (java.util.ArrayList)13 Ability (pcgen.core.Ability)10 Domain (pcgen.core.Domain)10 Prerequisite (pcgen.core.prereq.Prerequisite)10 StringTokenizer (java.util.StringTokenizer)9 QualifiedObject (pcgen.core.QualifiedObject)9 PCStat (pcgen.core.PCStat)6 List (java.util.List)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 CDOMReference (pcgen.cdom.base.CDOMReference)4 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)4 CharID (pcgen.cdom.enumeration.CharID)4 AbilityCategory (pcgen.core.AbilityCategory)4 PCClass (pcgen.core.PCClass)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 HashMap (java.util.HashMap)3 Formula (pcgen.base.formula.Formula)3