use of gmgen.plugin.dice.Dice in project pcgen by PCGen.
the class DDList method getData.
@Override
public ArrayList<DataValue> getData() {
retList.clear();
int rangeTop = getRange();
int modifier;
try {
modifier = Integer.parseInt(allVars.getVal(getId() + "modifier"));
} catch (Exception e) {
modifier = 0;
}
// Determine which entry to choose
Dice die = new Dice(1, rangeTop, 0);
int choice = die.roll();
choice += modifier;
choice = (choice < 0) ? rangeTop : choice;
//select the detail to return
int aWeight = 0;
//Iterate through the list of choices until the weights (from each DataValue) are greater the num chosen as the 'choice'
for (WeightedDataValue chkValue : this) {
int valueWeight = chkValue.getWeight();
if (valueWeight > 0) {
aWeight += valueWeight;
if (aWeight >= choice) {
retList.add(chkValue);
break;
}
}
}
return retList;
}
use of gmgen.plugin.dice.Dice in project pcgen by PCGen.
the class Initiative method bleed.
private void bleed(Combatant cbt) {
if (cbt.getStatus() == State.Bleeding) {
int stableType = SettingsHandler.getGMGenOption(InitiativePlugin.LOG_NAME + ".Damage.Stable", PreferencesDamagePanel.DAMAGE_STABLE_PERCENT);
if (stableType == PreferencesDamagePanel.DAMAGE_STABLE_PERCENT) {
int roll = new Dice(1, 100).roll();
if (roll <= 10) {
cbt.stabilize();
writeToCombatTabWithRound(cbt.getName() + " (" + cbt.getPlayer() + ") auto-stabilized (" + roll + "%)");
} else {
writeToCombatTabWithRound(cbt.getName() + " (" + cbt.getPlayer() + ") failed to auto-stabilize (" + roll + "%)");
}
} else if (stableType == PreferencesDamagePanel.DAMAGE_STABLE_SAVE) {
SavingThrowDialog dialog = new SavingThrowDialog(GMGenSystem.inst, true, cbt, 20, SavingThrowDialog.FORT_SAVE);
dialog.setVisible(true);
dialog.dispose();
//Show the dialog and get it's results
int returnVal = dialog.getReturnValue();
int roll = dialog.getRoll();
int total = dialog.getTotal();
int dc = dialog.getDC();
//stabilize if the combatant passes the save
if (dialog.getReturnValue() == SavingThrowDialog.PASS_OPTION) {
cbt.stabilize();
}
//Create a message out with the results
StringBuilder sb = new StringBuilder();
sb.append(dialog.getSaveAbbrev(dialog.getSaveType()));
sb.append(" save DC " + dc);
if (roll > 0) {
sb.append(" with a roll of " + (roll + total));
sb.append(" (" + total + " + Roll: " + roll + ')');
}
//write out the results to the combat tab
if (returnVal == SavingThrowDialog.PASS_OPTION) {
writeToCombatTabWithRound(cbt.getName() + " (" + cbt.getPlayer() + ") Passed a " + sb + " to auto-stabilize");
} else if (returnVal == SavingThrowDialog.FAIL_OPTION) {
writeToCombatTabWithRound(cbt.getName() + " (" + cbt.getPlayer() + ") Failed a " + sb + " to auto-stabilize");
}
}
State oldStatus = cbt.getStatus();
cbt.bleed();
combatantUpdated(cbt);
State newStatus = cbt.getStatus();
if ((oldStatus != newStatus) && (newStatus == State.Dead)) {
combatantDied(cbt);
}
}
}
use of gmgen.plugin.dice.Dice in project pcgen by PCGen.
the class SavingThrowDialog method roll.
private void roll() {
int total = getFieldValue(saveTotal);
int dc = getFieldValue(saveDC);
int roll = new Dice(1, 20).roll();
if ((total + roll) >= dc) {
retValue = PASS_OPTION;
JOptionPane.showMessageDialog(this, getSaveAbbrev(getSaveType()) + " DC " + dc + " Passed. Save: " + total + " + Roll: " + roll + " = " + (total + roll), "Save Passed", JOptionPane.INFORMATION_MESSAGE);
} else {
retValue = FAIL_OPTION;
JOptionPane.showMessageDialog(this, getSaveAbbrev(getSaveType()) + " DC " + dc + " Failed. Save: " + total + " + Roll: " + roll + " = " + (total + roll), "Save Failed", JOptionPane.INFORMATION_MESSAGE);
}
updateModel();
this.lastRoll = roll;
setVisible(false);
dispose();
}
use of gmgen.plugin.dice.Dice in project pcgen by PCGen.
the class InitHolderList method check.
/** Rolls an initiative check for the whole list */
public void check() {
Die d20 = new Dice(1, 20);
boolean pcroll = SettingsHandler.getGMGenOption(InitiativePlugin.LOG_NAME + ".rollPCInitiatives", true);
for (InitHolder c : this) {
int roll = d20.roll();
boolean doroll = true;
if (!pcroll && c instanceof Combatant) {
Combatant com = (Combatant) c;
if (com.getCombatantType().equals("PC")) {
doroll = false;
}
}
if (doroll) {
c.getInitiative().checkExtRoll(roll);
} else {
c.getInitiative().resetCurrentInitiative();
}
}
this.sort();
calculateNumberField();
}
use of gmgen.plugin.dice.Dice in project pcgen by PCGen.
the class RuleSet method getData.
/**
* Get the data
*
* @return A list of data
* @throws Exception
*/
@Override
public ArrayList<DataValue> getData() throws Exception {
retList.clear();
int rangeTop = getRange();
int modifier;
try {
modifier = Integer.parseInt(allVars.getVal(getId() + "modifier"));
} catch (Exception e) {
modifier = 0;
}
// Determine which entry to choose
Dice die = new Dice(1, rangeTop, 0);
int choice = die.roll();
choice = choice + modifier;
choice = (choice < 0) ? rangeTop : choice;
//select the detail to return
int aWeight = 0;
//Iterate through the list of choices until the weights (from each DataValue) are greater the num chosen as the 'choice'
for (String key : this) {
Rule chkValue = (Rule) allVars.getDataElement(key);
int valueWeight = chkValue.getWeight();
if (valueWeight > 0) {
aWeight = aWeight + valueWeight;
if (aWeight >= choice) {
retList.addAll(chkValue.getData());
break;
}
}
}
return retList;
}
Aggregations