From f89f308c525e9deebc6d2cf6416e27dfe1a299dc Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 19 May 2019 16:03:38 +0200 Subject: Cleanup DiscoBot Project --- DiscoBot/Auxiliary/Calculator/Argument.cs | 38 ----- DiscoBot/Auxiliary/Calculator/ISolvable.cs | 10 -- DiscoBot/Auxiliary/Calculator/Operator.cs | 50 ------ DiscoBot/Auxiliary/Calculator/Ops.cs | 13 -- DiscoBot/Auxiliary/Calculator/StringSolver.cs | 207 ------------------------ DiscoBot/Auxiliary/CommandExtension.cs | 98 +++++++++++ DiscoBot/Auxiliary/CommandInfo.cs | 32 ---- DiscoBot/Auxiliary/Dice.cs | 37 ++--- DiscoBot/Auxiliary/Extensions.cs | 33 ---- DiscoBot/Auxiliary/Permissions.cs | 32 ++++ DiscoBot/Auxiliary/RandomMisc.cs | 44 ++--- DiscoBot/Auxiliary/SpellCorrect.cs | 120 +++++--------- DiscoBot/Auxiliary/TalentEnumerableExtension.cs | 102 ------------ 13 files changed, 192 insertions(+), 624 deletions(-) delete mode 100644 DiscoBot/Auxiliary/Calculator/Argument.cs delete mode 100644 DiscoBot/Auxiliary/Calculator/ISolvable.cs delete mode 100644 DiscoBot/Auxiliary/Calculator/Operator.cs delete mode 100644 DiscoBot/Auxiliary/Calculator/Ops.cs delete mode 100644 DiscoBot/Auxiliary/Calculator/StringSolver.cs create mode 100644 DiscoBot/Auxiliary/CommandExtension.cs delete mode 100644 DiscoBot/Auxiliary/CommandInfo.cs delete mode 100644 DiscoBot/Auxiliary/Extensions.cs create mode 100644 DiscoBot/Auxiliary/Permissions.cs delete mode 100644 DiscoBot/Auxiliary/TalentEnumerableExtension.cs (limited to 'DiscoBot/Auxiliary') diff --git a/DiscoBot/Auxiliary/Calculator/Argument.cs b/DiscoBot/Auxiliary/Calculator/Argument.cs deleted file mode 100644 index 2379bfe..0000000 --- a/DiscoBot/Auxiliary/Calculator/Argument.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace DiscoBot.Auxiliary.Calculator -{ - using System; - - /// - /// Provides an ISolvable class to save numbers. The class handles Argument checking and conversion from string to int. - /// - public class Argument : ISolvable - { - private readonly int value; - - public Argument(string value) - { - // check whether the value given is an empty string - if (string.IsNullOrEmpty(value)) - { - throw new ArgumentException("Argument kann nicht mit einem leeren string instanziert werden. ", nameof(value)); - } - - if (!int.TryParse(value, out int result)) - { - throw new ArgumentException($"Kann {value} nicht in Integer konvertieren"); - } - - this.value = result; - } - - public int Solve() - { - return this.value; - } - - public override string ToString() - { - return this.value.ToString(); - } - } -} \ No newline at end of file diff --git a/DiscoBot/Auxiliary/Calculator/ISolvable.cs b/DiscoBot/Auxiliary/Calculator/ISolvable.cs deleted file mode 100644 index a869bdb..0000000 --- a/DiscoBot/Auxiliary/Calculator/ISolvable.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DiscoBot.Auxiliary.Calculator -{ - /// - /// Object has to be able to return an integer as it's value - /// - public interface ISolvable - { - int Solve(); - } -} diff --git a/DiscoBot/Auxiliary/Calculator/Operator.cs b/DiscoBot/Auxiliary/Calculator/Operator.cs deleted file mode 100644 index 0928ec2..0000000 --- a/DiscoBot/Auxiliary/Calculator/Operator.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; - -namespace DiscoBot.Auxiliary.Calculator -{ - /// - /// The Operator Class represents a binary operator with tow Arguments and an Operation type - /// - public class Operator : ISolvable - { - private readonly ISolvable arg1, arg2; - - public Operator(ISolvable arg1, ISolvable arg2, Ops operatorType) - { - this.arg1 = arg1; - this.arg2 = arg2; - this.OperatorType = operatorType; - } - - public Ops OperatorType { get; set; } - - public int Solve() - { - int result; - switch (this.OperatorType) - { - case Ops.Dice: - result = Dice.Roll(this.arg1.Solve(), this.arg2.Solve()); - break; - case Ops.Multiply: - result = this.arg1.Solve() * this.arg2.Solve(); - break; - case Ops.Add: - result = this.arg1.Solve() + this.arg2.Solve(); - break; - case Ops.Subtract: - result = this.arg1.Solve() - this.arg2.Solve(); - break; - default: - throw new ArgumentOutOfRangeException(); - } - - return result; - } - - public override string ToString() - { - return $"({this.arg1} {this.OperatorType} {this.arg2})"; - } - } -} diff --git a/DiscoBot/Auxiliary/Calculator/Ops.cs b/DiscoBot/Auxiliary/Calculator/Ops.cs deleted file mode 100644 index 62c1309..0000000 --- a/DiscoBot/Auxiliary/Calculator/Ops.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace DiscoBot.Auxiliary.Calculator -{ - /// - /// The Different Operations, witch can be performed in execution-order - /// - public enum Ops - { - Dice, - Multiply, - Subtract, - Add - } -} diff --git a/DiscoBot/Auxiliary/Calculator/StringSolver.cs b/DiscoBot/Auxiliary/Calculator/StringSolver.cs deleted file mode 100644 index 6e5b3a9..0000000 --- a/DiscoBot/Auxiliary/Calculator/StringSolver.cs +++ /dev/null @@ -1,207 +0,0 @@ -namespace DiscoBot.Auxiliary.Calculator -{ - using System; - using System.Collections.Generic; - using System.Linq; - - /// - /// The StringSolver divides the calculation string into operations and SubStringSolvers if the string contains parentheses - /// - public class StringSolver : ISolvable - { - public readonly string input; - public readonly List arguments = new List(); - - public StringSolver(string input) - { - this.input = input; - } - - public override string ToString() - { - return "(0+" + this.input.Replace(" ", string.Empty).ToLower() + ")"; - } - - public int Solve() - { - string workInput = "0+" + this.input.Replace(" ", string.Empty).ToLower(); - workInput = ExpandParentheses(workInput); - - // Create a List of the different parts of the calculation, e.g.:{"0", "+", "(5+6)", "d", "3"}. - this.AtomizeOperations(workInput); - - // traverse the List in order of Operation to Create the binary operation tree . - this.NestOperations(); - - // the List now contains only the top operation node, witch can be solved recursively, - return ((ISolvable)this.arguments.First()).Solve(); - } - - public static string GetInner(ref string input) // extract the inner bracket an remove the section from the input string - { - int depth = 0; - for (var index = 1; index < input.Length; index++) - { - char c = input[index]; - switch (c) - { - case '(': - depth++; - break; - case ')': - if (depth == 0) - { - var split = input.Substring(1, index - 1); - input = input.Substring(index + 1); - return split.Equals(string.Empty) ? "0" : split; - } - else - { - depth--; - } - - break; - } - } - - return string.Empty; - } - - public static Ops GetOps(char c) - { - switch (c) - { - case 'd': - case 'w': - return Ops.Dice; - case '+': - return Ops.Add; - case '-': - return Ops.Subtract; - case '*': - return Ops.Multiply; - default: - return Ops.Multiply; - } - } - - public static string ExpandParentheses(string input) // insert * between Parentheses and digits - { - for (int i = 0; i < input.Length - 1; i++) - { - if (input[i + 1] == '(' && char.IsNumber(input[i])) - { - input = input.Insert(i + 1, "*"); - } - } - - for (int i = 1; i < input.Length; i++) - { - if (input[i - 1] == ')' && char.IsNumber(input[i])) - { - input = input.Insert(i, "*"); - } - } - - return input; - } - - public void AtomizeOperations(string workInput) - { - for (var index = 0; index < workInput.Length; index++) - { - char c = workInput[index]; - - if (char.IsNumber(c)) - { - // if char number, check if at end of string, else continue looping - if (index == workInput.Length - 1) - { - // if at end of string; add remaining number to arguments - this.arguments.Add(new Argument(workInput.Substring(0, index + 1))); - } - - continue; - } - - switch (c) - { - case ')': - throw new ArgumentException($"Unmögliche Anordnung von Klammern"); - case '(': - this.arguments.Add(new StringSolver(GetInner(ref workInput))); - index = -1; - break; - default: - if (index > 0) - { - this.arguments.Add(new Argument(workInput.Substring(0, index))); - } - - this.arguments.Add(GetOps(c)); - workInput = workInput.Remove(0, index + 1); - index = -1; - break; - } - } - } - - public void NestOperations() - { - foreach (Ops currentOp in Enum.GetValues(typeof(Ops))) - { - // cycle through operators in operational order - for (var index = 0; index < this.arguments.Count; index++) - { - var arg = this.arguments[index]; - - if (arg.GetType() != typeof(Ops)) - { - continue; - } - - // arg is of type Ops - var op = (Ops)arg; - - if (op != currentOp) - { - continue; - } - - // arg describes the current operation - this.HandleSpecialFormatting(ref index, op); // Deal with special needs... - - // replace the previous current and next Element in the List with one Operation object - var temp = new Operator((ISolvable)this.arguments[index - 1], (ISolvable)this.arguments[index + 1], op); - this.arguments[index - 1] = temp; - this.arguments.RemoveRange(index, 2); - index--; - } - } - } - - public void HandleSpecialFormatting(ref int index, Ops op) - { - var arg1 = this.arguments[index - 1]; - if (arg1.GetType() == typeof(Ops)) - { - if (op == Ops.Dice) - { - this.arguments.Insert(index++, new Argument("1")); // w6 -> 1w6 - } - - if (op == Ops.Subtract) - { - this.arguments.Insert(index++, new Argument("0")); // +-3 -> +0-3 - } - } - - var arg2 = this.arguments[index + 1]; // 3+-5 -> 3+(0-5) - if (arg2.GetType() == typeof(Ops)) - { - this.arguments[index + 1] = new Operator(new Argument("0"), (ISolvable)this.arguments[index + 2], (Ops)arg2); - this.arguments.RemoveAt(index + 2); - } - } - } -} \ No newline at end of file diff --git a/DiscoBot/Auxiliary/CommandExtension.cs b/DiscoBot/Auxiliary/CommandExtension.cs new file mode 100644 index 0000000..ad9f323 --- /dev/null +++ b/DiscoBot/Auxiliary/CommandExtension.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; + +namespace DiscoBot.Auxiliary +{ + public static class CommandExtension + { + private static WebClient _client; + + public static async Task ReplyTimedAsync(this ModuleBase m, string message, TimeSpan time) + { + var token = message.GetHashCode(); + var send = m.Context.Channel.SendMessageAsync($"#{token}\n```xl\n{message}```"); + + var barInvoker = new BackgroundWorker(); + barInvoker.DoWork += delegate + { + Thread.Sleep(time); + Delete(token, m); + }; + + await send; + barInvoker.RunWorkerAsync(); + } + + private static void Delete(int token, ModuleBase m) + { + var messagesAsync = m.Context.Channel.GetMessagesAsync(); + Task.WaitAll(messagesAsync.ToArray()); + var list = messagesAsync.ToEnumerable().ToList(); + var messages = new List(); + foreach (var task in list) messages.AddRange(task.ToList()); + + var test = messages.Where(x => x.Content.StartsWith($"#{token}\n") && x.Author.IsBot).Select(c => c); + Task.WaitAll(test.Select(message => (message as IUserMessage)?.DeleteAsync()).ToArray()); + } + + public static async Task ReplyAsync(this ModuleBase m, IEnumerable message, bool directMessage = false) + { + var sb = new StringBuilder(); + foreach (var re in message) + { + if (sb.Length + re.Length > 1798) + { + if (directMessage) + await m.Context.User.SendMessageAsync("```xl\n" + sb + "\n```"); + else + await m.Context.Channel.SendMessageAsync("```xl\n" + sb + "\n```"); + + sb.Clear(); + } + + sb.AppendLine(re); + } + + if (directMessage) + await m.Context.User.SendMessageAsync("```xl\n" + sb + "\n```"); + else + await m.Context.Channel.SendMessageAsync("```xl\n" + sb + "\n```"); + } + + public static async Task ReplyAsync(this ModuleBase m, IEnumerable message, TimeSpan time) + { + var sb = new StringBuilder(); + foreach (var re in message) + { + if (sb.Length + re.Length > 1798) + { + await m.ReplyTimedAsync(sb.ToString(), time); + + + sb.Clear(); + } + + sb.AppendLine(re); + } + + await m.ReplyTimedAsync(sb.ToString(), TimeSpan.FromSeconds(90)); + } + + public static async Task SendWebFile(this IMessageChannel channel, + string url = "https://i.imgur.com/0iHEycJ.png") + { + if (_client == null) _client = new WebClient(); + + var stream = _client.OpenRead(url); + await channel.SendFileAsync(stream, url.Split('/').Last()); + } + } +} \ No newline at end of file diff --git a/DiscoBot/Auxiliary/CommandInfo.cs b/DiscoBot/Auxiliary/CommandInfo.cs deleted file mode 100644 index dfed417..0000000 --- a/DiscoBot/Auxiliary/CommandInfo.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DiscoBot.Auxiliary -{ - public struct CommandInfo - { - public CommandInfo(string name, string brief, string[] description, string scope) - { - this.Name = name; - this.Scope = scope; - this.Brief = brief; - this.Description = description; - } - - public string Name { get; } - - public string Scope { get; } - - public string Brief { get; } - - public string[] Description { get; } - - public string GetDescription() - { - return this.Description.Aggregate((s, c) => s + c); - } - } -} diff --git a/DiscoBot/Auxiliary/Dice.cs b/DiscoBot/Auxiliary/Dice.cs index 0cd9656..f0f4def 100644 --- a/DiscoBot/Auxiliary/Dice.cs +++ b/DiscoBot/Auxiliary/Dice.cs @@ -1,44 +1,25 @@ -namespace DiscoBot.Auxiliary -{ - using System; - using System.Linq; - - using Discord.Commands; +using System; +namespace DiscoBot.Auxiliary +{ public static class Dice // roll it! { - private static readonly System.Random Rnd = new System.Random(); + private static readonly Random Rnd = new 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; - } + if (d <= 0) return 0; - int sum = 0; - for (int i = 0; i < Math.Abs(count); i++) + var sum = 0; + for (var i = 0; i < Math.Abs(count); i++) { - var roll = Dice.Roll(d); + var roll = Roll(d); sum += roll; } @@ -47,4 +28,4 @@ return sum; } } -} +} \ No newline at end of file diff --git a/DiscoBot/Auxiliary/Extensions.cs b/DiscoBot/Auxiliary/Extensions.cs deleted file mode 100644 index fad5dd8..0000000 --- a/DiscoBot/Auxiliary/Extensions.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace DiscoBot.Auxiliary -{ - public static class StringExtension - { - //This mehod extends string. It adds spaces until a fixed length is reached. - //If the original string is already longer, it is returner unmodified. - public static string AddSpaces(this string str, int length) - { - string temp = str; - for(int i = str.Length; i < length; i++) - { - temp += " "; - } - return temp; - } - - - - //This mehod extends string. - //It adds spaces at the HEAD of a string until a fixed length is reached. - //If the original string is already longer, it is returner unmodified. - public static string AddSpacesAtHead(this string str, int length) - { - string temp = ""; - for (int i = str.Length; i < length; i++) - { - temp += " "; - } - return temp + str; - } - } - -} diff --git a/DiscoBot/Auxiliary/Permissions.cs b/DiscoBot/Auxiliary/Permissions.cs new file mode 100644 index 0000000..3ec4a2e --- /dev/null +++ b/DiscoBot/Auxiliary/Permissions.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Linq; +using Discord.Commands; +using Discord.WebSocket; + +namespace DiscoBot.Auxiliary +{ + public static class Permissions + { + public static bool Check(ICommandContext c, string role) + { + return ((SocketGuildUser) c.User).Roles.ToList().Exists(v => v.Name.Equals(role)); + } + + public static bool Check(ICommandContext c, IEnumerable roles) + { + return roles.Any(role => ((SocketGuildUser) c.User).Roles.ToList().Exists(v => v.Name.Equals(role))); + } + + public static bool Test(ICommandContext c, string role) + { + if (Check(c, role)) return true; + c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait(); + return false; + } + + public static void Test(ICommandContext c, string[] roles) + { + if (!Check(c, roles)) c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait(); + } + } +} \ No newline at end of file diff --git a/DiscoBot/Auxiliary/RandomMisc.cs b/DiscoBot/Auxiliary/RandomMisc.cs index 7ba625e..205b3a7 100644 --- a/DiscoBot/Auxiliary/RandomMisc.cs +++ b/DiscoBot/Auxiliary/RandomMisc.cs @@ -1,52 +1,36 @@ -namespace DiscoBot.Auxiliary -{ - using System; - using System.Linq; - using System.Text; +using System; +using System.Linq; +using System.Text; +namespace DiscoBot.Auxiliary +{ public static class RandomMisc { - private static readonly Random Rand = new Random(); - - // use: 4w6 +4 public static string Roll(string input) { var output = new StringBuilder(); var strings = input.Split('w', 'd').ToList(); - int count = Convert.ToInt32(strings[0]); + var count = Convert.ToInt32(strings[0]); strings = strings[1].Split(' ').ToList(); - int d = Convert.ToInt32(strings[0]); + var d = Convert.ToInt32(strings[0]); if (strings.Count > 0) { } - int sum = 0; - for (int i = 0; i < count; i++) + var sum = 0; + for (var i = 0; i < count; i++) { var roll = Dice.Roll(d); sum += roll; output.Append("[" + roll + "] "); } - - if (strings.Count > 1) - { - sum += Convert.ToInt32(strings[1]); - output.Append("sum: " + sum); - } - return output.ToString(); - } + if (strings.Count <= 1) return output.ToString(); + sum += Convert.ToInt32(strings[1]); + output.Append("sum: " + sum); - public static double Random(double stdDev = 1, double mean = 0) - { - double u1 = Rand.NextDouble(); // uniform(0,1) random doubles - double u2 = Rand.NextDouble(); - double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * - Math.Sin(2.0 * Math.PI * u2); // random normal(0,1) - double randNormal = - mean + stdDev * randStdNormal; // random normal(mean,stdDev^2) - return randNormal; + return output.ToString(); } } -} +} \ No newline at end of file diff --git a/DiscoBot/Auxiliary/SpellCorrect.cs b/DiscoBot/Auxiliary/SpellCorrect.cs index 01cce62..c4bd4bf 100644 --- a/DiscoBot/Auxiliary/SpellCorrect.cs +++ b/DiscoBot/Auxiliary/SpellCorrect.cs @@ -1,9 +1,8 @@ -namespace DiscoBot.Auxiliary -{ - using System; - using System.Diagnostics; - using System.Linq; +using System; +using System.Diagnostics; +namespace DiscoBot.Auxiliary +{ public class SpellCorrect : StringComparer { public const int ErrorThreshold = 94100; @@ -15,44 +14,25 @@ public static int CompareEasy(string x, string y) { - if (string.IsNullOrEmpty(x)) - { - throw new ArgumentException("message", nameof(x)); - } + if (string.IsNullOrEmpty(x)) throw new ArgumentException("message", nameof(x)); - if (string.IsNullOrEmpty(y)) - { - throw new ArgumentException("message", nameof(y)); - } + if (string.IsNullOrEmpty(y)) throw new ArgumentException("message", nameof(y)); - if (x.Equals(y)) - { - return 0; - } + if (x.Equals(y)) return 0; x = x.ToLower(); y = y.ToLower(); - if (x.Equals(y)) - { - return 1; - } + if (x.Equals(y)) return 1; var subs = y.Split(' ', '/'); - int score = subs.Count(); - foreach (string s in subs) - { + var score = subs.Length; + foreach (var s in subs) if (s.Equals(x)) - { score--; - } - } - if (score < subs.Count()) - { - return score + 1; - } + if (score < subs.Length) return score + 1; - return 100000 - (int)(CompareExact(x, y) * 1000.0); + return 100000 - (int) (CompareExact(x, y) * 1000.0); /*if (y.Contains(x)) return 6;*/ } @@ -70,78 +50,56 @@ public static double CompareExact(string s, string q) { - s = s.ToLower(); q = q.ToLower(); int i, j; - const double Match = 3.0; - const double Gap = -2.0; - const double Mismatch = -2.0; + const double match = 3.0; + const double gap = -2.0; + const double mismatch = -2.0; double decay; - double[,] matrix = new double[s.Length + 1, q.Length + 1]; - double max = 0.0; + var matrix = new double[s.Length + 1, q.Length + 1]; + var max = 0.0; matrix[0, 0] = 0.0; - + for (i = 1; i < s.Length; i++) - { - // matrix[i, 0] = 0.0; - matrix[i, 0] = i * Gap; - } + // matrix[i, 0] = 0.0; + matrix[i, 0] = i * gap; - for (i = 1; i < q.Length; i++) - { - matrix[0, i] = 0.0; - } + for (i = 1; i < q.Length; i++) matrix[0, i] = 0.0; for (i = 1; i <= s.Length; i++) + for (j = 1; j <= q.Length; j++) { - for (j = 1; j <= q.Length; j++) - { - decay = j / (double)(s.Length * 1000); - double add = s[i - 1] == q[j - 1] ? (Match - decay) : Mismatch; - double score = matrix[i - 1, j - 1] + add; + decay = j / (double) (s.Length * 1000); + var add = s[i - 1] == q[j - 1] ? match - decay : mismatch; + var score = matrix[i - 1, j - 1] + add; - if (score < (matrix[i - 1, j] + Gap)) - { - score = matrix[i - 1, j] + Gap; - } + if (score < matrix[i - 1, j] + gap) score = matrix[i - 1, j] + gap; - if (score < (matrix[i, j - 1] + Gap)) - { - score = matrix[i, j - 1] + Gap; - } + if (score < matrix[i, j - 1] + gap) score = matrix[i, j - 1] + gap; - if (i > 1 && j > 1) + if (i > 1 && j > 1) + if (s[i - 1] == q[j - 2] && s[i - 2] == q[j - 1]) { - if (s[i - 1] == q[j - 2] && s[i - 2] == q[j - 1]) - { - add = (3 / 2.0) * Match - decay; - if (score < matrix[i - 2, j - 2] + add) - { - score = matrix[i - 2, j - 2] + add; - } - } + add = 3 / 2.0 * match - decay; + if (score < matrix[i - 2, j - 2] + add) score = matrix[i - 2, j - 2] + add; } - - // if (score < 0) - // { - // score = 0; - // } - if (max < score && i == s.Length) - { - max = score; - } + // if (score < 0) + // { + // score = 0; + // } + + if (max < score && i == s.Length) max = score; - matrix[i, j] = score; - } + matrix[i, j] = score; } return max; } } -} +} \ No newline at end of file diff --git a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs b/DiscoBot/Auxiliary/TalentEnumerableExtension.cs deleted file mode 100644 index df01de3..0000000 --- a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; -using DSALib; - - -namespace DiscoBot.Auxiliary -{ - using DiscoBot.Audio; - using DiscoBot.DSA_Game.Characters; - - - public static class TalentEnumerableExtension - { - public static string ProbenTest(this IEnumerable List, Character c, string talent, int erschwernis = 0) - { - var output = new StringBuilder(); - var sc = new SpellCorrect(); - var tTalent = List.OrderBy(x => sc.Compare(talent, x.Name)).First(); - - if (sc.Compare(talent, tTalent.Name) > SpellCorrect.ErrorThreshold) - { - try - { - SoundEffects.Play("Stupid"); - } - catch { } - return $"{c.Name} kann nicht {talent}..."; - } - - var props = tTalent.GetEigenschaften(); // get the required properties - int tap = tTalent.Value; // get taw - var werte = props.Select(p => c.Eigenschaften[c.PropTable[p]]).ToList(); - - output.AppendFormat( - "{0} würfelt: {1} \n{2} - {3} taw:{4} {5} \n", - c.Name, - tTalent.Name, - tTalent.Probe, - string.Join("/", werte), - tTalent.Value, - erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); - - output.Append(" "); - tap -= erschwernis; - int gesamtErschwernis = tap; - if (gesamtErschwernis < 0) - { - tap = 0; - for (int i = 0; i <= 2; i++) - { - // foreach property, dice and tap - int temp = Dice.Roll(); - int eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; - - if (eigenschaft + gesamtErschwernis < temp) - { - tap -= temp - (eigenschaft + gesamtErschwernis); - } - - output.Append($"[{temp}]"); // add to string - } - - if (tap >= 0) - { - tap = 1; - } - } - else - { - for (int i = 0; i <= 2; i++) - { - // foreach property, dice and tap - int temp = Dice.Roll(); - int eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; - - if (eigenschaft < temp) - { - tap -= temp - eigenschaft; - } - - output.Append($"[{temp}]"); // add to string - } - } - - tap = (tap == 0) ? 1 : tap; - - if (tap < 0) - { - try - { - SoundEffects.Play("Wrong"); - } - catch { } - } - - output.AppendFormat(" tap: {0,2}", tap); - - return output.ToString(); // return output - } - } -} -- cgit v1.2.3-54-g00ecf