Search in sources :

Example 1 with KnownSpellIdentifier

use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.

the class PCClass method clone.

@Override
public PCClass clone() {
    PCClass aClass = null;
    try {
        aClass = (PCClass) super.clone();
        List<KnownSpellIdentifier> ksl = getListFor(ListKey.KNOWN_SPELLS);
        if (ksl != null) {
            aClass.removeListFor(ListKey.KNOWN_SPELLS);
            for (KnownSpellIdentifier ksi : ksl) {
                aClass.addToListFor(ListKey.KNOWN_SPELLS, ksi);
            }
        }
        Map<AttackType, Integer> acmap = getMapFor(MapKey.ATTACK_CYCLE);
        if (acmap != null && !acmap.isEmpty()) {
            aClass.removeMapFor(MapKey.ATTACK_CYCLE);
            for (Map.Entry<AttackType, Integer> me : acmap.entrySet()) {
                aClass.addToMapFor(MapKey.ATTACK_CYCLE, me.getKey(), me.getValue());
            }
        }
        aClass.levelMap = new TreeMap<>();
        for (Map.Entry<Integer, PCClassLevel> me : levelMap.entrySet()) {
            aClass.levelMap.put(me.getKey(), me.getValue().clone());
        }
    } catch (CloneNotSupportedException exc) {
        ShowMessageDelegate.showMessageDialog(exc.getMessage(), Constants.APPLICATION_NAME, MessageType.ERROR);
    }
    return aClass;
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) AttackType(pcgen.util.enumeration.AttackType) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 2 with KnownSpellIdentifier

use of pcgen.cdom.content.KnownSpellIdentifier 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 3 with KnownSpellIdentifier

use of pcgen.cdom.content.KnownSpellIdentifier 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 4 with KnownSpellIdentifier

use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.

the class KnownspellsToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    Changes<KnownSpellIdentifier> changes = context.getObjectContext().getListChanges(pcc, ListKey.KNOWN_SPELLS);
    List<String> list = new ArrayList<>();
    if (changes.includesGlobalClear()) {
        list.add(Constants.LST_DOT_CLEAR_ALL);
    }
    Collection<KnownSpellIdentifier> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty()) {
        context.addWriteMessage(getTokenName() + " does not support .CLEAR.");
        return null;
    }
    Collection<KnownSpellIdentifier> added = changes.getAdded();
    if (added != null && !added.isEmpty()) {
        TreeMapToList<CDOMReference<?>, Integer> map = new TreeMapToList<>(ReferenceUtilities.REFERENCE_SORTER);
        for (KnownSpellIdentifier ksi : added) {
            CDOMReference<Spell> ref = ksi.getSpellReference();
            Integer i = ksi.getSpellLevel();
            map.addToListFor(ref, i);
        }
        for (CDOMReference<?> ref : map.getKeySet()) {
            for (Integer lvl : map.getListFor(ref)) {
                StringBuilder sb = new StringBuilder();
                boolean needComma = false;
                String refString = ref.getLSTformat(false);
                if (!Constants.LST_ALL.equals(refString)) {
                    sb.append(refString);
                    needComma = true;
                }
                if (lvl != null) {
                    if (needComma) {
                        sb.append(',');
                    }
                    sb.append("LEVEL=").append(lvl);
                }
                list.add(sb.toString());
            }
        }
    }
    if (list.isEmpty()) {
        return null;
    }
    return new String[] { StringUtil.join(list, Constants.PIPE) };
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) TreeMapToList(pcgen.base.util.TreeMapToList) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 5 with KnownSpellIdentifier

use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.

the class KnownspellsTokenTest method testUnparseNegativeLevel.

@Test
public void testUnparseNegativeLevel() throws PersistenceLayerException {
    try {
        CDOMGroupRef<Spell> all = primaryContext.getReferenceContext().getCDOMAllReference(Spell.class);
        primaryProf.addToListFor(ListKey.KNOWN_SPELLS, new KnownSpellIdentifier(all, -3));
        assertBadUnparse();
    } catch (IllegalArgumentException e) {
    //Good here too :)
    }
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) Spell(pcgen.core.spell.Spell) Test(org.junit.Test)

Aggregations

KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)13 Spell (pcgen.core.spell.Spell)9 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)4 Ability (pcgen.core.Ability)4 List (java.util.List)3 PCClass (pcgen.core.PCClass)3 StringTokenizer (java.util.StringTokenizer)2 CDOMList (pcgen.cdom.base.CDOMList)2 CDOMReference (pcgen.cdom.base.CDOMReference)2 ComplexParseResult (pcgen.rules.persistence.token.ComplexParseResult)2 ParseResult (pcgen.rules.persistence.token.ParseResult)2 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Formula (pcgen.base.formula.Formula)1 TreeMapToList (pcgen.base.util.TreeMapToList)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 CharacterSpell (pcgen.core.character.CharacterSpell)1