Get the data @return A list of data @throws Exception
()
| 90 | * @throws Exception |
| 91 | */ |
| 92 | @Override |
| 93 | public List<DataValue> getData() throws Exception |
| 94 | { |
| 95 | retList.clear(); |
| 96 | |
| 97 | int rangeTop = getRange(); |
| 98 | int modifier; |
| 99 | |
| 100 | try |
| 101 | { |
| 102 | modifier = Integer.parseInt(allVars.getVal(getId() + "modifier")); |
| 103 | } |
| 104 | catch (Exception e) |
| 105 | { |
| 106 | modifier = 0; |
| 107 | } |
| 108 | |
| 109 | // Determine which entry to choose |
| 110 | Dice die = new Dice(1, rangeTop, 0); |
| 111 | int choice = die.roll(); |
| 112 | choice += modifier; |
| 113 | choice = (choice < 0) ? rangeTop : choice; |
| 114 | |
| 115 | //select the detail to return |
| 116 | int aWeight = 0; |
| 117 | |
| 118 | // Iterate through the list of choices until the weights (from each DataValue) |
| 119 | // are greater the num chosen as the 'choice' |
| 120 | for (String key : this) |
| 121 | { |
| 122 | DataElement chkValue = allVars.getDataElement(key); |
| 123 | int valueWeight = chkValue.getWeight(); |
| 124 | |
| 125 | if (valueWeight > 0) |
| 126 | { |
| 127 | aWeight += valueWeight; |
| 128 | |
| 129 | if (aWeight >= choice) |
| 130 | { |
| 131 | retList.addAll(chkValue.getData()); |
| 132 | |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return retList; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Set the id |