use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class SpellMemToken method replaceTokenSpellMemSourceLevel.
private static String replaceTokenSpellMemSourceLevel(Spell aSpell, PlayerCharacter aPC) {
final HashMapToList<CDOMList<Spell>, Integer> tempHash = aPC.getSpellLevelInfo(aSpell);
StringBuilder tempSource = new StringBuilder();
final Set<String> levelSet = new TreeSet<>();
for (CDOMList<Spell> spellList : tempHash.getKeySet()) {
String classKey = spellList.getKeyName();
for (Integer lvl : tempHash.getListFor(spellList)) {
PCClass pcc = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKey);
if (pcc != null) {
classKey = pcc.getAbbrev();
}
levelSet.add(classKey + lvl.toString());
}
}
for (String levelString : levelSet) {
if (tempSource.length() > 0) {
tempSource.append(", ");
}
tempSource.append(levelString);
}
return tempSource.toString();
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class AbilityLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Collection<CDOMReference<? extends CDOMList<?>>> changedLists = context.getListContext().getChangedLists(obj, AbilityList.class);
Changes<ListKey<ChooseSelectionActor<?>>> actors = context.getObjectContext().getListChanges(obj, ListKey.GA_CAKEYS);
Set<String> returnSet = new TreeSet<>();
TripleKeyMapToList<Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>> m = new TripleKeyMapToList<>();
TripleKeyMapToList<Nature, CDOMSingleRef<AbilityCategory>, List<Prerequisite>, CDOMReference<Ability>> clear = new TripleKeyMapToList<>();
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> csa : listAdded) {
if (csa.getSource().equals(getTokenName())) {
try {
AbilitySelector as = (AbilitySelector) csa;
StringBuilder sb = new StringBuilder();
sb.append(as.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
sb.append(as.getNature()).append(Constants.PIPE);
sb.append(as.getLstFormat());
returnSet.add(sb.toString());
} catch (PersistenceLayerException e) {
context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
return null;
}
}
}
}
for (CDOMReference ref : changedLists) {
AssociatedChanges<CDOMReference<Ability>> changes = context.getListContext().getChangesInList(getTokenName(), obj, ref);
if (changes.includesGlobalClear()) {
CDOMDirectSingleRef<AbilityList> dr = (CDOMDirectSingleRef<AbilityList>) ref;
AbilityList al = dr.get();
StringBuilder sb = new StringBuilder();
sb.append(al.getCategory().getLSTformat(false)).append(Constants.PIPE);
sb.append(al.getNature()).append(Constants.PIPE);
sb.append(Constants.LST_DOT_CLEAR);
returnSet.add(sb.toString());
}
MapToList<CDOMReference<Ability>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl != null) {
for (CDOMReference<Ability> ab : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
Nature nature = assoc.getAssociation(AssociationKey.NATURE);
CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
m.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
}
}
}
mtl = changes.getRemovedAssociations();
if (mtl != null) {
for (CDOMReference<Ability> ab : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
Nature nature = assoc.getAssociation(AssociationKey.NATURE);
CDOMSingleRef<AbilityCategory> cat = assoc.getAssociation(AssociationKey.CATEGORY);
clear.addToListFor(nature, cat, assoc.getPrerequisiteList(), ab);
}
}
}
}
for (Nature nature : m.getKeySet()) {
for (CDOMSingleRef<AbilityCategory> category : m.getSecondaryKeySet(nature)) {
for (List<Prerequisite> prereqs : m.getTertiaryKeySet(nature, category)) {
StringBuilder sb = new StringBuilder();
sb.append(category.getLSTformat(false)).append(Constants.PIPE);
sb.append(nature);
List<CDOMReference<Ability>> clearList = clear.removeListFor(nature, category, prereqs);
if (clearList != null && !clearList.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(Constants.LST_DOT_CLEAR_DOT);
sb.append(ReferenceUtilities.joinLstFormat(clearList, Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
}
sb.append(Constants.PIPE);
sb.append(ReferenceUtilities.joinLstFormat(m.getListFor(nature, category, prereqs), Constants.PIPE));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
returnSet.add(sb.toString());
}
}
}
for (Nature nature : clear.getKeySet()) {
for (CDOMSingleRef<AbilityCategory> category : clear.getSecondaryKeySet(nature)) {
for (List<Prerequisite> prereqs : clear.getTertiaryKeySet(nature, category)) {
StringBuilder sb = new StringBuilder();
sb.append(category.getLSTformat(false)).append(Constants.PIPE);
sb.append(nature).append(Constants.PIPE).append(Constants.LST_DOT_CLEAR_DOT);
sb.append(ReferenceUtilities.joinLstFormat(clear.getListFor(nature, category, prereqs), Constants.PIPE + Constants.LST_DOT_CLEAR_DOT));
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
returnSet.add(sb.toString());
}
}
}
Collection<ListKey<ChooseSelectionActor<?>>> addedActors = actors.getAdded();
if (addedActors != null) {
for (ListKey<ChooseSelectionActor<?>> lk : addedActors) {
Changes<ChooseSelectionActor<?>> cras = context.getObjectContext().getListChanges(obj, lk);
for (ChooseSelectionActor<?> cra : cras.getAdded()) {
if (getTokenName().equals(cra.getSource())) {
try {
AbilityTargetSelector ats = (AbilityTargetSelector) cra;
StringBuilder sb = new StringBuilder();
sb.append(ats.getAbilityCategory().getLSTformat(false)).append(Constants.PIPE);
sb.append(ats.getNature()).append(Constants.PIPE).append(cra.getLstFormat());
List<Prerequisite> prereqs = ats.getPrerequisiteList();
if (prereqs != null && !prereqs.isEmpty()) {
sb.append(Constants.PIPE);
sb.append(getPrerequisiteString(context, prereqs));
}
returnSet.add(sb.toString());
} catch (PersistenceLayerException e) {
context.addWriteMessage(getTokenName() + " encountered error: " + e.getMessage());
return null;
}
}
}
}
}
if (returnSet.isEmpty()) {
return null;
}
return returnSet.toArray(new String[returnSet.size()]);
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class CompanionListLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Changes<FollowerOption> changes = context.getObjectContext().getListChanges(obj, ListKey.COMPANIONLIST);
Collection<FollowerOption> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
context.addWriteMessage(getTokenName() + " does not support .CLEAR");
return null;
}
Collection<FollowerOption> added = changes.getAdded();
if (added == null || added.isEmpty()) {
// Zero indicates no Token (and no global clear, so nothing to do)
return null;
}
TripleKeyMapToList<Set<Prerequisite>, CDOMReference<? extends CDOMList<?>>, Integer, CDOMReference<Race>> m = new TripleKeyMapToList<>();
for (FollowerOption fo : added) {
m.addToListFor(new HashSet<>(fo.getPrerequisiteList()), fo.getListRef(), fo.getAdjustment(), fo.getRaceRef());
}
Set<String> set = new TreeSet<>();
StringBuilder sb = new StringBuilder();
for (Set<Prerequisite> prereqs : m.getKeySet()) {
String prereqString = null;
if (prereqs != null && !prereqs.isEmpty()) {
prereqString = getPrerequisiteString(context, prereqs);
}
for (CDOMReference<? extends CDOMList<?>> cl : m.getSecondaryKeySet(prereqs)) {
for (Integer fa : m.getTertiaryKeySet(prereqs, cl)) {
sb.setLength(0);
sb.append(cl.getLSTformat(false));
sb.append(Constants.PIPE);
Set<CDOMReference<Race>> raceSet = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
raceSet.addAll(m.getListFor(prereqs, cl, fa));
sb.append(ReferenceUtilities.joinLstFormat(raceSet, Constants.COMMA, true));
if (fa != null && fa != 0) {
sb.append(Constants.PIPE);
sb.append("FOLLOWERADJUSTMENT:");
sb.append(fa);
}
if (prereqString != null) {
sb.append(Constants.PIPE);
sb.append(prereqString);
}
set.add(sb.toString());
}
}
}
return set.toArray(new String[set.size()]);
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class AvailableSpellFacet method getSpellLevelInfo.
/**
* Returns a non-null HashMapToList indicating the spell levels and sources
* of those spell levels available to a Player Character for a given Spell.
*
* This may return multiple spell levels because it is possible for a spell
* to be accessible to a Player Character at multiple levels since it may be
* available from multiple sources. This also returns the spell lists
* associated with the given level, since it is possible for a multi-class
* character to have access to the same spell at different levels. By
* returning the source as well as the spell levels, such scenarios can be
* appropriately distinguished.
*
* This method is value-semantic in that ownership of the returned
* HashMapToList is transferred to the class calling this method.
* Modification of the returned HashMapToList will not modify this
* AvailableSpellFacet and modification of this AvailableSpellFacet will not
* modify the returned HashMapToList. Modifications to the returned
* HashMapToList will also not modify any future or previous objects
* returned by this (or other) methods on AvailableSpellFacet. If you wish
* to modify the information stored in this AvailableSpellFacet, you must
* use the add*() and remove*() methods of AvailableSpellFacet.
*
* @param id
* The CharID identifying the Player Character for which the
* spell levels should be returned
* @param sp
* The Spell for which the spell levels should be returned
* @return A non-null HashMapToList indicating the spell levels and sources
* of those spell levels available to a Player Character for a given
* Spell.
*/
public HashMapToList<CDOMList<Spell>, Integer> getSpellLevelInfo(CharID id, Spell sp) {
HashMapToList<CDOMList<Spell>, Integer> levelInfo = new HashMapToList<>();
Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> listMap = (Map<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>>) getCache(id);
if (listMap == null) {
return levelInfo;
}
for (Entry<CDOMList<Spell>, Map<Integer, Map<Spell, Set<Object>>>> me : listMap.entrySet()) {
CDOMList<Spell> list = me.getKey();
//Check to ensure we don't use SPELLS:
if (!(list instanceof ClassSpellList) && !(list instanceof DomainSpellList)) {
continue;
}
Map<Integer, Map<Spell, Set<Object>>> levelMap = me.getValue();
for (Map.Entry<Integer, Map<Spell, Set<Object>>> lme : levelMap.entrySet()) {
Integer level = lme.getKey();
Map<Spell, Set<Object>> spellMap = lme.getValue();
if (spellMap.containsKey(sp)) {
levelInfo.addToListFor(list, level);
} else {
for (Spell spell : spellMap.keySet()) {
if (spell.getKeyName().equals(sp.getKeyName())) {
if (Logging.isLoggable(Logging.INFO)) {
Logging.log(Logging.INFO, "Found alternate spell of same key: " + spell + " from " + spell.getSource() + " rather than " + sp.getSource());
}
levelInfo.addToListFor(list, level);
}
}
}
}
}
return levelInfo;
}
use of pcgen.cdom.base.CDOMList in project pcgen by PCGen.
the class PlayerCharacter method getTotalCasterLevelWithSpellBonus.
public int getTotalCasterLevelWithSpellBonus(CharacterSpell acs, final Spell aSpell, final String spellType, final String classOrRace, final int casterLev) {
if (aSpell != null && acs.getFixedCasterLevel() != null) {
return getVariableValue(acs.getFixedCasterLevel(), Constants.EMPTY_STRING).intValue();
}
int tBonus = casterLev;
boolean replaceCasterLevel = false;
String tType;
String tStr;
// final List<TypedBonus> bonuses = new ArrayList<TypedBonus>();
final List<CasterLevelSpellBonus> bonuses = new ArrayList<>();
if (classOrRace != null) {
// bonuses.addAll(getBonusesTo("CASTERLEVEL", classOrRace));
tBonus = (int) getTotalBonusTo("CASTERLEVEL", classOrRace);
if (tBonus > 0) {
tType = getSpellBonusType("CASTERLEVEL", classOrRace);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
// BONUS:CASTERLEVEL|CLASS.Sorcerer|1
if (!classOrRace.startsWith("RACE.")) {
tStr = "CLASS." + classOrRace;
// bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
}
}
if (aSpell == null) {
return tallyCasterlevelBonuses(casterLev, replaceCasterLevel, bonuses);
}
if (!spellType.equals(Constants.NONE)) {
tStr = "TYPE." + spellType;
// bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
tStr += ".RESET";
// final List<TypedBonus> reset = getBonusesTo("CASTERLEVEL", tStr);
// if ( reset.size() > 0 )
// {
// bonuses.addAll(reset);
// replaceCasterLevel = true;
// }
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
replaceCasterLevel = true;
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
}
tStr = "SPELL." + aSpell.getKeyName();
// bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
tStr += ".RESET";
// final List<TypedBonus> reset = getBonusesTo("CASTERLEVEL", tStr);
// if ( reset.size() > 0 )
// {
// bonuses.addAll(reset);
// replaceCasterLevel = true;
// }
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
replaceCasterLevel = true;
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
/*
* This wraps in TreeSet because it looks to me like this is ordered
* (given .RESET)
*/
for (SpellSchool school : new TreeSet<>(aSpell.getSafeListFor(ListKey.SPELL_SCHOOL))) {
tStr = "SCHOOL." + school.toString();
// bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (// Allow negative bonus to casterlevel
tBonus != 0) {
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
tStr += ".RESET";
// final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
// tStr);
// if ( reset.size() > 0 )
// {
// bonuses.addAll(reset1);
// replaceCasterLevel = true;
// }
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
replaceCasterLevel = true;
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
}
for (String subschool : new TreeSet<>(aSpell.getSafeListFor(ListKey.SPELL_SUBSCHOOL))) {
tStr = "SUBSCHOOL." + subschool;
// bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
tStr += ".RESET";
// final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
// tStr);
// if ( reset.size() > 0 )
// {
// bonuses.addAll(reset1);
// replaceCasterLevel = true;
// }
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
replaceCasterLevel = true;
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
}
//Not wrapped because it wasn't in 5.14
for (String desc : aSpell.getSafeListFor(ListKey.SPELL_DESCRIPTOR)) {
tStr = "DESCRIPTOR." + desc;
// bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
tStr += ".RESET";
// final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
// tStr);
// if ( reset.size() > 0 )
// {
// bonuses.addAll(reset1);
// replaceCasterLevel = true;
// }
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
replaceCasterLevel = true;
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
}
final HashMapToList<CDOMList<Spell>, Integer> domainMap = getSpellLevelInfo(aSpell);
if (domainMap != null) {
for (CDOMList<Spell> spellList : domainMap.getKeySet()) {
if (spellList instanceof DomainSpellList) {
tStr = "DOMAIN." + spellList.getKeyName();
// bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
tStr += ".RESET";
// final List<TypedBonus> reset1 =
// getBonusesTo("CASTERLEVEL", tStr);
// if ( reset.size() > 0 )
// {
// bonuses.addAll(reset1);
// replaceCasterLevel = true;
// }
tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
if (tBonus > 0) {
replaceCasterLevel = true;
tType = getSpellBonusType("CASTERLEVEL", tStr);
bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
}
}
}
}
int result = tallyCasterlevelBonuses(casterLev, replaceCasterLevel, bonuses);
return (result);
}
Aggregations