From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/DSALib/Auxiliary/Calculator/Argument.cs | 35 +++ dsa/DSALib/Auxiliary/Calculator/ISolvable.cs | 10 + dsa/DSALib/Auxiliary/Calculator/Operator.cs | 51 ++++ dsa/DSALib/Auxiliary/Calculator/Ops.cs | 13 + dsa/DSALib/Auxiliary/Calculator/StringSolver.cs | 183 +++++++++++++ dsa/DSALib/Auxiliary/CommandInfo.cs | 28 ++ dsa/DSALib/Auxiliary/Dice.cs | 45 ++++ dsa/DSALib/Auxiliary/Extensions.cs | 25 ++ .../Auxiliary/IDataObjectEnumerableExtension.cs | 25 ++ dsa/DSALib/Auxiliary/RandomMisc.cs | 52 ++++ dsa/DSALib/Auxiliary/SpellCorrect.cs | 61 +++++ dsa/DSALib/Auxiliary/TalentEnumerableExtension.cs | 74 ++++++ dsa/DSALib/Auxiliary/WeaponImporter.cs | 175 +++++++++++++ dsa/DSALib/Characters/Being.cs | 17 ++ dsa/DSALib/Characters/Critter.cs | 88 +++++++ dsa/DSALib/Characters/Entity.cs | 12 + dsa/DSALib/Characters/ICharacter.cs | 15 ++ dsa/DSALib/Characters/ICombatant.cs | 20 ++ dsa/DSALib/Commands/CommandHandler.cs | 135 ++++++++++ dsa/DSALib/Commands/CommandTypes.cs | 13 + dsa/DSALib/Commands/FileHandler.cs | 32 +++ dsa/DSALib/Commands/Gm.cs | 176 +++++++++++++ dsa/DSALib/Commands/HeldList.cs | 174 +++++++++++++ dsa/DSALib/Commands/Help.cs | 54 ++++ dsa/DSALib/Commands/LebenUndAstral.cs | 172 ++++++++++++ dsa/DSALib/Commands/List.cs | 39 +++ dsa/DSALib/Commands/MiscCommands.cs | 219 ++++++++++++++++ dsa/DSALib/Commands/NpcCommands.cs | 35 +++ dsa/DSALib/Commands/ProbenTest.cs | 85 ++++++ dsa/DSALib/DSALib.csproj | 11 + dsa/DSALib/DSA_Game/Characters/Character.cs | 269 +++++++++++++++++++ dsa/DSALib/DSA_Game/Characters/NPC.cs | 83 ++++++ dsa/DSALib/DSA_Game/Characters/SaveChar.cs | 38 +++ dsa/DSALib/DSA_Game/Dsa.cs | 95 +++++++ dsa/DSALib/DSA_Game/Save/Properties.cs | 74 ++++++ dsa/DSALib/DSA_Game/Save/SaveCommand.cs | 66 +++++ dsa/DSALib/DSA_Game/Save/Session.cs | 51 ++++ dsa/DSALib/FireBase/Database.cs | 270 +++++++++++++++++++ dsa/DSALib/Models/Database/DataObject.cs | 13 + dsa/DSALib/Models/Database/Dsa/Advantage.cs | 16 ++ dsa/DSALib/Models/Database/Dsa/CharSpell.cs | 16 ++ dsa/DSALib/Models/Database/Dsa/DatabaseChar.cs | 63 +++++ dsa/DSALib/Models/Database/Dsa/Field.cs | 16 ++ dsa/DSALib/Models/Database/Dsa/GeneralSpell.cs | 20 ++ dsa/DSALib/Models/Database/Dsa/GroupChar.cs | 13 + dsa/DSALib/Models/Database/Dsa/Inventory.cs | 12 + dsa/DSALib/Models/Database/Dsa/Talent.cs | 24 ++ dsa/DSALib/Models/Database/Dsa/Weapon.cs | 52 ++++ dsa/DSALib/Models/Database/Dsa/WeaponTalent.cs | 18 ++ dsa/DSALib/Models/Database/Groups/DSAGroup.cs | 10 + dsa/DSALib/Models/Database/Groups/Group.cs | 9 + dsa/DSALib/Models/Database/IDataObject.cs | 7 + dsa/DSALib/Models/Dsa/CritterAttack.cs | 19 ++ dsa/DSALib/Models/Dsa/KampfTalent.cs | 16 ++ dsa/DSALib/Models/Dsa/Talent.cs | 43 +++ dsa/DSALib/Models/Dsa/Vorteil.cs | 16 ++ dsa/DSALib/Models/Dsa/Zauber.cs | 16 ++ dsa/DSALib/Models/Network/Command.cs | 18 ++ dsa/DSALib/Models/Network/CommandResponse.cs | 28 ++ .../Properties-DSACore-Auxiliary-CommandInfo.json | 101 +++++++ ...ties-DSACore-DSA_Game-Characters-Character.json | 290 +++++++++++++++++++++ .../PropertiesNewtonsoft-Json-Linq-JProperty.json | 30 +++ 62 files changed, 3886 insertions(+) create mode 100644 dsa/DSALib/Auxiliary/Calculator/Argument.cs create mode 100644 dsa/DSALib/Auxiliary/Calculator/ISolvable.cs create mode 100644 dsa/DSALib/Auxiliary/Calculator/Operator.cs create mode 100644 dsa/DSALib/Auxiliary/Calculator/Ops.cs create mode 100644 dsa/DSALib/Auxiliary/Calculator/StringSolver.cs create mode 100644 dsa/DSALib/Auxiliary/CommandInfo.cs create mode 100644 dsa/DSALib/Auxiliary/Dice.cs create mode 100644 dsa/DSALib/Auxiliary/Extensions.cs create mode 100644 dsa/DSALib/Auxiliary/IDataObjectEnumerableExtension.cs create mode 100644 dsa/DSALib/Auxiliary/RandomMisc.cs create mode 100644 dsa/DSALib/Auxiliary/SpellCorrect.cs create mode 100644 dsa/DSALib/Auxiliary/TalentEnumerableExtension.cs create mode 100644 dsa/DSALib/Auxiliary/WeaponImporter.cs create mode 100644 dsa/DSALib/Characters/Being.cs create mode 100644 dsa/DSALib/Characters/Critter.cs create mode 100644 dsa/DSALib/Characters/Entity.cs create mode 100644 dsa/DSALib/Characters/ICharacter.cs create mode 100644 dsa/DSALib/Characters/ICombatant.cs create mode 100644 dsa/DSALib/Commands/CommandHandler.cs create mode 100644 dsa/DSALib/Commands/CommandTypes.cs create mode 100644 dsa/DSALib/Commands/FileHandler.cs create mode 100644 dsa/DSALib/Commands/Gm.cs create mode 100644 dsa/DSALib/Commands/HeldList.cs create mode 100644 dsa/DSALib/Commands/Help.cs create mode 100644 dsa/DSALib/Commands/LebenUndAstral.cs create mode 100644 dsa/DSALib/Commands/List.cs create mode 100644 dsa/DSALib/Commands/MiscCommands.cs create mode 100644 dsa/DSALib/Commands/NpcCommands.cs create mode 100644 dsa/DSALib/Commands/ProbenTest.cs create mode 100644 dsa/DSALib/DSALib.csproj create mode 100644 dsa/DSALib/DSA_Game/Characters/Character.cs create mode 100644 dsa/DSALib/DSA_Game/Characters/NPC.cs create mode 100644 dsa/DSALib/DSA_Game/Characters/SaveChar.cs create mode 100644 dsa/DSALib/DSA_Game/Dsa.cs create mode 100644 dsa/DSALib/DSA_Game/Save/Properties.cs create mode 100644 dsa/DSALib/DSA_Game/Save/SaveCommand.cs create mode 100644 dsa/DSALib/DSA_Game/Save/Session.cs create mode 100644 dsa/DSALib/FireBase/Database.cs create mode 100644 dsa/DSALib/Models/Database/DataObject.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/Advantage.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/CharSpell.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/DatabaseChar.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/Field.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/GeneralSpell.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/GroupChar.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/Inventory.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/Talent.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/Weapon.cs create mode 100644 dsa/DSALib/Models/Database/Dsa/WeaponTalent.cs create mode 100644 dsa/DSALib/Models/Database/Groups/DSAGroup.cs create mode 100644 dsa/DSALib/Models/Database/Groups/Group.cs create mode 100644 dsa/DSALib/Models/Database/IDataObject.cs create mode 100644 dsa/DSALib/Models/Dsa/CritterAttack.cs create mode 100644 dsa/DSALib/Models/Dsa/KampfTalent.cs create mode 100644 dsa/DSALib/Models/Dsa/Talent.cs create mode 100644 dsa/DSALib/Models/Dsa/Vorteil.cs create mode 100644 dsa/DSALib/Models/Dsa/Zauber.cs create mode 100644 dsa/DSALib/Models/Network/Command.cs create mode 100644 dsa/DSALib/Models/Network/CommandResponse.cs create mode 100644 dsa/DSALib/Properties-DSACore-Auxiliary-CommandInfo.json create mode 100644 dsa/DSALib/Properties-DSACore-DSA_Game-Characters-Character.json create mode 100644 dsa/DSALib/PropertiesNewtonsoft-Json-Linq-JProperty.json (limited to 'dsa/DSALib') diff --git a/dsa/DSALib/Auxiliary/Calculator/Argument.cs b/dsa/DSALib/Auxiliary/Calculator/Argument.cs new file mode 100644 index 0000000..e681377 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Calculator/Argument.cs @@ -0,0 +1,35 @@ +using System; + +namespace DSALib.Auxiliary.Calculator +{ + /// + /// Provides an ISolvable class to save numbers. The class handles Argument checking and conversion from string to int. + /// + public class Argument : ISolvable + { + private readonly int value; + + public Argument(string value) + { + // check whether the value given is an empty string + if (string.IsNullOrEmpty(value)) + throw new ArgumentException("Argument kann nicht mit einem leeren string instanziert werden. ", + nameof(value)); + + if (!int.TryParse(value, out var result)) + throw new ArgumentException($"Kann {value} nicht in Integer konvertieren"); + + this.value = result; + } + + public int Solve() + { + return value; + } + + public override string ToString() + { + return value.ToString(); + } + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/Calculator/ISolvable.cs b/dsa/DSALib/Auxiliary/Calculator/ISolvable.cs new file mode 100644 index 0000000..844e9b3 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Calculator/ISolvable.cs @@ -0,0 +1,10 @@ +namespace DSALib.Auxiliary.Calculator +{ + /// + /// Object has to be able to return an integer as it's value + /// + public interface ISolvable + { + int Solve(); + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/Calculator/Operator.cs b/dsa/DSALib/Auxiliary/Calculator/Operator.cs new file mode 100644 index 0000000..e6aeec6 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Calculator/Operator.cs @@ -0,0 +1,51 @@ +using System; +using DSALibv.Auxiliary.Calculator; + +namespace DSALib.Auxiliary.Calculator +{ + /// + /// The Operator Class represents a binary operator with tow Arguments and an Operation type + /// + public class Operator : ISolvable + { + private readonly ISolvable arg1, arg2; + + public Operator(ISolvable arg1, ISolvable arg2, Ops operatorType) + { + this.arg1 = arg1; + this.arg2 = arg2; + OperatorType = operatorType; + } + + public Ops OperatorType { get; set; } + + public int Solve() + { + int result; + switch (OperatorType) + { + case Ops.Dice: + result = Dice.Roll(arg1.Solve(), arg2.Solve()); + break; + case Ops.Multiply: + result = arg1.Solve() * arg2.Solve(); + break; + case Ops.Add: + result = arg1.Solve() + arg2.Solve(); + break; + case Ops.Subtract: + result = arg1.Solve() - arg2.Solve(); + break; + default: + throw new ArgumentOutOfRangeException(); + } + + return result; + } + + public override string ToString() + { + return $"({arg1} {OperatorType} {arg2})"; + } + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/Calculator/Ops.cs b/dsa/DSALib/Auxiliary/Calculator/Ops.cs new file mode 100644 index 0000000..93046d0 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Calculator/Ops.cs @@ -0,0 +1,13 @@ +namespace DSALibv.Auxiliary.Calculator +{ + /// + /// The Different Operations, witch can be performed in execution-order + /// + public enum Ops + { + Dice, + Multiply, + Subtract, + Add + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/Calculator/StringSolver.cs b/dsa/DSALib/Auxiliary/Calculator/StringSolver.cs new file mode 100644 index 0000000..45d6a54 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Calculator/StringSolver.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using DSALibv.Auxiliary.Calculator; + +namespace DSALib.Auxiliary.Calculator +{ + /// + /// The StringSolver divides the calculation string into operations and SubStringSolvers if the string contains + /// parentheses + /// + public class StringSolver : ISolvable + { + private readonly List arguments = new List(); + private readonly string input; + + public StringSolver(string input) + { + this.input = input; + } + + public int Solve() + { + 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"}. + AtomizeOperations(workInput); + + // traverse the List in order of Operation to Create the binary operation tree . + NestOperations(); + + // the List now contains only the top operation node, witch can be solved recursively, + return ((ISolvable) arguments.First()).Solve(); + } + + public override string ToString() + { + 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++) + { + var c = input[index]; + switch (c) + { + case '(': + depth++; + break; + case ')': + if (depth == 0) + { + var split = input.Substring(1, index - 1); + input = input.Substring(index + 1); + return split.Equals(string.Empty) ? "0" : split; + } + else + { + depth--; + } + + break; + } + } + + throw new ArgumentException("Invalid brace sequence"); + } + + private static Ops GetOps(char c) + { + switch (c) + { + case 'd': + case 'w': + return Ops.Dice; + case '+': + return Ops.Add; + case '-': + return Ops.Subtract; + case '*': + return Ops.Multiply; + default: + return Ops.Multiply; + } + } + + private static string ExpandParentheses(string input) // insert * between Parentheses and digits + { + for (var i = 0; i < input.Length - 1; i++) + if (input[i + 1] == '(' && char.IsNumber(input[i])) + input = input.Insert(i + 1, "*"); + + for (var i = 1; i < input.Length; i++) + if (input[i - 1] == ')' && char.IsNumber(input[i])) + input = input.Insert(i, "*"); + + return input; + } + + private void AtomizeOperations(string workInput) + { + for (var index = 0; index < workInput.Length; 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 + arguments.Add(new Argument(workInput.Substring(0, index + 1))); + + continue; + } + + switch (c) + { + case ')': + throw new ArgumentException("Invalid brace sequence"); + case '(': + arguments.Add(new StringSolver(GetInner(ref workInput))); + index = -1; + break; + default: + if (index > 0) arguments.Add(new Argument(workInput.Substring(0, index))); + + arguments.Add(GetOps(c)); + workInput = workInput.Remove(0, index + 1); + index = -1; + break; + } + } + } + + private void NestOperations() + { + foreach (Ops currentOp in Enum.GetValues(typeof(Ops))) + // cycle through operators in operational order + for (var index = 0; index < arguments.Count; index++) + { + var arg = arguments[index]; + + if (arg.GetType() != typeof(Ops)) continue; + + // arg is of type Ops + var op = (Ops) arg; + + if (op != currentOp) continue; + + // arg describes the current operation + 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) 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 = arguments[index - 1]; + if (arg1.GetType() == typeof(Ops)) + { + if (op == Ops.Dice) arguments.Insert(index++, new Argument("1")); // w6 -> 1w6 + + if (op == Ops.Subtract) arguments.Insert(index++, new Argument("0")); // +-3 -> +0-3 + } + + var arg2 = arguments[index + 1]; // 3+-5 -> 3+(0-5) + if (arg2.GetType() == typeof(Ops)) + { + arguments[index + 1] = new Operator(new Argument("0"), (ISolvable) arguments[index + 2], (Ops) arg2); + arguments.RemoveAt(index + 2); + } + } + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/CommandInfo.cs b/dsa/DSALib/Auxiliary/CommandInfo.cs new file mode 100644 index 0000000..d8e2188 --- /dev/null +++ b/dsa/DSALib/Auxiliary/CommandInfo.cs @@ -0,0 +1,28 @@ +using System.Linq; + +namespace DSALib.Auxiliary +{ + public struct CommandInfo + { + public CommandInfo(string name, string brief, string[] description, string scope) + { + Name = name; + Scope = scope; + Brief = brief; + Description = description; + } + + public string Name { get; } + + public string Scope { get; } + + public string Brief { get; } + + public string[] Description { get; } + + public string GetDescription() + { + return Description.Aggregate((s, c) => s + c); + } + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/Dice.cs b/dsa/DSALib/Auxiliary/Dice.cs new file mode 100644 index 0000000..0bfabeb --- /dev/null +++ b/dsa/DSALib/Auxiliary/Dice.cs @@ -0,0 +1,45 @@ +using System; +using System.Linq; + +namespace DSALib.Auxiliary +{ + public static class Dice // roll it! + { + private static readonly Random Rnd = new Random(); + + public static int Roll(int d = 20) + { + return Rnd.Next(d) + 1; + } + + public static int Roll(string input) + { + var strings = input.ToLower().Split(new[] {'w', 'd'}, 2, StringSplitOptions.RemoveEmptyEntries).ToList(); + + + if (strings.Count != 2) + throw new ArgumentException($"{input}: does not satisfy the format requirements( dice count (d|w) die size)"); + + var count = Convert.ToInt32(strings[0]); + var d = Convert.ToInt32(strings[0]); + + return Roll(count, d); + } + + public static int Roll(int count, int d) + { + if (d <= 0 || count <= 0) return 0; + + var sum = 0; + for (var i = 0; i < Math.Abs(count); i++) + { + var roll = Roll(d); + sum += roll; + } + + sum *= Math.Abs(count) / count; + + return sum; + } + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/Extensions.cs b/dsa/DSALib/Auxiliary/Extensions.cs new file mode 100644 index 0000000..7d367a5 --- /dev/null +++ b/dsa/DSALib/Auxiliary/Extensions.cs @@ -0,0 +1,25 @@ +namespace DSALib.Auxiliary +{ + public static class StringExtension + { + //This mehod extends string. It adds spaces until a fixed length is reached. + //If the original string is already longer, it is returner unmodified. + public static string AddSpaces(this string str, int length) + { + var temp = str; + for (var i = str.Length; i < length; i++) temp += " "; + return temp; + } + + + //This mehod extends string. + //It adds spaces at the HEAD of a string until a fixed length is reached. + //If the original string is already longer, it is returner unmodified. + public static string AddSpacesAtHead(this string str, int length) + { + var temp = ""; + for (var i = str.Length; i < length; i++) temp += " "; + return temp + str; + } + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/IDataObjectEnumerableExtension.cs b/dsa/DSALib/Auxiliary/IDataObjectEnumerableExtension.cs new file mode 100644 index 0000000..b8a6067 --- /dev/null +++ b/dsa/DSALib/Auxiliary/IDataObjectEnumerableExtension.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using DSALib.Auxiliary; +using DSALib.Models.Database; + +namespace DSACore.Auxiliary +{ + public static class DataObjectEnumerableExtension + { + public static IDataObject Match(this IEnumerable dataObjects, string name) + { + return (dataObjects as IOrderedEnumerable ?? throw new InvalidOperationException()).OrderBy(x => SpellCorrect.Compare(name,x.Name)).Last(); + } + + public static bool TryMatch(this IEnumerable dataObjects,out IDataObject data, string name) + { + data = (dataObjects as IOrderedEnumerable ?? throw new InvalidOperationException()).OrderBy(x => SpellCorrect.Compare(name,x.Name)).Last(); + + return SpellCorrect.IsMatch(name, data.Name); + } + } +} diff --git a/dsa/DSALib/Auxiliary/RandomMisc.cs b/dsa/DSALib/Auxiliary/RandomMisc.cs new file mode 100644 index 0000000..2723930 --- /dev/null +++ b/dsa/DSALib/Auxiliary/RandomMisc.cs @@ -0,0 +1,52 @@ +using System; +using System.Linq; +using System.Text; + +namespace DSALib.Auxiliary +{ + public static class RandomMisc + { + private static readonly Random Rand = new Random(); + + // use: 4w6 +4 + public static string Roll(string input) + { + var output = new StringBuilder(); + var strings = input.Split('w', 'd').ToList(); + var count = Convert.ToInt32(strings[0]); + strings = strings[1].Split(' ').ToList(); + var d = Convert.ToInt32(strings[0]); + + if (strings.Count > 0) + { + } + + var sum = 0; + for (var i = 0; i < count; i++) + { + var roll = Dice.Roll(d); + sum += roll; + output.Append("[" + roll + "] "); + } + + if (strings.Count > 1) + { + sum += Convert.ToInt32(strings[1]); + output.Append("sum: " + sum); + } + + return output.ToString(); + } + + public static double Random(double stdDev = 1, double mean = 0) + { + 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/dsa/DSALib/Auxiliary/SpellCorrect.cs b/dsa/DSALib/Auxiliary/SpellCorrect.cs new file mode 100644 index 0000000..79908c4 --- /dev/null +++ b/dsa/DSALib/Auxiliary/SpellCorrect.cs @@ -0,0 +1,61 @@ +using System; + +namespace DSALib.Auxiliary +{ + public class SpellCorrect + { + public const double ErrorThreshold = 1 / 3.0; + private const double Match = 3.0; + private const double Gap = -1.5; + private const double Mismatch = -2.0; + + public static double Compare(string s, string q) + { + s = s.ToLower(); + q = q.ToLower(); + + int i, j; + + 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] = i * Gap; + + 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++) + { + double decay = j / (s.Length * 1000.0); + 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, j - 1] + Gap) score = matrix[i, j - 1] + Gap; + + if (i > 1 && 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; + } + + if (max < score && i == s.Length) max = score; + + matrix[i, j] = score; + } + + return max; + } + + public static bool IsMatch(string s1, string s2) + { + var score = Compare(s1, s2); + return score > ErrorThreshold * s1.Length; + } + } +} \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/TalentEnumerableExtension.cs b/dsa/DSALib/Auxiliary/TalentEnumerableExtension.cs new file mode 100644 index 0000000..6ec7fcc --- /dev/null +++ b/dsa/DSALib/Auxiliary/TalentEnumerableExtension.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using DSACore.Auxiliary; +using DSALib.DSA_Game.Characters; +using DSALib.Models.Dsa; + +namespace DSALib.Auxiliary +{ + public static class TalentEnumerableExtension + { + public static string ProbenTest(this IEnumerable List, Character c, string talentName, int erschwernis = 0) + { + var output = new StringBuilder(); + var sc = new SpellCorrect(); + + if (!List.TryMatch(out var iTalent, talentName)) + return $"{c.Name} kann nicht {talentName}..."; + + var talent = (Talent) iTalent; + var props = talent.GetEigenschaften(); // get the required properties + var tap = talent.Value; // get taw + var werte = props.Select(p => c.Eigenschaften[c.PropTable[p]]).ToArray(); + + output.AppendFormat( + "{0} würfelt: {1} \n{2} - {3} taw:{4} {5} \n", + c.Name, + talent.Name, + talent.Probe, + string.Join("/", werte), + talent.Value, + erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); + + output.Append(" "); + tap -= erschwernis; + var gesamtErschwernis = tap; + if (gesamtErschwernis < 0) + { + tap = 0; + for (var i = 0; i <= 2; i++) + { + // foreach property, dice and tap + var temp = Dice.Roll(); + var eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; + + if (eigenschaft + gesamtErschwernis < temp) tap -= temp - (eigenschaft + gesamtErschwernis); + + output.Append($"[{temp}]"); // add to string + } + + if (tap >= 0) tap = 1; + } + else + { + for (var i = 0; i <= 2; i++) + { + // foreach property, dice and tap + var temp = Dice.Roll(); + var eigenschaft = c.Eigenschaften[c.PropTable[props[i]]]; + + if (eigenschaft < temp) tap -= temp - eigenschaft; + + output.Append($"[{temp}]"); // add to string + } + } + + 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/dsa/DSALib/Auxiliary/WeaponImporter.cs b/dsa/DSALib/Auxiliary/WeaponImporter.cs new file mode 100644 index 0000000..61eb33e --- /dev/null +++ b/dsa/DSALib/Auxiliary/WeaponImporter.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using DSALib.FireBase; +using DSALib.Models.Database.Dsa; + +namespace DSALib.Auxiliary +{ + public class WeaponImporter + { + private readonly List Range = new List(); + private readonly List Weapons = new List(); + + public async Task DownloadWeapons() + { + var client = new HttpClient(); + + + for (var i = 1; i <= 25; i++) + { + var responseString = + await client.GetStringAsync("http://diarium.eu/dsa4-forge/ajax/categoryChanged/" + i); + + var talentRegex = new Regex(@"(?<=