Search in sources :

Example 6 with Dice

use of gmgen.plugin.dice.Dice in project pcgen by PCGen.

the class RuleSet method getRule.

/**
	 * Get the rule
	 * 
	 * @return rule
	 * @throws Exception
	 */
public Rule getRule() throws Exception {
    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) {
                retRule = chkValue;
                return chkValue;
            }
        }
    }
    return retRule;
}
Also used : Dice(gmgen.plugin.dice.Dice)

Example 7 with Dice

use of gmgen.plugin.dice.Dice in project pcgen by PCGen.

the class EncounterPlugin method rollHP.

private static void rollHP(PlayerCharacter aPC) {
    CharacterDisplay display = aPC.getDisplay();
    for (PCClass pcClass : display.getClassSet()) {
        for (int j = 0; j < display.getLevel(pcClass); j++) {
            int bonus = (int) aPC.getTotalBonusTo("HD", "MIN") + (int) aPC.getTotalBonusTo("HD", "MIN;CLASS." + pcClass.getKeyName());
            int size = display.getLevelHitDie(pcClass, j + 1).getDie();
            PCClassLevel classLevel = display.getActiveClassLevel(pcClass, j);
            aPC.setHP(classLevel, new Dice(1, size, bonus).roll());
        }
    }
    aPC.setDirty(true);
}
Also used : CharacterDisplay(pcgen.core.display.CharacterDisplay) Dice(gmgen.plugin.dice.Dice) PCClass(pcgen.core.PCClass) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Aggregations

Dice (gmgen.plugin.dice.Dice)7 State (gmgen.plugin.State)1 Die (gmgen.plugin.dice.Die)1 PCClassLevel (pcgen.cdom.inst.PCClassLevel)1 PCClass (pcgen.core.PCClass)1 CharacterDisplay (pcgen.core.display.CharacterDisplay)1