private void addPaths( List<List<AbilityFacade>> abilityPaths, List<AbilityFacade> preAbilities, ArrayList<AbilityFacade> path) { if (path.size() > 20) { Logging.errorPrint( "Found probable ability prereq cycle [" + StringUtils.join(path, ",") + "] with prereqs [" + StringUtils.join(preAbilities, ",") + "]. Skipping."); return; } for (AbilityFacade preAbility : preAbilities) { @SuppressWarnings("unchecked") ArrayList<AbilityFacade> pathclone = (ArrayList<AbilityFacade>) path.clone(); pathclone.add(preAbility); List<AbilityFacade> preAbilities2 = dataset.getPrereqAbilities(preAbility); // Don't include self references in the path preAbilities2.remove(preAbility); preAbilities2.removeAll(pathclone); if (preAbilities2.isEmpty()) { abilityPaths.add(pathclone); } else { addPaths(abilityPaths, preAbilities2, pathclone); } } }
/** * Request the metamagic feats to be applied to a spell from the user via a chooser. * * @param spellNode The spell to have metamagic applied * @return The list of metamagic feats to be applied. */ private List<Ability> queryUserForMetamagic(SpellNode spellNode) { // get the list of metamagic feats for the PC List<InfoFacade> availableList = buildAvailableMetamagicFeatList(spellNode); if (availableList.isEmpty()) { return Collections.emptyList(); } String label = dataSet.getGameMode().getAddWithMetamagicMessage(); if (StringUtils.isEmpty(label)) { label = LanguageBundle.getString("InfoSpells.add.with.metamagic"); } final ArrayList<Ability> selectedList = new ArrayList<>(); GeneralChooserFacadeBase chooserFacade = new GeneralChooserFacadeBase(label, availableList, new ArrayList<>(), 99, infoFactory) { @Override public void commit() { for (InfoFacade item : getSelectedList()) { selectedList.add((Ability) item); } } }; chooserFacade.setDefaultView(ChooserTreeViewType.NAME); boolean result = delegate.showGeneralChooser(chooserFacade); return result ? selectedList : null; }
@Override public List<TreeViewPath<AbilityFacade>> getPaths(AbilityFacade pobj) { List<List<AbilityFacade>> abilityPaths = new ArrayList<List<AbilityFacade>>(); addPaths(abilityPaths, dataset.getPrereqAbilities(pobj), new ArrayList<AbilityFacade>()); if (abilityPaths.isEmpty()) { return Collections.singletonList(new TreeViewPath<AbilityFacade>(pobj)); } List<TreeViewPath<AbilityFacade>> paths = new ArrayList<TreeViewPath<AbilityFacade>>(); for (List<AbilityFacade> path : abilityPaths) { Collections.reverse(path); paths.add(new TreeViewPath<AbilityFacade>(path.toArray(), pobj)); } return paths; }