From f89f308c525e9deebc6d2cf6416e27dfe1a299dc Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 19 May 2019 16:03:38 +0200 Subject: Cleanup DiscoBot Project --- DSACore/DSA_Game/Characters/Character.cs | 176 ++++++++++++++----------------- DSACore/DSA_Game/Characters/NPC.cs | 80 +++++--------- DSACore/DSA_Game/Characters/SaveChar.cs | 3 +- DSACore/DSA_Game/Dsa.cs | 18 ++-- DSACore/DSA_Game/Save/Properties.cs | 17 ++- DSACore/DSA_Game/Save/SaveCommand.cs | 22 ++-- DSACore/DSA_Game/Save/Session.cs | 21 ++-- 7 files changed, 142 insertions(+), 195 deletions(-) (limited to 'DSACore/DSA_Game') diff --git a/DSACore/DSA_Game/Characters/Character.cs b/DSACore/DSA_Game/Characters/Character.cs index 247fc58..62d2e11 100644 --- a/DSACore/DSA_Game/Characters/Character.cs +++ b/DSACore/DSA_Game/Characters/Character.cs @@ -10,120 +10,110 @@ namespace DSACore.DSA_Game.Characters 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 Eigenschaften { get; set; } = new Dictionary(); // char properties + public Dictionary Eigenschaften { get; set; } = new Dictionary(); // char properties - public List Talente { get; set; } = new List(); // list of talent objects (talents) + 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 Zauber { get; set; } = new List(); // list of spell objects - public List Kampftalente { get; set; } = new List(); // list of combat 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 + 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 +122,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 +143,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 +163,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 +194,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 +202,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 +216,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 +234,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 +247,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 +259,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..e6b7bed 100644 --- a/DSACore/DSA_Game/Characters/NPC.cs +++ b/DSACore/DSA_Game/Characters/NPC.cs @@ -5,8 +5,7 @@ using DSALib.Characters; namespace DSACore.Characters { using System; - - using DSACore.Auxiliary; + using Auxiliary; using DSACore.DSA_Game.Characters; public class Npc : Being, ICharacter @@ -17,94 +16,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)); - return $"{this.Name} scheitert an {eigenschaft}"; + if (temp + erschwernis < prop) return $"{Name} vollführt {eigenschaft} erfolgreich"; + + 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 +84,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..f2ffe48 100644 --- a/DSACore/DSA_Game/Dsa.cs +++ b/DSACore/DSA_Game/Dsa.cs @@ -10,19 +10,20 @@ namespace DSACore.DSA_Game using System.Collections.Generic; using System.IO; using System.Linq; - using DSACore.DSA_Game.Characters; - using DSACore.DSA_Game.Save; + using Characters; + using 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 Chars { get; set; } = new List(); // list of all characters + public static List Chars { get; set; } = new List(); // list of all characters public static List Talente { get; set; } = new List(); @@ -39,10 +40,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 +59,9 @@ namespace DSACore.DSA_Game } */ - Properties.Deserialize(rootPath+"Properties"); + Properties.Deserialize(rootPath + "Properties"); 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..50bd8fa 100644 --- a/DSACore/DSA_Game/Save/Properties.cs +++ b/DSACore/DSA_Game/Save/Properties.cs @@ -39,17 +39,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 +55,6 @@ namespace DSACore.DSA_Game.Save // ignored Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen." + e); } - } } public static void Serialize(string path = @"..\..\Properties\") @@ -68,7 +63,7 @@ namespace DSACore.DSA_Game.Save { foreach (var o in objects) { - string assembly = o.Value is IList list + var assembly = o.Value is IList list ? ((IList) list)[0]?.GetType().FullName : o.Value.GetType().FullName; diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs index 198d707..80d4426 100644 --- a/DSACore/DSA_Game/Save/SaveCommand.cs +++ b/DSACore/DSA_Game/Save/SaveCommand.cs @@ -6,18 +6,18 @@ 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(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(); @@ -33,15 +33,15 @@ namespace DSACore.DSA_Game.Save if (name.Equals("?") || name.Equals(string.Empty)) { Console.WriteLine($"Gespeicherte Sessions:"); - Console.WriteLine(this.ListSessions()); + 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"); } @@ -58,13 +58,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..595f0e8 100644 --- a/DSACore/DSA_Game/Save/Session.cs +++ b/DSACore/DSA_Game/Save/Session.cs @@ -11,22 +11,25 @@ namespace DSACore.DSA_Game.Save { public static string DirectoryPath { get; set; } = Dsa.rootPath + @"sessions"; - public Dictionary Relation { get; set; } = new Dictionary(); // dictionary to match the char + public Dictionary Relation { get; set; } = + new Dictionary(); // dictionary to match the char - public List Chars { get; set; } = new List(); // list of all characters + 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 + 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); + Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen." + e); return null; } } @@ -35,13 +38,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 -- cgit v1.2.3-70-g09d2