use of pcgen.core.Ability 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.Ability in project pcgen by PCGen.
the class BonusCalc method bonusTo.
public static double bonusTo(PObject po, String aType, String aName, final Object obj, final Collection<BonusObj> aBonusList, final PlayerCharacter aPC) {
if ((aBonusList == null) || (aBonusList.isEmpty())) {
return 0;
}
double retVal = 0;
aType = aType.toUpperCase();
aName = aName.toUpperCase();
final String aTypePlusName = new StringBuilder(aType).append('.').append(aName).append('.').toString();
if (!BonusCalc.dontRecurse && (po instanceof Ability) && (AbilityUtilities.isFeat(obj)) && !Globals.checkRule(RuleConstants.FEATPRE)) {
// SUCK! This is horrid, but bonusTo is actually recursive with respect to
// passesPreReqToGain and there is no other way to do this without decomposing the
// dependencies. I am loathe to break working code.
// This addresses bug #709677 -- Feats give bonuses even if you no longer qualify
BonusCalc.dontRecurse = true;
boolean returnZero = false;
if (!po.qualifies(aPC, po)) {
returnZero = true;
}
BonusCalc.dontRecurse = false;
if (returnZero) {
return 0;
}
}
int iTimes = 1;
if (aPC != null && "VAR".equals(aType)) {
iTimes = Math.max(1, aPC.getConsolidatedAssociationList(po).size());
}
for (BonusObj bonus : aBonusList) {
String bString = bonus.toString().toUpperCase();
if (aPC != null && !aPC.getConsolidatedAssociationList(po).isEmpty()) {
int span = 4;
int idx = bString.indexOf("%VAR");
if (idx == -1) {
idx = bString.indexOf("%LIST|");
span = 5;
}
if (idx >= 0) {
final String firstPart = bString.substring(0, idx);
final String secondPart = bString.substring(idx + span);
for (String assoc : aPC.getConsolidatedAssociationList(po)) {
final String xString = new StringBuilder(50).append(firstPart).append(assoc).append(secondPart).toString().toUpperCase();
retVal += BonusCalc.calcBonus(po, xString, aType, aName, aTypePlusName, obj, iTimes, bonus, aPC);
}
}
} else {
retVal += BonusCalc.calcBonus(po, bString, aType, aName, aTypePlusName, obj, iTimes, bonus, aPC);
}
}
return retVal;
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class EqModSpellInfo method setSpellInfo.
/**
* Here be dragons
*
* Builds up a big mad string representing the spell info and then stores it
* in the first entry of associated.
*
* TODO store this a separate fields or as a spell object or some other way
* that doesn't involve turning this into a string and then parsing the
* string when we want to do something with the info.
*
* @param parent
* TODO
* @param spellCastingClass
* a PCClass Object, the class that this spell will be cast as
* @param theSpell
* a Spell Object
* @param spellVariant
* a string
* @param spellType
* arcane, divine, etc.
* @param spellLevel
* an int the level of the spell
* @param spellCasterLevel
* Caster level the spell is cast at
* @param spellMetamagicFeats
* Any metamagic feats applied
* @param charges
* how many times can it be cast
*/
public static void setSpellInfo(Equipment parent, EquipmentModifier eqMod, final CDOMObject spellCastingClass, final Spell theSpell, final String spellVariant, final String spellType, final int spellLevel, final int spellCasterLevel, final Object[] spellMetamagicFeats, final int charges) {
final StringBuilder spellInfo = new StringBuilder(100);
spellInfo.append("SPELLNAME[").append(theSpell.getKeyName()).append("] ");
spellInfo.append("CASTER[").append(spellCastingClass.getKeyName()).append("] ");
if (!spellVariant.isEmpty()) {
spellInfo.append("VARIANT[").append(spellVariant).append("] ");
}
spellInfo.append("SPELLTYPE[").append(spellType).append("] ");
spellInfo.append("SPELLLEVEL[").append(spellLevel).append("] ");
spellInfo.append("CASTERLEVEL[").append(spellCasterLevel).append("] ");
if (charges > 0) {
spellInfo.append(s_CHARGES).append('[').append(charges).append("] ");
}
if ((spellMetamagicFeats != null) && (spellMetamagicFeats.length > 0)) {
/*
* Have considered whether this needs to be expanded to include
* Category. These are actually Feats and the information is only
* used by toString()
*/
spellInfo.append("METAFEATS[");
for (int i = 0; i < spellMetamagicFeats.length; i++) {
final Ability aFeat = (Ability) spellMetamagicFeats[i];
if (i != 0) {
spellInfo.append(", ");
}
spellInfo.append(aFeat.getKeyName());
}
spellInfo.append("] ");
}
parent.addAssociation(eqMod, spellInfo.toString());
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class GrantedAbilityFacet method getCNAbilities.
public Collection<CNAbility> getCNAbilities(CharID id, Ability ability) {
Set<CNAbility> returnList = new HashSet<>();
List<List<SourcedCNAS>> list = getList(id);
if (list != null) {
Category<Ability> cat = ability.getCDOMCategory();
for (List<SourcedCNAS> array : list) {
CNAbility cna = array.get(0).cnas.getCNAbility();
if (cna.getAbilityCategory().getParentCategory().equals(cat) && cna.getAbilityKey().equals(ability.getKeyName())) {
returnList.add(cna);
}
}
}
return returnList;
}
use of pcgen.core.Ability in project pcgen by PCGen.
the class NPCGenerator method getFeatWeights.
private WeightedCollection<Ability> getFeatWeights(final PCClass aClass) {
WeightedCollection<Ability> weightedCollection = theConfiguration.getAbilityWeights(aClass.getKeyName(), AbilityCategory.FEAT);
if (weightedCollection == null) {
weightedCollection = new WeightedCollection<>();
// any other type
for (Ability ability : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, AbilityCategory.FEAT).getAllObjects()) {
int weight = 1;
if (ability.getSafe(ObjectKey.VISIBILITY) != Visibility.DEFAULT) {
continue;
}
if (//$NON-NLS-1$
ability.isType("GENERAL")) {
weight = 5;
}
weightedCollection.add(ability, weight);
}
}
return weightedCollection;
}
Aggregations