|
From: <nu...@us...> - 2006-03-15 01:43:28
|
Revision: 233 Author: nuance Date: 2006-03-14 17:43:22 -0800 (Tue, 14 Mar 2006) ViewCVS: http://svn.sourceforge.net/pcgen/?rev=233&view=rev Log Message: ----------- Refactor modFeatsFromList out of PlayerCharacter intoPlayerCharacterUtilities as a static method. Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PCClass.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacterUtilities.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PCClass.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PCClass.java 2006-03-15 01:27:35 UTC (rev 232) +++ Trunk/pcgen/code/src/java/pcgen/core/PCClass.java 2006-03-15 01:43:22 UTC (rev 233) @@ -5179,7 +5179,7 @@ if (aLevel == Integer.parseInt(getToken(0, feats, ":"))) { final double preFeatCount = aPC.getUsedFeatCount(); - aPC.modFeatsFromList(pcLevelInfo, getToken(1, feats, ":"), addThem, aLevel == 1); + PlayerCharacterUtilities.modFeatsFromList(aPC, pcLevelInfo, getToken(1, feats, ":"), addThem, aLevel == 1); final double postFeatCount = aPC.getUsedFeatCount(); Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-03-15 01:27:35 UTC (rev 232) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-03-15 01:43:22 UTC (rev 233) @@ -7791,7 +7791,7 @@ for (int i = 0, x = templateFeats.size(); i < x; ++i) { - modFeatsFromList(null, (String) templateFeats.get(i), true, false); + PlayerCharacterUtilities.modFeatsFromList(this, null, (String) templateFeats.get(i), true, false); } } else @@ -11178,170 +11178,6 @@ return false; } - /** - * Add multiple feats from a String list separated by commas. - * @param playerCharacterLevelInfo - * @param aList - * @param addIt - * @param all - */ - void modFeatsFromList(final PCLevelInfo playerCharacterLevelInfo, final String aList, final boolean addIt, final boolean all) - { - final StringTokenizer aTok = new StringTokenizer(aList, ","); - - while (aTok.hasMoreTokens()) - { - String aString = aTok.nextToken(); - Ability anAbility = getFeatNamed(aString); - StringTokenizer bTok = null; - - if (anAbility != null) - { - continue; - } - - // does not already have feat - anAbility = Globals.getAbilityNamed("FEAT", aString); - - if (anAbility == null) - { - // could not find Feat, try trimming off contents of parenthesis - bTok = new StringTokenizer(aString, "()", true); - - final String bString = bTok.nextToken(); - final int beginIndex = bString.length() + 1; - final int endIndex = aString.lastIndexOf(')'); - - if (beginIndex <= aString.length()) - { - if (endIndex >= beginIndex) - { - bTok = new StringTokenizer(aString.substring(beginIndex, endIndex), ","); - } - else - { - bTok = new StringTokenizer(aString.substring(beginIndex), ","); - } - } - else - { - bTok = null; - } - aString = bString.replace('(', ' ').replace(')', ' ').trim(); - } - else - { - final Ability tempAbility = getFeatNamed(anAbility.getName()); - if (tempAbility != null) - { - anAbility = tempAbility; - } - else - { - // add the Feat found, as a CharacterFeat - anAbility = (Ability) anAbility.clone(); - addFeat(anAbility, playerCharacterLevelInfo); - } - } - - if (anAbility == null) - { - // if we still haven't found it, try a different string - if (!addIt) - { - return; - } - - anAbility = Globals.getAbilityNamed("FEAT", aString); - - if (anAbility == null) - { - Logging.errorPrint("Feat not found in PlayerCharacter.modFeatsFromList: " + aString); - - return; - } - - anAbility = (Ability) anAbility.clone(); - addFeat(anAbility, playerCharacterLevelInfo); - } - - if ((bTok != null) && bTok.hasMoreTokens()) - { - while (bTok.hasMoreTokens()) - { - aString = bTok.nextToken(); - - if ("DEITYWEAPON".equals(aString)) - { - WeaponProf wp = null; - - if (getDeity() != null) - { - wp = Globals.getWeaponProfNamed(getDeity().getFavoredWeapon()); - } - - if (wp != null) - { - if (addIt) // TODO: condition always true - { - anAbility.addAssociated(wp.getName()); - } - else - { - anAbility.removeAssociated(wp.getName()); - } - } - } - else - { - if (addIt) // TODO: condition always true - { - anAbility.addAssociated(aString); - } - else - { - anAbility.removeAssociated(aString); - } - } - } - } - else - { - if (!all && !anAbility.isMultiples()) - { - if (addIt) - { -// setFeats(getFeats() + anAbility.getCost(this)); - adjustFeats(anAbility.getCost(this)); - } - else - { -// setFeats(getFeats() - anAbility.getCost(this)); - adjustFeats(-anAbility.getCost(this)); - } - } - - AbilityUtilities.modFeat(this, playerCharacterLevelInfo, aString, addIt, all); - } - - if (anAbility.getName().endsWith("Weapon Proficiency")) - { - for (int e = 0; e < anAbility.getAssociatedCount(); ++e) - { - final String wprof = anAbility.getAssociated(e); - final WeaponProf wp = Globals.getWeaponProfNamed(wprof); - - if (wp != null) - { - addWeaponProfToChosenFeats(wprof); - } - } - } - } - - setAutomaticFeatsStable(false); - } - boolean removeFavoredClass(final String aString) { if (favoredClasses.contains(aString)) @@ -14412,7 +14248,7 @@ for (int j = 0, y = templateFeats.size(); j < y; ++j) { - modFeatsFromList(null, (String) templateFeats.get(j), true, false); + PlayerCharacterUtilities.modFeatsFromList(this, null, (String) templateFeats.get(j), true, false); } } } Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacterUtilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacterUtilities.java 2006-03-15 01:27:35 UTC (rev 232) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacterUtilities.java 2006-03-15 01:43:22 UTC (rev 233) @@ -24,8 +24,10 @@ */ package pcgen.core; +import pcgen.core.pclevelinfo.PCLevelInfo; import pcgen.core.utils.MessageType; import pcgen.core.utils.ShowMessageDelegate; +import pcgen.util.Logging; import java.util.List; import java.util.StringTokenizer; @@ -267,4 +269,170 @@ eqm.setWeight("0"); eqm.setCost("0"); } + + /** + * Add multiple feats from a String list separated by commas. + * @param playerCharacterLevelInfo + * @param aList + * @param addIt + * @param all + */ + static void modFeatsFromList(final PlayerCharacter aPC, + final PCLevelInfo playerCharacterLevelInfo, + final String aList, + final boolean addIt, + final boolean all) + { + final StringTokenizer aTok = new StringTokenizer(aList, ","); + + while (aTok.hasMoreTokens()) + { + String aString = aTok.nextToken(); + Ability anAbility = aPC.getFeatNamed(aString); + StringTokenizer bTok = null; + + if (anAbility != null) + { + continue; + } + + // does not already have feat + anAbility = Globals.getAbilityNamed("FEAT", aString); + + if (anAbility == null) + { + // could not find Feat, try trimming off contents of parenthesis + bTok = new StringTokenizer(aString, "()", true); + + final String bString = bTok.nextToken(); + final int beginIndex = bString.length() + 1; + final int endIndex = aString.lastIndexOf(')'); + + if (beginIndex <= aString.length()) + { + if (endIndex >= beginIndex) + { + bTok = new StringTokenizer(aString.substring(beginIndex, endIndex), ","); + } + else + { + bTok = new StringTokenizer(aString.substring(beginIndex), ","); + } + } + else + { + bTok = null; + } + aString = bString.replace('(', ' ').replace(')', ' ').trim(); + } + else + { + final Ability tempAbility = aPC.getFeatNamed(anAbility.getName()); + if (tempAbility != null) + { + anAbility = tempAbility; + } + else + { + // add the Feat found, as a CharacterFeat + anAbility = (Ability) anAbility.clone(); + aPC.addFeat(anAbility, playerCharacterLevelInfo); + } + } + + if (anAbility == null) + { + // if we still haven't found it, try a different string + if (!addIt) + { + return; + } + + anAbility = Globals.getAbilityNamed("FEAT", aString); + + if (anAbility == null) + { + Logging.errorPrint("Feat not found in PlayerCharacter.modFeatsFromList: " + aString); + + return; + } + + anAbility = (Ability) anAbility.clone(); + aPC.addFeat(anAbility, playerCharacterLevelInfo); + } + + if ((bTok != null) && bTok.hasMoreTokens()) + { + while (bTok.hasMoreTokens()) + { + aString = bTok.nextToken(); + + if ("DEITYWEAPON".equals(aString)) + { + WeaponProf wp = null; + + if (aPC.getDeity() != null) + { + wp = Globals.getWeaponProfNamed(aPC.getDeity().getFavoredWeapon()); + } + + if (wp != null) + { + if (addIt) // TODO: condition always true + { + anAbility.addAssociated(wp.getName()); + } + else + { + anAbility.removeAssociated(wp.getName()); + } + } + } + else + { + if (addIt) // TODO: condition always true + { + anAbility.addAssociated(aString); + } + else + { + anAbility.removeAssociated(aString); + } + } + } + } + else + { + if (!all && !anAbility.isMultiples()) + { + if (addIt) + { + aPC.adjustFeats(anAbility.getCost(aPC)); + } + else + { + aPC.adjustFeats(-anAbility.getCost(aPC)); + } + } + + AbilityUtilities.modFeat(aPC, playerCharacterLevelInfo, aString, addIt, all); + } + + if (anAbility.getName().endsWith("Weapon Proficiency")) + { + for (int e = 0; e < anAbility.getAssociatedCount(); ++e) + { + final String wprof = anAbility.getAssociated(e); + final WeaponProf wp = Globals.getWeaponProfNamed(wprof); + + if (wp != null) + { + aPC.addWeaponProfToChosenFeats(wprof); + } + } + } + } + + aPC.setAutomaticFeatsStable(false); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |