Search in sources :

Example 16 with HashMapToList

use of pcgen.base.util.HashMapToList in project pcgen by PCGen.

the class FeatAutoListToken method getAbilityList.

/**
	 * @see pcgen.io.exporttoken.AbilityListToken#getAbilityList(pcgen.core.PlayerCharacter, pcgen.core.AbilityCategory)
	 */
@Override
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
    final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
    Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
    for (AbilityCategory aCat : allCats) {
        if (aCat.getParentCategory().equals(aCategory)) {
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.AUTOMATIC)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
        }
    }
    return listOfAbilities;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Example 17 with HashMapToList

use of pcgen.base.util.HashMapToList in project pcgen by PCGen.

the class AvailableSpellFacet method getSpellLevelInfo.

/**
	 * Returns a non-null HashMapToList indicating the spell levels and sources
	 * of those spell levels available to a Player Character for a given Spell.
	 * 
	 * This may return multiple spell levels because it is possible for a spell
	 * to be accessible to a Player Character at multiple levels since it may be
	 * available from multiple sources. This also returns the spell lists
	 * associated with the given level, since it is possible for a multi-class
	 * character to have access to the same spell at different levels. By
	 * returning the source as well as the spell levels, such scenarios can be
	 * appropriately distinguished.
	 * 
	 * This method is value-semantic in that ownership of the returned
	 * HashMapToList is transferred to the class calling this method.
	 * Modification of the returned HashMapToList will not modify this
	 * AvailableSpellFacet and modification of this AvailableSpellFacet will not
	 * modify the returned HashMapToList. Modifications to the returned
	 * HashMapToList will also not modify any future or previous objects
	 * returned by this (or other) methods on AvailableSpellFacet. If you wish
	 * to modify the information stored in this AvailableSpellFacet, you must
	 * use the add*() and remove*() methods of AvailableSpellFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            spell levels should be returned
	 * @param sp
	 *            The Spell for which the spell levels should be returned
	 * @return A non-null HashMapToList indicating the spell levels and sources
	 *         of those spell levels available to a Player Character for a given
	 *         Spell.
	 */
public HashMapToList<CDOMList<Spell>, Integer> getSpellLevelInfo(CharID id, Spell sp) {
    HashMapToList<CDOMList<Spell>, Integer> levelInfo = new HashMapToList<>();
    Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> listMap = (Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>>) getCache(id);
    if (listMap == null) {
        return levelInfo;
    }
    for (Entry<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> me : listMap.entrySet()) {
        CDOMList<Spell> list = me.getKey();
        //Check to ensure we don't use SPELLS:
        if (!(list instanceof ClassSpellList) && !(list instanceof DomainSpellList)) {
            continue;
        }
        Map<Integer, Map<Spell, Set<Object>>> levelMap = me.getValue();
        for (Map.Entry<Integer, Map<Spell, Set<Object>>> lme : levelMap.entrySet()) {
            Integer level = lme.getKey();
            Map<Spell, Set<Object>> spellMap = lme.getValue();
            if (spellMap.containsKey(sp)) {
                levelInfo.addToListFor(list, level);
            } else {
                for (Spell spell : spellMap.keySet()) {
                    if (spell.getKeyName().equals(sp.getKeyName())) {
                        if (Logging.isLoggable(Logging.INFO)) {
                            Logging.log(Logging.INFO, "Found alternate spell of same key: " + spell + " from " + spell.getSource() + " rather than " + sp.getSource());
                        }
                        levelInfo.addToListFor(list, level);
                    }
                }
            }
        }
    }
    return levelInfo;
}
Also used : Set(java.util.Set) ClassSpellList(pcgen.cdom.list.ClassSpellList) Spell(pcgen.core.spell.Spell) DomainSpellList(pcgen.cdom.list.DomainSpellList) HashMapToList(pcgen.base.util.HashMapToList) CDOMList(pcgen.cdom.base.CDOMList) Map(java.util.Map)

Example 18 with HashMapToList

use of pcgen.base.util.HashMapToList in project pcgen by PCGen.

the class CoreUtils method buildCoreDebugList.

static <T> List<CoreViewNodeFacade> buildCoreDebugList(PlayerCharacter pc, CorePerspective pers) {
    CharID id = pc.getCharID();
    List<CoreViewNodeFacade> coreViewList = new ArrayList<>();
    Collection<Object> locations = CorePerspectiveDB.getLocations(pers);
    MapToList<Object, FacetView<T>> sources = new HashMapToList<>();
    Map<FacetView<T>, CoreViewNodeBase> facetToNode = new HashMap<>();
    /*
		 * Create the nodes that are part of this perspective.
		 */
    for (Object location : locations) {
        //Create (w/ identifier)
        FacetView<T> view = CorePerspectiveDB.getView(pers, location);
        CoreViewNodeBase node = new LocationCoreViewNode<>(location);
        facetToNode.put(view, node);
        coreViewList.add(node);
        //Store what facets listen to my content (for use later)
        for (Object listener : view.getChildren()) {
            Object lView = CorePerspectiveDB.getViewOfFacet(listener);
            Object src = (lView == null) ? listener : lView;
            sources.addToListFor(src, view);
        }
        Collection<Object> parents = CorePerspectiveDB.getVirtualParents(view);
        if (parents != null) {
            for (Object parent : parents) {
                FacetView<T> parentView = CorePerspectiveDB.getViewOfFacet(parent);
                if (parentView == null) {
                    Logging.errorPrint("Expected " + parent + " to be a registered Facet in Perspective " + pers);
                }
                sources.addToListFor(view, parentView);
            }
        }
    }
    for (Object location : locations) {
        FacetView<T> view = CorePerspectiveDB.getView(pers, location);
        CoreViewNodeBase node = facetToNode.get(view);
        /*
			 * Check the source of each child to identify if:
			 * 
			 * (a) The source is a Loadable that can thus be identified as such
			 * 
			 * (b) The source is a known facet (and thus is identified as such)
			 * 
			 * (c) the source is not something recognized
			 */
        for (T obj : view.getSet(id)) {
            List<String> sourceDesc = new ArrayList<>();
            for (Object src : view.getSources(id, obj)) {
                if (src instanceof Identified) {
                    sourceDesc.add(getLoadID(src));
                } else {
                    FacetView<Object> srcView = CorePerspectiveDB.getViewOfFacet(src);
                    if (srcView == null) {
                        //Not a recognized view
                        sourceDesc.add("Orphaned [" + src.getClass().getSimpleName() + "]");
                    } else if (facetToNode.get(srcView) == null) {
                        //A View, but not part of this perspective
                        sourceDesc.add("Other Perspective [" + CorePerspectiveDB.getPerspectiveOfFacet(src) + ": " + srcView.getDescription() + "]");
                    }
                }
            }
            //Insert the contents of the facet as children of this node
            ObjectCoreViewNode<T> sourceNode = new ObjectCoreViewNode<>(pc, obj, sourceDesc);
            sourceNode.addGrantedByNode(node);
            coreViewList.add(sourceNode);
        }
    }
    /*
		 * For each location, put sources as children in the tree
		 */
    for (Object location : locations) {
        FacetView<T> view = CorePerspectiveDB.getView(pers, location);
        CoreViewNodeBase node = facetToNode.get(view);
        List<FacetView<T>> facetInputs = sources.getListFor(view);
        if (facetInputs != null) {
            for (FacetView<T> facet : facetInputs) {
                facetToNode.get(facet).addGrantedByNode(node);
            }
        }
    }
    return coreViewList;
}
Also used : Identified(pcgen.cdom.base.Identified) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FacetView(pcgen.cdom.meta.FacetView) CharID(pcgen.cdom.enumeration.CharID) CoreViewNodeFacade(pcgen.facade.core.CoreViewNodeFacade) HashMapToList(pcgen.base.util.HashMapToList) PrereqObject(pcgen.cdom.base.PrereqObject) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) CoreViewNodeBase(pcgen.cdom.meta.CoreViewNodeBase)

Example 19 with HashMapToList

use of pcgen.base.util.HashMapToList in project pcgen by PCGen.

the class AbilityListToken method getAbilityList.

/**
	 * Returns the correct list of abilities of a particular category for the character.
	 * This method is overridden in subclasses if they need to change the list
	 * of abilities looked at.
	 *
	 * @param pc the character who's feats we are retrieving.
	 * @param aCategory The category of ability required.
	 * @return List of feats.
	 */
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
    final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
    Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
    for (AbilityCategory aCat : allCats) {
        if (AbilityCategory.ANY.equals(aCategory) || aCat.getParentCategory().equals(aCategory)) {
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.NORMAL)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
        }
    }
    return listOfAbilities;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Example 20 with HashMapToList

use of pcgen.base.util.HashMapToList in project pcgen by PCGen.

the class EquipToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    List<String> list = new ArrayList<>();
    PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
    Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Changes<QualifiedObject<CDOMReference<Equipment>>> changes = context.getObjectContext().getListChanges(obj, ListKey.EQUIPMENT);
    Collection<QualifiedObject<CDOMReference<Equipment>>> added = changes.getAdded();
    HashMapToList<List<Prerequisite>, CDOMReference<Equipment>> m = new HashMapToList<>();
    if (added != null) {
        for (QualifiedObject<CDOMReference<Equipment>> qo : added) {
            m.addToListFor(qo.getPrerequisiteList(), qo.getRawObject());
        }
    }
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
        for (ChooseSelectionActor<?> cra : listAdded) {
            if (cra.getSource().equals(getTokenName())) {
                try {
                    list.add(cra.getLstFormat());
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
            }
        }
    }
    for (List<Prerequisite> prereqs : m.getKeySet()) {
        List<CDOMReference<Equipment>> eq = m.getListFor(prereqs);
        WeightedCollection<CDOMReference<Equipment>> refs = new WeightedCollection<>(ReferenceUtilities.REFERENCE_SORTER);
        refs.addAll(eq);
        String ab = ReferenceUtilities.joinLstFormat(refs, Constants.PIPE);
        if (prereqs != null && !prereqs.isEmpty()) {
            if (prereqs.size() > 1) {
                context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had more than one Prerequisite for " + getFullName());
                return null;
            }
            Prerequisite p = prereqs.get(0);
            StringWriter swriter = new StringWriter();
            try {
                prereqWriter.write(swriter, p);
            } catch (PersistenceLayerException e) {
                context.addWriteMessage("Error writing Prerequisite: " + e);
                return null;
            }
            ab = ab + '|' + swriter.toString();
        }
        list.add(ab);
    }
    if (list.isEmpty()) {
        // Empty indicates no Token
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : PrerequisiteWriter(pcgen.persistence.lst.output.prereq.PrerequisiteWriter) ArrayList(java.util.ArrayList) ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) HashMapToList(pcgen.base.util.HashMapToList) Equipment(pcgen.core.Equipment) StringWriter(java.io.StringWriter) QualifiedObject(pcgen.core.QualifiedObject) WeightedCollection(pcgen.base.util.WeightedCollection) ArrayList(java.util.ArrayList) HashMapToList(pcgen.base.util.HashMapToList) List(java.util.List) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

HashMapToList (pcgen.base.util.HashMapToList)24 CNAbility (pcgen.cdom.content.CNAbility)15 Ability (pcgen.core.Ability)14 AbilityCategory (pcgen.core.AbilityCategory)14 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 CDOMReference (pcgen.cdom.base.CDOMReference)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 CategorizedCDOMReference (pcgen.cdom.reference.CategorizedCDOMReference)2 Qualifier (pcgen.cdom.reference.Qualifier)2 QualifiedObject (pcgen.core.QualifiedObject)2 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1