| 23 | import gmgen.plugin.dice.Dice; |
| 24 | |
| 25 | public class DDList extends ArrayList<WeightedDataValue> implements DataElement |
| 26 | { |
| 27 | private final List<DataValue> retList = new ArrayList<>(); |
| 28 | private String id; |
| 29 | private String title; |
| 30 | private final VariableHashMap allVars; |
| 31 | private int weight; |
| 32 | |
| 33 | /** |
| 34 | * Constructor |
| 35 | * @param allVars |
| 36 | * @param title |
| 37 | * @param id |
| 38 | */ |
| 39 | public DDList(VariableHashMap allVars, String title, String id) |
| 40 | { |
| 41 | this(allVars, title, id, 1); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Constructor |
| 46 | * @param allVars |
| 47 | * @param title |
| 48 | * @param id |
| 49 | * @param weight |
| 50 | */ |
| 51 | private DDList(VariableHashMap allVars, String title, String id, int weight) |
| 52 | { |
| 53 | this.allVars = allVars; |
| 54 | this.title = title; |
| 55 | this.id = id; |
| 56 | this.weight = weight; |
| 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 |
nothing calls this directly
no outgoing calls
no test coverage detected