|
From: <jde...@us...> - 2006-12-13 07:47:59
|
Revision: 1760
http://svn.sourceforge.net/pcgen/?rev=1760&view=rev
Author: jdempsey
Date: 2006-12-12 23:47:59 -0800 (Tue, 12 Dec 2006)
Log Message:
-----------
Fix part 2 of bug #1613069 - Sort Spells bug.
- Fixed level primary and secondary sorts.
- Fixed duration secondary sort.
- Fixed NPE on showing spell info on non class spells.
Modified Paths:
--------------
Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java
Trunk/pcgen/code/src/java/pcgen/core/spell/Spell.java
Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/SpellModel.java
Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-12-13 01:21:40 UTC (rev 1759)
+++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-12-13 07:47:59 UTC (rev 1760)
@@ -6179,7 +6179,7 @@
public String getSpellRange(final Spell aSpell, final PObject owner, final SpellInfo si)
{
String aRange = aSpell.getRange();
- final String aSpellClass = "CLASS:" + owner.getKeyName();
+ final String aSpellClass = "CLASS:" + (owner != null ? owner.getKeyName() : "");
int rangeInFeet = 0;
String aString = Globals.getGameModeSpellRangeFormula(aRange.toUpperCase());
@@ -15387,6 +15387,8 @@
setFeats(arg);
return;
}
+
+ //TODO: What about other types of ability pools?
}
public void setUserPoolBonus( final AbilityCategory aCategory, final BigDecimal anAmount )
Modified: Trunk/pcgen/code/src/java/pcgen/core/spell/Spell.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/spell/Spell.java 2006-12-13 01:21:40 UTC (rev 1759)
+++ Trunk/pcgen/code/src/java/pcgen/core/spell/Spell.java 2006-12-13 07:47:59 UTC (rev 1760)
@@ -1035,17 +1035,44 @@
*/
public boolean isLevel(final int aLevel, final PlayerCharacter aPC)
{
- final Map<String, Integer> wLevelInfo = getLevelInfo(aPC);
final Integer levelKey = Integer.valueOf(aLevel);
- for (Integer value : wLevelInfo.values())
+ for (PCClass cls : aPC.getClassList())
{
- if (value.equals(levelKey))
+ if (levelKey.equals(levelInfo.get("CLASS|" + cls.getKeyName())))
{
return true;
}
}
+ for (CharacterDomain domain : aPC.getCharacterDomainList())
+ {
+ if (levelKey.equals(levelInfo.get("DOMAIN|" + domain.getDomain().getKeyName())))
+ {
+ return true;
+ }
+ }
return false;
}
+
+ /**
+ * Assess if this spell is of the requested level for any class.
+ * @param level The level to be checked.
+ * @return True if the spell is the requested level.
+ */
+ public boolean isLevel(final int level)
+ {
+ if (levelInfo == null)
+ {
+ return false;
+ }
+ for (String key : levelInfo.keySet())
+ {
+ if (level == levelInfo.get(key))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
public int levelForKey(final String mType, final String sType, final PlayerCharacter aPC)
{
Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/SpellModel.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/SpellModel.java 2006-12-13 01:21:40 UTC (rev 1759)
+++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/SpellModel.java 2006-12-13 07:47:59 UTC (rev 1760)
@@ -695,6 +695,7 @@
PObject aClass = null;
int iLev = -1;
+ PObjectNode primaryNode = primaryNodes[pindex];
switch (primaryMode)
{
case GuiConstants.INFOSPELLS_VIEW_CLASS: // By Class
@@ -735,23 +736,23 @@
continue;
break;
case GuiConstants.INFOSPELLS_VIEW_DESCRIPTOR: // By Descriptor
- primaryMatch = spell.getDescriptorList().contains(primaryNodes[pindex].toString());
+ primaryMatch = spell.getDescriptorList().contains(primaryNode.toString());
break;
case GuiConstants.INFOSPELLS_VIEW_RANGE: // By Range
- primaryMatch = spell.getRange().equals(primaryNodes[pindex].toString());
+ primaryMatch = spell.getRange().equals(primaryNode.toString());
break;
case GuiConstants.INFOSPELLS_VIEW_DURATION: // By Duration
- primaryMatch = spell.getDuration().equals(primaryNodes[pindex].toString());
+ primaryMatch = spell.getDuration().equals(primaryNode.toString());
break;
case GuiConstants.INFOSPELLS_VIEW_TYPE: // By Type
- primaryMatch = spell.isType(primaryNodes[pindex].toString());
+ primaryMatch = spell.isType(primaryNode.toString());
break;
case GuiConstants.INFOSPELLS_VIEW_SCHOOL: // By Type
- primaryMatch = spell.getSchools().contains(primaryNodes[pindex].toString());
+ primaryMatch = spell.getSchools().contains(primaryNode.toString());
break;
}
- if (secondaryMode == GuiConstants.INFOSPELLS_VIEW_NOTHING)
+ if (secondaryMode == GuiConstants.INFOSPELLS_VIEW_NOTHING)
{
if (!firstPass && !primaryMatch)
continue;
@@ -769,12 +770,12 @@
{
continue;
}
- primaryNodes[pindex].getChildren().toArray(secondaryNodes);
+ primaryNode.getChildren().toArray(secondaryNodes);
}
for (int sindex = 0 ; sindex < secondaryNodes.length; sindex++)
{
- mapKey = bookName+"."+primaryNodes[pindex].toString()+"."+secondaryNodes[sindex].toString(); //$NON-NLS-1$ //$NON-NLS-2$
+ mapKey = bookName+"."+primaryNode.toString()+"."+secondaryNodes[sindex].toString(); //$NON-NLS-1$ //$NON-NLS-2$
switch (secondaryMode)
{
case GuiConstants.INFOSPELLS_VIEW_CLASS: // By Class
@@ -783,18 +784,31 @@
break;
case GuiConstants.INFOSPELLS_VIEW_LEVEL: // By Level
iLev = sindex;
- spellMatch = primaryMatch;
+ spellMatch = false;
si = null;
- if (spellMatch && cs != null)
+ if (primaryMatch)
{
- si = cs.getSpellInfoFor(bookName, iLev, -1);
+ if (cs != null)
+ {
+ si = cs.getSpellInfoFor(bookName, iLev, -1);
+ spellMatch = si != null;
+ }
+ if (si == null)
+ {
+ if (aClass != null)
+ {
+ spellMatch = spell.levelForKeyContains(aClass.getSpellKey(), iLev, pc);
+ }
+ else
+ {
+ spellMatch = spell.isLevel(iLev, pc);
+ }
+ }
}
- if (si == null && primaryMatch)
+ if (!knownSpellsOnly && si != null && si.getFeatList()!=null)
{
- spellMatch = spell.levelForKeyContains(aClass.getSpellKey(), iLev, pc);
+ continue;
}
- if (!knownSpellsOnly && si != null && si.getFeatList()!=null)
- continue;
break;
case GuiConstants.INFOSPELLS_VIEW_DESCRIPTOR: // By Descriptor
spellMatch = primaryMatch && spell.getDescriptorList().contains(secondaryNodes[sindex].toString());
@@ -803,7 +817,7 @@
spellMatch = primaryMatch && spell.getRange().equals(secondaryNodes[sindex].toString());
break;
case GuiConstants.INFOSPELLS_VIEW_DURATION: // By Duration
- spellMatch = primaryMatch && spell.getRange().equals(secondaryNodes[sindex].toString());
+ spellMatch = primaryMatch && spell.getDuration().equals(secondaryNodes[sindex].toString());
break;
case GuiConstants.INFOSPELLS_VIEW_TYPE: // By Type
spellMatch = primaryMatch && spell.isType(secondaryNodes[sindex].toString());
@@ -817,7 +831,7 @@
}
if (firstPass && secondaryMode != GuiConstants.INFOSPELLS_VIEW_NOTHING)
{
- secondaryNodes[sindex].setParent(primaryNodes[pindex]);
+ secondaryNodes[sindex].setParent(primaryNode);
if (!knownSpellsOnly && aClass != null && iLev > -1 && (aClass instanceof PCClass))
{
addDomainSpellsForClass(Globals.getClassKeyed(((PCClass)aClass).getCastAs()), secondaryNodes[sindex], iLev);
@@ -858,7 +872,7 @@
cs = new CharacterSpell(bClass, spell);
si = cs.addInfo(iLev, 1, bookName);
}
- // didn't find a match, so continue
+ // didn't find a match, so try the next node
if (!spellMatch || si == null)
{
continue;
@@ -866,30 +880,22 @@
// Everything looks ok
// so add this spell
- PObjectNode spellNode = new PObjectNode();
- spellNode.setItem(si);
PObjectNode thisNode = secondaryNodes[sindex];
if (secondaryMode == GuiConstants.INFOSPELLS_VIEW_NOTHING)
- thisNode = primaryNodes[pindex];
- spellNode.setParent(thisNode);
- thisNode.addChild(spellNode);
- List<SpellInfo> aList = usedMap.get(mapKey);
- if (aList == null)
{
- aList = new ArrayList<SpellInfo>();
+ thisNode = primaryNode;
}
- aList.add(si);
- usedMap.put(mapKey, aList);
+ addSpellToNode(si, thisNode, usedMap, mapKey);
}
if (secondaryMode != GuiConstants.INFOSPELLS_VIEW_NOTHING)
- primaryNodes[pindex].setChildren(secondaryNodes);
+ primaryNode.setChildren(secondaryNodes);
if (!knownSpellsOnly)
{
- primaryNodes[pindex].setParent(theRoot);
+ primaryNode.setParent(theRoot);
}
else
{
- primaryNodes[pindex].setParent(bookNodes[ix]);
+ primaryNode.setParent(bookNodes[ix]);
}
} // end primaryNodes
if (knownSpellsOnly)
@@ -925,6 +931,33 @@
/**
+ * Add the spell to the node and to the map of spell assignments.
+ *
+ * @param si The spell to be added.
+ * @param parentNode The node to add the spell to.
+ * @param usedMap The map of spell assignments
+ * @param mapKey The key of the node the spell is being added to.
+ */
+ private void addSpellToNode(SpellInfo si, PObjectNode parentNode, HashMap<String, List<SpellInfo>> usedMap, String mapKey)
+ {
+ // Add the spell to the node
+ PObjectNode spellNode = new PObjectNode();
+ spellNode.setItem(si);
+ spellNode.setParent(parentNode);
+ parentNode.addChild(spellNode);
+
+ // Add it to the map of spells
+ List<SpellInfo> aList = usedMap.get(mapKey);
+ if (aList == null)
+ {
+ aList = new ArrayList<SpellInfo>();
+ usedMap.put(mapKey, aList);
+ }
+ aList.add(si);
+ }
+
+
+ /**
* @param spellListType
* @param classList
* @param spellList
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|