Search in sources :

Example 61 with CDOMObject

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

the class CharacterFacadeImpl method buildAppliedTempBonusList.

/**
	 * Build up the list of temporary bonuses which have been applied to this character.
	 */
private void buildAppliedTempBonusList() {
    Set<String> found = new HashSet<>();
    for (TempBonusInfo tbi : theCharacter.getTempBonusMap().values()) {
        Object aC = tbi.source;
        Object aT = tbi.target;
        String name = BonusDisplay.getBonusDisplayName(tbi);
        if (!found.contains(name)) {
            found.add(name);
            TempBonusFacadeImpl facade = new TempBonusFacadeImpl((CDOMObject) aC, aT, name);
            facade.setActive(!theCharacter.getTempBonusFilters().contains(name));
            appliedTempBonuses.addElement(facade);
        }
    }
}
Also used : TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) CDOMObject(pcgen.cdom.base.CDOMObject) QualifiedObject(pcgen.core.QualifiedObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) HashSet(java.util.HashSet)

Example 62 with CDOMObject

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

the class CompanionSupportFacadeImpl method initCompData.

/**
	 * Initialisation of the character's companion data.
	 * @param rebuildCompanionList Should the list of the character;s companions be rebuilt?
	 */
private void initCompData(boolean rebuildCompanionList) {
    List<CompanionStub> companions = new ArrayList<>();
    for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
        keyToCompanionListMap.put(compList.getKeyName(), compList);
        Map<FollowerOption, CDOMObject> fMap = charDisplay.getAvailableFollowers(compList.getKeyName(), null);
        for (FollowerOption followerOpt : fMap.keySet()) {
            if (followerOpt.getRace() != Globals.s_EMPTYRACE && followerOpt.qualifies(theCharacter, null)) {
                companions.add(new CompanionStub(followerOpt.getRace(), compList.getKeyName()));
            }
        }
        int maxVal = theCharacter.getMaxFollowers(compList);
        if (maxVal == 0) {
            maxCompanionsMap.removeKey(compList.toString());
        } else {
            maxCompanionsMap.putValue(compList.toString(), maxVal);
        }
    }
    availCompList.updateContents(companions);
    if (rebuildCompanionList) {
        for (Follower follower : charDisplay.getFollowerList()) {
            CompanionFacade comp = new CompanionNotLoaded(follower.getName(), new File(follower.getFileName()), follower.getRace(), follower.getType().toString());
            CompanionFacadeDelegate delegate = new CompanionFacadeDelegate();
            delegate.setCompanionFacade(comp);
            companionList.addElement(delegate);
        }
    }
    //Logging.debugPrint("Companion list " + companionList);
    for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
        updateCompanionTodo(compList.toString());
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) ArrayList(java.util.ArrayList) Follower(pcgen.core.character.Follower) CompanionFacade(pcgen.facade.core.CompanionFacade) CDOMObject(pcgen.cdom.base.CDOMObject) File(java.io.File)

Example 63 with CDOMObject

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

the class VariableFacet method dataAdded.

/**
	 * Adds variables and their Formulas when a variable is granted by a
	 * CDOMObject which is added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which VariableFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    Set<VariableKey> keys = cdo.getVariableKeys();
    CharID id = dfce.getCharID();
    for (VariableKey vk : keys) {
        add(id, vk, cdo.get(vk), cdo);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) VariableKey(pcgen.cdom.enumeration.VariableKey) CharID(pcgen.cdom.enumeration.CharID)

Example 64 with CDOMObject

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

the class VisionFacet method getActiveVision.

/**
	 * Returns a non-null copy of the Collection of Vision objects which are
	 * active on the Player Character identified by the given CharID.
	 * 
	 * This method is value-semantic in that ownership of the returned
	 * Collection is transferred to the class calling this method. Modification
	 * of the returned Collection will not modify this VisionFacet and
	 * modification of this VisionFacet will not modify the returned Collection.
	 * Modifications to the returned Collection will also not modify any future
	 * or previous objects returned by this (or other) methods on VisionFacet.
	 * If you wish to modify the information stored in this VisionFacet, you
	 * must use the add*() and remove*() methods of VisionFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            active Vision objects is to be returned
	 * @return a non-null copy of the Collection of Vision objects which are
	 *         active on the Player Character identified by the given CharID
	 */
public Collection<Vision> getActiveVision(CharID id) {
    Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
    if (componentMap == null) {
        return Collections.emptyList();
    }
    Map<VisionType, Integer> map = new HashMap<>();
    for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
        QualifiedObject<Vision> qo = me.getKey();
        for (Object source : me.getValue()) {
            if (prerequisiteFacet.qualifies(id, qo, source)) {
                String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
                Vision v = qo.getRawObject();
                Formula distance = v.getDistance();
                int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
                VisionType visType = v.getType();
                Integer current = map.get(visType);
                if (current == null || current < a) {
                    map.put(visType, a);
                }
            }
        }
    }
    /*
		 * parse through the global list of vision tags and see if this PC has
		 * any BONUS:VISION tags which will create a new visionMap entry, and
		 * add any BONUS to existing entries in the map
		 */
    for (VisionType vType : VisionType.getAllVisionTypes()) {
        int aVal = (int) bonusCheckingFacet.getBonus(id, "VISION", vType.toString());
        if (aVal > 0) {
            Integer current = map.get(vType);
            map.put(vType, aVal + (current == null ? 0 : current));
        }
    }
    TreeSet<Vision> returnSet = new TreeSet<>();
    for (Map.Entry<VisionType, Integer> me : map.entrySet()) {
        returnSet.add(new Vision(me.getKey(), FormulaFactory.getFormulaFor(me.getValue())));
    }
    return returnSet;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) VisionType(pcgen.util.enumeration.VisionType) Formula(pcgen.base.formula.Formula) QualifiedObject(pcgen.core.QualifiedObject) Vision(pcgen.core.Vision) CDOMObject(pcgen.cdom.base.CDOMObject) TreeSet(java.util.TreeSet) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 65 with CDOMObject

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

the class AbstractReferenceManufacturer method validateDuplicates.

private boolean validateDuplicates() {
    boolean returnGood = true;
    for (CaseInsensitiveString second : duplicates.getKeySet()) {
        List<T> list = duplicates.getListFor(second);
        T good = active.get(second.toString());
        /*
			 * CONSIDER Should get CDOMObject reference out of here :(
			 */
        if (good instanceof CDOMObject) {
            CDOMObject cdo = (CDOMObject) good;
            for (int i = 0; i < list.size(); i++) {
                T dupe = list.get(i);
                if (cdo.isCDOMEqual((CDOMObject) dupe)) {
                    for (Iterator<WeakReference<T>> it = manufactured.iterator(); it.hasNext(); ) {
                        WeakReference<T> wr = it.next();
                        T mfg = wr.get();
                        if (mfg == null) {
                            it.remove();
                        } else // Yes this is instance equality, not .equals
                        if (mfg == good) {
                            forgetObject(good);
                            break;
                        }
                    }
                }
            }
        }
        if (duplicates.containsListFor(second)) {
            Logging.errorPrint("More than one " + factory.getReferenceDescription() + " with key/name " + good.getKeyName() + " was built");
            List<T> dupes = duplicates.getListFor(second);
            StringBuilder sb = new StringBuilder(1000);
            sb.append("Sources: ");
            sb.append(good.isInternal() ? "<internal>" : good.getSourceURI());
            for (T dupe : dupes) {
                sb.append(", ").append(dupe.isInternal() ? "<internal>" : dupe.getSourceURI());
                if (!dupe.getKeyName().equals(good.getKeyName())) {
                    Logging.errorPrint("Key case differed for " + dupe.getKeyName());
                }
            }
            Logging.errorPrint(sb.toString());
            returnGood = false;
        }
    }
    return returnGood;
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) WeakReference(java.lang.ref.WeakReference) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Aggregations

CDOMObject (pcgen.cdom.base.CDOMObject)235 Test (org.junit.Test)68 CharID (pcgen.cdom.enumeration.CharID)53 PCTemplate (pcgen.core.PCTemplate)30 ArrayList (java.util.ArrayList)22 PCClass (pcgen.core.PCClass)18 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)17 Race (pcgen.core.Race)17 Equipment (pcgen.core.Equipment)15 PlayerCharacter (pcgen.core.PlayerCharacter)15 Map (java.util.Map)14 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)14 CDOMReference (pcgen.cdom.base.CDOMReference)14 BonusObj (pcgen.core.bonus.BonusObj)14 IdentityHashMap (java.util.IdentityHashMap)12 Set (java.util.Set)12 VariableKey (pcgen.cdom.enumeration.VariableKey)11 HashMap (java.util.HashMap)10 CNAbility (pcgen.cdom.content.CNAbility)10 Spell (pcgen.core.spell.Spell)9