use of pcgen.cdom.base.ChooseDriver in project pcgen by PCGen.
the class CharacterFacadeImpl method removeLanguage.
@Override
public void removeLanguage(LanguageFacade lang) {
ChooseDriver owner = getLaguageOwner(lang);
if (owner == null) {
return;
}
List<Language> availLangs = new ArrayList<>();
List<Language> selLangs = new ArrayList<>();
ChoiceManagerList<Language> choiceManager = ChooserUtilities.getChoiceManager(owner, theCharacter);
choiceManager.getChoices(theCharacter, availLangs, selLangs);
selLangs.remove(lang);
choiceManager.applyChoices(theCharacter, selLangs);
}
use of pcgen.cdom.base.ChooseDriver in project pcgen by PCGen.
the class Description method getDescription.
/**
* Gets the description string after having tested all prereqs and
* substituting all variables.
*
* @param aPC The PlayerCharacter used to evaluate formulas.
*
* @return The fully substituted description string.
*/
public String getDescription(final PlayerCharacter aPC, List<? extends Object> objList) {
if (objList.isEmpty()) {
return Constants.EMPTY_STRING;
}
PObject sampleObject;
Object b = objList.get(0);
if (b instanceof PObject) {
sampleObject = (PObject) b;
} else if (b instanceof CNAbility) {
sampleObject = ((CNAbility) b).getAbility();
} else {
Logging.errorPrint("Unable to resolve Description with object of type: " + b.getClass().getName());
return Constants.EMPTY_STRING;
}
final StringBuilder buf = new StringBuilder(250);
if (this.qualifies(aPC, sampleObject)) {
for (final String comp : theComponents) {
if (comp.startsWith(VAR_MARKER)) {
final int ind = Integer.parseInt(comp.substring(VAR_MARKER.length()));
if (theVariables == null || ind > theVariables.size()) {
continue;
}
final String var = theVariables.get(ind - 1);
if (var.equals(VAR_NAME)) {
if (sampleObject != null) {
buf.append(sampleObject.getOutputName());
}
} else if (var.equals(VAR_CHOICE)) {
if (b instanceof ChooseDriver) {
ChooseDriver object = (ChooseDriver) b;
if (aPC.hasAssociations(object)) {
//TODO This is ill defined
buf.append(aPC.getAssociationList(object).get(0));
}
} else {
Logging.errorPrint("In Description resolution, " + "Ignoring object of type: " + b.getClass().getName() + " because " + VAR_CHOICE + " was requested but the object does not support CHOOSE");
continue;
}
} else if (var.equals(VAR_LIST)) {
List<String> assocList = new ArrayList<>();
for (Object obj : objList) {
if (obj instanceof ChooseDriver) {
ChooseDriver object = (ChooseDriver) obj;
if (aPC.hasAssociations(object)) {
assocList.addAll(aPC.getAssociationList(object));
}
} else {
Logging.errorPrint("In Description resolution, " + "Ignoring object of type: " + b.getClass().getName() + " because " + VAR_CHOICE + " was requested but the object does not support CHOOSE");
continue;
}
}
String joinString;
if (assocList.size() == 2) {
joinString = " and ";
} else {
joinString = ", ";
}
Collections.sort(assocList);
buf.append(StringUtil.joinToStringBuilder(assocList, joinString));
} else if (var.startsWith(VAR_FEATS)) {
final String featName = var.substring(VAR_FEATS.length());
List<CNAbility> feats;
if (featName.startsWith("TYPE=") || featName.startsWith("TYPE.")) {
feats = aPC.getCNAbilities(AbilityCategory.FEAT);
} else {
Ability feat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, featName);
if (feat == null) {
Logging.errorPrint("Found invalid Feat reference in Description: " + featName);
}
feats = aPC.getMatchingCNAbilities(feat);
}
boolean needSpace = false;
for (final CNAbility cna : feats) {
if (cna.getAbility().isType(featName.substring(5))) {
if (needSpace) {
buf.append(' ');
}
buf.append(aPC.getDescription(Collections.singletonList(cna)));
needSpace = true;
}
}
} else if (//$NON-NLS-1$
var.startsWith("\"")) {
buf.append(var.substring(1, var.length() - 1));
} else {
//$NON-NLS-1$
buf.append(aPC.getVariableValue(var, "Description").intValue());
}
} else {
buf.append(comp);
}
}
}
return buf.toString();
}
use of pcgen.cdom.base.ChooseDriver in project pcgen by PCGen.
the class AbstractSelectionActorTest method testAddRemoveSimple.
@Test
public void testAddRemoveSimple() throws PersistenceLayerException {
setUpPC();
finishLoad(Globals.getContext());
InequalityTester it = InequalityTesterInst.getInstance();
ChooseDriver owner = getOwner();
T t = construct("Templ");
T t2 = construct("Templ2");
PlayerCharacter pc1 = new PlayerCharacter();
PlayerCharacter pc2 = new PlayerCharacter();
preparePC(pc1, owner);
preparePC(pc2, owner);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
ChooseSelectionActor<T> actor = getActor();
actor.applyChoice(owner, t, pc2);
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc2);
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc2);
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc2);
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc1);
actor.applyChoice(owner, t2, pc1);
actor.removeChoice(owner, t, pc1);
actor.applyChoice(owner, t2, pc2);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
}
use of pcgen.cdom.base.ChooseDriver in project pcgen by PCGen.
the class AbstractSelectionActorTest method testAddRemoveHasChild.
@Test
public void testAddRemoveHasChild() throws PersistenceLayerException {
if (isGranted()) {
setUpPC();
T t = construct("Templ");
T t2 = construct("Templ2");
Globals.getContext().unconditionallyProcess(t, "AUTO", "LANG|Universal");
Globals.getContext().unconditionallyProcess(t2, "AUTO", "LANG|Other");
finishLoad(Globals.getContext());
InequalityTester it = InequalityTesterInst.getInstance();
ChooseDriver owner = getOwner();
PlayerCharacter pc1 = new PlayerCharacter();
PlayerCharacter pc2 = new PlayerCharacter();
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
ChooseSelectionActor<T> actor = getActor();
actor.applyChoice(owner, t, pc2);
assertTrue(pc2.hasLanguage(universal));
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc2);
assertFalse(pc2.hasLanguage(universal));
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc2);
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc2);
assertFalse(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.removeChoice(owner, t, pc1);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
actor.applyChoice(owner, t, pc1);
actor.applyChoice(owner, t2, pc1);
actor.removeChoice(owner, t, pc1);
actor.applyChoice(owner, t2, pc2);
assertTrue(AbstractStorageFacet.areEqualCache(pc1.getCharID(), pc2.getCharID(), it));
}
}
use of pcgen.cdom.base.ChooseDriver in project pcgen by PCGen.
the class PlayerCharacter method getConsolidatedAssociationList.
public List<String> getConsolidatedAssociationList(CDOMObject cdo) {
if (cdo instanceof Ability) {
List<String> list = new ArrayList<>();
List<CNAbility> cnabilities = getMatchingCNAbilities((Ability) cdo);
for (CNAbility cna : cnabilities) {
list.addAll(getAssociationList(cna));
}
return list;
} else if (cdo instanceof ChooseDriver) {
return getAssociationList((ChooseDriver) cdo);
} else {
// + cdo.getClass() + " but it is not a ChooseDriver");
return Collections.emptyList();
}
}
Aggregations