public AttackRoll(Attack attack) : base(attack.attacker.encounter) { this.attack = attack; GetSource(attack); die = 20; DC = attack.defender.AC; roller = attack.attacker; bonus = attack.GetAttackBonus(); advantage = attack.GetAdvantage(); disadvantage = attack.GetDisadvantage(); finishRoll += new RollDelegate(attack.FinishAttackRoll); }
public SavingThrow(Stats stat, Creature creature, Object source, List <string> tags = null) : base(creature.encounter, tags) { roller = creature; this.source = source; this.stat = stat; bonus = creature.StatMod(stat); if (creature.Proficiencies.Contains(stat.ToString())) { bonus += creature.proficiencyBonus; } if (source is Spell) { finishRoll += new RollDelegate((source as Spell).SavingThrowFinished); } }
/// <summary> /// Roll a single die for its quantity and return an array with the results /// </summary> /// <param name="die"></param> /// <returns></returns> private List <int> RollDie(Die die) { List <int> dieRolls = new List <int>(); RollDelegate callback = this.Standard; int sides = die.Sides; // Ensure roll quantity is valid die.Quantity = (die.Quantity > 0) ? die.Quantity : 1; // Check for non-numerical dice formats if (die.Fudge) { // We have a fudge dice. Set the callback to fudge callback = this.Fudge; // Set the sides to the correct value for the fudge type if (die.FudgeString.Length < 2 || !int.TryParse(die.FudgeString[1].ToString(), out sides)) { // Well, it's not a number. Use default sides = 2; } } else if (die.SidesString == "%") { // It's a percentile sides = 100; } if (sides > 0) { List <int> rerolls; int rollCount = 0; int rerollIndex = 0; int roll = 0; // Loop through and roll for the quantity for (int i = 0; i < die.Quantity; ++i) { rerolls = new List <int> (); rollCount = 0; roll = 0; rerollIndex = 0; // Roll the die once, then check if it exploded and keep rolling until it stops do { rerollIndex = rerolls.Count; // Get total roll on this die roll = callback.Invoke(sides); // Add the roll to our list //rerolls[rerollIndex] = rerolls[rerollIndex] + roll; rerolls.Add(roll); // Subtract 1 from penetrated rolls (only consecutive rolls, after initial roll are not subtracted) if (die.Penetrate && rollCount > 0) { rerolls[rerollIndex]--; } rollCount++; } while (die.Explode && IsComparePoint(die.ComparePoint, roll)); // Add the rolls dieRolls.AddRange(rerolls); } } return(dieRolls); }