Search in sources :

Example 21 with ChooseSelectionActor

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

the class ChooseFeatSelectionToken method removeChoice.

@Override
public void removeChoice(PlayerCharacter pc, ChooseDriver owner, AbilitySelection choice) {
    pc.removeAssoc(owner, getListKey(), choice);
    List<ChooseSelectionActor<?>> actors = owner.getActors();
    if (actors != null) {
        for (ChooseSelectionActor ca : actors) {
            ca.removeChoice(owner, choice, pc);
        }
    }
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor)

Example 22 with ChooseSelectionActor

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

the class AbstractSimpleChooseToken method removeChoice.

@Override
public void removeChoice(PlayerCharacter pc, ChooseDriver owner, T choice) {
    pc.removeAssoc(owner, getListKey(), choice);
    List<ChooseSelectionActor<?>> actors = owner.getActors();
    if (actors != null) {
        for (ChooseSelectionActor ca : actors) {
            ca.removeChoice(owner, choice, pc);
        }
    }
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor)

Example 23 with ChooseSelectionActor

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

the class AbstractQualifiedChooseToken method restoreChoice.

@Override
public void restoreChoice(PlayerCharacter pc, ChooseDriver owner, T choice) {
    pc.addAssoc(owner, getListKey(), choice);
    List<ChooseSelectionActor<?>> actors = owner.getActors();
    if (actors != null) {
        for (ChooseSelectionActor ca : actors) {
            ca.applyChoice(owner, choice, pc);
        }
    }
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor)

Example 24 with ChooseSelectionActor

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

the class ArmorProfToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<ArmorProfProvider> changes = context.getObjectContext().getListChanges(obj, ListKey.AUTO_ARMORPROF);
    Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Collection<ArmorProfProvider> added = changes.getAdded();
    Set<String> set = new TreeSet<>();
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    boolean foundAny = false;
    boolean foundOther = false;
    if (listAdded != null && !listAdded.isEmpty()) {
        for (ChooseSelectionActor<?> cra : listAdded) {
            if (cra.getSource().equals(getTokenName())) {
                try {
                    set.add(cra.getLstFormat());
                    foundOther = true;
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
            }
        }
    }
    if (added != null) {
        for (ArmorProfProvider spp : added) {
            StringBuilder sb = new StringBuilder();
            sb.append(spp.getLstFormat());
            if (spp.hasPrerequisites()) {
                sb.append('|');
                sb.append(getPrerequisiteString(context, spp.getPrerequisiteList()));
            }
            String ab = sb.toString();
            boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
            foundAny |= isUnconditionalAll;
            foundOther |= !isUnconditionalAll;
            set.add(ab);
        }
    }
    if (foundAny && foundOther) {
        context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + set);
        return null;
    }
    if (set.isEmpty()) {
        //okay
        return null;
    }
    return set.toArray(new String[set.size()]);
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) TreeSet(java.util.TreeSet)

Example 25 with ChooseSelectionActor

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

ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)27 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)7 Prerequisite (pcgen.core.prereq.Prerequisite)6 ArrayList (java.util.ArrayList)5 CDOMReference (pcgen.cdom.base.CDOMReference)5 TreeSet (java.util.TreeSet)3 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 StringWriter (java.io.StringWriter)2 List (java.util.List)2 StringTokenizer (java.util.StringTokenizer)2 ListKey (pcgen.cdom.enumeration.ListKey)2 Nature (pcgen.cdom.enumeration.Nature)2 AbilitySelector (pcgen.cdom.helper.AbilitySelector)2 AbilityTargetSelector (pcgen.cdom.helper.AbilityTargetSelector)2 AbilityList (pcgen.cdom.list.AbilityList)2 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)2 Ability (pcgen.core.Ability)2 AbilityCategory (pcgen.core.AbilityCategory)2 Language (pcgen.core.Language)2 QualifiedObject (pcgen.core.QualifiedObject)2