/** * 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); } }
public static void addDomainsUpToLevel(PCClass cl, final int aLevel, final PlayerCharacter aPC) { // any domains set by level would have already been saved // and don't need to be re-set at level up time if (aPC.isImporting()) { return; } /* * Note this uses ALL of the domains up to and including this level, * because there is the possibility (albeit strange) that the PC was not * qualified at a previous level change, but the PlayerCharacter is now * qualified for the given Domain. Even this has quirks, since it is * only applied at the time of level increase, but I think that quirk * should be resolved by a CDOM system around 6.0 - thpr 10/23/06 */ for (QualifiedObject<CDOMSingleRef<Domain>> qo : cl.getSafeListFor(ListKey.DOMAIN)) { CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl); if (ref != null) { addDomain(aPC, cl, ref.resolvesTo()); } } for (int i = 0; i <= aLevel; i++) { // TODO This stinks for really high level characters - can this ever // get null back? PCClassLevel pcl = aPC.getActiveClassLevel(cl, i); for (QualifiedObject<CDOMSingleRef<Domain>> qo : pcl.getSafeListFor(ListKey.DOMAIN)) { CDOMSingleRef<Domain> ref = qo.getObject(aPC, cl); if (ref != null) { addDomain(aPC, cl, ref.resolvesTo()); } } } }
/** * Drives the selection of the AgeSet Kit for a Player Character when relevant changes (change to * an AgeSet) are made to a Player Character. * * <p>Triggered when one of the Facets to which AgeSetKitFacet listens fires a * DataFacetChangeEvent to indicate a CDOMObject was added to a Player Character. * * @param dfce The DataFacetChangeEvent containing the information about the change * @see * pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent) */ @Override public void dataAdded(DataFacetChangeEvent<CharID, Integer> dfce) { CharID id = dfce.getCharID(); AgeSet ageSet = ageSetFacet.get(id); PlayerCharacter pc = trackingFacet.getPC(id); // TODO Is ageSet null check necessary? if (ageSet == null || pc.isImporting()) { return; } int ageSetIndex = ageSetFacet.getAgeSetIndex(id); /* * TODO The method of storing what AgeSets have had kit selections made * should be converted to store the actual AgeSet rather than the index, * in order to reduce the number of calls to ageSetFacet.getAgeSetIndex. * This (of course) drives the move of the AgeSets for which a kit * selection has been made into a Facet. It is possible that the * CacheInfo of AgeSetKitFacet is actually a good place to store that * information (or it may be implicit with the information already * stored there??) */ if (!pc.hasMadeKitSelectionForAgeSet(ageSetIndex)) { CacheInfo cache = getConstructingClassInfo(id); List<Kit> kits = cache.get(ageSet); if (kits != null) { // Need to do selection BioSet bioSet = bioSetFacet.get(id); for (TransitionChoice<Kit> kit : ageSet.getKits()) { Collection<? extends Kit> choice = kit.driveChoice(pc); cache.put(ageSet, choice); kit.act(choice, bioSet, pc); } } pc.setHasMadeKitSelectionForAgeSet(ageSetIndex, true); } }
@Override public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) { skillsToAdd = new ArrayList<KitSkillAdd>(); List<Skill> skillChoices = getSkillChoices(aPC); if (skillChoices == null || skillChoices.size() == 0) { // They didn't make a choice so don't add any ranks. return false; } for (Skill skill : skillChoices) { BigDecimal ranksLeftToAdd = getRank(); if (ranksLeftToAdd == null) { ranksLeftToAdd = BigDecimal.ONE; } double ranksLeft = ranksLeftToAdd.doubleValue(); List<PCClass> classList = new ArrayList<PCClass>(); if (className != null) { String classKey = className.resolvesTo().getKeyName(); // Make sure if they specified a class to add from we try that // class first. PCClass pcClass = aPC.getClassKeyed(classKey); if (pcClass != null) { classList.add(pcClass); } else { warnings.add( "SKILL: Could not find specified class " + classKey + " in PC to add ranks from."); } } for (PCClass pcClass : aPC.getClassSet()) { if (!classList.contains(pcClass)) { classList.add(pcClass); } } // Try and find a class we can add them from. boolean oldImporting = aPC.isImporting(); aPC.setImporting(true); for (PCClass pcClass : classList) { final KitSkillAdd sta = addRanks(aPC, pcClass, skill, ranksLeft, isFree(), warnings); if (sta != null) { skillsToAdd.add(sta); ranksLeft -= sta.getRanks(); if (ranksLeft <= 0.0) { break; } } } aPC.setImporting(oldImporting); if (ranksLeft > 0.0) { warnings.add( "SKILL: Could not add " + ranksLeft + " ranks to " + skill.getKeyName() + ". Not enough points."); } } return true; }
/** * Needs documentation. * * @param pc update skills for this PC * @param aSkill Skill to update * @param aRank Number of ranks to add * @param aCost Cost of added ranks * @param langList Languages to be selected for a language skill * @param pcClass skills apply to this class * @return <code>true</code> for success TODO What about throwing on failure? */ private boolean updatePCSkills( final PlayerCharacter pc, final Skill aSkill, final int aRank, final double aCost, List<Language> langList, final PCClass pcClass) { pc.addSkill(aSkill); boolean oldImporting = pc.isImporting(); pc.setImporting(true); final String aString = SkillRankControl.modRanks(aRank, pcClass, true, pc, aSkill); pc.setImporting(oldImporting); if (aString.length() > 0) { Logging.errorPrint("SKILL: " + aString); return false; } // Add any supplied languages ChoiceManagerList<Language> controller = ChooserUtilities.getConfiguredController(aSkill, pc, null, new ArrayList<String>()); for (Language lang : langList) { if (!controller.conditionallyApply(pc, lang)) { Logging.errorPrint("Failed to apply Language into Skill: " + lang.getLSTformat()); } } // // Fix up the skill pools to reflect what we just spent. // double ptsToSpend = aCost; if (ptsToSpend >= 0.0) { for (PCLevelInfo info : pc.getLevelInfo()) { if (info.getClassKeyName().equals(pcClass.getKeyName())) { // We are spending this class' points. int remaining = info.getSkillPointsRemaining(); if (remaining == 0) { continue; } int left = remaining - (int) Math.min(remaining, ptsToSpend); info.setSkillPointsRemaining(left); ptsToSpend -= (remaining - left); if (ptsToSpend <= 0) { break; } } } } return true; }
@Override public void removeChoice( PlayerCharacter pc, CDOMObject owner, CategorizedAbilitySelection choice) { if (!pc.isImporting()) { pc.getSpellList(); } // See if our choice is not auto or virtual Ability anAbility = pc.getMatchingAbility(AbilityCategory.FEAT, choice.getAbility(), Nature.NORMAL); if (anAbility != null) { pc.removeRealAbility(AbilityCategory.FEAT, anAbility); CDOMObjectUtilities.removeAdds(anAbility, pc); CDOMObjectUtilities.restoreRemovals(anAbility, pc); pc.adjustMoveRates(); } }
@Override public void applyChoice( CDOMObject owner, CategorizedAbilitySelection choice, PlayerCharacter pc) { if (!pc.isImporting()) { pc.getSpellList(); } // See if our choice is not auto or virtual Ability anAbility = pc.getMatchingAbility(AbilityCategory.FEAT, choice.getAbility(), Nature.NORMAL); if (anAbility != null) { // how many sub-choices to make double abilityCount = (pc.getSelectCorrectedAssociationCount(anAbility) * anAbility.getSafe(ObjectKey.SELECTION_COST).doubleValue()); boolean result = false; // adjust the associated List if (anAbility.getSafe(ObjectKey.MULTIPLE_ALLOWED)) { pc.removeAssociation(anAbility, choice.getSelection()); result = pc.hasAssociations(anAbility); } boolean removed = false; // if no sub choices made (i.e. all of them removed in Chooser box), // then remove the Feat if (!result) { removed = pc.removeRealAbility(AbilityCategory.FEAT, anAbility); CDOMObjectUtilities.removeAdds(anAbility, pc); CDOMObjectUtilities.restoreRemovals(anAbility, pc); } AbilityUtilities.adjustPool(anAbility, pc, false, abilityCount, removed); pc.adjustMoveRates(); } double cost = choice.getAbility().getSafe(ObjectKey.SELECTION_COST).doubleValue(); pc.adjustAbilities(AbilityCategory.FEAT, BigDecimal.valueOf(-cost)); }