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);
}
}
}
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);
}
}
}
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);
}
}
}
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()]);
}
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()]);
}
Aggregations