summaryrefslogtreecommitdiff
path: root/DSACore/Auxiliary
diff options
context:
space:
mode:
Diffstat (limited to 'DSACore/Auxiliary')
-rw-r--r--DSACore/Auxiliary/Calculator/Argument.cs23
-rw-r--r--DSACore/Auxiliary/Calculator/ISolvable.cs4
-rw-r--r--DSACore/Auxiliary/Calculator/Operator.cs18
-rw-r--r--DSACore/Auxiliary/Calculator/Ops.cs4
-rw-r--r--DSACore/Auxiliary/Calculator/StringSolver.cs109
-rw-r--r--DSACore/Auxiliary/CommandInfo.cs18
-rw-r--r--DSACore/Auxiliary/Dice.cs23
-rw-r--r--DSACore/Auxiliary/Extensions.cs18
-rw-r--r--DSACore/Auxiliary/RandomMisc.cs32
-rw-r--r--DSACore/Auxiliary/SpellCorrect.cs113
-rw-r--r--DSACore/Auxiliary/TalentEnumerableExtension.cs43
-rw-r--r--DSACore/Auxiliary/WeaponImporter.cs61
12 files changed, 181 insertions, 285 deletions
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