From 2ab4051c6fe720dc47e99b0c305a0d779ee02d51 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 19 May 2019 17:58:42 +0200 Subject: Moved Gamelogic to DSALib --- DSACore/DSA_Game/Characters/Character.cs | 271 ------------------------------- DSACore/DSA_Game/Characters/NPC.cs | 83 ---------- DSACore/DSA_Game/Characters/SaveChar.cs | 38 ----- DSACore/DSA_Game/Dsa.cs | 94 ----------- DSACore/DSA_Game/Save/Properties.cs | 80 --------- DSACore/DSA_Game/Save/SaveCommand.cs | 66 -------- DSACore/DSA_Game/Save/Session.cs | 51 ------ 7 files changed, 683 deletions(-) delete mode 100644 DSACore/DSA_Game/Characters/Character.cs delete mode 100644 DSACore/DSA_Game/Characters/NPC.cs delete mode 100644 DSACore/DSA_Game/Characters/SaveChar.cs delete mode 100644 DSACore/DSA_Game/Dsa.cs delete mode 100644 DSACore/DSA_Game/Save/Properties.cs delete mode 100644 DSACore/DSA_Game/Save/SaveCommand.cs delete mode 100644 DSACore/DSA_Game/Save/Session.cs (limited to 'DSACore/DSA_Game') diff --git a/DSACore/DSA_Game/Characters/Character.cs b/DSACore/DSA_Game/Characters/Character.cs deleted file mode 100644 index ac890cb..0000000 --- a/DSACore/DSA_Game/Characters/Character.cs +++ /dev/null @@ -1,271 +0,0 @@ -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 -{ - public class Character : Being, ICharacter - { - public Character() - { - 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() - { - Load(new MemoryStream(File.ReadAllBytes(path))); // load - Post_process(); // calculate derived values - } - - public Character(MemoryStream stream) : this() - { - Load(stream); // load - Post_process(); // calculate derived values - } - - public Character(Character c, string name, int stDv = 2) : this() - { - Name = name; - foreach (var i in c.Eigenschaften) - Eigenschaften.Add(i.Key, i.Value + (int) Math.Round(RandomMisc.Random(stDv))); - - foreach (var i in c.Vorteile) - Vorteile.Add(new Vorteil(i.Name, i.Value + (int) Math.Round(RandomMisc.Random(stDv)))); - - foreach (var i in c.Talente) - Talente.Add(new Talent(i.Name, i.Probe, i.Value + (int) Math.Round(RandomMisc.Random(stDv)))); - - foreach (var i in c.Zauber) - 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) - Kampftalente.Add(new KampfTalent(i.Name, i.At + (int) Math.Round(RandomMisc.Random(stDv)), - i.Pa + (int) Math.Round(RandomMisc.Random(stDv)))); - - Post_process(); // calculate derived values - } - - public Dictionary Eigenschaften { get; set; } = new Dictionary(); // char properties - - public List Talente { get; set; } = new List(); // list of talent objects (talents) - - public List Zauber { get; set; } = new List(); // list of spell objects - - public List Kampftalente { get; set; } = new List(); // list of combat objects - - public List Vorteile { get; set; } = new List(); - - public Dictionary PropTable { get; set; } = new Dictionary(); // -> Körperkraft - - public string TestTalent(string talent, int erschwernis = 0) // Talentprobe - { - return Talente.ProbenTest(this, talent, erschwernis); - } - - public string TestZauber(string zauber, int erschwernis = 0) // Talentprobe - { - return Zauber.ProbenTest(this, zauber, erschwernis); - } - - public string TestEigenschaft(string eigenschaft, int erschwernis = 0) - { - var output = new StringBuilder(); - 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); - 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 - { - var output = new StringBuilder(); - var sc = new SpellCorrect(); - var attack = Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First(); - if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) - return $"{Name} kann nicht mit der Waffenart {talent} umgehen..."; - - var tap = attack.At; - output.AppendFormat( - "{0}-Angriff taw:{1} {2} \n", - attack.Name, - tap, - erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); - - var temp = Dice.Roll(); - output.Append(temp - erschwernis); - return output.ToString(); - } - - public string Parade(string talent, int erschwernis = 0) - { - var output = new StringBuilder(); - var sc = new SpellCorrect(); - var attack = Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First(); - - if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) - return $"{Name} kann nicht mit der Waffenart {talent} umgehen..."; - - var tap = attack.Pa; - output.AppendFormat( - "{0}-Parade taw:{1} {2}\n", - attack.Name, - tap, - erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); - - var temp = Dice.Roll(); - output.Append(temp - erschwernis); - return output.ToString(); - } - - public string Fernkampf(string talent, int erschwernis = 0) - { - var output = new StringBuilder(); - var sc = new SpellCorrect(); - var fk = Eigenschaften["fk"]; - var attack = Talente.OrderBy(x => sc.Compare(talent, x.Name)).First(); - if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) - return $"{Name} kann nicht mit der Waffenart {talent} umgehen..."; - - var tap = attack.Value; - output.AppendFormat( - "{0} taw:{1} {2} \n", - attack.Name, - tap, - erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); - tap -= erschwernis; - var temp = Dice.Roll(); - tap -= temp > fk ? temp - fk : 0; - output.Append($"W20: {temp} tap: {tap}"); - return output.ToString(); - } - - private void Post_process() - { - 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 = 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"]; - - Astralpunkte_Basis = 0; - - Ausdauer_Basis = 0; - - Lebenspunkte_Basis = LE_Wert + (int) (KO__Wert + KK_Wert / 2.0 + 0.5); - - 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) - { - var reader = new XmlTextReader(stream); - while (reader.Read()) - { - // read until he hits keywords - if (reader.NodeType != XmlNodeType.Element) continue; - - switch (reader.Name) - { - case "Wesen": - reader.Skip(); - break; - case "held": - Name = reader.GetAttribute("name"); // name - break; - case "eigenschaft": - Eigenschaften.Add( - reader.GetAttribute("name") ?? throw new InvalidOperationException(), - Convert.ToInt32(reader.GetAttribute("value")) + - Convert.ToInt32(reader.GetAttribute("mod"))); - break; - case "vt": - reader.Read(); - while (reader.Name.Equals("vorteil")) - { - try - { - Vorteile.Add(new Vorteil( - reader.GetAttribute("name"), - // Convert.ToInt32(reader.GetAttribute("value")))); - reader.GetAttribute("value"))); - } - catch - { - Vorteile.Add(new Vorteil(reader.GetAttribute("name"))); - } - - reader.Read(); - } - - break; - case "talentliste": - reader.Read(); - while (reader.Name.Equals("talent")) - { - Talente.Add( - new Talent( - reader.GetAttribute("name"), - reader.GetAttribute("probe")?.Remove(0, 2).Trim(')'), - Convert.ToInt32(reader.GetAttribute("value")))); - reader.Read(); - } - - break; - case "zauberliste": - reader.Read(); - while (reader.Name.Equals("zauber")) - { - Zauber.Add( - new Zauber( - reader.GetAttribute("name"), - reader.GetAttribute("probe")?.Remove(0, 2).Trim(')'), - Convert.ToInt32(reader.GetAttribute("value")), - reader.GetAttribute("k").ToCharArray()[0], - reader.GetAttribute("repraesentation"))); - reader.Read(); - } - - break; - case "kampfwerte": - var atName = reader.GetAttribute("name"); - reader.Read(); - var at = Convert.ToInt32(reader.GetAttribute("value")); - reader.Read(); - var pa = Convert.ToInt32(reader.GetAttribute("value")); - Kampftalente.Add(new KampfTalent(atName, at, pa)); - break; - } - } - } - } -} \ No newline at end of file diff --git a/DSACore/DSA_Game/Characters/NPC.cs b/DSACore/DSA_Game/Characters/NPC.cs deleted file mode 100644 index 75c3fe9..0000000 --- a/DSACore/DSA_Game/Characters/NPC.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using DSACore.Auxiliary; -using DSALib.Characters; - -namespace DSACore.Characters -{ - public class Npc : Being, ICharacter - { - private readonly int mean, stDv; - - public Npc(string name, int mean, int stDv) - { - this.mean = mean; - this.stDv = stDv; - Name = name; - } - - public string TestTalent(string talent, int tap = 3) - { - for (var i = 0; i <= 2; i++) - { - // foreach property, dice and tap - var temp = Dice.Roll(); - var eigenschaft = (int) Math.Round(RandomMisc.Random(stDv, mean)); - - if (eigenschaft < temp) tap -= temp - eigenschaft; - } - - if (tap >= 0) return $"{Name} vollführt {talent} erfolgreich"; - - - return $"{Name} scheitert an {talent}"; - } - - public string TestEigenschaft(string eigenschaft, int erschwernis = 0) - { - var temp = Dice.Roll(); - var prop = (int) Math.Round(RandomMisc.Random(stDv, stDv)); - - if (temp + erschwernis < prop) return $"{Name} vollführt {eigenschaft} erfolgreich"; - - return $"{Name} scheitert an {eigenschaft}"; - } - - public string Angriff(string waffe, int erschwernis = 0) - { - var temp = Dice.Roll(); - - if (temp == 1) return $"{Name} greift kritisch mit {waffe} an"; - - if (temp < erschwernis) return $"{Name} greift mit {waffe} an"; - - return $"{Name} haut mit {waffe} daneben"; - } - - public string Parade(string waffe, int erschwernis = 0) - { - var temp = Dice.Roll(); - - if (temp == 1) return $"{Name} pariert mit {waffe} meisterlich"; - - if (temp < erschwernis) return $"{Name} pariert mit {waffe} an"; - - return $"{Name} schafft es nicht mit {waffe} zu parieren"; - } - - public string Fernkampf(string waffe, int erschwernis = 0) - { - var temp = Dice.Roll(); - - if (temp == 1) return $"{Name} trifft kritisch mit {waffe}"; - - if (temp < erschwernis) return $"{Name} greift mit {waffe} an"; - - return $"{Name} schießt mit {waffe} daneben"; - } - - public string TestZauber(string zauber, int erschwernis) - { - 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 deleted file mode 100644 index 7b29b4e..0000000 --- a/DSACore/DSA_Game/Characters/SaveChar.cs +++ /dev/null @@ -1,38 +0,0 @@ -using DSALib.Characters; - -namespace DSACore.DSA_Game.Characters -{ - public class SaveChar - { - public string Name { get; set; } - - public int Lebenspunkte_Aktuell { get; set; } - - public int Ausdauer_Aktuell { get; set; } - - public int Astralpunkte_Aktuell { get; set; } - - public static SaveChar FromICharacter(ICharacter c) - { - return new SaveChar - { - Astralpunkte_Aktuell = c.Astralpunkte_Aktuell, - Ausdauer_Aktuell = c.Ausdauer_Aktuell, - Lebenspunkte_Aktuell = c.Lebenspunkte_Aktuell, - Name = c.Name - }; - } - } - - - public static class ICharExtension - { - public static void Update(this ICharacter c, SaveChar s) - { - c.Astralpunkte_Aktuell = s.Astralpunkte_Aktuell; - c.Ausdauer_Aktuell = s.Ausdauer_Aktuell; - c.Lebenspunkte_Aktuell = s.Lebenspunkte_Aktuell; - c.Name = s.Name; - } - } -} \ No newline at end of file diff --git a/DSACore/DSA_Game/Dsa.cs b/DSACore/DSA_Game/Dsa.cs deleted file mode 100644 index 18d0b81..0000000 --- a/DSACore/DSA_Game/Dsa.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using DSACore.DSA_Game.Characters; -using DSACore.DSA_Game.Save; -using DSALib; -using DSALib.Characters; - -namespace DSACore.DSA_Game -{ - public static class Dsa - { -#if DEBUG - 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 Chars { get; set; } = new List(); // list of all characters - - public static List Talente { get; set; } = new List(); - - public static List Zauber { get; set; } = new List(); - - public static Session Session - { - get - { - s_session.Chars = Chars.Select(x => SaveChar.FromICharacter(x)).ToList(); - return s_session; - } - - set - { - s_session = value; - foreach (var x in value.Chars) Chars.Find(c => c.Name.Equals(x.Name)).Update(x); - } - } - - public static void Startup() - { - //new .Auxiliary.Calculator.StringSolver("1d100 - (1d200 + 1) * -50000").Solve(); - /*Session = new Session();*/ - // relation.Add("Papo", "Pump aus der Gosse"); - /*foreach (var filename in Directory.GetFiles(rootPath + "helden", "*.xml")) - { - Chars.Add(new Character(filename)); - (Chars.Last() as Character)?.Talente.Select(x => new Talent(x.Name, x.Probe, 0)) - .Where(c => !Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Talente.Add(v)); - (Chars.Last() as Character)?.Zauber.Select(x => new Zauber(x.Name, x.Probe, 0, x.Complexity)) - .Where(c => !Zauber.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Zauber.Add(v)); - } -*/ - - Properties.Deserialize(); - Properties.Serialize(rootPath + "Properties"); - - - Talente = Talente.OrderBy(x => x.Name).ToList(); - Zauber = Zauber.OrderBy(x => x.Name).ToList(); - - /*foreach (var talent in Talente) - { - Database.AddTalent(new Models.Database.Talent(talent.Name, talent.Probe)); - } - - foreach (var talent in Zauber) - { - Database.AddSpell(new Models.Database.GeneralSpell(talent.Name, talent.Probe, talent.Complexity)); - }*/ - - //new WeaponImporter().DownloadWeapons().Wait(); - - - Session = new Session - { - Chars = Chars.Select(SaveChar.FromICharacter).ToList() - }; - //Session.Save(); - } - - public static ICharacter GetCharacter(ulong id) - { - throw new NotImplementedException(); - } - - public static ICharacter GetCharacter(string name, ulong groupId) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/DSACore/DSA_Game/Save/Properties.cs b/DSACore/DSA_Game/Save/Properties.cs deleted file mode 100644 index 7eba911..0000000 --- a/DSACore/DSA_Game/Save/Properties.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using DSACore.Audio; -using DSACore.Auxiliary; -using Newtonsoft.Json; - -namespace DSACore.DSA_Game.Save -{ - public static class Properties - { - public static Dictionary objects; - - static Properties() - { - objects = new Dictionary(); - /*this.objects.Add("Sounds", new List()); - this.objects.Add("CommandInfos", new List());*/ - } - - public static List CommandInfos - { - get => objects["CommandInfo"] as List; - set => objects["CommandInfo"] = value; - } // use Properties.Commandinfos to access the abstract Object array - - public static List Sounds - { - get => objects["Sound"] as List; - set => objects["Sound"] = value; - } - - public static void Deserialize(string path = @"Properties") - { - var files = Directory.GetFiles(path, "*.json"); - - foreach (var file in files) - try - { - 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); - } - catch (Exception e) - { - // ignored - Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen." + e); - } - } - - public static void Serialize(string path = @"..\..\Properties\") - { - try - { - foreach (var o in objects) - { - var assembly = o.Value is IList list - ? list[0]?.GetType().FullName - : o.Value.GetType().FullName; - - var name = path + assembly.Replace('.', '-') + ".json"; - File.WriteAllText(name, - JsonConvert.SerializeObject(o.Value, - Formatting.Indented)); // Deserialize Data and create CommandInfo Struct - } - } - catch (Exception e) - { - // ignored - Console.WriteLine("Speichern von Save-File fehlgeschlagen." + e); - } - } - } -} \ No newline at end of file diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs deleted file mode 100644 index f358047..0000000 --- a/DSACore/DSA_Game/Save/SaveCommand.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.IO; -using System.Linq; - -namespace DSACore.DSA_Game.Save -{ - public class SaveCommand - { - public void LoadSession(string name = "") - { - if (name.Equals("?") || name.Equals(string.Empty)) - { - Console.WriteLine("Gespeicherte Sessions:"); - Console.WriteLine(ListSessions()); - return; - } - - var path = Session.DirectoryPath + @"\" + name; - - var files = Directory.GetFiles(path); - var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First(); - Dsa.Session = Session.Load(session); - - Console.WriteLine($"{name} wurde geladen"); - } - - public void SessionSave(string name = "") - { - //var sendFile = this.Context.Channel.SendWebFile("https://cdn.discordapp.com/attachments/377123019673567232/465615882048110603/giphy.gif"); - - if (name.Equals("?") || name.Equals(string.Empty)) - { - Console.WriteLine("Gespeicherte Sessions:"); - Console.WriteLine(ListSessions()); - return; - } - - var path = Session.DirectoryPath + @"\" + name; - if (Directory.Exists(path)) - { - var files = Directory.GetFiles(path); - var current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())); - Dsa.Session.SessionName = name; - Dsa.Session.Save(path + "\\" + name + $"-{++current}.json"); - } - else - { - Directory.CreateDirectory(path); - Dsa.Session.SessionName = name; - Dsa.Session.Save(path + "\\" + name + "-0.json"); - } - - Console.WriteLine($"{name} wurde gespeichert"); - //await sendFile; - } - - private string[] ListSessions() - { - 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 deleted file mode 100644 index 6944fb1..0000000 --- a/DSACore/DSA_Game/Save/Session.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using DSACore.DSA_Game.Characters; -using Newtonsoft.Json; - -namespace DSACore.DSA_Game.Save -{ - public class Session - { - public static string DirectoryPath { get; set; } = Dsa.rootPath + @"sessions"; - - public Dictionary Relation { get; set; } = - new Dictionary(); // dictionary to match the char - - public List Chars { get; set; } = new List(); // list of all characters - - public string SessionName { get; set; } - - public static Session Load(string path) - { - try - { - return - JsonConvert.DeserializeObject( - File.ReadAllText(path)); // Deserialize Data and create Session Object - } - catch (Exception e) - { - // ignored - Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen." + e); - return null; - } - } - - public void Save(string path) - { - try - { - 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); - // ignored - } - } - } -} \ No newline at end of file -- cgit v1.2.3-70-g09d2