use of pcgen.core.PCClass in project pcgen by PCGen.
the class SpellLevel method isLevel.
/**
* isLevel(int aLevel)
*
* @param aLevel
* level of the spell
* @param aPC
* @return true if the spell is of the given level in any spell list
*/
public static boolean isLevel(Spell sp, int aLevel, PlayerCharacter aPC) {
Integer levelKey = aLevel;
MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
for (PCClass pcc : aPC.getClassSet()) {
ClassSpellList csl = pcc.get(ObjectKey.CLASS_SPELLLIST);
Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(csl, sp);
if (assoc != null) {
for (AssociatedPrereqObject apo : assoc) {
if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
return true;
}
}
}
}
}
for (Domain domain : aPC.getDomainSet()) {
DomainSpellList dsl = domain.get(ObjectKey.DOMAIN_SPELLLIST);
Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(dsl, sp);
if (assoc != null) {
for (AssociatedPrereqObject apo : assoc) {
if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
return true;
}
}
}
}
}
return false;
}
use of pcgen.core.PCClass in project pcgen by PCGen.
the class SubClassApplication method checkForSubClass.
public static void checkForSubClass(PlayerCharacter aPC, PCClass cl) {
List<SubClass> subClassList = cl.getListFor(ListKey.SUB_CLASS);
if (subClassList == null || subClassList.isEmpty()) {
return;
}
List<PCClass> availableList = new ArrayList<>();
String subClassKey = aPC.getSubClassName(cl);
boolean subClassSelected = subClassKey != null && !subClassKey.equals(Constants.NONE) && !subClassKey.equals("");
for (SubClass sc : subClassList) {
if (!PrereqHandler.passesAll(sc.getPrerequisiteList(), aPC, cl)) {
continue;
}
// If a subclass has already been selected, only add that one
if (!subClassSelected || sc.getKeyName().equals(aPC.getSubClassName(cl))) {
availableList.add(sc);
}
}
// add base class to the chooser
if (cl.getSafe(ObjectKey.ALLOWBASECLASS) && (!subClassSelected || cl.getKeyName().equals(aPC.getSubClassName(cl)))) {
availableList.add(0, cl);
}
/*
* REFACTOR This makes an assumption that SubClasses are ONLY Schools, which may
* not be a fabulous assumption
*/
List<PCClass> selectedSubClasses;
CDOMChooserFacadeImpl<PCClass> chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
LanguageBundle.getString("in_schoolSpecChoice"), //$NON-NLS-1$
availableList, new ArrayList<>(), 1);
chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
if (availableList.size() == 1) {
selectedSubClasses = availableList;
} else if (availableList.isEmpty()) {
if (Logging.isLoggable(Logging.WARNING)) {
Logging.log(Logging.WARNING, "No subclass choices avaialble for " + cl);
}
return;
} else {
ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
selectedSubClasses = chooserFacade.getFinalSelected();
}
if (!cl.getSafe(ObjectKey.ALLOWBASECLASS)) {
while (selectedSubClasses.isEmpty()) {
ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
selectedSubClasses = chooserFacade.getFinalSelected();
}
}
if (selectedSubClasses.isEmpty()) {
return;
}
PCClass subselected = selectedSubClasses.get(0);
if (subselected instanceof SubClass) {
aPC.removeProhibitedSchools(cl);
/*
* CONSIDER What happens to this reset during PCClass/PCClassLevel split
*/
aPC.removeAssoc(cl, AssociationKey.SPECIALTY);
SubClass sc = (SubClass) subselected;
availableList.clear();
for (SubClass sub : subClassList) {
if (sub.equals(sc)) {
//Skip the selected specialist school
continue;
}
if (!PrereqHandler.passesAll(sub.getPrerequisiteList(), aPC, cl)) {
continue;
}
int displayedCost = sub.getProhibitCost();
if (displayedCost == 0) {
continue;
}
availableList.add(sub);
}
setSubClassKey(aPC, cl, sc.getKeyName());
if (sc.get(ObjectKey.CHOICE) != null) {
aPC.setAssoc(cl, AssociationKey.SPECIALTY, sc.getChoice());
}
if (sc.getSafe(IntegerKey.COST) != 0) {
chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
LanguageBundle.getString("in_schoolProhibitChoice"), availableList, new ArrayList<>(), sc.getSafe(IntegerKey.COST));
chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
chooserFacade.setRequireCompleteSelection(true);
ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
selectedSubClasses = chooserFacade.getFinalSelected();
for (PCClass choice : chooserFacade.getFinalSelected()) {
sc = (SubClass) choice;
SpellProhibitor prohibSchool = new SpellProhibitor();
prohibSchool.setType(ProhibitedSpellType.SCHOOL);
prohibSchool.addValue(sc.getChoice());
SpellProhibitor prohibSubSchool = new SpellProhibitor();
prohibSubSchool.setType(ProhibitedSpellType.SUBSCHOOL);
prohibSubSchool.addValue(sc.getChoice());
aPC.addProhibitedSchool(prohibSchool, cl);
aPC.addProhibitedSchool(prohibSubSchool, cl);
}
}
}
}
use of pcgen.core.PCClass in project pcgen by PCGen.
the class DomainApplication method removeDomain.
/**
* Remove a domain from the character.
* @param pc The character
* @param domain The domain.
*/
public static void removeDomain(PlayerCharacter pc, Domain domain) {
ClassSource source = pc.getDomainSource(domain);
PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
if (aClass != null) {
int maxLevel;
for (maxLevel = 0; maxLevel < 10; maxLevel++) {
if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
break;
}
}
if (maxLevel > 0) {
removeSpellsFromClassForLevels(pc, domain, aClass);
}
if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
DomainSpellList domainSpellList = domain.get(ObjectKey.DOMAIN_SPELLLIST);
final List<Spell> aList = pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));
for (Spell gcs : aList) {
if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
pc.removeDomainSpellCount(aClass);
break;
}
}
}
}
if (!pc.isImporting()) {
BonusActivation.deactivateBonuses(domain, pc);
}
}
use of pcgen.core.PCClass in project pcgen by PCGen.
the class SubstitutionLevelSupport method levelArrayQualifies.
private static boolean levelArrayQualifies(int level, final PlayerCharacter pc, final String aLine, final SourceEntry tempSource, CDOMObject source) {
final PCClassLoader classLoader = new PCClassLoader();
PCClass dummyClass = new PCClass();
try {
classLoader.parseLine(Globals.getContext(), dummyClass, aLine, tempSource);
} catch (PersistenceLayerException e) {
Logging.errorPrint("Unable to parse line from levelArray: " + aLine);
}
return dummyClass.getOriginalClassLevel(level).qualifies(pc, source);
}
use of pcgen.core.PCClass in project pcgen by PCGen.
the class ExportHandler method processSpellcasterExpression.
/**
* Deal with SPELLCASTER.
*
* Could look like one of the following:
*
* Arcane
* Chaos
* Divine
* EleMage
* Psionic
* Wizard
* Prepare
* !Prepare
* 0=Wizard (%classNum=className)
* 0=Divine (%classNum=spell_type)
* 0=Prepare (%classNum=preparation_type)
*
* @param expr1 Expression to evaluate
* @param aPC PC containing values to help evaluate the expression
* @return true if the expression was evaluated successfully, else false
*/
private static boolean processSpellcasterExpression(String expr1, PlayerCharacter aPC) {
final String fString = expr1.substring(12).trim();
// If the SPELLCASTER expression has an '=' sign
if (fString.indexOf('=') != -1) {
final StringTokenizer aTok = new StringTokenizer(fString, "=", false);
final int i = Integer.parseInt(aTok.nextToken());
final String cs = aTok.nextToken();
final List<PCClass> cList = aPC.getClassList();
if (i >= cList.size()) {
return false;
}
final PCClass aClass = cList.get(i);
if (cs.equalsIgnoreCase(aClass.getSpellType())) {
return true;
}
if (cs.equalsIgnoreCase(aClass.getKeyName())) {
return true;
}
if ("!Prepare".equalsIgnoreCase(cs) && aClass.getSafe(ObjectKey.MEMORIZE_SPELLS)) {
return true;
}
if ("Prepare".equalsIgnoreCase(cs) && (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS))) {
return true;
}
} else {
for (final PCClass pcClass : aPC.getClassSet()) {
if (fString.equalsIgnoreCase(pcClass.getSpellType())) {
return true;
}
if (fString.equalsIgnoreCase(pcClass.getKeyName())) {
return true;
}
if ("!Prepare".equalsIgnoreCase(fString) && pcClass.getSafe(ObjectKey.MEMORIZE_SPELLS)) {
return true;
}
if ("Prepare".equalsIgnoreCase(fString) && (!pcClass.getSafe(ObjectKey.MEMORIZE_SPELLS))) {
return true;
}
}
}
Logging.errorPrint("Should have exited before this in ExportHandler::processSpellcasterExpression");
return false;
}
Aggregations