Search in sources :

Example 11 with PersistentTransitionChoice

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

the class SkillToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
    Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
    if (addedItems == null || addedItems.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    List<String> addStrings = new ArrayList<>();
    for (TransitionChoice<?> container : addedItems) {
        SelectableSet<?> cs = container.getChoices();
        if (getTokenName().equals(cs.getName()) && SKILL_CLASS.equals(cs.getChoiceClass())) {
            Formula f = container.getCount();
            if (f == null) {
                context.addWriteMessage("Unable to find " + getFullName() + " Count");
                return null;
            }
            if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
                context.addWriteMessage("Count in " + getFullName() + " must be > 0");
                return null;
            }
            if (!cs.getGroupingState().isValid()) {
                context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + cs.getLSTformat());
                return null;
            }
            StringBuilder sb = new StringBuilder();
            if (!FormulaFactory.ONE.equals(f)) {
                sb.append(f).append(Constants.PIPE);
            }
            sb.append(cs.getLSTformat());
            addStrings.add(sb.toString());
        }
    }
    return addStrings.toArray(new String[addStrings.size()]);
}
Also used : Formula(pcgen.base.formula.Formula) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList)

Example 12 with PersistentTransitionChoice

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

the class SpellCasterToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
    Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
    if (addedItems == null || addedItems.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    List<String> addStrings = new ArrayList<>();
    for (TransitionChoice<?> container : addedItems) {
        SelectableSet<?> cs = container.getChoices();
        if (PCCLASS_CLASS.equals(cs.getChoiceClass())) {
            Formula f = container.getCount();
            if (f == null) {
                context.addWriteMessage("Unable to find " + getFullName() + " Count");
                return null;
            }
            if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
                context.addWriteMessage("Count in " + getFullName() + " must be > 0");
                return null;
            }
            if (!cs.getGroupingState().isValid()) {
                context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + cs.getLSTformat());
                return null;
            }
            StringBuilder sb = new StringBuilder();
            if (!FormulaFactory.ONE.equals(f)) {
                sb.append(f).append(Constants.PIPE);
            }
            sb.append(cs.getLSTformat());
            addStrings.add(sb.toString());
        // assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
        }
    }
    return addStrings.toArray(new String[addStrings.size()]);
}
Also used : Formula(pcgen.base.formula.Formula) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList)

Example 13 with PersistentTransitionChoice

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

the class EquipToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<PersistentTransitionChoice<?>> grantChanges = context.getObjectContext().getListChanges(obj, ListKey.ADD);
    Collection<PersistentTransitionChoice<?>> addedItems = grantChanges.getAdded();
    if (addedItems == null || addedItems.isEmpty()) {
        // Zero indicates no Token
        return null;
    }
    List<String> addStrings = new ArrayList<>();
    for (TransitionChoice<?> container : addedItems) {
        SelectableSet<?> cs = container.getChoices();
        if (EQUIPMENT_CLASS.equals(cs.getChoiceClass())) {
            Formula f = container.getCount();
            if (f == null) {
                context.addWriteMessage("Unable to find " + getFullName() + " Count");
                return null;
            }
            if (f.isStatic() && f.resolveStatic().doubleValue() <= 0) {
                context.addWriteMessage("Count in " + getFullName() + " must be > 0");
                return null;
            }
            StringBuilder sb = new StringBuilder();
            if (!FormulaFactory.ONE.equals(f)) {
                sb.append(f).append(Constants.PIPE);
            }
            sb.append(cs.getLSTformat());
            addStrings.add(sb.toString());
        // assoc.getAssociation(AssociationKey.CHOICE_MAXCOUNT);
        }
    }
    return addStrings.toArray(new String[addStrings.size()]);
}
Also used : Formula(pcgen.base.formula.Formula) ConcretePersistentTransitionChoice(pcgen.cdom.base.ConcretePersistentTransitionChoice) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) ArrayList(java.util.ArrayList)

Example 14 with PersistentTransitionChoice

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

the class PCGVer2Parser method resolveLanguages.

private void resolveLanguages() {
    CNAbility langbonus = thePC.getBonusLanguageAbility();
    int currentBonusLang = thePC.getDetailedAssociationCount(langbonus);
    boolean foundLang = currentBonusLang > 0;
    Set<Language> foundLanguages = new HashSet<>(thePC.getLanguageSet());
    //Captures Auto (AUTO:LANG) and Persistent choices (ADD ex ability and CHOOSE)
    cachedLanguages.removeAll(foundLanguages);
    HashMapToList<Language, Object> langSources = new HashMapToList<>();
    Map<Object, Integer> actorLimit = new IdentityHashMap<>();
    Map<PersistentTransitionChoice, CDOMObject> ptcSources = new IdentityHashMap<>();
    List<? extends CDOMObject> abilities = thePC.getCDOMObjectList();
    for (CDOMObject a : abilities) {
        List<PersistentTransitionChoice<?>> addList = a.getListFor(ListKey.ADD);
        if (addList != null) {
            for (PersistentTransitionChoice<?> ptc : addList) {
                SelectableSet<?> ss = ptc.getChoices();
                if (ss.getName().equals("LANGUAGE") && LANGUAGE_CLASS.equals(ss.getChoiceClass())) {
                    Collection<Language> selected = (Collection<Language>) ss.getSet(thePC);
                    for (Language l : selected) {
                        if (cachedLanguages.contains(l)) {
                            String source = SourceFormat.getFormattedString(a, Globals.getSourceDisplay(), true);
                            int choiceCount = ptc.getCount().resolve(thePC, source).intValue();
                            if (choiceCount > 0) {
                                langSources.addToListFor(l, ptc);
                                ptcSources.put(ptc, a);
                                actorLimit.put(ptc, choiceCount);
                            }
                        }
                    }
                }
            }
        }
    }
    if (!foundLang) {
        Set<Language> bonusAllowed = thePC.getLanguageBonusSelectionList();
        int count = thePC.getBonusLanguageCount();
        int choiceCount = count - currentBonusLang;
        if (choiceCount > 0) {
            for (Language l : bonusAllowed) {
                if (cachedLanguages.contains(l)) {
                    langSources.addToListFor(l, langbonus);
                    actorLimit.put(langbonus, choiceCount);
                }
            }
        }
    }
    //Try to match them up as best as possible (this matches things with only one possible location...)
    boolean acted = !cachedLanguages.isEmpty();
    while (acted) {
        acted = false;
        for (Language l : langSources.getKeySet()) {
            List<Object> actors = langSources.getListFor(l);
            if ((actors != null) && (actors.size() == 1)) {
                Object actor = actors.get(0);
                acted = true;
                processRemoval(langbonus, langSources, actorLimit, ptcSources, l, actor);
            }
        }
        if (!acted && !langSources.isEmpty() && !actorLimit.isEmpty()) {
            //pick one
            Language l = langSources.getKeySet().iterator().next();
            Object source = langSources.getListFor(l).get(0);
            processRemoval(langbonus, langSources, actorLimit, ptcSources, l, source);
            acted = true;
        }
    }
    for (Language l : cachedLanguages) {
        warnings.add("Unable to find source: " + "Character no longer speaks language: " + l.getDisplayName());
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) Language(pcgen.core.Language) CDOMObject(pcgen.cdom.base.CDOMObject) Collection(java.util.Collection) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) HashSet(java.util.HashSet)

Example 15 with PersistentTransitionChoice

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

the class RemoveFacet method dataAdded.

/**
	 * Drives the necessary selections for REMOVE tokens on a Player Character.
	 * 
	 * Triggered when one of the Facets to which RemoveFacet 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) {
    CharID id = dfce.getCharID();
    PlayerCharacter aPC = trackingFacet.getPC(id);
    if (!aPC.isImporting()) {
        CDOMObject cdo = dfce.getCDOMObject();
        List<PersistentTransitionChoice<?>> removeList = cdo.getListFor(ListKey.REMOVE);
        if (removeList != null) {
            for (PersistentTransitionChoice<?> tc : removeList) {
                driveChoice(cdo, tc, aPC);
            }
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CDOMObject(pcgen.cdom.base.CDOMObject) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) CharID(pcgen.cdom.enumeration.CharID)

Aggregations

PersistentTransitionChoice (pcgen.cdom.base.PersistentTransitionChoice)16 ArrayList (java.util.ArrayList)12 Formula (pcgen.base.formula.Formula)9 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)9 PCClass (pcgen.core.PCClass)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 CDOMObject (pcgen.cdom.base.CDOMObject)3 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)3 PCTemplate (pcgen.core.PCTemplate)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 IdentityHashMap (java.util.IdentityHashMap)1 Set (java.util.Set)1 UnreachableError (pcgen.base.lang.UnreachableError)1 HashMapToList (pcgen.base.util.HashMapToList)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 AbilityChoiceSet (pcgen.cdom.base.ChoiceSet.AbilityChoiceSet)1