use of pcgen.facade.core.AbilityFacade in project pcgen by PCGen.
the class Gui2InfoFactory method getHTMLInfo.
@Override
public String getHTMLInfo(InfoFacade facade) {
if (facade == null) {
return EMPTY_STRING;
}
// Use a more detailed info if we can
if (facade instanceof AbilityFacade) {
return getHTMLInfo((AbilityFacade) facade);
}
if (facade instanceof ClassFacade) {
return getHTMLInfo((ClassFacade) facade, null);
}
if (facade instanceof DeityFacade) {
return getHTMLInfo((DeityFacade) facade);
}
if (facade instanceof DomainFacade) {
return getHTMLInfo((DomainFacade) facade);
}
if (facade instanceof EquipmentFacade) {
return getHTMLInfo((EquipmentFacade) facade);
}
if (facade instanceof KitFacade) {
return getHTMLInfo((KitFacade) facade);
}
if (facade instanceof RaceFacade) {
return getHTMLInfo((RaceFacade) facade);
}
if (facade instanceof SkillFacade) {
return getHTMLInfo((SkillFacade) facade);
}
if (facade instanceof SpellFacade) {
return getHTMLInfo((SpellFacade) facade);
}
if (facade instanceof TempBonusFacade) {
return getHTMLInfo((TempBonusFacade) facade);
}
if (facade instanceof TemplateFacade) {
return getHTMLInfo((TemplateFacade) facade);
}
final HtmlInfoBuilder infoText = new HtmlInfoBuilder();
infoText.appendTitleElement(facade.toString());
infoText.appendLineBreak();
if (!facade.getType().isEmpty()) {
//$NON-NLS-1$
infoText.appendI18nElement("in_irInfoType", facade.getType());
infoText.appendLineBreak();
}
infoText.appendI18nElement(//$NON-NLS-1$
"in_itmInfoLabelTextSource", facade.getSource());
return infoText.toString();
}
use of pcgen.facade.core.AbilityFacade in project pcgen by PCGen.
the class DataSetTest method testGetPrereqAbilities.
/**
* Verify the getPrereqAbilities method is functioning correctly.
* @throws Exception
*/
public void testGetPrereqAbilities() throws Exception {
Ability acrobatics = TestHelper.makeAbility("Acrobatics", AbilityCategory.FEAT, "general");
Ability dodge = TestHelper.makeAbility("Dodge", AbilityCategory.FEAT, "general");
Ability mobility = TestHelper.makeAbility("Mobility", AbilityCategory.FEAT, "general");
Ability springAttack = TestHelper.makeAbility("Spring Attack", AbilityCategory.FEAT, "general");
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY=FEAT,KEY_Dodge", false, false);
mobility.addPrerequisite(prereq);
prereq = parser.parse("ability", "2,CATEGORY=FEAT,KEY_Dodge,KEY_Mobility", false, false);
springAttack.addPrerequisite(prereq);
DataSet dataset = new DataSet(Globals.getContext(), SettingsHandler.getGame(), new DefaultListFacade<>());
List<AbilityFacade> abilities = dataset.getPrereqAbilities(acrobatics);
assertEquals("Acrobatics prereq should be empty", 0, abilities.size());
abilities = dataset.getPrereqAbilities(dodge);
assertEquals("Dodge prereq should be empty", 0, abilities.size());
abilities = dataset.getPrereqAbilities(mobility);
assertEquals("Mobility prereq should not be empty", 1, abilities.size());
assertEquals("Mobility prereq should be dodge", dodge, abilities.get(0));
abilities = dataset.getPrereqAbilities(springAttack);
assertEquals("Spring Attack prereq should not be empty", 2, abilities.size());
assertEquals("Spring Attack prereq should be dodge", dodge, abilities.get(0));
assertEquals("Spring Attack prereq should be mobility", mobility, abilities.get(1));
}
use of pcgen.facade.core.AbilityFacade in project pcgen by PCGen.
the class CharacterAbilitiesTest method testRebuildAbilityListsMult.
/**
* Test method for {@link pcgen.gui2.facade.CharacterAbilities#rebuildAbilityLists()}.
*/
@Test
public final void testRebuildAbilityListsMult() {
PlayerCharacter pc = getCharacter();
CharacterAbilities ca = new CharacterAbilities(pc, uiDelegate, dataset, todoManager);
ca.rebuildAbilityLists();
ListFacade<AbilityCategoryFacade> categories = ca.getActiveAbilityCategories();
assertNotNull("Categories should not be null", categories);
assertTrue("Feat should be active", categories.containsElement(AbilityCategory.FEAT));
ListFacade<AbilityFacade> abilities = ca.getAbilities(AbilityCategory.FEAT);
assertNotNull("Feat list should not be null", abilities);
assertTrue("Feat list should be empty", abilities.isEmpty());
// Add an entry - note rebuild is implicit
Ability reading = TestHelper.makeAbility("reading", AbilityCategory.FEAT, "interest");
reading.put(ObjectKey.MULTIPLE_ALLOWED, Boolean.TRUE);
StringToken st = new plugin.lsttokens.choose.StringToken();
ParseResult pr = st.parseToken(Globals.getContext(), reading, "STRING|Magazines|Books");
assertTrue(pr.passed());
Globals.getContext().commit();
applyAbility(pc, AbilityCategory.FEAT, reading, "Books");
abilities = ca.getAbilities(AbilityCategory.FEAT);
assertFalse("Feat list should not be empty", abilities.isEmpty());
Ability abilityFromList = (Ability) abilities.getElementAt(0);
assertEquals("Should have found reading", reading, abilityFromList);
assertEquals("Feat list should have one entry", 1, abilities.getSize());
// Now add the choice
pcgenFinalize(abilityFromList, "Magazines", pc, AbilityCategory.FEAT);
ca.rebuildAbilityLists();
abilities = ca.getAbilities(AbilityCategory.FEAT);
assertEquals("Feat list should have one entry", 1, abilities.getSize());
abilityFromList = (Ability) abilities.getElementAt(0);
assertEquals("Should have found reading", reading, abilityFromList);
}
use of pcgen.facade.core.AbilityFacade in project pcgen by PCGen.
the class CharacterAbilities method rebuildAbilityLists.
/**
* Rebuild the ability lists for the character to include the character's
* current abilities.
*/
synchronized void rebuildAbilityLists() {
Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap = new LinkedHashMap<>();
DefaultListFacade<AbilityCategoryFacade> workingActiveCategories = new DefaultListFacade<>();
for (AbilityCategoryFacade category : dataSetFacade.getAbilities().getKeys()) {
AbilityCategory cat = (AbilityCategory) category;
for (CNAbility cna : theCharacter.getPoolAbilities(cat)) {
addCategorisedAbility(cna, workingAbilityListMap);
}
// deal with visibility
boolean visible = cat.isVisibleTo(theCharacter, View.VISIBLE_DISPLAY);
if (visible && !workingActiveCategories.containsElement(cat)) {
int index = getCatIndex(cat, workingActiveCategories);
workingActiveCategories.addElement(index, cat);
}
if (!visible && workingActiveCategories.containsElement(cat)) {
workingActiveCategories.removeElement(cat);
// updateAbilityCategoryTodo(cat);
}
if (visible) {
adviseSelectionChangeLater(cat);
}
}
// Update map contents
for (AbilityCategoryFacade category : workingAbilityListMap.keySet()) {
DefaultListFacade<AbilityFacade> workingListFacade = workingAbilityListMap.get(category);
DefaultListFacade<AbilityFacade> masterListFacade = abilityListMap.get(category);
if (masterListFacade == null) {
abilityListMap.put(category, workingListFacade);
} else {
masterListFacade.updateContentsNoOrder(workingListFacade.getContents());
}
updateAbilityCategoryTodo((AbilityCategory) category);
}
Set<AbilityCategoryFacade> origCats = new HashSet<>(abilityListMap.keySet());
for (AbilityCategoryFacade category : origCats) {
if (!workingAbilityListMap.containsKey(category)) {
if (workingActiveCategories.containsElement(category)) {
abilityListMap.get(category).clearContents();
} else {
abilityListMap.remove(category);
}
updateAbilityCategoryTodo((AbilityCategory) category);
}
}
activeCategories.updateContents(workingActiveCategories.getContents());
}
use of pcgen.facade.core.AbilityFacade in project pcgen by PCGen.
the class CharacterAbilities method removeElement.
private void removeElement(CNAbilitySelection cnas) {
CNAbility cas = cnas.getCNAbility();
Ability ability = cas.getAbility();
AbilityCategoryFacade cat = (AbilityCategoryFacade) cas.getAbilityCategory();
DefaultListFacade<AbilityFacade> listFacade = abilityListMap.get(cat);
if (listFacade != null) {
listFacade.removeElement(ability);
}
}
Aggregations