diff options
Diffstat (limited to 'DSACore')
55 files changed, 613 insertions, 904 deletions
diff --git a/DSACore/Audio/Sound.cs b/DSACore/Audio/Sound.cs index d259850..aee3060 100644 --- a/DSACore/Audio/Sound.cs +++ b/DSACore/Audio/Sound.cs @@ -4,9 +4,9 @@ { public Sound(string name, string url, int volume) { - this.Name = name; - this.Url = url; - this.Volume = volume; + Name = name; + Url = url; + Volume = volume; } public string Name { get; } @@ -15,4 +15,4 @@ public int Volume { get; } } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/Calculator/Argument.cs b/DSACore/Auxiliary/Calculator/Argument.cs index 52f33a9..5ed9ee3 100644 --- a/DSACore/Auxiliary/Calculator/Argument.cs +++ b/DSACore/Auxiliary/Calculator/Argument.cs @@ -1,9 +1,9 @@ -namespace DSACore.Auxiliary.Calculator +using System; + +namespace DSACore.Auxiliary.Calculator { - using System; - /// <summary> - /// Provides an ISolvable class to save numbers. The class handles Argument checking and conversion from string to int. + /// Provides an ISolvable class to save numbers. The class handles Argument checking and conversion from string to int. /// </summary> public class Argument : ISolvable { @@ -12,27 +12,24 @@ 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 (string.IsNullOrEmpty(value)) + throw new ArgumentException("Argument kann nicht mit einem leeren string instanziert werden. ", + nameof(value)); - if (!int.TryParse(value, out int result)) - { + if (!int.TryParse(value, out var result)) throw new ArgumentException($"Kann {value} nicht in Integer konvertieren"); - } this.value = result; } public int Solve() { - return this.value; + return value; } public override string ToString() { - return this.value.ToString(); + return value.ToString(); } } }
\ No newline at end of file diff --git a/DSACore/Auxiliary/Calculator/ISolvable.cs b/DSACore/Auxiliary/Calculator/ISolvable.cs index 1f571d0..7be4d19 100644 --- a/DSACore/Auxiliary/Calculator/ISolvable.cs +++ b/DSACore/Auxiliary/Calculator/ISolvable.cs @@ -1,10 +1,10 @@ namespace DSACore.Auxiliary.Calculator { /// <summary> - /// Object has to be able to return an integer as it's value + /// Object has to be able to return an integer as it's value /// </summary> public interface ISolvable { int Solve(); } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/Calculator/Operator.cs b/DSACore/Auxiliary/Calculator/Operator.cs index 440e21e..31b2a9b 100644 --- a/DSACore/Auxiliary/Calculator/Operator.cs +++ b/DSACore/Auxiliary/Calculator/Operator.cs @@ -4,7 +4,7 @@ using DSACorev.Auxiliary.Calculator; namespace DSACore.Auxiliary.Calculator { /// <summary> - /// The Operator Class represents a binary operator with tow Arguments and an Operation type + /// The Operator Class represents a binary operator with tow Arguments and an Operation type /// </summary> public class Operator : ISolvable { @@ -14,7 +14,7 @@ namespace DSACore.Auxiliary.Calculator { this.arg1 = arg1; this.arg2 = arg2; - this.OperatorType = operatorType; + OperatorType = operatorType; } public Ops OperatorType { get; set; } @@ -22,19 +22,19 @@ namespace DSACore.Auxiliary.Calculator public int Solve() { int result; - switch (this.OperatorType) + switch (OperatorType) { case Ops.Dice: - result = Dice.Roll(this.arg1.Solve(), this.arg2.Solve()); + result = Dice.Roll(arg1.Solve(), arg2.Solve()); break; case Ops.Multiply: - result = this.arg1.Solve() * this.arg2.Solve(); + result = arg1.Solve() * arg2.Solve(); break; case Ops.Add: - result = this.arg1.Solve() + this.arg2.Solve(); + result = arg1.Solve() + arg2.Solve(); break; case Ops.Subtract: - result = this.arg1.Solve() - this.arg2.Solve(); + result = arg1.Solve() - arg2.Solve(); break; default: throw new ArgumentOutOfRangeException(); @@ -45,7 +45,7 @@ namespace DSACore.Auxiliary.Calculator public override string ToString() { - return $"({this.arg1} {this.OperatorType} {this.arg2})"; + return $"({arg1} {OperatorType} {arg2})"; } } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/Calculator/Ops.cs b/DSACore/Auxiliary/Calculator/Ops.cs index 702558d..a5c9a2d 100644 --- a/DSACore/Auxiliary/Calculator/Ops.cs +++ b/DSACore/Auxiliary/Calculator/Ops.cs @@ -1,7 +1,7 @@ namespace DSACorev.Auxiliary.Calculator { /// <summary> - /// The Different Operations, witch can be performed in execution-order + /// The Different Operations, witch can be performed in execution-order /// </summary> public enum Ops { @@ -10,4 +10,4 @@ Subtract, Add } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/Calculator/StringSolver.cs b/DSACore/Auxiliary/Calculator/StringSolver.cs index 2eff5b4..b2a7d83 100644 --- a/DSACore/Auxiliary/Calculator/StringSolver.cs +++ b/DSACore/Auxiliary/Calculator/StringSolver.cs @@ -5,49 +5,47 @@ using DSACorev.Auxiliary.Calculator; namespace DSACore.Auxiliary.Calculator { - using System; - using System.Collections.Generic; - using System.Linq; - /// <summary> - /// The StringSolver divides the calculation string into operations and SubStringSolvers if the string contains parentheses + /// The StringSolver divides the calculation string into operations and SubStringSolvers if the string contains + /// parentheses /// </summary> public class StringSolver : ISolvable { - private readonly string input; private readonly List<object> arguments = new List<object>(); + private readonly string input; 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(); + var workInput = "0+" + 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); + AtomizeOperations(workInput); // traverse the List in order of Operation to Create the binary operation tree . - this.NestOperations(); + NestOperations(); // the List now contains only the top operation node, witch can be solved recursively, - return ((ISolvable)this.arguments.First()).Solve(); + return ((ISolvable) arguments.First()).Solve(); } - private static string GetInner(ref string input) // extract the inner bracket an remove the section from the input string + public override string ToString() { - int depth = 0; + return "(0+" + input.Replace(" ", string.Empty).ToLower() + ")"; + } + + private static string + GetInner(ref string input) // extract the inner bracket an remove the section from the input string + { + var depth = 0; for (var index = 1; index < input.Length; index++) { - char c = input[index]; + var c = input[index]; switch (c) { case '(': @@ -92,21 +90,13 @@ namespace DSACore.Auxiliary.Calculator private static string ExpandParentheses(string input) // insert * between Parentheses and digits { - for (int i = 0; i < input.Length - 1; i++) - { + for (var 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++) - { + for (var i = 1; i < input.Length; i++) if (input[i - 1] == ')' && char.IsNumber(input[i])) - { input = input.Insert(i, "*"); - } - } return input; } @@ -115,16 +105,14 @@ namespace DSACore.Auxiliary.Calculator { for (var index = 0; index < workInput.Length; index++) { - char c = workInput[index]; + var 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))); - } + arguments.Add(new Argument(workInput.Substring(0, index + 1))); continue; } @@ -132,18 +120,15 @@ namespace DSACore.Auxiliary.Calculator switch (c) { case ')': - throw new ArgumentException($"Unmögliche Anordnung von Klammern"); + throw new ArgumentException("Unmögliche Anordnung von Klammern"); case '(': - this.arguments.Add(new StringSolver(GetInner(ref workInput))); + arguments.Add(new StringSolver(GetInner(ref workInput))); index = -1; break; default: - if (index > 0) - { - this.arguments.Add(new Argument(workInput.Substring(0, index))); - } + if (index > 0) arguments.Add(new Argument(workInput.Substring(0, index))); - this.arguments.Add(GetOps(c)); + arguments.Add(GetOps(c)); workInput = workInput.Remove(0, index + 1); index = -1; break; @@ -154,58 +139,44 @@ namespace DSACore.Auxiliary.Calculator private 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++) + for (var index = 0; index < arguments.Count; index++) { - var arg = this.arguments[index]; + var arg = arguments[index]; - if (arg.GetType() != typeof(Ops)) - { - continue; - } + if (arg.GetType() != typeof(Ops)) continue; // arg is of type Ops - var op = (Ops)arg; + var op = (Ops) arg; - if (op != currentOp) - { - continue; - } + if (op != currentOp) continue; // arg describes the current operation - this.HandleSpecialFormatting(ref index, op); // Deal with special needs... + 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); + var temp = new Operator((ISolvable) arguments[index - 1], (ISolvable) arguments[index + 1], op); + arguments[index - 1] = temp; + arguments.RemoveRange(index, 2); index--; } - } } private void HandleSpecialFormatting(ref int index, Ops op) { - var arg1 = this.arguments[index - 1]; + var arg1 = arguments[index - 1]; if (arg1.GetType() == typeof(Ops)) { - if (op == Ops.Dice) - { - this.arguments.Insert(index++, new Argument("1")); // w6 -> 1w6 - } + if (op == Ops.Dice) arguments.Insert(index++, new Argument("1")); // w6 -> 1w6 - if (op == Ops.Subtract) - { - this.arguments.Insert(index++, new Argument("0")); // +-3 -> +0-3 - } + if (op == Ops.Subtract) arguments.Insert(index++, new Argument("0")); // +-3 -> +0-3 } - var arg2 = this.arguments[index + 1]; // 3+-5 -> 3+(0-5) + var arg2 = 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); + arguments[index + 1] = new Operator(new Argument("0"), (ISolvable) arguments[index + 2], (Ops) arg2); + arguments.RemoveAt(index + 2); } } } diff --git a/DSACore/Auxiliary/CommandInfo.cs b/DSACore/Auxiliary/CommandInfo.cs index a83e30a..1472587 100644 --- a/DSACore/Auxiliary/CommandInfo.cs +++ b/DSACore/Auxiliary/CommandInfo.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Linq; namespace DSACore.Auxiliary { @@ -10,10 +6,10 @@ namespace DSACore.Auxiliary { public CommandInfo(string name, string brief, string[] description, string scope) { - this.Name = name; - this.Scope = scope; - this.Brief = brief; - this.Description = description; + Name = name; + Scope = scope; + Brief = brief; + Description = description; } public string Name { get; } @@ -26,7 +22,7 @@ namespace DSACore.Auxiliary public string GetDescription() { - return this.Description.Aggregate((s, c) => s + c); + return Description.Aggregate((s, c) => s + c); } } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/Dice.cs b/DSACore/Auxiliary/Dice.cs index 2df8aa7..3dd6562 100644 --- a/DSACore/Auxiliary/Dice.cs +++ b/DSACore/Auxiliary/Dice.cs @@ -5,7 +5,7 @@ namespace DSACore.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) { @@ -14,29 +14,24 @@ namespace DSACore.Auxiliary 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]); + var strings = input.ToLower().Split(new[] {'w', 'd'}, 2, StringSplitOptions.RemoveEmptyEntries).ToList(); + var count = Convert.ToInt32(strings[0]); + var 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; } @@ -45,4 +40,4 @@ namespace DSACore.Auxiliary return sum; } } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/Extensions.cs b/DSACore/Auxiliary/Extensions.cs index 8ef6298..f8e9d8e 100644 --- a/DSACore/Auxiliary/Extensions.cs +++ b/DSACore/Auxiliary/Extensions.cs @@ -6,14 +6,10 @@ //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 += " "; - } + var temp = str; + for (var i = str.Length; i < length; i++) temp += " "; return temp; } - //This mehod extends string. @@ -21,13 +17,9 @@ //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 += " "; - } + var temp = ""; + for (var i = str.Length; i < length; i++) temp += " "; return temp + str; } } - -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/RandomMisc.cs b/DSACore/Auxiliary/RandomMisc.cs index 1295f02..72c2234 100644 --- a/DSACore/Auxiliary/RandomMisc.cs +++ b/DSACore/Auxiliary/RandomMisc.cs @@ -13,40 +13,40 @@ namespace DSACore.Auxiliary { 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); - } + + if (strings.Count > 1) + { + sum += Convert.ToInt32(strings[1]); + output.Append("sum: " + sum); + } return output.ToString(); } 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 = + var u1 = Rand.NextDouble(); // uniform(0,1) random doubles + var u2 = Rand.NextDouble(); + var randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * + Math.Sin(2.0 * Math.PI * u2); // random normal(0,1) + var randNormal = mean + stdDev * randStdNormal; // random normal(mean,stdDev^2) return randNormal; } } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/SpellCorrect.cs b/DSACore/Auxiliary/SpellCorrect.cs index c9603f6..77d1cf3 100644 --- a/DSACore/Auxiliary/SpellCorrect.cs +++ b/DSACore/Auxiliary/SpellCorrect.cs @@ -1,9 +1,9 @@ -namespace DSACore.Auxiliary -{ - using System; - using System.Diagnostics; - using System.Linq; +using System; +using System.Diagnostics; +using System.Linq; +namespace DSACore.Auxiliary +{ public class SpellCorrect : StringComparer { public const int ErrorThreshold = 94100; @@ -15,44 +15,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.Count(); + foreach (var s in subs) if (s.Equals(x)) - { score--; - } - } - if (score < subs.Count()) - { - return score + 1; - } + if (score < subs.Count()) 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,7 +51,6 @@ public static double CompareExact(string s, string q) { - s = s.ToLower(); q = q.ToLower(); @@ -81,67 +61,46 @@ 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] = 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/DSACore/Auxiliary/TalentEnumerableExtension.cs b/DSACore/Auxiliary/TalentEnumerableExtension.cs index a4ace2f..d83114c 100644 --- a/DSACore/Auxiliary/TalentEnumerableExtension.cs +++ b/DSACore/Auxiliary/TalentEnumerableExtension.cs @@ -1,7 +1,7 @@ -using DSACore.DSA_Game.Characters; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Text; +using DSACore.DSA_Game.Characters; using DSALib; namespace DSACore.Auxiliary @@ -15,12 +15,10 @@ namespace DSACore.Auxiliary var tTalent = List.OrderBy(x => sc.Compare(talent, x.Name)).First(); if (sc.Compare(talent, tTalent.Name) > SpellCorrect.ErrorThreshold) - { return $"{c.Name} kann nicht {talent}..."; - } var props = tTalent.GetEigenschaften(); // get the required properties - int tap = tTalent.Value; // get taw + var tap = tTalent.Value; // get taw var werte = props.Select(p => c.Eigenschaften[c.PropTable[p]]).ToList(); output.AppendFormat( @@ -34,51 +32,42 @@ namespace DSACore.Auxiliary output.Append(" "); tap -= erschwernis; - int gesamtErschwernis = tap; + var gesamtErschwernis = tap; if (gesamtErschwernis < 0) { tap = 0; - for (int i = 0; i <= 2; i++) + for (var i = 0; i <= 2; i++) { // foreach property, dice and tap - int temp = Dice.Roll(); - int eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; + var temp = Dice.Roll(); + var eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; - if (eigenschaft + gesamtErschwernis < temp) - { - tap -= temp - (eigenschaft + gesamtErschwernis); - } + if (eigenschaft + gesamtErschwernis < temp) tap -= temp - (eigenschaft + gesamtErschwernis); output.Append($"[{temp}]"); // add to string } - if (tap >= 0) - { - tap = 1; - } + if (tap >= 0) tap = 1; } else { - for (int i = 0; i <= 2; i++) + for (var i = 0; i <= 2; i++) { // foreach property, dice and tap - int temp = Dice.Roll(); - int eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; + var temp = Dice.Roll(); + var eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; - if (eigenschaft < temp) - { - tap -= temp - eigenschaft; - } + if (eigenschaft < temp) tap -= temp - eigenschaft; output.Append($"[{temp}]"); // add to string } } - tap = (tap == 0) ? 1 : tap; - + tap = tap == 0 ? 1 : tap; + output.AppendFormat(" tap: {0,2}", tap); return output.ToString(); // return output } } -} +}
\ No newline at end of file diff --git a/DSACore/Auxiliary/WeaponImporter.cs b/DSACore/Auxiliary/WeaponImporter.cs index 635d477..3375236 100644 --- a/DSACore/Auxiliary/WeaponImporter.cs +++ b/DSACore/Auxiliary/WeaponImporter.cs @@ -1,5 +1,4 @@ -using DSACore.Models.Database; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -7,26 +6,25 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using DSACore.FireBase; using DSACore.Models.Database.DSA; -using Group = System.Text.RegularExpressions.Group; namespace DSACore.Auxiliary { public class WeaponImporter { - private List<MeleeWeapon> Weapons = new List<MeleeWeapon>(); - private List<RangedWeapon> Range = new List<RangedWeapon>(); + private readonly List<RangedWeapon> Range = new List<RangedWeapon>(); + private readonly List<MeleeWeapon> Weapons = new List<MeleeWeapon>(); public async Task DownloadWeapons() { var client = new HttpClient(); - - for (int i = 1; i <= 25; i++) + for (var i = 1; i <= 25; i++) { - var responseString = await client.GetStringAsync("http://diarium.eu/dsa4-forge/ajax/categoryChanged/" + i); + var responseString = + await client.GetStringAsync("http://diarium.eu/dsa4-forge/ajax/categoryChanged/" + i); - Regex talentRegex = new Regex(@"(?<=<option value="")([0-9]*)("">)(.*?)(?=<)"); + var talentRegex = new Regex(@"(?<=<option value="")([0-9]*)("">)(.*?)(?=<)"); //Regex idsRegex = new Regex(@"(?<=<option value=\"")([0-9]*)"); @@ -37,25 +35,25 @@ namespace DSACore.Auxiliary var ids = new List<int>(); foreach (var matchGroup in talentMatch.ToList()) - { if (matchGroup.Success) { lines.Add(matchGroup.Groups[3].Value); ids.Add(int.Parse(matchGroup.Groups[1].Value)); } - } - - for (int j = 0; j < lines.Count; j++) + for (var j = 0; j < lines.Count; j++) { var talent = lines[j]; - var values = await client.GetStringAsync($"http://diarium.eu/dsa4-forge/ajax/calculate/" + i + "/" + ids[j] + "/0/0/0/0/0/10/0/0/0"); + var values = await client.GetStringAsync("http://diarium.eu/dsa4-forge/ajax/calculate/" + i + "/" + + ids[j] + "/0/0/0/0/0/10/0/0/0"); values = Regex.Unescape(values.Replace(@"\t", "")); // ... Use named group in regular expression. - Regex expression = new Regex(@"(((?<=(<td>))|(?<=(<td style=\""padding:2px\"">))).*?(?=<\/td>))|((?<=<span style=\""font-weight:bold;text-decoration:underline;\"">).*?(?=<\/span>))"); + var expression = + new Regex( + @"(((?<=(<td>))|(?<=(<td style=\""padding:2px\"">))).*?(?=<\/td>))|((?<=<span style=\""font-weight:bold;text-decoration:underline;\"">).*?(?=<\/span>))"); // ... See if we matched. var matches = expression.Matches(values).Select(x => x.ToString()).ToList(); @@ -64,7 +62,6 @@ namespace DSACore.Auxiliary await AddMelee(i, talent, matches); Console.Write(j + ","); //await Task.Delay(TimeSpan.FromSeconds(5)); - } Console.WriteLine($"{i}: {ids.Count} => {Weapons.Count}"); @@ -76,17 +73,17 @@ namespace DSACore.Auxiliary private async Task AddMelee(int i, string talent, List<string> matches) { - string name = talent.Replace(' ', '_').Replace(".", ""); + var name = talent.Replace(' ', '_').Replace(".", ""); if (!matches[1].Equals(string.Empty)) { var temp = new MeleeWeapon( name, matches[1], - int.TryParse(matches[10], out int weight) ? weight : 0, + int.TryParse(matches[10], out var weight) ? weight : 0, matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(), matches[11]) { - INI = int.TryParse(matches[3], out int ini) ? ini : 0, + INI = int.TryParse(matches[3], out var ini) ? ini : 0, MW = matches[4], TpKK = matches[2] }; @@ -94,6 +91,7 @@ namespace DSACore.Auxiliary Weapons.Add(temp); await Database.AddWeapon(temp); } + /*if (i > 23) { var range = new RangedWeapon( @@ -118,15 +116,15 @@ namespace DSACore.Auxiliary var range = new RangedWeapon( name, matches[13].Replace(' ', '+'), - int.TryParse(matches[10], out int weight) ? weight : 0, + int.TryParse(matches[10], out var weight) ? weight : 0, matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(), matches[11]) { - AtMod = int.TryParse(matches[18], out int atMod) ? atMod : 0, - KKMod = int.TryParse(matches[17], out int kkMod) ? kkMod : 0, + AtMod = int.TryParse(matches[18], out var atMod) ? atMod : 0, + KKMod = int.TryParse(matches[17], out var kkMod) ? kkMod : 0, AtReach = matches[14], TpReach = matches[15], - LoadTime = int.TryParse(matches[18], out int loadTime) ? loadTime : 0 + LoadTime = int.TryParse(matches[18], out var loadTime) ? loadTime : 0 }; Range.Add(range); await Database.AddWeapon(range); @@ -135,17 +133,17 @@ namespace DSACore.Auxiliary private async Task AddRanged(int i, string talent, List<string> matches) { - string name = talent.Replace(' ', '_').Replace(".", ""); + var name = talent.Replace(' ', '_').Replace(".", ""); if (!matches[1].Equals(string.Empty)) { var temp = new MeleeWeapon( name, matches[1], - int.TryParse(matches[10], out int weight) ? weight : 0, + int.TryParse(matches[10], out var weight) ? weight : 0, matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(), matches[11]) { - INI = int.TryParse(matches[3], out int ini) ? ini : 0, + INI = int.TryParse(matches[3], out var ini) ? ini : 0, MW = matches[4], TpKK = matches[2] }; @@ -159,20 +157,19 @@ namespace DSACore.Auxiliary var range = new RangedWeapon( name, matches[13].Replace(' ', '+'), - int.TryParse(matches[10], out int weight) ? weight : 0, + int.TryParse(matches[10], out var weight) ? weight : 0, matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(), matches[11]) { - AtMod = int.TryParse(matches[18], out int atMod) ? atMod : 0, - KKMod = int.TryParse(matches[17], out int kkMod) ? kkMod : 0, + AtMod = int.TryParse(matches[18], out var atMod) ? atMod : 0, + KKMod = int.TryParse(matches[17], out var kkMod) ? kkMod : 0, AtReach = matches[14], TpReach = matches[15], - LoadTime = int.TryParse(matches[18], out int loadTime) ? loadTime : 0 + LoadTime = int.TryParse(matches[18], out var loadTime) ? loadTime : 0 }; Range.Add(range); await Database.AddWeapon(range); } } } -} - +}
\ No newline at end of file diff --git a/DSACore/Commands/CommandHandler.cs b/DSACore/Commands/CommandHandler.cs index f43633f..f74f87f 100644 --- a/DSACore/Commands/CommandHandler.cs +++ b/DSACore/Commands/CommandHandler.cs @@ -1,7 +1,7 @@ using System; using DSACore.Auxiliary; +using DSACore.Auxiliary.Calculator; using DSACore.DSA_Game; -using DSACore.Models; using DSACore.Models.Network; namespace DSACore.Commands @@ -10,8 +10,8 @@ namespace DSACore.Commands { public static CommandResponse ExecuteCommand(Command cmd) { - string res = string.Empty; - ResponseType type = ResponseType.Broadcast; + var res = string.Empty; + var type = ResponseType.Broadcast; switch (cmd.CmdIdentifier.ToLower()) { case "addChar": @@ -21,7 +21,7 @@ namespace DSACore.Commands case "wert": case "werte": case "char": - res = Commands.HeldList.ListAsync(cmd.CharId, cmd.CmdText); + res = HeldList.ListAsync(cmd.CharId, cmd.CmdText); break; case "help": case "man": @@ -49,28 +49,21 @@ namespace DSACore.Commands res = RandomMisc.Roll(cmd.CmdText + " " + cmd.Cmdmodifier); break; case "solve": - res = new Auxiliary.Calculator.StringSolver(cmd.CmdText + cmd.Cmdmodifier).Solve().ToString(); + res = new StringSolver(cmd.CmdText + cmd.Cmdmodifier).Solve().ToString(); break; case "npc": res = NpcCommands.CreateNpc(cmd.CharId, cmd.CmdTexts, cmd.Cmdmodifier); break; - } - if (res == string.Empty) - { - res= Proben(cmd.Name, cmd.CmdIdentifier, cmd.CmdText, cmd.Cmdmodifier); - } - if (res != string.Empty) - { - return new CommandResponse(res, type); - } + if (res == string.Empty) res = Proben(cmd.Name, cmd.CmdIdentifier, cmd.CmdText, cmd.Cmdmodifier); + if (res != string.Empty) return new CommandResponse(res, type); return new CommandResponse($"Kommando {cmd.CmdIdentifier} nicht gefunden", ResponseType.Error); } private static string Proben(string name, string command, string waffe, int erschwernis = 0) { - string res = string.Empty; + var res = string.Empty; switch (command.ToLower()) { case "f": @@ -138,4 +131,4 @@ namespace DSACore.Commands throw new NotImplementedException("access char by id ore name and group id"); } } -} +}
\ No newline at end of file diff --git a/DSACore/Commands/CommandTypes.cs b/DSACore/Commands/CommandTypes.cs index d53328b..6838ac2 100644 --- a/DSACore/Commands/CommandTypes.cs +++ b/DSACore/Commands/CommandTypes.cs @@ -10,4 +10,4 @@ KeinChar, Zauber } -} +}
\ No newline at end of file diff --git a/DSACore/Commands/FileHandler.cs b/DSACore/Commands/FileHandler.cs index af4698a..bce7c54 100644 --- a/DSACore/Commands/FileHandler.cs +++ b/DSACore/Commands/FileHandler.cs @@ -1,37 +1,29 @@ -using DSACore.DSA_Game; +using System; +using System.Linq; +using System.Net; +using DSACore.DSA_Game; using DSACore.DSA_Game.Characters; +using DSALib; namespace DSACore.Commands { - using System; - using System.Linq; - using System.Net; - - using DSALib; - public class FileHandler { public static string AddChar(ulong id, string url) { - if (url == string.Empty) - { - throw new ArgumentException("Es wurde keine Datei angehängt"); - } - + if (url == string.Empty) throw new ArgumentException("Es wurde keine Datei angehängt"); + + + if (!url.EndsWith(".xml")) throw new ArgumentException("Es wurde kein xml Held mitgeschickt"); - if (!url.EndsWith(".xml")) + using (var client = new WebClient()) { - throw new ArgumentException("Es wurde kein xml Held mitgeschickt"); + client.DownloadFile(url, "helden\\" + url.Split("/").Last()); } - - using (var client = new WebClient()) - { - client.DownloadFile(url, "helden\\" + url.Split("/").Last()); - } - Dsa.Chars.Add(new Character("helden\\" + url.Split("/").Last())); - (Dsa.Chars.Last() as Character)?.Talente.Select(x => new Talent(x.Name, x.Probe, 0)) - .Where(c => !Dsa.Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Dsa.Talente.Add(v)); + Dsa.Chars.Add(new Character("helden\\" + url.Split("/").Last())); + (Dsa.Chars.Last() as Character)?.Talente.Select(x => new Talent(x.Name, x.Probe, 0)) + .Where(c => !Dsa.Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Dsa.Talente.Add(v)); return $"{url.Split("/").Last()} wurde erfolgreich gespeichert"; } diff --git a/DSACore/Commands/Gm.cs b/DSACore/Commands/Gm.cs index a320269..98b62db 100644 --- a/DSACore/Commands/Gm.cs +++ b/DSACore/Commands/Gm.cs @@ -1,12 +1,5 @@ -using DSACore.Auxiliary; -using DSACore.DSA_Game; - -namespace DSACore.Commands +namespace DSACore.Commands { - using System.Linq; - using System.Threading.Tasks; - using DSALib.Characters; - /*public class Iam { @@ -180,4 +173,4 @@ namespace DSACore.Commands return res; } }*/ -} +}
\ No newline at end of file diff --git a/DSACore/Commands/HeldList.cs b/DSACore/Commands/HeldList.cs index 825474c..370af34 100644 --- a/DSACore/Commands/HeldList.cs +++ b/DSACore/Commands/HeldList.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using DSACore.DSA_Game.Characters; using DSACore.Auxiliary; using DSACore.DSA_Game; +using DSACore.DSA_Game.Characters; namespace DSACore.Commands { @@ -15,63 +15,65 @@ namespace DSACore.Commands var character = Dsa.GetCharacter(id) as Character; - int first_column_width = 18; - + var first_column_width = 18; - if (prop_list.Length == 0 || prop_list[0].ToLower().StartsWith("all") || prop_list[0].ToLower().StartsWith("brief") || prop_list[0].ToLower().StartsWith("zettel")) - { + if (prop_list.Length == 0 || prop_list[0].ToLower().StartsWith("all") || + prop_list[0].ToLower().StartsWith("brief") || prop_list[0].ToLower().StartsWith("zettel")) + { res.Add(character.Name + ":\n"); //Eigenschaften res.AddRange( - character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); + character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); res.Add(""); //LE/AE res.Add("LE:\t " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); if (character.Astralpunkte_Basis > 0) - { res.Add("AE:\t " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis); - } res.Add(""); //Kampfwerte res.Add("".AddSpaces(first_column_width) + " AT/PA"); res.AddRange( - character.Kampftalente.Select(s => s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + "/" + s.Pa.ToString().AddSpacesAtHead(2))); + character.Kampftalente.Select(s => + s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + "/" + + s.Pa.ToString().AddSpacesAtHead(2))); res.Add(""); //Fernkampf res.Add("".AddSpaces(first_column_width) + " FK"); res.AddRange( - character.Talente.Where(x => x.IstFernkampftalent()).Select(s => s.Name.AddSpaces(first_column_width) + " " + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); + character.Talente.Where(x => x.IstFernkampftalent()).Select(s => + s.Name.AddSpaces(first_column_width) + " " + + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); res.Add(""); //Vorteile res.AddRange( character.Vorteile - .Select(s => s.Name + "\t " + s.Value)); + .Select(s => s.Name + "\t " + s.Value)); res.Add(""); //Talente res.AddRange( - character.Talente.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); + character.Talente.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + + s.Probe)); res.Add(""); //evtl Zauber if (character.Zauber.Count > 0) - { res.AddRange( - character.Zauber.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); - } - + character.Zauber.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + + " " + s.Probe)); } - else if (prop_list[0].ToLower().StartsWith("man") || prop_list[0].ToLower().StartsWith("help") || prop_list[0].ToLower().StartsWith("hilf")) + else if (prop_list[0].ToLower().StartsWith("man") || prop_list[0].ToLower().StartsWith("help") || + prop_list[0].ToLower().StartsWith("hilf")) { return "```xl\n" + Help.Get_Specific_Help("Held") + "\n```"; } else { - res.Add(character.Name + ":\n"); - foreach (string prop in prop_list) + foreach (var prop in prop_list) { - switch (prop.ToLower()) { case "e": @@ -79,18 +81,16 @@ namespace DSACore.Commands case "eigenschaft": case "eigenschaften": res.AddRange( - character.Eigenschaften.Take(8).Select(s => s.Key + ":\t " + s.Value)); + character.Eigenschaften.Take(8).Select(s => s.Key + ":\t " + s.Value)); break; case "stat": case "stats": res.AddRange( - character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); + character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); res.Add(""); res.Add("LE:\t " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); if (character.Astralpunkte_Basis > 0) - { res.Add("AE:\t " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis); - } break; case "le": res.Add("LE:\t " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); @@ -103,12 +103,16 @@ namespace DSACore.Commands case "talent": case "talente": res.AddRange( - character.Talente.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); + character.Talente.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces( + first_column_width + 5) + " " + s.Probe)); break; case "zauber": case "z": res.AddRange( - character.Zauber.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); + character.Zauber.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces( + first_column_width + 5) + " " + s.Probe)); break; case "w": case "waffe": @@ -118,13 +122,17 @@ namespace DSACore.Commands case "kampfwerte": res.Add("".AddSpaces(first_column_width) + " AT/PA"); res.AddRange( - character.Kampftalente.Select(s => s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + "/" + s.Pa.ToString().AddSpacesAtHead(2))); + character.Kampftalente.Select(s => + s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + + "/" + s.Pa.ToString().AddSpacesAtHead(2))); break; case "f": case "fern": res.Add("".AddSpaces(first_column_width) + " FK"); res.AddRange( - character.Talente.Where(x => x.IstFernkampftalent()).Select(s => s.Name.AddSpaces(first_column_width) + " " + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); + character.Talente.Where(x => x.IstFernkampftalent()).Select(s => + s.Name.AddSpaces(first_column_width) + " " + + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); break; case "v": case "vt": @@ -135,7 +143,7 @@ namespace DSACore.Commands case "nachteile": res.AddRange( character.Vorteile - .Select(s => s.Name + "\t " + s.Value)); + .Select(s => s.Name + "\t " + s.Value)); break; default: @@ -145,15 +153,11 @@ namespace DSACore.Commands res.Add(""); } - } var sb = new StringBuilder(); - foreach (string re in res) - { - sb.AppendLine(re); - } + foreach (var re in res) sb.AppendLine(re); return sb.ToString(); /* @@ -167,4 +171,4 @@ namespace DSACore.Commands }*/ } } -} +}
\ No newline at end of file diff --git a/DSACore/Commands/Help.cs b/DSACore/Commands/Help.cs index 1575b36..974c44c 100644 --- a/DSACore/Commands/Help.cs +++ b/DSACore/Commands/Help.cs @@ -1,76 +1,54 @@ using System.Linq; -using System.Threading.Tasks; using DSACore.Auxiliary; +using DSACore.DSA_Game.Save; namespace DSACore.Commands { public class Help { - static Help() - { - /*TextReader stream = new StreamReader(@"..\..\Help.json"); // Load command-description file - var reader = new JsonTextReader(stream); // create stream reader - - reader.Read(); // step into structure, until the array starts - reader.Read(); - reader.Read(); - - try - { - var test = new JsonSerializer().Deserialize<List<CommandInfo>>(reader); // Deserialize Data and create CommandInfo Struct - - Commands.AddRange(test); // Add new CommandInfos to List - } - catch (Exception e) - { - // ignored - }*/ - } - //public static List<CommandInfo> Commands { get; } = new List<CommandInfo>(); public static string Get_Specific_Help(string command) { // return command specific help - var com = DSACore.DSA_Game.Save.Properties.CommandInfos.OrderBy(x => SpellCorrect.CompareEasy(x.Name, command.ToLower())).First(); // get best fit command + var com = Properties.CommandInfos + .OrderBy(x => SpellCorrect.CompareEasy(x.Name, command.ToLower())).First(); // get best fit command return com.GetDescription(); } public static string Get_Generic_Help() { - string res = ""; - foreach (var com in DSACore.DSA_Game.Save.Properties.CommandInfos) + var res = ""; + foreach (var com in Properties.CommandInfos) { - int first_column_width = 8; + var first_column_width = 8; res += ("!" + com.Name + ": ").AddSpaces(first_column_width) + com.Brief; if (com.Description.Length > 1) - { - res += "\n" + "".AddSpaces(first_column_width) + "(\"!man " + com.Name + "\" gibt genauere Informationen)"; - } + res += "\n" + "".AddSpaces(first_column_width) + "(\"!man " + com.Name + + "\" gibt genauere Informationen)"; res += "\n\n"; } + return res; } - + public static string ShowHelp(params string[] commandList) { var command = ""; - if (commandList.Length > 0) { - command = commandList.Aggregate((s, c) => s + " " + c); - } + if (commandList.Length > 0) command = commandList.Aggregate((s, c) => s + " " + c); if (command.Equals(string.Empty)) // return generic Help { - string res = Get_Generic_Help(); - + var res = Get_Generic_Help(); + return res; } - + return Get_Specific_Help(command); } } -} +}
\ No newline at end of file diff --git a/DSACore/Commands/LebenUndAstral.cs b/DSACore/Commands/LebenUndAstral.cs index b5bc260..a671296 100644 --- a/DSACore/Commands/LebenUndAstral.cs +++ b/DSACore/Commands/LebenUndAstral.cs @@ -1,8 +1,6 @@ using System; -using System.Linq; -using System.Threading.Tasks; -using DSACore.DSA_Game; using DSACore.Auxiliary; +using DSACore.DSA_Game; using DSALib.Characters; namespace DSACore.Commands @@ -12,9 +10,9 @@ namespace DSACore.Commands public static string LEAsync(ulong id, string modifier) { //This is the string that will be printed - string res = ""; + var res = ""; + - //Get the actual text res += Dsa.GetCharacter(id).get_LE_Text(modifier); @@ -23,17 +21,17 @@ namespace DSACore.Commands } } - public class AE + public class AE { public static string AEAsync(ulong id, string modifier) { //This is the string that will be printed - string res = ""; + var res = ""; //Get the actual text res += Dsa.GetCharacter(id).get_AE_Text(modifier); - + return res; } } @@ -42,11 +40,11 @@ namespace DSACore.Commands { public static string get_LE_Text(this ICharacter c, string prop) { - string res = ""; + var res = ""; var comp = new SpellCorrect(); var character = c; - res += (character.Name + ":\n"); + res += character.Name + ":\n"; //If there is actual input we process it if (prop.Length > 0) @@ -60,15 +58,20 @@ namespace DSACore.Commands //Allow overflowing the max if (prop.StartsWith("++")) { - character.Lebenspunkte_Aktuell = character.Lebenspunkte_Aktuell + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); + character.Lebenspunkte_Aktuell = character.Lebenspunkte_Aktuell + + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); } else { - int temp = character.Lebenspunkte_Aktuell + Convert.ToInt32(prop) - character.Lebenspunkte_Basis; + var temp = character.Lebenspunkte_Aktuell + Convert.ToInt32(prop) - + character.Lebenspunkte_Basis; //Stop from overflow overflow if (temp > 0 && prop.StartsWith("+")) { - character.Lebenspunkte_Aktuell = (character.Lebenspunkte_Basis > character.Lebenspunkte_Aktuell) ? character.Lebenspunkte_Basis : character.Lebenspunkte_Aktuell; + character.Lebenspunkte_Aktuell = + character.Lebenspunkte_Basis > character.Lebenspunkte_Aktuell + ? character.Lebenspunkte_Basis + : character.Lebenspunkte_Aktuell; res += " Maximale Lebenspunkte sind erreicht "; } //Simply apply change @@ -91,23 +94,23 @@ namespace DSACore.Commands //If no value is passed, the curent value is displayed else { - res += ("LE: " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); + res += "LE: " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis; } return res; } + public static string get_AE_Text(this ICharacter c, string prop) { - string res = ""; + var res = ""; var comp = new SpellCorrect(); var character = c; - res += (character.Name + ":\n"); + res += character.Name + ":\n"; //If there is actual input we process it if (prop.Length > 0) { - res += "AE: "; res += character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis + " -> "; @@ -117,15 +120,20 @@ namespace DSACore.Commands //Allow overflowing the max if (prop.StartsWith("++")) { - character.Astralpunkte_Aktuell = character.Astralpunkte_Aktuell + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); + character.Astralpunkte_Aktuell = character.Astralpunkte_Aktuell + + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); } else { - int temp = character.Astralpunkte_Aktuell + Convert.ToInt32(prop) - character.Astralpunkte_Basis; + var temp = character.Astralpunkte_Aktuell + Convert.ToInt32(prop) - + character.Astralpunkte_Basis; //Stop from overflow overflow if (temp > 0 && prop.StartsWith("+")) { - character.Astralpunkte_Aktuell = (character.Astralpunkte_Basis > character.Astralpunkte_Aktuell) ? character.Astralpunkte_Basis : character.Astralpunkte_Aktuell; + character.Astralpunkte_Aktuell = + character.Astralpunkte_Basis > character.Astralpunkte_Aktuell + ? character.Astralpunkte_Basis + : character.Astralpunkte_Aktuell; res += " Maximale Astralpunkte sind erreicht "; } //Simply apply change @@ -142,7 +150,6 @@ namespace DSACore.Commands } res += character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis; - } //Set to new value regardless of original else @@ -155,14 +162,11 @@ namespace DSACore.Commands //If no value is passed, the curent value is displayed else { - res += ("AE: " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis); + res += "AE: " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis; } return res; } } -} - - - +}
\ No newline at end of file diff --git a/DSACore/Commands/List.cs b/DSACore/Commands/List.cs index 1fa0dde..7fc682f 100644 --- a/DSACore/Commands/List.cs +++ b/DSACore/Commands/List.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; -using DSACore.DSA_Game; using DSACore.Audio; +using DSACore.DSA_Game; namespace DSACore.Commands { @@ -12,7 +11,7 @@ namespace DSACore.Commands public static string ListAsync(string prop) { var res = new List<string>(); - + //int persist = 0; switch (prop.ToLower()) @@ -20,7 +19,7 @@ namespace DSACore.Commands case "man": case "help": return Help.Get_Specific_Help("List"); - // break; + // break; case "chars": res.AddRange(Dsa.Chars.Select(x => x.Name)); break; @@ -44,4 +43,4 @@ namespace DSACore.Commands return res.ToString(); } } -} +}
\ No newline at end of file diff --git a/DSACore/Commands/MiscCommands.cs b/DSACore/Commands/MiscCommands.cs index 21646e7..ebd1598 100644 --- a/DSACore/Commands/MiscCommands.cs +++ b/DSACore/Commands/MiscCommands.cs @@ -1,15 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using DSACore.DSA_Game; -using DSACore.Auxiliary; -using Microsoft.AspNetCore.Hosting.Internal; - -namespace DSACore.Commands +namespace DSACore.Commands { public class MiscCommands { @@ -227,4 +216,4 @@ namespace DSACore.Commands }*/ } -} +}
\ No newline at end of file diff --git a/DSACore/Commands/NpcCommands.cs b/DSACore/Commands/NpcCommands.cs index 50ea966..95243ca 100644 --- a/DSACore/Commands/NpcCommands.cs +++ b/DSACore/Commands/NpcCommands.cs @@ -1,27 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using DSACore.Characters; using DSACore.DSA_Game; using DSACore.DSA_Game.Characters; -using DSACore.Auxiliary; -using Microsoft.AspNetCore.Mvc.Internal; namespace DSACore.Commands { public class NpcCommands { - public static string CreateNpc(ulong id, IEnumerable<string> props, int modifier) { - if (int.TryParse(props.Last(), out int mean)) - { - return Random(id, props.First(), mean, modifier); - } + if (int.TryParse(props.Last(), out var mean)) return Random(id, props.First(), mean, modifier); return Copy(id, props.First(), props.Last(), modifier); - } private static string Random(ulong id, string npcName, int mean = 9, int stDv = 1) @@ -30,13 +22,10 @@ namespace DSACore.Commands Dsa.Chars.Add(new Npc(npcName, mean, stDv)); return $"{npcName} wurde zufällig generiert"; } - + private static string Copy(ulong id, string npcName, string source, int stDv = 1) { - if (Dsa.Chars.Exists(x => x.Name.Equals(npcName))) - { - throw new Exception("Char gibt es schon"); - } + if (Dsa.Chars.Exists(x => x.Name.Equals(npcName))) throw new Exception("Char gibt es schon"); throw new NotImplementedException(); var chr = Dsa.GetCharacter(id); Dsa.Chars.Add(new Character(chr as Character, npcName, stDv)); diff --git a/DSACore/Commands/ProbenTest.cs b/DSACore/Commands/ProbenTest.cs index a927cd9..d0800d6 100644 --- a/DSACore/Commands/ProbenTest.cs +++ b/DSACore/Commands/ProbenTest.cs @@ -1,6 +1,6 @@ namespace DSACore.Commands { - public class ProbenTest + public class ProbenTest { /*[Command("t"), Summary("Würfelt ein Talent-/Zauberprobe")] [Alias("T", "Talent", "talent", "versuche")] @@ -82,4 +82,4 @@ return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Session.Relation[this.Context.User.Username])).Fernkampf(waffe, erschwernis) + "\n```"); }*/ } -} +}
\ No newline at end of file diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs index d35690c..5addf82 100644 --- a/DSACore/Controllers/CommandsController.cs +++ b/DSACore/Controllers/CommandsController.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using DSACore.Models; +using DSACore.Commands; using DSACore.Models.Network; using Microsoft.AspNetCore.Mvc; @@ -29,17 +26,16 @@ namespace DSACore.Controllers // POST api/<controller>/Felis [HttpPost] - public string Post([FromBody]Command cmd) + public string Post([FromBody] Command cmd) { try { - return Commands.CommandHandler.ExecuteCommand(cmd).message; + return CommandHandler.ExecuteCommand(cmd).message; } catch (Exception e) { return $"Ein Fehler ist aufgetreten: \n {e.Message}"; } - } /* @@ -56,4 +52,4 @@ namespace DSACore.Controllers { }*/ } -} +}
\ No newline at end of file diff --git a/DSACore/Controllers/LobbyController.cs b/DSACore/Controllers/LobbyController.cs index a946184..df22607 100644 --- a/DSACore/Controllers/LobbyController.cs +++ b/DSACore/Controllers/LobbyController.cs @@ -1,5 +1,6 @@ -using DSACore.Models.Network; using System; +using DSACore.Commands; +using DSACore.Models.Network; using Microsoft.AspNetCore.Mvc; namespace DSACore.Controllers @@ -13,20 +14,18 @@ namespace DSACore.Controllers { return "Usage: get /tokens/{Token}"; } - + [HttpPost] - public string Post([FromBody]Command cmd) + public string Post([FromBody] Command cmd) { try { - return Commands.CommandHandler.ExecuteCommand(cmd).message; + return CommandHandler.ExecuteCommand(cmd).message; } catch (Exception e) { return $"Ein Fehler ist aufgetreten: \n {e.Message}"; } - - } - + } } }
\ No newline at end of file diff --git a/DSACore/Controllers/TokensController.cs b/DSACore/Controllers/TokensController.cs index 1d49f44..a85cabe 100644 --- a/DSACore/Controllers/TokensController.cs +++ b/DSACore/Controllers/TokensController.cs @@ -1,3 +1,4 @@ +using DSACore.Hubs; using Microsoft.AspNetCore.Mvc; namespace DSACore.Controllers @@ -6,23 +7,19 @@ namespace DSACore.Controllers [ApiController] public class TokensController : Controller { - // GET [HttpGet("{token}")] public ActionResult<string> Get(string token) { - if (!int.TryParse(token, out var inttoken)) - { + if (!int.TryParse(token, out var intToken)) return BadRequest("The token has to be a 32 bit unsigned integer"); - } - if (!Hubs.Users.Tokens.Exists(x => x.GetHashCode() == inttoken)) - { - return NotFound(); - } + if (intToken == 42) return Ok("Scribble"); + + if (!Users.Tokens.Exists(x => x.GetHashCode() == intToken)) return NotFound(); - var group = Hubs.Users.Tokens.Find(x => x.GetHashCode() == inttoken); - return Ok(group); + var group = Users.Tokens.Find(x => x.GetHashCode() == intToken); + return Ok(group.Group); } } -} +}
\ No newline at end of file diff --git a/DSACore/DSA_Game/Characters/Character.cs b/DSACore/DSA_Game/Characters/Character.cs index 247fc58..ac890cb 100644 --- a/DSACore/DSA_Game/Characters/Character.cs +++ b/DSACore/DSA_Game/Characters/Character.cs @@ -1,129 +1,117 @@ -using System.IO; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Xml; using DSACore.Auxiliary; using DSALib; using DSALib.Characters; namespace DSACore.DSA_Game.Characters { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Xml; - - public class Character : Being, ICharacter { public Character() { - this.PropTable.Add("MU", "Mut"); // routing - this.PropTable.Add("KL", "Klugheit"); - this.PropTable.Add("IN", "Intuition"); - this.PropTable.Add("CH", "Charisma"); - this.PropTable.Add("FF", "Fingerfertigkeit"); - this.PropTable.Add("GE", "Gewandtheit"); - this.PropTable.Add("KO", "Konstitution"); - this.PropTable.Add("KK", "Körperkraft"); - + PropTable.Add("MU", "Mut"); // routing + PropTable.Add("KL", "Klugheit"); + PropTable.Add("IN", "Intuition"); + PropTable.Add("CH", "Charisma"); + PropTable.Add("FF", "Fingerfertigkeit"); + PropTable.Add("GE", "Gewandtheit"); + PropTable.Add("KO", "Konstitution"); + PropTable.Add("KK", "Körperkraft"); } public Character(string path) : this() { - this.Load(new MemoryStream(File.ReadAllBytes(path))); // load - this.Post_process(); // calculate derived values + Load(new MemoryStream(File.ReadAllBytes(path))); // load + Post_process(); // calculate derived values } + public Character(MemoryStream stream) : this() { - this.Load(stream); // load - this.Post_process(); // calculate derived values + Load(stream); // load + Post_process(); // calculate derived values } public Character(Character c, string name, int stDv = 2) : this() { - this.Name = name; + Name = name; foreach (var i in c.Eigenschaften) - { - this.Eigenschaften.Add(i.Key, i.Value + (int)Math.Round(RandomMisc.Random(stDv))); - } + Eigenschaften.Add(i.Key, i.Value + (int) Math.Round(RandomMisc.Random(stDv))); foreach (var i in c.Vorteile) - { - this.Vorteile.Add(new Vorteil(i.Name, i.Value + (int)Math.Round(RandomMisc.Random(stDv)))); - } + Vorteile.Add(new Vorteil(i.Name, i.Value + (int) Math.Round(RandomMisc.Random(stDv)))); foreach (var i in c.Talente) - { - this.Talente.Add(new Talent(i.Name, i.Probe, i.Value + (int)Math.Round(RandomMisc.Random(stDv)))); - } + Talente.Add(new Talent(i.Name, i.Probe, i.Value + (int) Math.Round(RandomMisc.Random(stDv)))); foreach (var i in c.Zauber) - { - this.Zauber.Add(new Zauber(i.Name, i.Probe, i.Value + (int)Math.Round(RandomMisc.Random(stDv)), i.Complexity, i.Representation)); - } + Zauber.Add(new Zauber(i.Name, i.Probe, i.Value + (int) Math.Round(RandomMisc.Random(stDv)), + i.Complexity, i.Representation)); foreach (var i in c.Kampftalente) - { - this.Kampftalente.Add(new KampfTalent(i.Name, i.At + (int)Math.Round(RandomMisc.Random(stDv)), i.Pa + (int)Math.Round(RandomMisc.Random(stDv)))); - } + Kampftalente.Add(new KampfTalent(i.Name, i.At + (int) Math.Round(RandomMisc.Random(stDv)), + i.Pa + (int) Math.Round(RandomMisc.Random(stDv)))); - this.Post_process(); // calculate derived values + Post_process(); // calculate derived values } - public Dictionary<string, int> Eigenschaften { get; set; } = new Dictionary<string, int>(); // char properties + public Dictionary<string, int> Eigenschaften { get; set; } = new Dictionary<string, int>(); // char properties - public List<Talent> Talente { get; set; } = new List<Talent>(); // list of talent objects (talents) + public List<Talent> Talente { get; set; } = new List<Talent>(); // list of talent objects (talents) - public List<Zauber> Zauber { get; set; } = new List<Zauber>(); // list of spell objects + public List<Zauber> Zauber { get; set; } = new List<Zauber>(); // list of spell objects - public List<KampfTalent> Kampftalente { get; set; } = new List<KampfTalent>(); // list of combat objects + public List<KampfTalent> Kampftalente { get; set; } = new List<KampfTalent>(); // list of combat objects public List<Vorteil> Vorteile { get; set; } = new List<Vorteil>(); public Dictionary<string, string> PropTable { get; set; } = new Dictionary<string, string>(); // -> Körperkraft - public string TestTalent(string talent, int erschwernis = 0) // Talentprobe + public string TestTalent(string talent, int erschwernis = 0) // Talentprobe { - return this.Talente.ProbenTest(this, talent, erschwernis); + return Talente.ProbenTest(this, talent, erschwernis); } - public string TestZauber(string zauber, int erschwernis = 0) // Talentprobe + public string TestZauber(string zauber, int erschwernis = 0) // Talentprobe { - return this.Zauber.ProbenTest(this, zauber, erschwernis); + return Zauber.ProbenTest(this, zauber, erschwernis); } public string TestEigenschaft(string eigenschaft, int erschwernis = 0) { var output = new StringBuilder(); - var prop = this.PropTable[eigenschaft.ToUpper()]; - int tap = this.Eigenschaften[prop]; + var prop = PropTable[eigenschaft.ToUpper()]; + var tap = Eigenschaften[prop]; output.AppendFormat( "{0}-Eigenschaftsprobe ew:{1} {2} \n", prop, tap, erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); - int roll = Dice.Roll(); + var roll = Dice.Roll(); output.Append($"Gewürfelt: {roll} übrig: {tap - roll - erschwernis}"); return output.ToString(); } - public string Angriff(string talent, int erschwernis = 0) // pretty self explanatory + public string Angriff(string talent, int erschwernis = 0) // pretty self explanatory { var output = new StringBuilder(); var sc = new SpellCorrect(); - var attack = this.Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First(); + var attack = Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First(); if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) - { - return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; - } + return $"{Name} kann nicht mit der Waffenart {talent} umgehen..."; - int tap = attack.At; + var tap = attack.At; output.AppendFormat( "{0}-Angriff taw:{1} {2} \n", attack.Name, tap, erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); - int temp = Dice.Roll(); + var temp = Dice.Roll(); output.Append(temp - erschwernis); return output.ToString(); } @@ -132,21 +120,19 @@ namespace DSACore.DSA_Game.Characters { var output = new StringBuilder(); var sc = new SpellCorrect(); - var attack = this.Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First(); + var attack = Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First(); if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) - { - return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; - } + return $"{Name} kann nicht mit der Waffenart {talent} umgehen..."; - int tap = attack.Pa; + var tap = attack.Pa; output.AppendFormat( "{0}-Parade taw:{1} {2}\n", attack.Name, tap, erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); - int temp = Dice.Roll(); + var temp = Dice.Roll(); output.Append(temp - erschwernis); return output.ToString(); } @@ -155,21 +141,19 @@ namespace DSACore.DSA_Game.Characters { var output = new StringBuilder(); var sc = new SpellCorrect(); - int fk = this.Eigenschaften["fk"]; - var attack = this.Talente.OrderBy(x => sc.Compare(talent, x.Name)).First(); + var fk = Eigenschaften["fk"]; + var attack = Talente.OrderBy(x => sc.Compare(talent, x.Name)).First(); if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) - { - return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; - } + return $"{Name} kann nicht mit der Waffenart {talent} umgehen..."; - int tap = attack.Value; + var tap = attack.Value; output.AppendFormat( "{0} taw:{1} {2} \n", attack.Name, tap, erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); tap -= erschwernis; - int temp = Dice.Roll(); + var temp = Dice.Roll(); tap -= temp > fk ? temp - fk : 0; output.Append($"W20: {temp} tap: {tap}"); return output.ToString(); @@ -177,34 +161,30 @@ namespace DSACore.DSA_Game.Characters private void Post_process() { - var LE_Wert = this.Eigenschaften["Lebensenergie"]; - var AE_Wert = this.Eigenschaften.First(s => s.Key.Contains("Astralenergie")).Value; + var LE_Wert = Eigenschaften["Lebensenergie"]; + var AE_Wert = Eigenschaften.First(s => s.Key.Contains("Astralenergie")).Value; //var KL_Wert = this.Eigenschaften.First(s => s.Key.Contains("Klugheit")).Value; - var MU_Wert = this.Eigenschaften.First(s => s.Key.Contains("Mut")).Value; - var IN_Wert = this.Eigenschaften.First(s => s.Key.Contains("Intuition")).Value; - var CH_Wert = this.Eigenschaften.First(s => s.Key.Contains("Charisma")).Value; - var KK_Wert = this.Eigenschaften["Körperkraft"]; - var KO__Wert = this.Eigenschaften["Konstitution"]; - - this.Astralpunkte_Basis = 0; + var MU_Wert = Eigenschaften.First(s => s.Key.Contains("Mut")).Value; + var IN_Wert = Eigenschaften.First(s => s.Key.Contains("Intuition")).Value; + var CH_Wert = Eigenschaften.First(s => s.Key.Contains("Charisma")).Value; + var KK_Wert = Eigenschaften["Körperkraft"]; + var KO__Wert = Eigenschaften["Konstitution"]; - this.Ausdauer_Basis = 0; + Astralpunkte_Basis = 0; - this.Lebenspunkte_Basis = LE_Wert + (int)(KO__Wert + (KK_Wert / 2.0) + 0.5); + Ausdauer_Basis = 0; - if (this.Vorteile.Exists(x => x.Name.ToLower().Contains("zauberer"))) - { - this.Astralpunkte_Basis = AE_Wert + (int)((MU_Wert + IN_Wert + CH_Wert) / 2.0 + 0.5); - } + Lebenspunkte_Basis = LE_Wert + (int) (KO__Wert + KK_Wert / 2.0 + 0.5); - this.Lebenspunkte_Aktuell = this.Lebenspunkte_Basis; - this.Astralpunkte_Aktuell = this.Astralpunkte_Basis; - this.Ausdauer_Aktuell = this.Ausdauer_Basis; + if (Vorteile.Exists(x => x.Name.ToLower().Contains("zauberer"))) + Astralpunkte_Basis = AE_Wert + (int) ((MU_Wert + IN_Wert + CH_Wert) / 2.0 + 0.5); + Lebenspunkte_Aktuell = Lebenspunkte_Basis; + Astralpunkte_Aktuell = Astralpunkte_Basis; + Ausdauer_Aktuell = Ausdauer_Basis; } - private void Load(MemoryStream stream) { @@ -212,10 +192,7 @@ namespace DSACore.DSA_Game.Characters while (reader.Read()) { // read until he hits keywords - if (reader.NodeType != XmlNodeType.Element) - { - continue; - } + if (reader.NodeType != XmlNodeType.Element) continue; switch (reader.Name) { @@ -223,12 +200,13 @@ namespace DSACore.DSA_Game.Characters reader.Skip(); break; case "held": - this.Name = reader.GetAttribute("name"); // name + Name = reader.GetAttribute("name"); // name break; case "eigenschaft": - this.Eigenschaften.Add( + Eigenschaften.Add( reader.GetAttribute("name") ?? throw new InvalidOperationException(), - Convert.ToInt32(reader.GetAttribute("value")) + Convert.ToInt32(reader.GetAttribute("mod"))); + Convert.ToInt32(reader.GetAttribute("value")) + + Convert.ToInt32(reader.GetAttribute("mod"))); break; case "vt": reader.Read(); @@ -236,14 +214,14 @@ namespace DSACore.DSA_Game.Characters { try { - this.Vorteile.Add(new Vorteil( + Vorteile.Add(new Vorteil( reader.GetAttribute("name"), - // Convert.ToInt32(reader.GetAttribute("value")))); - reader.GetAttribute("value"))); + // Convert.ToInt32(reader.GetAttribute("value")))); + reader.GetAttribute("value"))); } catch { - this.Vorteile.Add(new Vorteil(reader.GetAttribute("name"))); + Vorteile.Add(new Vorteil(reader.GetAttribute("name"))); } reader.Read(); @@ -254,7 +232,7 @@ namespace DSACore.DSA_Game.Characters reader.Read(); while (reader.Name.Equals("talent")) { - this.Talente.Add( + Talente.Add( new Talent( reader.GetAttribute("name"), reader.GetAttribute("probe")?.Remove(0, 2).Trim(')'), @@ -267,7 +245,7 @@ namespace DSACore.DSA_Game.Characters reader.Read(); while (reader.Name.Equals("zauber")) { - this.Zauber.Add( + Zauber.Add( new Zauber( reader.GetAttribute("name"), reader.GetAttribute("probe")?.Remove(0, 2).Trim(')'), @@ -279,12 +257,12 @@ namespace DSACore.DSA_Game.Characters break; case "kampfwerte": - string atName = reader.GetAttribute("name"); + var atName = reader.GetAttribute("name"); reader.Read(); - int at = Convert.ToInt32(reader.GetAttribute("value")); + var at = Convert.ToInt32(reader.GetAttribute("value")); reader.Read(); - int pa = Convert.ToInt32(reader.GetAttribute("value")); - this.Kampftalente.Add(new KampfTalent(atName, at, pa)); + var pa = Convert.ToInt32(reader.GetAttribute("value")); + Kampftalente.Add(new KampfTalent(atName, at, pa)); break; } } diff --git a/DSACore/DSA_Game/Characters/NPC.cs b/DSACore/DSA_Game/Characters/NPC.cs index 0a660ee..75c3fe9 100644 --- a/DSACore/DSA_Game/Characters/NPC.cs +++ b/DSACore/DSA_Game/Characters/NPC.cs @@ -4,11 +4,6 @@ using DSALib.Characters; namespace DSACore.Characters { - using System; - - using DSACore.Auxiliary; - using DSACore.DSA_Game.Characters; - public class Npc : Being, ICharacter { private readonly int mean, stDv; @@ -17,94 +12,67 @@ namespace DSACore.Characters { this.mean = mean; this.stDv = stDv; - this.Name = name; + Name = name; } public string TestTalent(string talent, int tap = 3) { - for (int i = 0; i <= 2; i++) + for (var i = 0; i <= 2; i++) { // foreach property, dice and tap - int temp = Dice.Roll(); - int eigenschaft = (int)Math.Round(RandomMisc.Random(this.stDv, this.mean)); + var temp = Dice.Roll(); + var eigenschaft = (int) Math.Round(RandomMisc.Random(stDv, mean)); - if (eigenschaft < temp) - { - tap -= temp - eigenschaft; - } + if (eigenschaft < temp) tap -= temp - eigenschaft; } - if (tap >= 0) - { - return $"{this.Name} vollführt {talent} erfolgreich"; - } + if (tap >= 0) return $"{Name} vollführt {talent} erfolgreich"; - return $"{this.Name} scheitert an {talent}"; + return $"{Name} scheitert an {talent}"; } public string TestEigenschaft(string eigenschaft, int erschwernis = 0) { - int temp = Dice.Roll(); - int prop = (int)Math.Round(RandomMisc.Random(this.stDv, this.stDv)); - - if (temp + erschwernis < prop) - { - return $"{this.Name} vollführt {eigenschaft} erfolgreich"; - } + var temp = Dice.Roll(); + var prop = (int) Math.Round(RandomMisc.Random(stDv, stDv)); + + if (temp + erschwernis < prop) return $"{Name} vollführt {eigenschaft} erfolgreich"; - return $"{this.Name} scheitert an {eigenschaft}"; + return $"{Name} scheitert an {eigenschaft}"; } public string Angriff(string waffe, int erschwernis = 0) { - int temp = Dice.Roll(); + var temp = Dice.Roll(); - if (temp == 1) - { - return $"{this.Name} greift kritisch mit {waffe} an"; - } + if (temp == 1) return $"{Name} greift kritisch mit {waffe} an"; - if (temp < erschwernis) - { - return $"{this.Name} greift mit {waffe} an"; - } + if (temp < erschwernis) return $"{Name} greift mit {waffe} an"; - return $"{this.Name} haut mit {waffe} daneben"; + return $"{Name} haut mit {waffe} daneben"; } public string Parade(string waffe, int erschwernis = 0) { - int temp = Dice.Roll(); + var temp = Dice.Roll(); - if (temp == 1) - { - return $"{this.Name} pariert mit {waffe} meisterlich"; - } + if (temp == 1) return $"{Name} pariert mit {waffe} meisterlich"; - if (temp < erschwernis) - { - return $"{this.Name} pariert mit {waffe} an"; - } + if (temp < erschwernis) return $"{Name} pariert mit {waffe} an"; - return $"{this.Name} schafft es nicht mit {waffe} zu parieren"; + return $"{Name} schafft es nicht mit {waffe} zu parieren"; } public string Fernkampf(string waffe, int erschwernis = 0) { - int temp = Dice.Roll(); + var temp = Dice.Roll(); - if (temp == 1) - { - return $"{this.Name} trifft kritisch mit {waffe}"; - } + if (temp == 1) return $"{Name} trifft kritisch mit {waffe}"; - if (temp < erschwernis) - { - return $"{this.Name} greift mit {waffe} an"; - } + if (temp < erschwernis) return $"{Name} greift mit {waffe} an"; - return $"{this.Name} schießt mit {waffe} daneben"; + return $"{Name} schießt mit {waffe} daneben"; } public string TestZauber(string zauber, int erschwernis) @@ -112,4 +80,4 @@ namespace DSACore.Characters return TestTalent(zauber, erschwernis); } } -} +}
\ No newline at end of file diff --git a/DSACore/DSA_Game/Characters/SaveChar.cs b/DSACore/DSA_Game/Characters/SaveChar.cs index 87c2566..7b29b4e 100644 --- a/DSACore/DSA_Game/Characters/SaveChar.cs +++ b/DSACore/DSA_Game/Characters/SaveChar.cs @@ -2,7 +2,6 @@ namespace DSACore.DSA_Game.Characters { - public class SaveChar { public string Name { get; set; } @@ -36,4 +35,4 @@ namespace DSACore.DSA_Game.Characters c.Name = s.Name; } } -} +}
\ No newline at end of file diff --git a/DSACore/DSA_Game/Dsa.cs b/DSACore/DSA_Game/Dsa.cs index cbdb734..18d0b81 100644 --- a/DSACore/DSA_Game/Dsa.cs +++ b/DSACore/DSA_Game/Dsa.cs @@ -1,28 +1,24 @@ using System; -using DSACore.Auxiliary; -using DSACore.FireBase; +using System.Collections.Generic; +using System.Linq; +using DSACore.DSA_Game.Characters; +using DSACore.DSA_Game.Save; using DSALib; using DSALib.Characters; -using Microsoft.EntityFrameworkCore.Design; namespace DSACore.DSA_Game { - using System.Collections.Generic; - using System.IO; - using System.Linq; - using DSACore.DSA_Game.Characters; - using DSACore.DSA_Game.Save; - public static class Dsa { #if DEBUG - public const string rootPath = "";//"C:\\Users\\Dennis\\Source\\Repos\\DiscoBot\\DSACore\\";//"DiscoBot\\DSACore\\"; + public const string + rootPath = ""; //"C:\\Users\\Dennis\\Source\\Repos\\DiscoBot\\DSACore\\";//"DiscoBot\\DSACore\\"; #else public const string rootPath = "";//"DiscoBot\\DSACore\\"; #endif private static Session s_session; - public static List<ICharacter> Chars { get; set; } = new List<ICharacter>(); // list of all characters + public static List<ICharacter> Chars { get; set; } = new List<ICharacter>(); // list of all characters public static List<Talent> Talente { get; set; } = new List<Talent>(); @@ -39,10 +35,7 @@ namespace DSACore.DSA_Game set { s_session = value; - foreach (var x in value.Chars) - { - Chars.Find(c => c.Name.Equals(x.Name)).Update(x); - } + foreach (var x in value.Chars) Chars.Find(c => c.Name.Equals(x.Name)).Update(x); } } @@ -61,9 +54,9 @@ namespace DSACore.DSA_Game } */ - Properties.Deserialize(rootPath+"Properties"); + Properties.Deserialize(); Properties.Serialize(rootPath + "Properties"); - + Talente = Talente.OrderBy(x => x.Name).ToList(); Zauber = Zauber.OrderBy(x => x.Name).ToList(); diff --git a/DSACore/DSA_Game/Save/Properties.cs b/DSACore/DSA_Game/Save/Properties.cs index 459a9c7..7eba911 100644 --- a/DSACore/DSA_Game/Save/Properties.cs +++ b/DSACore/DSA_Game/Save/Properties.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -8,10 +9,6 @@ using Newtonsoft.Json; namespace DSACore.DSA_Game.Save { - using System.Collections; - using System.IO; - using Newtonsoft.Json; - public static class Properties { public static Dictionary<string, object> objects; @@ -39,17 +36,13 @@ namespace DSACore.DSA_Game.Save { var files = Directory.GetFiles(path, "*.json"); - foreach (string file in files) - { + foreach (var file in files) try { - string name = file.Split('\\').Last().Split('.')[0].Replace('-', '.'); - string data = File.ReadAllText(file); - Type type = Type.GetType(name); - if (data.StartsWith("[")) - { - type = typeof(List<>).MakeGenericType(type); - } + var name = file.Split('\\').Last().Split('.')[0].Replace('-', '.'); + var data = File.ReadAllText(file); + var type = Type.GetType(name); + if (data.StartsWith("[")) type = typeof(List<>).MakeGenericType(type); var o = JsonConvert.DeserializeObject(data, type); objects.Add(name.Split('.').Last(), o); @@ -59,7 +52,6 @@ namespace DSACore.DSA_Game.Save // ignored Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen." + e); } - } } public static void Serialize(string path = @"..\..\Properties\") @@ -68,8 +60,8 @@ namespace DSACore.DSA_Game.Save { foreach (var o in objects) { - string assembly = o.Value is IList list - ? ((IList) list)[0]?.GetType().FullName + var assembly = o.Value is IList list + ? list[0]?.GetType().FullName : o.Value.GetType().FullName; var name = path + assembly.Replace('.', '-') + ".json"; @@ -81,7 +73,7 @@ namespace DSACore.DSA_Game.Save catch (Exception e) { // ignored - Console.WriteLine($"Speichern von Save-File fehlgeschlagen." + e); + Console.WriteLine("Speichern von Save-File fehlgeschlagen." + e); } } } diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs index 198d707..f358047 100644 --- a/DSACore/DSA_Game/Save/SaveCommand.cs +++ b/DSACore/DSA_Game/Save/SaveCommand.cs @@ -1,23 +1,21 @@ using System; +using System.IO; using System.Linq; -using System.Threading.Tasks; namespace DSACore.DSA_Game.Save { - using System.IO; - - public class SaveCommand + public class SaveCommand { public void LoadSession(string name = "") { if (name.Equals("?") || name.Equals(string.Empty)) { - Console.WriteLine($"Gespeicherte Sessions:"); - Console.WriteLine(this.ListSessions()); + Console.WriteLine("Gespeicherte Sessions:"); + Console.WriteLine(ListSessions()); return; } - var path = Save.Session.DirectoryPath + @"\" + name; + var path = Session.DirectoryPath + @"\" + name; var files = Directory.GetFiles(path); var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First(); @@ -32,16 +30,16 @@ namespace DSACore.DSA_Game.Save if (name.Equals("?") || name.Equals(string.Empty)) { - Console.WriteLine($"Gespeicherte Sessions:"); - Console.WriteLine(this.ListSessions()); + Console.WriteLine("Gespeicherte Sessions:"); + Console.WriteLine(ListSessions()); return; } - var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name; + var path = Session.DirectoryPath + @"\" + name; if (Directory.Exists(path)) { var files = Directory.GetFiles(path); - int current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())); + var current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())); Dsa.Session.SessionName = name; Dsa.Session.Save(path + "\\" + name + $"-{++current}.json"); } @@ -49,7 +47,7 @@ namespace DSACore.DSA_Game.Save { Directory.CreateDirectory(path); Dsa.Session.SessionName = name; - Dsa.Session.Save(path + "\\" + name + $"-0.json"); + Dsa.Session.Save(path + "\\" + name + "-0.json"); } Console.WriteLine($"{name} wurde gespeichert"); @@ -58,13 +56,11 @@ namespace DSACore.DSA_Game.Save private string[] ListSessions() { - string[] dirs = Directory.GetDirectories(Session.DirectoryPath).OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray(); - for (int i = 0; i < dirs.Length; i++) - { - dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime; - } + var dirs = Directory.GetDirectories(Session.DirectoryPath) + .OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray(); + for (var i = 0; i < dirs.Length; i++) dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime; return dirs; } } -} +}
\ No newline at end of file diff --git a/DSACore/DSA_Game/Save/Session.cs b/DSACore/DSA_Game/Save/Session.cs index b402656..6944fb1 100644 --- a/DSACore/DSA_Game/Save/Session.cs +++ b/DSACore/DSA_Game/Save/Session.cs @@ -1,32 +1,34 @@ using System; using System.Collections.Generic; +using System.IO; +using DSACore.DSA_Game.Characters; +using Newtonsoft.Json; namespace DSACore.DSA_Game.Save { - using System.IO; - using Characters; - using Newtonsoft.Json; - public class Session { public static string DirectoryPath { get; set; } = Dsa.rootPath + @"sessions"; - public Dictionary<string, string> Relation { get; set; } = new Dictionary<string, string>(); // dictionary to match the char + public Dictionary<string, string> Relation { get; set; } = + new Dictionary<string, string>(); // dictionary to match the char - public List<SaveChar> Chars { get; set; } = new List<SaveChar>(); // list of all characters + public List<SaveChar> Chars { get; set; } = new List<SaveChar>(); // list of all characters public string SessionName { get; set; } - + public static Session Load(string path) { try { - return JsonConvert.DeserializeObject<Session>(File.ReadAllText(path)); // Deserialize Data and create Session Object + return + JsonConvert.DeserializeObject<Session>( + File.ReadAllText(path)); // Deserialize Data and create Session Object } catch (Exception e) { // ignored - Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen."+ e); + Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen." + e); return null; } } @@ -35,13 +37,15 @@ namespace DSACore.DSA_Game.Save { try { - File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct + File.WriteAllText(path, + JsonConvert.SerializeObject(this, + Formatting.Indented)); // Deserialize Data and create CommandInfo Struct } catch (Exception e) { - Console.WriteLine($"Speichern von Save-File {path} fehlgeschlagen.\n"+ e); + Console.WriteLine($"Speichern von Save-File {path} fehlgeschlagen.\n" + e); // ignored } } } -} +}
\ No newline at end of file diff --git a/DSACore/FireBase/Database.cs b/DSACore/FireBase/Database.cs index 15b76f0..8946cf0 100644 --- a/DSACore/FireBase/Database.cs +++ b/DSACore/FireBase/Database.cs @@ -1,14 +1,13 @@ -using DSACore.DSA_Game.Characters; -using DSACore.Models.Database; -using Firebase.Database; -using Firebase.Database.Query; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using DSACore.DSA_Game; +using DSACore.DSA_Game.Characters; using DSACore.Models.Database.DSA; -using DSACore.Models.Database.Groups; - +using DSACore.Models.Network; +using Firebase.Database; +using Firebase.Database.Query; namespace DSACore.FireBase { @@ -16,9 +15,20 @@ namespace DSACore.FireBase { public static FirebaseClient firebase; + public static Dictionary<string, DatabaseChar> Chars = new Dictionary<string, DatabaseChar>(); + + public static Dictionary<string, MeleeWeapon> MeleeList = new Dictionary<string, MeleeWeapon>(); + + public static Dictionary<string, RangedWeapon> RangedWeapons = new Dictionary<string, RangedWeapon>(); + + public static Dictionary<string, Talent> Talents = new Dictionary<string, Talent>(); + + public static Dictionary<string, GeneralSpell> Spells = new Dictionary<string, GeneralSpell>(); + static Database() { - var auth = File.ReadAllText(DSACore.DSA_Game.Dsa.rootPath + "Token"); ; // your app secret + var auth = File.ReadAllText(Dsa.rootPath + "Token"); + ; // your app secret firebase = new FirebaseClient( "https://heldenonline-4d828.firebaseio.com/", new FirebaseOptions @@ -45,32 +55,19 @@ namespace DSACore.FireBase .OrderByKey() .OnceAsync<T>(); - foreach (var firebaseObject in temp) - { - list.Add(firebaseObject.Key, firebaseObject.Object); - } + foreach (var firebaseObject in temp) list.Add(firebaseObject.Key, firebaseObject.Object); } - public static Dictionary<string,DatabaseChar> Chars = new Dictionary<string, DatabaseChar>(); - - public static Dictionary<string, MeleeWeapon> MeleeList = new Dictionary<string, MeleeWeapon>(); - - public static Dictionary<string, RangedWeapon> RangedWeapons = new Dictionary<string, RangedWeapon>(); - - public static Dictionary<string, Talent> Talents = new Dictionary<string, Talent>(); - - public static Dictionary<string, GeneralSpell> Spells = new Dictionary<string, GeneralSpell>(); - - public static async Task<int> AddChar(Character file, Models.Network.Group group) + public static async Task<int> AddChar(Character file, Group group) { - DatabaseChar.LoadChar(file, out GroupChar groupChar, out DatabaseChar data); + DatabaseChar.LoadChar(file, out var groupChar, out var data); var lastChar = await firebase .Child("Chars") .OrderByKey() .LimitToLast(1) .OnceAsync<DatabaseChar>(); - int id = groupChar.Id = data.Id = lastChar.First().Object.Id + 1; + var id = groupChar.Id = data.Id = lastChar.First().Object.Id + 1; await firebase //TODO Reomve await Operators .Child("Groups") @@ -94,7 +91,6 @@ namespace DSACore.FireBase public static async Task RemoveChar(int id) { - await firebase .Child("Groups") .Child("Char" + id) @@ -111,7 +107,6 @@ namespace DSACore.FireBase .Child("Inventories") .Child("Inventory" + id) .DeleteAsync(); - } public static async Task<DatabaseChar> GetChar(int id) @@ -158,11 +153,12 @@ namespace DSACore.FireBase } public static async Task<Talent> GetTalent(string talent) - {/* - return await firebase - .Child("Talents") - .Child(talent) - .OnceSingleAsync<Talent>();*/ + { + /* + return await firebase + .Child("Talents") + .Child(talent) + .OnceSingleAsync<Talent>();*/ return Talents[talent]; } @@ -194,7 +190,7 @@ namespace DSACore.FireBase public static async Task AddWeapon(Weapon wep) { - string collection = wep.GetType() == typeof(MeleeWeapon) ? "MeleeWeapons" : "RangedWeapons"; + var collection = wep.GetType() == typeof(MeleeWeapon) ? "MeleeWeapons" : "RangedWeapons"; await firebase .Child(collection) .Child(wep.Name) @@ -203,7 +199,7 @@ namespace DSACore.FireBase public static async Task RemoveWeapon(string weapon, bool ranged = false) { - string collection = ranged ? "RangedWeapons" : "MeleeWeapons"; + var collection = ranged ? "RangedWeapons" : "MeleeWeapons"; await firebase .Child(collection) .Child(weapon) @@ -212,46 +208,44 @@ namespace DSACore.FireBase public static async Task<Weapon> GetWeapon(string weapon, bool ranged = false) { - string collection = ranged ? "RangedWeapons" : "MeleeWeapons"; + var collection = ranged ? "RangedWeapons" : "MeleeWeapons"; return await firebase .Child(collection) .Child(weapon) .OnceSingleAsync<Weapon>(); } - public static async Task<List<Models.Network.Group>> GetGroups() + public static async Task<List<Group>> GetGroups() { var groups = await firebase .Child("Groups") .OrderByKey() - .OnceAsync<Group>(); - var ret = new List<Models.Network.Group>(); + .OnceAsync<Models.Database.Groups.Group>(); + var ret = new List<Group>(); foreach (var firebaseObject in groups) - { - ret.Add(new Models.Network.Group(firebaseObject.Object.Name, firebaseObject.Object.Password)); - } + ret.Add(new Group(firebaseObject.Object.Name, firebaseObject.Object.Password)); return ret; } - public static async Task<Group> GetGroup(int id) + public static async Task<Models.Database.Groups.Group> GetGroup(int id) { var group = await firebase .Child("Groups") .Child("Group" + id) - .OnceSingleAsync<Group>(); + .OnceSingleAsync<Models.Database.Groups.Group>(); return group; } - public static async Task AddGroup(Group group) + public static async Task AddGroup(Models.Database.Groups.Group group) { var lastChar = await firebase .Child("Groups") .OrderByKey() .LimitToLast(1) - .OnceAsync<Group>(); - int id = group.Id = lastChar.First().Object.Id + 1; + .OnceAsync<Models.Database.Groups.Group>(); + var id = group.Id = lastChar.First().Object.Id + 1; await firebase .Child("Groups") @@ -259,7 +253,7 @@ namespace DSACore.FireBase .PutAsync(group); } - public static async void SetGroup(Group group) + public static async void SetGroup(Models.Database.Groups.Group group) { await firebase .Child("Groups") @@ -275,4 +269,4 @@ namespace DSACore.FireBase .DeleteAsync(); } } -} +}
\ No newline at end of file diff --git a/DSACore/Hubs/Login.cs b/DSACore/Hubs/Login.cs index 5f984e2..1f6ca39 100644 --- a/DSACore/Hubs/Login.cs +++ b/DSACore/Hubs/Login.cs @@ -1,25 +1,22 @@ -using DSACore.DSA_Game.Characters; -using DSACore.FireBase; -using DSACore.Models.Network; -using Microsoft.AspNetCore.SignalR; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CSharp.Syntax; +using DSACore.Commands; +using DSACore.DSA_Game.Characters; +using DSACore.FireBase; +using DSACore.Models.Network; +using Microsoft.AspNetCore.SignalR; namespace DSACore.Hubs { public class Users : Hub { //private static Dictionary<string, User> UserGroup = new Dictionary<string, User>(); - - private const string ReceiveMethod = "ReceiveMessage";//receiveMethod; - private static List<Group> DsaGroups {get; set; } - public static List<Token> Tokens { get;} = new List<Token>(); + private const string ReceiveMethod = "ReceiveMessage"; //receiveMethod; static Users() { @@ -29,41 +26,41 @@ namespace DSACore.Hubs //AddGroups(); } - + private static List<Group> DsaGroups { get; } + public static List<Token> Tokens { get; } = new List<Token>(); + + [Obsolete] private static async void AddGroups() { - await Database.AddGroup(new Models.Database.Groups.Group { Name = "HalloWelt", Password = "valid" }); - await Database.AddGroup(new Models.Database.Groups.Group { Name = "Die Krassen Gamer", Password = "valid" }); - await Database.AddGroup(new Models.Database.Groups.Group { Name = "DSA", Password = "valid" }); - await Database.AddGroup(new Models.Database.Groups.Group { Name = "Die Überhelden", Password = "valid" }); + await Database.AddGroup(new Models.Database.Groups.Group {Name = "HalloWelt", Password = "valid"}); + await Database.AddGroup(new Models.Database.Groups.Group {Name = "Die Krassen Gamer", Password = "valid"}); + await Database.AddGroup(new Models.Database.Groups.Group {Name = "DSA", Password = "valid"}); + await Database.AddGroup(new Models.Database.Groups.Group {Name = "Die Überhelden", Password = "valid"}); } public async Task SendMessage(string user, string message) { try { - string group = getGroup(Context.ConnectionId).Name; + var group = getGroup(Context.ConnectionId).Name; } catch (InvalidOperationException e) { //await Clients.Caller.SendCoreAsync(receiveMethod, - // new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); + // new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); } if (message[0] == '/') { var args = message.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); - bool Timon = args.Any(x => x == "hallo"); + var Timon = args.Any(x => x == "hallo"); var ident = args.First().Replace("/", ""); - if (args.Count > 0) - { - args.RemoveAt(0); - } + if (args.Count > 0) args.RemoveAt(0); - var ret = Commands.CommandHandler.ExecuteCommand(new Command + var ret = CommandHandler.ExecuteCommand(new Command { CharId = 0, CmdIdentifier = ident, @@ -81,63 +78,57 @@ namespace DSACore.Hubs await SendToGroup(ret.message); break; } - - } else { await SendToGroup(message); } - } private Task SendToGroup(string message) { try { - string group = getGroup(Context.ConnectionId).Name; + var group = getGroup(Context.ConnectionId).Name; return Clients.Group(group).SendCoreAsync(ReceiveMethod, new object[] {getUser(Context.ConnectionId).Name, message}); } catch (InvalidOperationException e) { return Clients.Caller.SendCoreAsync(ReceiveMethod, - new object[] { "Nutzer ist in keiner Gruppe. Erst joinen!" }); + new object[] {"Nutzer ist in keiner Gruppe. Erst joinen!"}); } } - private Models.Network.Group getGroup(string id) + private Group getGroup(string id) { return DsaGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))); } private User getUser(string id) { - return DsaGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))).Users.First(z => z.ConnectionId.Equals(id)); + return DsaGroups.First(x => x.Users.Exists(y => y.ConnectionId.Equals(id))).Users + .First(z => z.ConnectionId.Equals(id)); } public async Task GetGroups() { var test = await Database.GetGroups(); - + foreach (var group in test) - { if (!DsaGroups.Exists(x => x.Name.Equals(group.Name))) - { DsaGroups.Add(group); - } - } - await Clients.Caller.SendCoreAsync("ListGroups", new object[] { DsaGroups.Select(x => x.SendGroup()) }); + await Clients.Caller.SendCoreAsync("ListGroups", new object[] {DsaGroups.Select(x => x.SendGroup())}); //throw new NotImplementedException("add database call to get groups"); } public async Task AddGroup(string group, string password) { DsaGroups.Add(new Group(group, password)); - var Dgroup = new Models.Database.Groups.Group { Name = group, Id = DsaGroups.Count - 1 }; + var Dgroup = new Models.Database.Groups.Group {Name = group, Id = DsaGroups.Count - 1}; //Database.AddGroup(Dgroup); - await Clients.Caller.SendCoreAsync(ReceiveMethod, new[] { $"group {@group} sucessfully added" }); + await Clients.Caller.SendCoreAsync(ReceiveMethod, new[] {$"group {group} sucessfully added"}); //throw new NotImplementedException("add database call to add groups"); } @@ -159,7 +150,7 @@ namespace DSACore.Hubs { await Groups.RemoveFromGroupAsync(Context.ConnectionId, "login"); await Groups.AddToGroupAsync(Context.ConnectionId, group); - gGroup.Users.Add(new User { ConnectionId = Context.ConnectionId, Name = user }); + gGroup.Users.Add(new User {ConnectionId = Context.ConnectionId, Name = user}); await SendToGroup("Ein neuer Nutzer hat die Gruppe betreten"); await Clients.Caller.SendAsync("LoginResponse", 0); await Clients.Caller.SendAsync("PlayerStatusChanged", new[] {user, "online"}); @@ -202,7 +193,6 @@ namespace DSACore.Hubs { await Groups.RemoveFromGroupAsync(Context.ConnectionId, "online"); if (DsaGroups.Exists(x => x.Users.Exists(y => y.ConnectionId == Context.ConnectionId))) - { try { var group = getGroup(Context.ConnectionId); @@ -210,7 +200,7 @@ namespace DSACore.Hubs var user = getUser(Context.ConnectionId); - await Clients.Caller.SendAsync("PlayerStatusChanged", new[] { user.Name, "offline" }); + await Clients.Caller.SendAsync("PlayerStatusChanged", new[] {user.Name, "offline"}); //await SendToGroup(user.Name + " disconnected from the Server"); group.Users.Remove(user); await Groups.RemoveFromGroupAsync(Context.ConnectionId, group.Name); @@ -220,9 +210,6 @@ namespace DSACore.Hubs Console.WriteLine(e); //throw; } - } - } - } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/Advantage.cs b/DSACore/Models/Database/DSA/Advantage.cs index 2f0b443..cc8f5cc 100644 --- a/DSACore/Models/Database/DSA/Advantage.cs +++ b/DSACore/Models/Database/DSA/Advantage.cs @@ -13,4 +13,4 @@ namespace DSACore.Models.Database.DSA public string Name { get; set; } public string Value { get; set; } } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/CharSpell.cs b/DSACore/Models/Database/DSA/CharSpell.cs index 63d917a..fabd456 100644 --- a/DSACore/Models/Database/DSA/CharSpell.cs +++ b/DSACore/Models/Database/DSA/CharSpell.cs @@ -13,4 +13,4 @@ namespace DSACore.Models.Database.DSA public string representation { get; set; } public int value { get; set; } } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/DatabaseChar.cs b/DSACore/Models/Database/DSA/DatabaseChar.cs index 8c51821..872b82e 100644 --- a/DSACore/Models/Database/DSA/DatabaseChar.cs +++ b/DSACore/Models/Database/DSA/DatabaseChar.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using DSACore.DSA_Game.Characters; namespace DSACore.Models.Database.DSA { @@ -10,7 +11,8 @@ namespace DSACore.Models.Database.DSA { } - public DatabaseChar(int id, string name, string rasse, List<Field> skills, List<Field> talents, List<Advantage> advantages, List<CharSpell> spells, List<WeaponTalent> weaponTalents) + public DatabaseChar(int id, string name, string rasse, List<Field> skills, List<Field> talents, + List<Advantage> advantages, List<CharSpell> spells, List<WeaponTalent> weaponTalents) { Id = id; Name = name ?? throw new ArgumentNullException(nameof(name)); @@ -39,7 +41,7 @@ namespace DSACore.Models.Database.DSA public List<WeaponTalent> WeaponTalents { get; set; } = new List<WeaponTalent>(); - public static void LoadChar(DSA_Game.Characters.Character file, out GroupChar group, out DatabaseChar data) + public static void LoadChar(Character file, out GroupChar group, out DatabaseChar data) { group = new GroupChar(); data = new DatabaseChar(); @@ -58,4 +60,4 @@ namespace DSACore.Models.Database.DSA data.WeaponTalents = file.Kampftalente.Select(x => new WeaponTalent(x.Name, x.At, x.Pa)).ToList(); } } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/Field.cs b/DSACore/Models/Database/DSA/Field.cs index 5022768..e63aeb4 100644 --- a/DSACore/Models/Database/DSA/Field.cs +++ b/DSACore/Models/Database/DSA/Field.cs @@ -7,10 +7,10 @@ namespace DSACore.Models.Database.DSA public Field(string name, int value = 0) { Name = name ?? throw new ArgumentNullException(nameof(name)); - this.Value = value; + Value = value; } public string Name { get; set; } public int Value { get; set; } } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/GeneralSpell.cs b/DSACore/Models/Database/DSA/GeneralSpell.cs index 74b95d7..b4dbc0b 100644 --- a/DSACore/Models/Database/DSA/GeneralSpell.cs +++ b/DSACore/Models/Database/DSA/GeneralSpell.cs @@ -4,7 +4,7 @@ { public char Comlexity = 'A'; - public GeneralSpell(string name, string roll, char comlexity = 'A') :base(name, roll) + public GeneralSpell(string name, string roll, char comlexity = 'A') : base(name, roll) { Comlexity = comlexity; } @@ -17,4 +17,4 @@ { } } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/GroupChar.cs b/DSACore/Models/Database/DSA/GroupChar.cs index 70b8fc1..31fc583 100644 --- a/DSACore/Models/Database/DSA/GroupChar.cs +++ b/DSACore/Models/Database/DSA/GroupChar.cs @@ -10,4 +10,4 @@ public int AsMax { get; set; } public Weapon Weapon { get; set; } } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/Inventory.cs b/DSACore/Models/Database/DSA/Inventory.cs index 69c7b08..9a025d4 100644 --- a/DSACore/Models/Database/DSA/Inventory.cs +++ b/DSACore/Models/Database/DSA/Inventory.cs @@ -9,4 +9,4 @@ namespace DSACore.Models.Database.DSA public Dictionary<string, bool> Food { get; set; } = new Dictionary<string, bool>(); public List<Weapon> Weapons { get; set; } = new List<Weapon>(); } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/Talent.cs b/DSACore/Models/Database/DSA/Talent.cs index a6de395..59ff4bc 100644 --- a/DSACore/Models/Database/DSA/Talent.cs +++ b/DSACore/Models/Database/DSA/Talent.cs @@ -13,7 +13,7 @@ namespace DSACore.Models.Database.DSA Name = name ?? throw new ArgumentNullException(nameof(name)); } - public Talent(string name, String roll) + public Talent(string name, string roll) { Name = name ?? throw new ArgumentNullException(nameof(name)); Roll = roll.Split('/'); @@ -23,4 +23,4 @@ namespace DSACore.Models.Database.DSA public string[] Roll { get; set; } = new string[3]; } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/Weapon.cs b/DSACore/Models/Database/DSA/Weapon.cs index 24b334a..58a44cd 100644 --- a/DSACore/Models/Database/DSA/Weapon.cs +++ b/DSACore/Models/Database/DSA/Weapon.cs @@ -26,25 +26,27 @@ namespace DSACore.Models.Database.DSA public class MeleeWeapon : Weapon { + public MeleeWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, + damage, weight, weaponTalent, price) + { + } + public string TpKK { get; set; } public int INI { get; set; } public string MW { get; set; } - - public MeleeWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, damage, weight, weaponTalent, price) - { - } } public class RangedWeapon : Weapon { + public RangedWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, + damage, weight, weaponTalent, price) + { + } + public int AtMod { get; set; } public int KKMod { get; set; } public string AtReach { get; set; } public string TpReach { get; set; } public int LoadTime { get; set; } - - public RangedWeapon(string name, string damage, int weight, string weaponTalent, string price) : base(name, damage, weight, weaponTalent, price) - { - } } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Database/DSA/WeaponTalent.cs b/DSACore/Models/Database/DSA/WeaponTalent.cs index 869cb35..98eb38d 100644 --- a/DSACore/Models/Database/DSA/WeaponTalent.cs +++ b/DSACore/Models/Database/DSA/WeaponTalent.cs @@ -2,7 +2,7 @@ namespace DSACore.Models.Database.DSA { - public class WeaponTalent + public class WeaponTalent { public WeaponTalent(string name, int at, int pa) { diff --git a/DSACore/Models/Database/Groups/DSAGroup.cs b/DSACore/Models/Database/Groups/DSAGroup.cs index 8f20278..89fac2f 100644 --- a/DSACore/Models/Database/Groups/DSAGroup.cs +++ b/DSACore/Models/Database/Groups/DSAGroup.cs @@ -5,6 +5,6 @@ namespace DSACore.Models.Database.Groups { public class DSAGroup : Group { - public List<GroupChar> Chars { get; set; }= new List<GroupChar>(); + public List<GroupChar> Chars { get; set; } = new List<GroupChar>(); } }
\ No newline at end of file diff --git a/DSACore/Models/Database/Groups/Group.cs b/DSACore/Models/Database/Groups/Group.cs index 23e5f68..77d3a64 100644 --- a/DSACore/Models/Database/Groups/Group.cs +++ b/DSACore/Models/Database/Groups/Group.cs @@ -6,8 +6,5 @@ public string Discord { get; set; } public string Password { get; set; } public int Id { get; set; } - } - - -} +}
\ No newline at end of file diff --git a/DSACore/Models/Network/Command.cs b/DSACore/Models/Network/Command.cs index 456a896..00b00a6 100644 --- a/DSACore/Models/Network/Command.cs +++ b/DSACore/Models/Network/Command.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; namespace DSACore.Models.Network { @@ -14,7 +12,7 @@ namespace DSACore.Models.Network public List<string> CmdTexts { get; set; } public string CmdText => CmdTexts.Count != 0 ? CmdTexts.First() : ""; - public int Cmdmodifier => CmdTexts.Count != 0 && int.TryParse(CmdTexts.Last(), out int mod) ? mod : 0; + public int Cmdmodifier => CmdTexts.Count != 0 && int.TryParse(CmdTexts.Last(), out var mod) ? mod : 0; public bool IsDm { get; set; } = false; } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Network/CommandResponse.cs b/DSACore/Models/Network/CommandResponse.cs index ed4b7d0..c7a410a 100644 --- a/DSACore/Models/Network/CommandResponse.cs +++ b/DSACore/Models/Network/CommandResponse.cs @@ -1,20 +1,17 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace DSACore.Models.Network { public class CommandResponse { - public CommandResponse(string message, ResponseType responseType= ResponseType.Broadcast) + public CommandResponse(string message, ResponseType responseType = ResponseType.Broadcast) { this.message = message ?? throw new ArgumentNullException(nameof(message)); ResponseType = responseType; } - public string message { get; private set; } - public ResponseType ResponseType { get; private set;} + public string message { get; } + public ResponseType ResponseType { get; } public override string ToString() { @@ -28,4 +25,4 @@ namespace DSACore.Models.Network Caller, Error } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Network/Group.cs b/DSACore/Models/Network/Group.cs index 76c3efb..efe12ee 100644 --- a/DSACore/Models/Network/Group.cs +++ b/DSACore/Models/Network/Group.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace DSACore.Models.Network { @@ -22,14 +20,11 @@ namespace DSACore.Models.Network public string Password { get; set; } public List<User> Users { get; set; } = new List<User>(); - public int UserCount - { - get { return Users.Count; } - } + public int UserCount => Users.Count; public SendGroup SendGroup() { - return new SendGroup( Name, UserCount); + return new SendGroup(Name, UserCount); } } @@ -44,6 +39,5 @@ namespace DSACore.Models.Network public string Name { get; set; } public int UserCount { get; set; } - } -} +}
\ No newline at end of file diff --git a/DSACore/Models/Network/Token.cs b/DSACore/Models/Network/Token.cs index 0021317..451cafc 100644 --- a/DSACore/Models/Network/Token.cs +++ b/DSACore/Models/Network/Token.cs @@ -1,18 +1,18 @@ using System; -using Microsoft.EntityFrameworkCore; namespace DSACore.Models.Network { public class Token { - public string Group { get; set; } - private DateTime creation = DateTime.Now; + private readonly DateTime creation = DateTime.Now; - public Token(string @group) + public Token(string group) { - Group = @group; + Group = group; } + public string Group { get; set; } + public bool IsValid() { return DateTime.Now - creation < TimeSpan.FromMinutes(1); diff --git a/DSACore/Models/Network/User.cs b/DSACore/Models/Network/User.cs index 04ef0a9..8b8008c 100644 --- a/DSACore/Models/Network/User.cs +++ b/DSACore/Models/Network/User.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DSACore.Models.Network +namespace DSACore.Models.Network { public class User { @@ -11,4 +6,4 @@ namespace DSACore.Models.Network public string ConnectionId { get; set; } public int Char { get; set; } } -} +}
\ No newline at end of file diff --git a/DSACore/Program.cs b/DSACore/Program.cs index d8cb67c..46baf2d 100644 --- a/DSACore/Program.cs +++ b/DSACore/Program.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; +using DSACore.DSA_Game; using DSACore.FireBase; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; namespace DSACore { @@ -16,14 +10,15 @@ namespace DSACore public static void Main(string[] args) { Database.GetGroup(0).Wait(); - DSA_Game.Dsa.Startup(); + Dsa.Startup(); CreateWebHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) + public static IWebHostBuilder CreateWebHostBuilder(string[] args) + { + return WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseUrls("http://0.0.0.0:5000"); - + } } -} +}
\ No newline at end of file diff --git a/DSACore/Startup.cs b/DSACore/Startup.cs index 1dcc690..372caca 100644 --- a/DSACore/Startup.cs +++ b/DSACore/Startup.cs @@ -1,16 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using DSACore.Hubs; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; -using DSACore.Hubs; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; namespace DSACore { @@ -52,23 +45,19 @@ namespace DSACore public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) - { app.UseDeveloperExceptionPage(); - } else - { app.UseHsts(); - } app.UseCors("CorsPolicy"); app.UseSignalR(routes => { routes.MapHub<Users>("/login"); }); app.UseWebSockets(); - - //app.UseCors("AllowSpecificOrigin"); + + //app.UseCors("AllowSpecificOrigin"); app.UseHttpsRedirection(); app.UseMvc(); } } -} +}
\ No newline at end of file |