use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class CharacterAbilities method removeAbility.
/**
* Process a request by the user to remove an ability. The user will be
* informed if the request cannot be allowed. Updates to the displayed
* lists are handled by events (see initForCharacter).
*
* @param categoryFacade The category from which the ability is being removed.
* @param abilityFacade The ability to be removed.
*/
public void removeAbility(AbilityCategoryFacade categoryFacade, AbilityFacade abilityFacade) {
if (abilityFacade == null || !(abilityFacade instanceof Ability) || categoryFacade == null || !(categoryFacade instanceof AbilityCategory)) {
return;
}
Ability anAbility = (Ability) abilityFacade;
AbilityCategory theCategory = (AbilityCategory) categoryFacade;
try {
Ability pcAbility = theCharacter.getMatchingAbility(theCategory, anAbility, Nature.NORMAL);
if (pcAbility != null) {
CNAbility cna = CNAbilityFactory.getCNAbility(theCategory, Nature.NORMAL, anAbility);
AbilityUtilities.driveChooseAndAdd(cna, theCharacter, false);
theCharacter.adjustMoveRates();
}
} catch (Exception exc) {
//$NON-NLS-1$
Logging.errorPrintLocalised("in_iayFailedToRemoveAbility", exc);
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getString(//$NON-NLS-1$
"in_iayRemoveAbility") + ": " + exc.getMessage());
return;
}
theCharacter.calcActiveBonuses();
// update the ability info
rebuildAbilityLists();
return;
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class GameModeFileLoader method loadGameModeMiscInfo.
private static GameMode loadGameModeMiscInfo(String aName, URI uri) {
GameMode gameMode = null;
String data;
try {
data = LstFileLoader.readFromURI(uri).toString();
} catch (final PersistenceLayerException ple) {
Logging.errorPrint(LanguageBundle.getFormattedString(//$NON-NLS-1$
"Errors.LstSystemLoader.loadGameModeInfoFile", uri, ple.getMessage()));
return gameMode;
}
String[] fileLines = data.split(LstFileLoader.LINE_SEPARATOR_REGEXP);
for (int i = 0; i < fileLines.length; i++) {
String aLine = fileLines[i];
// Ignore commented-out and empty lines
if (((!aLine.isEmpty()) && (aLine.charAt(0) == '#')) || aLine.isEmpty()) {
continue;
}
if (gameMode == null) {
gameMode = new GameMode(aName);
SystemCollections.addToGameModeList(gameMode);
gameMode.getModeContext().getReferenceContext().importObject(AbilityCategory.FEAT);
}
GameModeLoader.parseMiscGameInfoLine(gameMode, aLine, uri, i + 1);
}
// Record how the FEAT category was configured
AbilityCategory feat = new AbilityCategory();
feat.copyFields(AbilityCategory.FEAT);
gameMode.setFeatTemplate(feat);
int[] dieSizes = gameMode.getDieSizes();
if (dieSizes == null || dieSizes.length == 0) {
final int[] defaultDieSizes = { 1, 2, 3, 4, 6, 8, 10, 12, 20, 100, 1000 };
gameMode.setDieSizes(defaultDieSizes);
Logging.log(Logging.LST_ERROR, "GameMode (" + gameMode.getName() + ") : MiscInfo.lst did not contain any valid DIESIZES. " + "Using the system default DIESIZES.");
}
addDefaultUnitSet(gameMode);
addDefaultTabInfo(gameMode);
gameMode.applyPreferences();
return gameMode;
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class ChooserUtilities method getConfiguredController.
public static <T> ChoiceManagerList<T> getConfiguredController(final ChooseDriver aPObject, final PlayerCharacter aPC, final AbilityCategory category, List<String> reservedList) {
ChoiceManagerList aMan = getChoiceManager(aPObject, aPC);
if (aMan == null) {
return null;
}
if (aPObject instanceof CNAbility) {
CNAbility driver = (CNAbility) aPObject;
Ability a = driver.getAbility();
AbilityCategory cat;
if (category == null) {
cat = SettingsHandler.getGame().getAbilityCategory(a.getCategory());
} else {
cat = category;
}
aMan.setController(new AbilityChooseController(a, cat, aPC, aMan));
List<CNAbility> abilities = aPC.getMatchingCNAbilities(a);
for (CNAbility cna : abilities) {
reservedList.addAll(aPC.getAssociationList(cna));
}
} else if (aPObject instanceof Skill) {
Skill s = (Skill) aPObject;
aMan.setController(new SkillChooseController(s, aPC));
}
return aMan;
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class AbilitySelection method getAbilitySelectionFromPersistentFormat.
/**
* Decodes the given String into an AbilitySelection. The String format to
* be passed into this method is defined solely by the return result of the
* getPersistentFormat method. There is no guarantee that the encoding is
* human readable, simply that the encoding is uniquely identifying such
* that this method is capable of decoding the String into an
* AbilitySelection.
*
* @param persistentFormat
* The String which should be decoded to provide an
* AbilitySelection.
*
* @return An AbilitySelection that was encoded in the given String.
*/
public static AbilitySelection getAbilitySelectionFromPersistentFormat(LoadContext context, String persistentFormat) {
if (!persistentFormat.contains(Constants.PIPE)) {
return decodeFeatSelectionChoice(context, persistentFormat);
}
StringTokenizer st = new StringTokenizer(persistentFormat, Constants.PIPE);
String catString = st.nextToken();
if (!catString.startsWith("CATEGORY=")) {
throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must start with CATEGORY=, found: " + persistentFormat);
}
String cat = catString.substring(9);
AbilityCategory ac = SettingsHandler.getGame().getAbilityCategory(cat);
if (ac == null) {
throw new IllegalArgumentException("Category in getAbilitySelectionFromPersistentFormat " + "must exist found: " + cat);
}
String ab = st.nextToken();
Ability a = context.getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, ac, ab);
if (a == null) {
throw new IllegalArgumentException("Second argument in String in getAbilitySelectionFromPersistentFormat " + "must be an Ability, but it was not found: " + persistentFormat);
}
String sel = null;
if (st.hasMoreTokens()) {
/*
* No need to check for MULT:YES/NO here, as that is checked
* implicitly in the construction of AbilitySelection below
*/
sel = st.nextToken();
} else if (persistentFormat.endsWith(Constants.PIPE)) {
// Handle the StringTokenizer ignoring blank tokens at the end
sel = "";
}
if (st.hasMoreTokens()) {
throw new IllegalArgumentException("String in getAbilitySelectionFromPersistentFormat " + "must have 2 or 3 arguments, but found more: " + persistentFormat);
}
return new AbilitySelection(a, sel);
}
use of pcgen.core.AbilityCategory in project pcgen by PCGen.
the class KitAbilities method testApply.
@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
abilitiesToAdd = new ArrayList<>();
double minCost = Double.MAX_VALUE;
List<AbilitySelection> available = new ArrayList<>();
for (CDOMReference<Ability> ref : abilities) {
String choice = ref.getChoice();
for (Ability a : ref.getContainedObjects()) {
if (a == null) {
warnings.add("ABILITY: " + ref + " could not be found.");
minCost = 0;
continue;
}
if (a.getCost() < minCost) {
minCost = a.getCost();
}
if ((choice == null) && a.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
available.add(new AbilitySelection(a, ""));
} else {
available.add(new AbilitySelection(a, choice));
}
}
}
int numberOfChoices = getSafeCount();
// TODO this fails if SELECT != 1
if (numberOfChoices > available.size()) {
numberOfChoices = available.size();
}
/*
* this section needs to be rewritten once we determine how
* the new Ability Pools are going to work
*/
AbilityCategory category = catRef.get();
boolean tooManyAbilities = false;
// Don't allow choosing of more than allotted number of abilities
int maxChoices = minCost > 0.0d ? aPC.getAvailableAbilityPool(category).divide(new BigDecimal(minCost)).intValue() : numberOfChoices;
if (!isFree() && numberOfChoices > maxChoices) {
numberOfChoices = maxChoices;
tooManyAbilities = true;
}
if (!isFree() && numberOfChoices == 0) {
warnings.add("ABILITY: Not enough " + category.getPluralName() + " available to take \"" + this + "\"");
return false;
}
List<AbilitySelection> selected;
if (numberOfChoices == available.size()) {
selected = available;
} else {
selected = new ArrayList<>();
// Force user to make enough selections
while (true) {
selected = Globals.getChoiceFromList("Choose abilities", available, new ArrayList<>(), numberOfChoices, aPC);
if (!selected.isEmpty()) {
break;
}
}
}
// Add to list of things to add to the character
for (AbilitySelection as : selected) {
Ability ability = as.ability;
if (isFree()) {
// Need to pay for it first
if (free) {
aPC.adjustAbilities(category, BigDecimal.ONE);
}
}
if (ability.getCost() > aPC.getAvailableAbilityPool(category).doubleValue()) {
tooManyAbilities = true;
} else {
CNAbility cna = CNAbilityFactory.getCNAbility(category, Nature.NORMAL, ability);
CNAbilitySelection cnas = new CNAbilitySelection(cna, as.selection);
abilitiesToAdd.add(cnas);
aPC.addAbility(cnas, UserSelection.getInstance(), this);
}
}
if (tooManyAbilities) {
warnings.add("ABILITY: Some Abilities were not granted -- not enough remaining feats");
return false;
}
return true;
}
Aggregations