| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public List<DataValue> getData() |
| 61 | { |
| 62 | retList.clear(); |
| 63 | |
| 64 | int rangeTop = getRange(); |
| 65 | int modifier; |
| 66 | |
| 67 | try |
| 68 | { |
| 69 | modifier = Integer.parseInt(allVars.getVal(getId() + "modifier")); |
| 70 | } |
| 71 | catch (NumberFormatException | variableException e) |
| 72 | { |
| 73 | modifier = 0; |
| 74 | } |
| 75 | |
| 76 | // Determine which entry to choose |
| 77 | Dice die = new Dice(1, rangeTop, 0); |
| 78 | int choice = die.roll(); |
| 79 | choice += modifier; |
| 80 | choice = (choice < 0) ? rangeTop : choice; |
| 81 | |
| 82 | //select the detail to return |
| 83 | int aWeight = 0; |
| 84 | |
| 85 | // Iterate through the list of choices until the weights (from each DataValue) |
| 86 | // are greater the num chosen as the 'choice' |
| 87 | for (WeightedDataValue chkValue : this) |
| 88 | { |
| 89 | int valueWeight = chkValue.getWeight(); |
| 90 | |
| 91 | if (valueWeight > 0) |
| 92 | { |
| 93 | aWeight += valueWeight; |
| 94 | |
| 95 | if (aWeight >= choice) |
| 96 | { |
| 97 | retList.add(chkValue); |
| 98 | |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return retList; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Set the id of the list |