コード例 #1
0
        public string RollDice(IUser user, List <string> arguments)
        {
            DiceRollerFunctions functions = new DiceRollerFunctions();
            StringBuilder       message   = new StringBuilder();
            int diceCount = 1;

            functions.MultiplierAsString = String.Empty;

            if (arguments.Count > 1)
            {
                diceCount = int.Parse(arguments[(int)DiceRollerFunctions.Arguments.numberOfDice]);
                var numberOfFaces = int.Parse(arguments[(int)DiceRollerFunctions.Arguments.numberOfFaces]);

                functions.DiceCount     = diceCount;
                functions.NumberOfFaces = numberOfFaces;
            }
            else
            {
                functions.DiceCount     = diceCount;
                functions.NumberOfFaces = int.Parse(arguments[(int)DiceRollerFunctions.Arguments.numberOfFaces]);
            }

            if (!functions.ValidateDiceFaceNumber())
            {
                message.AppendLine($"{user.Mention}, there is an invalid number of die faces. You may only roll a D4, D6, D8, D10, D12, D20 or D100.");
                return(message.ToString());
            }


            var result    = functions.RollAllDice();
            var resultSum = result.Sum();

            if (arguments.Count == 3)
            {
                functions.MultiplierAsString = arguments[(int)DiceRollerFunctions.Arguments.multiplier];
                resultSum += functions.GetMultiplier();

                if (!ArgumentHasValidSymbol(functions.MultiplierAsString[0]))
                {
                    functions.MultiplierAsString = String.Empty;
                }
            }

            message.AppendLine($"*{user.Mention} rolled {diceCount} D{functions.NumberOfFaces} with a multiplier of {(string.IsNullOrEmpty(functions.MultiplierAsString) ? "0" : functions.MultiplierAsString)}*");
            message.AppendLine($"**{string.Join(", ", result)}**");
            message.AppendLine($"The sum of your rolled dice including multiplier is **{resultSum}**");

            return(message.ToString());
        }
コード例 #2
0
        public string RollWithDisadvantage(IUser user, int multiplier)
        {
            DiceRollerFunctions functions = new DiceRollerFunctions();
            StringBuilder       message   = new StringBuilder();

            functions.DiceCount     = 2;
            functions.NumberOfFaces = 20;

            List <int> rolledDice  = functions.RollAllDice();
            int        lowestValue = functions.TakeLowestValue(rolledDice);

            message.AppendLine($"{user.Mention} rolled with disadvantage.");
            message.AppendLine($"You rolled: **{string.Join(" and ", rolledDice)}** with a multiplier of **{multiplier}**");
            message.AppendLine($"The lowest value including multiplier is: {lowestValue + multiplier}");

            return(message.ToString());
        }