diff options
author | TrueDoctor <d-kobert@web.de> | 2018-09-26 20:51:37 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-09-26 20:51:37 +0200 |
commit | b411aa2128c2724bec0ecedb8cb4e1ffa59f3b53 (patch) | |
tree | 14e0a0cca2cf66b95fda402c8c7d7b6bd5b7b222 /DSACore/Auxiliary/Dice.cs | |
parent | 92e8bb7523c775014ccf68355e3f0178ebf4a61c (diff) |
disconnected most vital calles from the Discord Bot
Diffstat (limited to 'DSACore/Auxiliary/Dice.cs')
-rw-r--r-- | DSACore/Auxiliary/Dice.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/DSACore/Auxiliary/Dice.cs b/DSACore/Auxiliary/Dice.cs new file mode 100644 index 0000000..2df8aa7 --- /dev/null +++ b/DSACore/Auxiliary/Dice.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq; + +namespace DSACore.Auxiliary +{ + public static class Dice // roll it! + { + private static readonly System.Random Rnd = new System.Random(); + + public static int Roll(int d = 20) + { + return Rnd.Next(d) + 1; + } + + public static int Roll(string input) + { + var strings = input.ToLower().Split(new[] { 'w', 'd' }, 2, StringSplitOptions.RemoveEmptyEntries).ToList(); + int count = Convert.ToInt32(strings[0]); + int d = Convert.ToInt32(strings[0]); + + if (strings.Count != 2) + { + throw new ArgumentException($"{input}: erfüllt nicht die Formatvogaben( Anzahl d Augenzahl)"); + } + + return Roll(count, d); + } + + public static int Roll(int count, int d) + { + if (d <= 0) + { + return 0; + } + + int sum = 0; + for (int i = 0; i < Math.Abs(count); i++) + { + var roll = Dice.Roll(d); + sum += roll; + } + + sum *= Math.Abs(count) / count; + + return sum; + } + } +} |