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

Method getRule

code/src/java/pcgen/core/doomsdaybook/RuleSet.java:209–254  ·  view source on GitHub ↗

Get the rule. @return rule @throws Exception When no entry exists for the supplied key.

()

Source from the content-addressed store, hash-verified

207 * @throws Exception When no entry exists for the supplied key.
208 */
209 public Rule getRule() throws Exception
210 {
211 int rangeTop = getRange();
212 int modifier;
213
214 try
215 {
216 modifier = Integer.parseInt(allVars.getVal(getId() + "modifier"));
217 }
218 catch (Exception e)
219 {
220 modifier = 0;
221 }
222
223 // Determine which entry to choose
224 Dice die = new Dice(1, rangeTop, 0);
225 int choice = die.roll();
226 choice += modifier;
227
228 choice = (choice < 0) ? rangeTop : choice;
229
230 //select the detail to return
231 int aWeight = 0;
232
233 // Iterate through the list of choices until the weights (from each DataValue)
234 // are greater the num chosen as the 'choice'
235 for (String key : this)
236 {
237 Rule chkValue = (Rule) allVars.getDataElement(key);
238 int valueWeight = chkValue.getWeight();
239
240 if (valueWeight > 0)
241 {
242 aWeight += valueWeight;
243
244 if (aWeight >= choice)
245 {
246 retRule = chkValue;
247
248 return chkValue;
249 }
250 }
251 }
252
253 return retRule;
254 }
255
256 /**
257 * Get the rule given a choice

Callers 1

generateMethod · 0.95

Calls 7

getRangeMethod · 0.95
getIdMethod · 0.95
getWeightMethod · 0.95
parseIntMethod · 0.80
getValMethod · 0.80
rollMethod · 0.65
getDataElementMethod · 0.45

Tested by

no test coverage detected