Search in sources :

Example 1 with ChooseSelectionActor

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

the class AbstractQualifiedChooseToken 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 2 with ChooseSelectionActor

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

the class AbstractSimpleChooseToken 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) {
            applyChoice(owner, choice, pc, ca);
        }
    }
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor)

Example 3 with ChooseSelectionActor

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

the class MoncskillToken method unparse.

@Override
public String[] unparse(LoadContext context, Race race) {
    CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
    AssociatedChanges<CDOMReference<Skill>> changes = context.getListContext().getChangesInList(getTokenName(), race, monsterList);
    Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(race, ListKey.NEW_CHOOSE_ACTOR);
    List<String> list = new ArrayList<>();
    Collection<CDOMReference<Skill>> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty()) {
        if (changes.includesGlobalClear()) {
            context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
            return null;
        }
        list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
    }
    Collection<ChooseSelectionActor<?>> listRemoved = listChanges.getRemoved();
    if (listRemoved != null && !listRemoved.isEmpty()) {
        if (listRemoved.contains(this)) {
            list.add(".CLEAR.LIST");
        }
    }
    if (changes.includesGlobalClear()) {
        list.add(Constants.LST_DOT_CLEAR);
    }
    MapToList<CDOMReference<Skill>, AssociatedPrereqObject> map = changes.getAddedAssociations();
    if (map != null && !map.isEmpty()) {
        Set<CDOMReference<Skill>> added = map.getKeySet();
        for (CDOMReference<Skill> ab : added) {
            for (AssociatedPrereqObject assoc : map.getListFor(ab)) {
                if (!SkillCost.CLASS.equals(assoc.getAssociation(AssociationKey.SKILL_COST))) {
                    context.addWriteMessage("Skill Cost must be " + "CLASS for Token " + getTokenName());
                    return null;
                }
            }
        }
        list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE));
    }
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    if (listAdded != null && !listAdded.isEmpty()) {
        for (ChooseSelectionActor<?> csa : listAdded) {
            if (csa.getSource().equals(getTokenName())) {
                try {
                    list.add(csa.getLstFormat());
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
            }
        }
    }
    if (list.isEmpty()) {
        // Zero indicates no add or clear
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) ArrayList(java.util.ArrayList) ClassSkillList(pcgen.cdom.list.ClassSkillList) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 4 with ChooseSelectionActor

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

the class LangToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
    Changes<QualifiedObject<CDOMReference<Language>>> changes = context.getObjectContext().getListChanges(obj, ListKey.AUTO_LANGUAGE);
    Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Collection<QualifiedObject<CDOMReference<Language>>> added = changes.getAdded();
    StringBuilder sb = new StringBuilder();
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    boolean foundAny = false;
    boolean foundOther = false;
    if (changes.includesGlobalClear()) {
        sb.append(Constants.LST_DOT_CLEAR);
    }
    if (listAdded != null && !listAdded.isEmpty()) {
        for (ChooseSelectionActor<?> cra : listAdded) {
            if (cra.getSource().equals(getTokenName())) {
                try {
                    if (sb.length() > 0) {
                        sb.append('|');
                    }
                    sb.append(cra.getLstFormat());
                    foundOther = true;
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
            }
        }
    }
    if (added != null) {
        boolean needPipe = sb.length() > 0;
        Prerequisite prereq = null;
        for (QualifiedObject<CDOMReference<Language>> spp : added) {
            CDOMReference<Language> lang = spp.getRawObject();
            List<Prerequisite> prereqs = spp.getPrerequisiteList();
            String ab = lang.getLSTformat(false);
            boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
            foundAny |= isUnconditionalAll;
            foundOther |= !isUnconditionalAll;
            if (needPipe) {
                sb.append('|');
            }
            needPipe = true;
            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);
                if (prereq != null && !p.equals(prereq)) {
                    context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had differing Prerequisites for " + getFullName());
                    return null;
                }
                prereq = p;
            }
            sb.append(ab);
        }
        if (prereq != null) {
            StringWriter swriter = new StringWriter();
            try {
                prereqWriter.write(swriter, prereq);
            } catch (PersistenceLayerException e) {
                context.addWriteMessage("Error writing Prerequisite: " + e);
                return null;
            }
            sb.append('|').append(swriter.toString());
        }
    }
    if (foundAny && foundOther) {
        context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + sb);
        return null;
    }
    if (sb.length() == 0) {
        // okay
        return null;
    }
    return new String[] { sb.toString() };
}
Also used : PrerequisiteWriter(pcgen.persistence.lst.output.prereq.PrerequisiteWriter) ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Language(pcgen.core.Language) StringWriter(java.io.StringWriter) QualifiedObject(pcgen.core.QualifiedObject) CDOMReference(pcgen.cdom.base.CDOMReference) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 5 with ChooseSelectionActor

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

the class WeaponProfToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    List<String> list = new ArrayList<>();
    Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
    Changes<WeaponProfProvider> changes = context.getObjectContext().getListChanges(obj, ListKey.WEAPONPROF);
    QualifiedObject<Boolean> deityweap = context.getObjectContext().getObject(obj, ObjectKey.HAS_DEITY_WEAPONPROF);
    Collection<WeaponProfProvider> added = changes.getAdded();
    Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
    boolean foundAny = false;
    boolean foundOther = false;
    if (listAdded != null && !listAdded.isEmpty()) {
        foundOther = true;
        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;
                }
            }
        }
    }
    if (deityweap != null && deityweap.getRawObject()) {
        foundOther = true;
        StringBuilder sb = new StringBuilder();
        sb.append("DEITYWEAPONS");
        if (deityweap.hasPrerequisites()) {
            sb.append('|');
            sb.append(context.getPrerequisiteString(deityweap.getPrerequisiteList()));
        }
        list.add(sb.toString());
    }
    if (added != null) {
        for (WeaponProfProvider wpp : added) {
            if (!wpp.isValid()) {
                context.addWriteMessage("Non-sensical " + "WeaponProfProvider in " + getFullName() + ": Had invalid contents");
                return null;
            }
            StringBuilder sb = new StringBuilder(wpp.getLstFormat());
            List<Prerequisite> prereqs = wpp.getPrerequisiteList();
            if (prereqs != null && !prereqs.isEmpty()) {
                if (prereqs.size() > 1) {
                    context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had more than one Prerequisite for " + getFullName());
                    return null;
                }
                sb.append('|');
                sb.append(context.getPrerequisiteString(prereqs));
            }
            String lstFormat = sb.toString();
            boolean isUnconditionalAll = Constants.LST_ALL.equals(lstFormat);
            foundAny |= isUnconditionalAll;
            foundOther |= !isUnconditionalAll;
            list.add(lstFormat);
        }
    }
    if (foundAny && foundOther) {
        context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + list);
        return null;
    }
    if (list.isEmpty()) {
        // Empty indicates no Token
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : ArrayList(java.util.ArrayList) ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) 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