Пример #1
0
        /// <summary>
        /// Evaluates the term (as well as the dice expression), returning the sum of the highest n
        /// rolls in the dice term.
        /// </summary>
        /// <param name="rng">The rng to use -- passed to the dice term being operated on.</param>
        /// <returns>
        /// The sum of the highest n rolls of the dice term being operated on, where n is equal to
        /// the value of the keep variable taken in the constructor.
        /// </returns>
        public int GetResult(IGenerator rng)
        {
            int keepVal = keep.GetResult(rng);

            if (keepVal < 0)
            {
                throw new Exceptions.InvalidChooseException();
            }

            diceTerm.GetResult(rng); // Roll so we can check chooses

            if (keepVal > diceTerm.LastMultiplicity)
            {
                throw new Exceptions.InvalidChooseException();
            }

            return(diceTerm.DiceResults.OrderByDescending(value => value).Take(keepVal).Sum());
        }
Пример #2
0
        /// <summary>
        /// Evaluates the term (as well as the dice expression), returning the sum of the highest n
        /// rolls in the dice term.
        /// </summary>
        /// <param name="rng">The rng to use -- passed to the dice term being operated on.</param>
        /// <returns>
        /// The sum of the highest n rolls of the dice term being operated on, where n is equal to
        /// the value of the keep variable taken in the constructor.
        /// </returns>
        public int GetResult(IEnhancedRandom rng)
        {
            var keepVal = Keep.GetResult(rng);

            if (keepVal < 0)
            {
                throw new InvalidChooseException();
            }

            DiceTerm.GetResult(rng); // Roll so we can check chooses

            if (keepVal > DiceTerm.LastMultiplicity)
            {
                throw new InvalidChooseException();
            }

            return(DiceTerm.DiceResults.OrderByDescending(value => value).Take(keepVal).Sum());
        }