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