Search in sources :

Example 6 with CDOMList

use of pcgen.cdom.base.CDOMList 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 7 with CDOMList

use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.

the class ClassDataHandler method getSpellsIn.

/**
	 * Returns a List of Spell with following criteria:
	 *
	 * @param level      (optional, ignored if < 0),
	 * @param spellLists the lists of spells
	 * @param pc TODO
	 * @return a List of Spell
	 */
public static List<Spell> getSpellsIn(final int level, List<? extends CDOMList<Spell>> spellLists) {
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    ArrayList<CDOMReference<CDOMList<Spell>>> useLists = new ArrayList<>();
    for (CDOMReference ref : masterLists.getActiveLists()) {
        for (CDOMList<Spell> list : spellLists) {
            if (ref.contains(list)) {
                useLists.add(ref);
                break;
            }
        }
    }
    boolean allLevels = level == -1;
    Set<Spell> spellList = new HashSet<>();
    for (CDOMReference<CDOMList<Spell>> ref : useLists) {
        for (Spell spell : masterLists.getObjects(ref)) {
            Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, spell);
            for (AssociatedPrereqObject apo : assoc) {
                // TODO Not sure if effect of null for PC
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), (PlayerCharacter) null, null)) {
                    int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
                    if (allLevels || level == lvl) {
                        spellList.add(spell);
                        break;
                    }
                }
            }
        }
    }
    return new ArrayList<>(spellList);
}
Also used : ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) MasterListInterface(pcgen.cdom.base.MasterListInterface) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 8 with CDOMList

use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.

the class AbstractListContext method commit.

void commit() {
    ListCommitStrategy commit = getCommitStrategy();
    for (CDOMReference<? extends CDOMList<?>> list : edits.positiveMasterMap.getKeySet()) {
        //Note: Intentional Generics Violation due to Sun Compiler
        commitDirect((CDOMReference) list);
    }
    for (CDOMReference<? extends CDOMList<?>> list : edits.negativeMasterMap.getKeySet()) {
        //Note: Intentional Generics Violation due to Sun Compiler
        removeDirect((CDOMReference) list);
    }
    for (URI uri : edits.globalClearSet.getKeySet()) {
        for (CDOMObject owner : edits.globalClearSet.getSecondaryKeySet(uri)) {
            for (String tokenName : edits.globalClearSet.getTertiaryKeySet(uri, owner)) {
                for (CDOMReference<? extends CDOMList<?>> list : edits.globalClearSet.getListFor(uri, owner, tokenName)) {
                    commit.removeAllFromList(tokenName, owner, list);
                }
            }
        }
    }
    for (URI uri : edits.negativeMap.getKeySet()) {
        for (CDOMObject owner : edits.negativeMap.getSecondaryKeySet(uri)) {
            CDOMObject neg = edits.negativeMap.get(uri, owner);
            Collection<CDOMReference<? extends CDOMList<?>>> modifiedLists = neg.getModifiedLists();
            for (CDOMReference<? extends CDOMList<?>> list : modifiedLists) {
                //Note: Intentional Generics Violation due to Sun Compiler
                remove(owner, neg, (CDOMReference) list);
            }
        }
    }
    for (URI uri : edits.positiveMap.getKeySet()) {
        for (CDOMObject owner : edits.positiveMap.getSecondaryKeySet(uri)) {
            CDOMObject neg = edits.positiveMap.get(uri, owner);
            Collection<CDOMReference<? extends CDOMList<?>>> modifiedLists = neg.getModifiedLists();
            for (CDOMReference<? extends CDOMList<?>> list : modifiedLists) {
                //Note: Intentional Generics Violation due to Sun Compiler
                add(owner, neg, (CDOMReference) list);
            }
        }
    }
    for (String token : edits.masterAllClear.getKeySet()) {
        for (OwnerURI ou : edits.masterAllClear.getListFor(token)) {
            commit.clearAllMasterLists(token, ou.owner);
        }
    }
    rollback();
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) CDOMList(pcgen.cdom.base.CDOMList) URI(java.net.URI) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 9 with CDOMList

use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.

the class SpelllevelLst method subParse.

private <CL extends Loadable & CDOMList<Spell>> boolean subParse(LoadContext context, CDOMObject obj, Class<CL> tagType, String tokString, String spellString, List<Prerequisite> prereqs) {
    int equalLoc = tokString.indexOf(Constants.EQUALS);
    if (equalLoc == -1) {
        Logging.errorPrint("Expected an = in SPELLLEVEL " + "definition: " + tokString);
        return false;
    }
    String casterString = tokString.substring(0, equalLoc);
    String spellLevel = tokString.substring(equalLoc + 1);
    Integer splLevel;
    try {
        splLevel = Integer.decode(spellLevel);
    } catch (NumberFormatException nfe) {
        Logging.errorPrint("Expected a number for SPELLLEVEL, found: " + spellLevel);
        return false;
    }
    if (isEmpty(casterString) || hasIllegalSeparator(',', casterString)) {
        return false;
    }
    StringTokenizer clTok = new StringTokenizer(casterString, Constants.COMMA);
    List<CDOMReference<? extends CDOMList<Spell>>> slList = new ArrayList<>();
    while (clTok.hasMoreTokens()) {
        String classString = clTok.nextToken();
        CDOMReference<CL> ref;
        if (classString.startsWith("SPELLCASTER.")) {
            /*
				 * This is actually a TYPE
				 */
            ref = context.getReferenceContext().getCDOMTypeReference(tagType, classString.substring(12));
        } else {
            ref = context.getReferenceContext().getCDOMReference(tagType, classString);
        }
        slList.add(ref);
    }
    if (hasIllegalSeparator(',', spellString)) {
        return false;
    }
    StringTokenizer spTok = new StringTokenizer(spellString, ",");
    while (spTok.hasMoreTokens()) {
        String spellName = spTok.nextToken();
        CDOMReference<Spell> sp = context.getReferenceContext().getCDOMReference(Spell.class, spellName);
        for (CDOMReference<? extends CDOMList<Spell>> sl : slList) {
            AssociatedPrereqObject tpr = context.getListContext().addToList(getTokenName(), obj, sl, sp);
            tpr.setAssociation(AssociationKey.SPELL_LEVEL, splLevel);
            tpr.addAllPrerequisites(prereqs);
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) StringTokenizer(java.util.StringTokenizer) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 10 with CDOMList

use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.

the class SpellknownLst method subParse.

/**
	 * Parse the tag contents after the SPELLKNOWN:CLASS| section.
	 *
	 * @param context the context under which the tag is being parsed.
	 * @param obj the obj The object owning the tag.
	 * @param tagType the type of object the tag creates
	 * @param tokString the tok string The string defining the caster type/class and spell level.
	 * @param spellString the spell string The string containing the spell name(s)
	 * @param prereqs the prereqs The prerequisites to be applied.
	 *
	 * @return true, if successful
	 */
private <CL extends Loadable & CDOMList<Spell>> boolean subParse(LoadContext context, CDOMObject obj, Class<CL> tagType, String tokString, String spellString, List<Prerequisite> prereqs) {
    int equalLoc = tokString.indexOf(Constants.EQUALS);
    if (equalLoc == -1) {
        Logging.errorPrint("Expected an = in SPELLKNOWN " + "definition: " + tokString);
        return false;
    }
    String casterString = tokString.substring(0, equalLoc);
    String spellLevel = tokString.substring(equalLoc + 1);
    Integer splLevel;
    try {
        splLevel = Integer.decode(spellLevel);
    } catch (NumberFormatException nfe) {
        Logging.errorPrint("Expected a number for SPELLKNOWN, found: " + spellLevel);
        return false;
    }
    if (isEmpty(casterString) || hasIllegalSeparator(',', casterString)) {
        return false;
    }
    StringTokenizer clTok = new StringTokenizer(casterString, Constants.COMMA);
    List<CDOMReference<? extends CDOMList<Spell>>> slList = new ArrayList<>();
    while (clTok.hasMoreTokens()) {
        String classString = clTok.nextToken();
        CDOMReference<CL> ref;
        if (classString.startsWith("SPELLCASTER.")) {
            /*
				 * This is actually a TYPE
				 */
            ref = context.getReferenceContext().getCDOMTypeReference(tagType, classString.substring(12));
        } else {
            ref = context.getReferenceContext().getCDOMReference(tagType, classString);
        }
        slList.add(ref);
    }
    if (hasIllegalSeparator(',', spellString)) {
        return false;
    }
    StringTokenizer spTok = new StringTokenizer(spellString, ",");
    while (spTok.hasMoreTokens()) {
        String spellName = spTok.nextToken();
        CDOMReference<Spell> sp = context.getReferenceContext().getCDOMReference(Spell.class, spellName);
        for (CDOMReference<? extends CDOMList<Spell>> sl : slList) {
            AssociatedPrereqObject tpr = context.getListContext().addToList(getTokenName(), obj, sl, sp);
            tpr.setAssociation(AssociationKey.SPELL_LEVEL, splLevel);
            tpr.setAssociation(AssociationKey.KNOWN, Boolean.TRUE);
            tpr.addAllPrerequisites(prereqs);
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) StringTokenizer(java.util.StringTokenizer) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

CDOMList (pcgen.cdom.base.CDOMList)17 CDOMReference (pcgen.cdom.base.CDOMReference)10 Spell (pcgen.core.spell.Spell)10 ArrayList (java.util.ArrayList)6 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)6 TreeSet (java.util.TreeSet)4 DomainSpellList (pcgen.cdom.list.DomainSpellList)4 HashSet (java.util.HashSet)3 TripleKeyMapToList (pcgen.base.util.TripleKeyMapToList)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 ClassSpellList (pcgen.cdom.list.ClassSpellList)3 PCClass (pcgen.core.PCClass)3 CharacterSpell (pcgen.core.character.CharacterSpell)3 Set (java.util.Set)2 StringTokenizer (java.util.StringTokenizer)2 Test (org.junit.Test)2 MasterListInterface (pcgen.cdom.base.MasterListInterface)2 CharID (pcgen.cdom.enumeration.CharID)2 AvailableSpell (pcgen.cdom.helper.AvailableSpell)2 Prerequisite (pcgen.core.prereq.Prerequisite)2