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

Method newBonus

code/src/java/pcgen/core/bonus/Bonus.java:53–222  ·  view source on GitHub ↗

Create a new Bonus @param context TODO @param bonusString @return BonusObj TODO - This is doing all manner of string parsing. It really belongs in the persistence layer.

(LoadContext context, final String bonusString)

Source from the content-addressed store, hash-verified

51 * the persistence layer.
52 */
53 public static BonusObj newBonus(LoadContext context, final String bonusString)
54 {
55 ParsingSeparator sep = new ParsingSeparator(bonusString, '|');
56 sep.addGroupingPair('[', ']');
57 sep.addGroupingPair('(', ')');
58
59 if ((bonusString.indexOf(Constants.PIPE) == bonusString.lastIndexOf(Constants.PIPE))
60 && bonusString.indexOf('%') < 0)
61 {
62 Logging.errorPrint("Illegal bonus format: " + bonusString);
63
64 return null;
65 }
66
67 String bonusName = sep.next();
68
69 try
70 {
71 //Throw away old level value if present
72 Integer.parseInt(bonusName);
73 bonusName = sep.next().toUpperCase(Locale.ENGLISH);
74 }
75 catch (NumberFormatException exc)
76 {
77 bonusName = bonusName.toUpperCase(Locale.ENGLISH);
78 }
79
80 int equalOffset = -1;
81 Class<? extends BonusObj> bEntry = TokenLibrary.getBonus(bonusName);
82 String typeOfBonus = bonusName;
83 if (bEntry == null)
84 {
85 equalOffset = bonusName.indexOf('=');
86 if (equalOffset >= 0)
87 {
88 typeOfBonus = bonusName.substring(0, equalOffset + 1);
89 bEntry = TokenLibrary.getBonus(typeOfBonus);
90 }
91 if (bEntry == null)
92 {
93 Logging.errorPrint("Unrecognized bonus: " + bonusString);
94 return null;
95 }
96 }
97
98 String bonusInfo = sep.next();
99 String bValue = "0";
100
101 if (sep.hasNext())
102 {
103 bValue = sep.next();
104 }
105
106 if (bValue.startsWith("PRE") || bValue.startsWith("!PRE"))
107 {
108 Logging.errorPrint("Invalid BONUS has no value: " + bonusString);
109 return null;
110 }

Callers 15

setUpMethod · 0.95
setUpMethod · 0.95
setUpMethod · 0.95
setUpMethod · 0.95
setUpMethod · 0.95
setUpMethod · 0.95
setUpMethod · 0.95
test885958AMethod · 0.95
test885958BMethod · 0.95
testChoiceMethod · 0.95
setUpMethod · 0.95
testGetVariableValue1Method · 0.95

Calls 15

addGroupingPairMethod · 0.95
errorPrintMethod · 0.95
nextMethod · 0.95
getBonusMethod · 0.95
hasNextMethod · 0.95
putOriginalStringMethod · 0.95
setBonusNameMethod · 0.95
setTypeOfBonusMethod · 0.95
setValueMethod · 0.95
isValidMethod · 0.95
isPreReqStringMethod · 0.95
getInstanceMethod · 0.95

Tested by 15

setUpMethod · 0.76
setUpMethod · 0.76
setUpMethod · 0.76
setUpMethod · 0.76
setUpMethod · 0.76
setUpMethod · 0.76
setUpMethod · 0.76
test885958AMethod · 0.76
test885958BMethod · 0.76
testChoiceMethod · 0.76
setUpMethod · 0.76
testGetVariableValue1Method · 0.76