Beispiel #1
0
        /// <summary>Roll one or more CustomDice. Returns the total value of the rolled Dice</summary>
        public static int RollCustomDice(Die.CustomDie _customDice, int _numOfDice)
        {
            int result = 0;

            for (int i = 0; i < _numOfDice; i++)
            {
                result += RollCustomDice(_customDice);
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>Roll a custom Die. Returns the value of the rolled side</summary>
        public static int RollCustomDice(Die.CustomDie _customDie)
        {
            float totalWeight = 0;

            for (int i = 0; i < _customDie.Sides.Length; i++)
            {
                totalWeight += _customDie.Sides[i].W;
            }

            float weightResult = (float)R.Next(0, 100) / 100 * totalWeight;

            float processedWeight = 0;

            for (int i = 0; i < _customDie.Sides.Length; i++)
            {
                processedWeight += _customDie.Sides[i].W;
                if (weightResult <= processedWeight)
                {
                    return(_customDie.Sides[i].V);
                }
            }
            return(0);
        }