use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.
the class PCClass method clone.
@Override
public PCClass clone() {
PCClass aClass = null;
try {
aClass = (PCClass) super.clone();
List<KnownSpellIdentifier> ksl = getListFor(ListKey.KNOWN_SPELLS);
if (ksl != null) {
aClass.removeListFor(ListKey.KNOWN_SPELLS);
for (KnownSpellIdentifier ksi : ksl) {
aClass.addToListFor(ListKey.KNOWN_SPELLS, ksi);
}
}
Map<AttackType, Integer> acmap = getMapFor(MapKey.ATTACK_CYCLE);
if (acmap != null && !acmap.isEmpty()) {
aClass.removeMapFor(MapKey.ATTACK_CYCLE);
for (Map.Entry<AttackType, Integer> me : acmap.entrySet()) {
aClass.addToMapFor(MapKey.ATTACK_CYCLE, me.getKey(), me.getValue());
}
}
aClass.levelMap = new TreeMap<>();
for (Map.Entry<Integer, PCClassLevel> me : levelMap.entrySet()) {
aClass.levelMap.put(me.getKey(), me.getValue().clone());
}
} catch (CloneNotSupportedException exc) {
ShowMessageDelegate.showMessageDialog(exc.getMessage(), Constants.APPLICATION_NAME, MessageType.ERROR);
}
return aClass;
}
use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.
the class KitSpells method testApply.
@Override
public boolean testApply(Kit aKit, PlayerCharacter aPC, List<String> warnings) {
theSpells = null;
PCClass aClass = findDefaultSpellClass(castingClass, aPC);
if (aClass == null) {
warnings.add("SPELLS: Character does not have " + castingClass + " spellcasting class.");
return false;
}
String workingBook = spellBook == null ? Globals.getDefaultSpellBook() : spellBook;
List<KitSpellBookEntry> aSpellList = new ArrayList<>();
if (!aClass.getSafe(ObjectKey.MEMORIZE_SPELLS) && !workingBook.equals(Globals.getDefaultSpellBook())) {
warnings.add("SPELLS: " + aClass.getDisplayName() + " can only add to " + Globals.getDefaultSpellBook());
return false;
}
for (KnownSpellIdentifier ksi : spells.getKeySet()) {
Collection<Spell> allSpells = ksi.getContainedSpells(aPC, Collections.singletonList(aClass.get(ObjectKey.CLASS_SPELLLIST)));
Set<List<CDOMSingleRef<Ability>>> feats = spells.getSecondaryKeySet(ksi);
for (Spell sp : allSpells) {
for (List<CDOMSingleRef<Ability>> list : feats) {
Integer count = spells.get(ksi, list);
aSpellList.add(new KitSpellBookEntry(spellBook, sp, list, count));
}
}
}
final Formula choiceFormula = getCount();
int numberOfChoices;
if (choiceFormula == null) {
numberOfChoices = aSpellList.size();
} else {
numberOfChoices = choiceFormula.resolve(aPC, "").intValue();
}
//
if (numberOfChoices > aSpellList.size()) {
numberOfChoices = aSpellList.size();
}
if (numberOfChoices == 0) {
return false;
}
List<KitSpellBookEntry> xs;
if (numberOfChoices == aSpellList.size()) {
xs = aSpellList;
} else {
//
while (true) {
xs = Globals.getChoiceFromList("Choose " + aClass.getKeyName() + " spell(s) for " + workingBook, aSpellList, new ArrayList<>(), numberOfChoices, aPC);
if (!xs.isEmpty()) {
break;
}
}
}
//
for (KitSpellBookEntry obj : xs) {
if (obj != null) {
obj.setPCClass(aClass);
if (theSpells == null) {
theSpells = new ArrayList<>();
}
theSpells.add(obj);
} else {
warnings.add("SPELLS: Non-existant spell chosen");
}
}
if (theSpells != null && !theSpells.isEmpty()) {
return true;
}
return false;
}
use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.
the class KitSpells method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (castingClass != null) {
sb.append(castingClass.getLSTformat(false));
}
sb.append(' ').append(spellBook).append(": ");
boolean needComma = false;
for (KnownSpellIdentifier ksi : spells.getKeySet()) {
if (needComma) {
sb.append(',');
}
needComma = true;
sb.append(ksi.getLSTformat());
Set<List<CDOMSingleRef<Ability>>> abilities = spells.getSecondaryKeySet(ksi);
for (List<CDOMSingleRef<Ability>> list : abilities) {
if (list != null) {
sb.append(" [");
sb.append(ReferenceUtilities.joinLstFormat(list, ","));
sb.append(']');
}
Integer count = spells.get(ksi, list);
if (count > 1) {
sb.append(" (").append(count).append(")");
}
}
}
return sb.toString();
}
use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.
the class KnownspellsToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClass pcc) {
Changes<KnownSpellIdentifier> changes = context.getObjectContext().getListChanges(pcc, ListKey.KNOWN_SPELLS);
List<String> list = new ArrayList<>();
if (changes.includesGlobalClear()) {
list.add(Constants.LST_DOT_CLEAR_ALL);
}
Collection<KnownSpellIdentifier> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty()) {
context.addWriteMessage(getTokenName() + " does not support .CLEAR.");
return null;
}
Collection<KnownSpellIdentifier> added = changes.getAdded();
if (added != null && !added.isEmpty()) {
TreeMapToList<CDOMReference<?>, Integer> map = new TreeMapToList<>(ReferenceUtilities.REFERENCE_SORTER);
for (KnownSpellIdentifier ksi : added) {
CDOMReference<Spell> ref = ksi.getSpellReference();
Integer i = ksi.getSpellLevel();
map.addToListFor(ref, i);
}
for (CDOMReference<?> ref : map.getKeySet()) {
for (Integer lvl : map.getListFor(ref)) {
StringBuilder sb = new StringBuilder();
boolean needComma = false;
String refString = ref.getLSTformat(false);
if (!Constants.LST_ALL.equals(refString)) {
sb.append(refString);
needComma = true;
}
if (lvl != null) {
if (needComma) {
sb.append(',');
}
sb.append("LEVEL=").append(lvl);
}
list.add(sb.toString());
}
}
}
if (list.isEmpty()) {
return null;
}
return new String[] { StringUtil.join(list, Constants.PIPE) };
}
use of pcgen.cdom.content.KnownSpellIdentifier in project pcgen by PCGen.
the class KnownspellsTokenTest method testUnparseNegativeLevel.
@Test
public void testUnparseNegativeLevel() throws PersistenceLayerException {
try {
CDOMGroupRef<Spell> all = primaryContext.getReferenceContext().getCDOMAllReference(Spell.class);
primaryProf.addToListFor(ListKey.KNOWN_SPELLS, new KnownSpellIdentifier(all, -3));
assertBadUnparse();
} catch (IllegalArgumentException e) {
//Good here too :)
}
}
Aggregations