MCPcopy Create free account
hub / github.com/PCGen/pcgen / testApply

Method testApply

code/src/java/pcgen/core/kit/KitSpells.java:113–217  ·  view source on GitHub ↗
(Kit aKit, PlayerCharacter aPC, List<String> warnings)

Source from the content-addressed store, hash-verified

111 }
112
113 @Override
114 public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings)
115 {
116 theSpells = null;
117
118 PCClass aClass = findDefaultSpellClass(castingClass, aPC);
119 if (aClass == null)
120 {
121 warnings.add("SPELLS: Character does not have " + castingClass + " spellcasting class.");
122 return false;
123 }
124
125 String workingBook = spellBook == null ? Globals.getDefaultSpellBook() : spellBook;
126 List<KitSpellBookEntry> aSpellList = new ArrayList<>();
127 if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS) && !workingBook.equals(Globals.getDefaultSpellBook()))
128 {
129 warnings.add("SPELLS: " + aClass.getDisplayName() + " can only add to " + Globals.getDefaultSpellBook());
130 return false;
131 }
132
133 for (KnownSpellIdentifier ksi : spells.getKeySet())
134 {
135 Collection<Spell> allSpells =
136 ksi.getContainedSpells(aPC, Collections.singletonList(aClass.get(ObjectKey.CLASS_SPELLLIST)));
137 Set<List<CDOMSingleRef<Ability>>> feats = spells.getSecondaryKeySet(ksi);
138 for (Spell sp : allSpells)
139 {
140 for (List<CDOMSingleRef<Ability>> list : feats)
141 {
142 Integer count = spells.get(ksi, list);
143 aSpellList.add(new KitSpellBookEntry(spellBook, sp, list, count));
144 }
145 }
146 }
147
148 final Formula choiceFormula = getCount();
149 int numberOfChoices;
150
151 if (choiceFormula == null)
152 {
153 numberOfChoices = aSpellList.size();
154 }
155 else
156 {
157 numberOfChoices = choiceFormula.resolve(aPC, "").intValue();
158 }
159
160 //
161 // Can't choose more entries than there are...
162 //
163 if (numberOfChoices > aSpellList.size())
164 {
165 numberOfChoices = aSpellList.size();
166 }
167
168 if (numberOfChoices == 0)
169 {
170 return false;

Callers

nothing calls this directly

Calls 15

findDefaultSpellClassMethod · 0.95
getDefaultSpellBookMethod · 0.95
getCountMethod · 0.95
resolveMethod · 0.95
getChoiceFromListMethod · 0.95
getSafeMethod · 0.80
getContainedSpellsMethod · 0.80
intValueMethod · 0.80
setPCClassMethod · 0.80
addMethod · 0.65
equalsMethod · 0.65
getDisplayNameMethod · 0.65

Tested by

no test coverage detected