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